From afe8058b6cd583a9f5bc619d9e6462df0137215d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 22 Aug 2022 07:57:47 +0800 Subject: [PATCH] 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 --- qa/tasks/mgr/dashboard/helper.py | 10 ++++++---- qa/tasks/mgr/dashboard/test_requests.py | 6 ++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/qa/tasks/mgr/dashboard/helper.py b/qa/tasks/mgr/dashboard/helper.py index f64ad825e8e..d80e238a2a8 100644 --- a/qa/tasks/mgr/dashboard/helper.py +++ b/qa/tasks/mgr/dashboard/helper.py @@ -277,10 +277,11 @@ class DashboardTestCase(MgrTestCase): # pylint: disable=inconsistent-return-statements, too-many-arguments, too-many-branches @classmethod def _request(cls, url, method, data=None, params=None, version=DEFAULT_API_VERSION, - set_cookies=False): + set_cookies=False, headers=None): url = "{}{}".format(cls._base_uri, url) log.debug("Request %s to %s", method, url) - headers = {} + if headers is None: + headers = {} cookies = {} if cls._token: if set_cookies: @@ -336,8 +337,9 @@ class DashboardTestCase(MgrTestCase): raise ex @classmethod - def _get(cls, url, params=None, version=DEFAULT_API_VERSION, set_cookies=False): - return cls._request(url, 'GET', params=params, version=version, set_cookies=set_cookies) + def _get(cls, url, params=None, version=DEFAULT_API_VERSION, set_cookies=False, headers=None): + return cls._request(url, 'GET', params=params, version=version, + set_cookies=set_cookies, headers=headers) @classmethod def _view_cache_get(cls, url, retries=5): diff --git a/qa/tasks/mgr/dashboard/test_requests.py b/qa/tasks/mgr/dashboard/test_requests.py index 0d7fb75adc8..834ba174ad3 100644 --- a/qa/tasks/mgr/dashboard/test_requests.py +++ b/qa/tasks/mgr/dashboard/test_requests.py @@ -15,12 +15,10 @@ class RequestsTest(DashboardTestCase): }) def test_force_no_gzip(self): - self._get('/api/summary', params=dict( - headers={'Accept-Encoding': 'identity'} - )) + self._get('/api/summary', headers={'Accept-Encoding': 'identity'}) self.assertNotIn('Content-Encoding', self._resp.headers) self.assertHeaders({ - 'Content-Type': 'application/json' + 'Content-Type': 'application/vnd.ceph.api.v{}+json'.format(DEFAULT_API_VERSION) }) def test_server(self): -- 2.39.5