]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa/tasks/mgr/dashboard: accept headers as an option param
authorKefu Chai <tchaikov@gmail.com>
Sun, 21 Aug 2022 23:57:47 +0000 (07:57 +0800)
committerKefu Chai <tchaikov@gmail.com>
Mon, 22 Aug 2022 06:01:16 +0000 (14:01 +0800)
* 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>
qa/tasks/mgr/dashboard/helper.py
qa/tasks/mgr/dashboard/test_requests.py

index f64ad825e8e81deb02b9ee6471e09f3e50bb0056..d80e238a2a8788e0f2cdce54f442653ee220fb4b 100644 (file)
@@ -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):
index 0d7fb75adc8edfbcc34ec3029b93e26614d8c27a..834ba174ad30f816810b2887399158ff0c66152e 100644 (file)
@@ -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):