Skip to content

Commit

Permalink
mgr/dashboard: home controller unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Dias <[email protected]>
  • Loading branch information
rjfd committed Oct 15, 2019
1 parent 4675116 commit 87a0395
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/pybind/mgr/dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ def __getattr__(self, item):
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")
8 changes: 5 additions & 3 deletions src/pybind/mgr/dashboard/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,20 @@ def __init__(self, *args, **kwargs):
})
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
else:
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)
Expand Down
33 changes: 33 additions & 0 deletions src/pybind/mgr/dashboard/tests/test_home.py
Original file line number Diff line number Diff line change
@@ -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('<html lang="en">', 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('<html lang="en">', 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('<html lang="en">', self.body.decode('utf-8'))

0 comments on commit 87a0395

Please sign in to comment.