From 6b007f39604d3d01e39957b88de095ddd8755ddc Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Wed, 24 Aug 2016 18:20:12 +0200 Subject: [PATCH] Add CAS_INFO_MESSAGES tests --- cas_server/tests/test_view.py | 39 +++++++++++++++++++++++++++++++++++ cas_server/utils.py | 5 ++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/cas_server/tests/test_view.py b/cas_server/tests/test_view.py index 6cf0b14..c623a27 100644 --- a/cas_server/tests/test_view.py +++ b/cas_server/tests/test_view.py @@ -75,6 +75,45 @@ class LoginTestCase(TestCase, BaseServicePattern, CanLogin): response = client.get("/login") self.assertNotIn(b"A new version of the application is available", response.content) + @override_settings(CAS_INFO_MESSAGES_ORDER=["cas_explained"]) + def test_messages_info_box_enabled(self): + """test that the message info-box is displayed then enabled""" + client = Client() + response = client.get("/login") + self.assertIn( + b"The Central Authentication Service grants you access to most of our websites by ", + response.content + ) + + @override_settings(CAS_INFO_MESSAGES_ORDER=[]) + def test_messages_info_box_disabled(self): + """test that the message info-box is not displayed then disabled""" + client = Client() + response = client.get("/login") + self.assertNotIn( + b"The Central Authentication Service grants you access to most of our websites by ", + response.content + ) + + # test1 and test2 are malformed and should be ignored, test3 is ok, test5 do not + # exists and should be ignored + @override_settings(CAS_INFO_MESSAGES_ORDER=["test1", "test2", "test3", "test5"]) + @override_settings(CAS_INFO_MESSAGES={ + "test1": "test", # not a dict, should be ignored + "test2": {"type": "success"}, # not "message" key, should be ignored + "test3": {"message": "test3"}, + "test4": {"message": "test4"}, + }) + def test_messages_info_box_bad_messages(self): + """test that mal formated messages dict are ignored""" + client = Client() + # not errors should be raises + response = client.get("/login") + # test3 is ok est should be there + self.assertIn(b"test3", response.content) + # test4 is not in CAS_INFO_MESSAGES_ORDER and should not be there + self.assertNotIn(b"test4", response.content) + def test_login_view_post_goodpass_goodlt(self): """Test a successul login""" # we get a client who fetch a frist time the login page and the login form default diff --git a/cas_server/utils.py b/cas_server/utils.py index 17ec5f9..8817b22 100644 --- a/cas_server/utils.py +++ b/cas_server/utils.py @@ -78,10 +78,9 @@ def context(params): params["CAS_INFO_RENDER"] = [] for msg_name in settings.CAS_INFO_MESSAGES_ORDER: if msg_name in settings.CAS_INFO_MESSAGES: - try: - msg = settings.CAS_INFO_MESSAGES[msg_name].copy() - except AttributeError: + if not isinstance(settings.CAS_INFO_MESSAGES[msg_name], dict): continue + msg = settings.CAS_INFO_MESSAGES[msg_name].copy() if "message" in msg: msg["name"] = msg_name # use info as default infox type