From 340aa9246bd7179deb46c6ab1e583c3f2da06f0b Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Tue, 15 Oct 2019 13:12:34 +0100 Subject: [PATCH] mgr/dashboard: home controller unit test Signed-off-by: Ricardo Dias (cherry picked from commit 87a0395c717b5bf232b2c669fd7d1d7377710281) --- src/pybind/mgr/dashboard/__init__.py | 2 +- src/pybind/mgr/dashboard/tests/__init__.py | 8 +++-- src/pybind/mgr/dashboard/tests/test_home.py | 33 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/pybind/mgr/dashboard/tests/test_home.py diff --git a/src/pybind/mgr/dashboard/__init__.py b/src/pybind/mgr/dashboard/__init__.py index 4322245b861d8..798ed37e3ab6c 100644 --- a/src/pybind/mgr/dashboard/__init__.py +++ b/src/pybind/mgr/dashboard/__init__.py @@ -51,4 +51,4 @@ else: sys.modules['ceph_module'] = mock.Mock() mgr = mock.Mock() - mgr.get_frontend_path.side_effect = lambda: "./frontend/dist" + mgr.get_frontend_path.side_effect = lambda: os.path.abspath("./frontend/dist") diff --git a/src/pybind/mgr/dashboard/tests/__init__.py b/src/pybind/mgr/dashboard/tests/__init__.py index ee2c4912d38a9..913d5bb5b79c3 100644 --- a/src/pybind/mgr/dashboard/tests/__init__.py +++ b/src/pybind/mgr/dashboard/tests/__init__.py @@ -108,7 +108,7 @@ class ControllerTestCase(helper.CPWebCase): }) super(ControllerTestCase, self).__init__(*args, **kwargs) - def _request(self, url, method, data=None): + def _request(self, url, method, data=None, headers=None): if not data: b = None h = None @@ -116,10 +116,12 @@ class ControllerTestCase(helper.CPWebCase): b = json.dumps(data) h = [('Content-Type', 'application/json'), ('Content-Length', str(len(b)))] + if headers: + h = headers self.getPage(url, method=method, body=b, headers=h) - def _get(self, url): - self._request(url, 'GET') + def _get(self, url, headers=None): + self._request(url, 'GET', headers=headers) def _post(self, url, data=None): self._request(url, 'POST', data) diff --git a/src/pybind/mgr/dashboard/tests/test_home.py b/src/pybind/mgr/dashboard/tests/test_home.py new file mode 100644 index 0000000000000..341762572aaa0 --- /dev/null +++ b/src/pybind/mgr/dashboard/tests/test_home.py @@ -0,0 +1,33 @@ +from __future__ import absolute_import + +import logging + +from . import ControllerTestCase +from ..controllers.home import HomeController + + +logger = logging.getLogger() + + +class HomeTest(ControllerTestCase): + @classmethod + def setup_server(cls): + cls.setup_controllers([HomeController]) + + def test_home_default_lang(self): + self._get('/') + self.assertStatus(200) + logger.info(self.body) + self.assertIn('', self.body.decode('utf-8')) + + def test_home_en_us(self): + self._get('/', headers=[('Accept-Language', 'en-US')]) + self.assertStatus(200) + logger.info(self.body) + self.assertIn('', self.body.decode('utf-8')) + + def test_home_non_supported_lang(self): + self._get('/', headers=[('Accept-Language', 'NO-NO')]) + self.assertStatus(200) + logger.info(self.body) + self.assertIn('', self.body.decode('utf-8')) -- 2.39.5