1
0
mirror of https://github.com/ceph/ceph synced 2024-12-12 14:39:05 +00:00
ceph/qa/tasks/mgr/dashboard/test_requests.py
Kefu Chai afe8058b6c qa/tasks/mgr/dashboard: accept headers as an option param
* add optional "headers" parameter to _request() and _get()
* correct the test of test_force_no_gzip, as the header in response
  should be "application/vnd.ceph.api.v1.0+json", not "application/json"

with this change, we are able to pass headers to _get() in dashboard api
tests.

without this change, we'd have following error when testing
`test_force_no_gzip` defined by `tasks.mgr.dashboard.test_requests.RequestsTest`:

raceback (most recent call last):
  File "/home/jenkins-build/build/workspace/ceph-api/src/pybind/mgr/dashboard/services/exception.py", line 47, in dashboard_exception_handler
    return handler(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/cherrypy/_cpdispatch.py", line 54, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/home/jenkins-build/build/workspace/ceph-api/src/pybind/mgr/dashboard/controllers/_base_controller.py", line 263, in inner
    ret = func(*args, **kwargs)
TypeError: Summary.__call__() got an unexpected keyword argument 'headers'

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
2022-08-22 14:01:16 +08:00

33 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import absolute_import
from . import DEFAULT_API_VERSION
from .helper import DashboardTestCase
class RequestsTest(DashboardTestCase):
def test_gzip(self):
self._get('/api/summary')
self.assertHeaders({
'Content-Encoding': 'gzip',
'Content-Type': 'application/vnd.ceph.api.v{}+json'.format(DEFAULT_API_VERSION)
})
def test_force_no_gzip(self):
self._get('/api/summary', headers={'Accept-Encoding': 'identity'})
self.assertNotIn('Content-Encoding', self._resp.headers)
self.assertHeaders({
'Content-Type': 'application/vnd.ceph.api.v{}+json'.format(DEFAULT_API_VERSION)
})
def test_server(self):
self._get('/api/summary')
self.assertHeaders({
'server': 'Ceph-Dashboard',
'Content-Type': 'application/vnd.ceph.api.v{}+json'.format(DEFAULT_API_VERSION),
'Content-Security-Policy': "frame-ancestors 'self';",
'X-Content-Type-Options': 'nosniff',
'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload'
})