From 6296b97414c2802944306121c1628ce6d0c7053b Mon Sep 17 00:00:00 2001 From: Sebastian Lobinger <sebastian.lobinger@fu-berlin.de> Date: Fri, 2 Jun 2017 08:33:47 +0200 Subject: [PATCH] update test_sams_Hub.py to make a reflect the exampleApp szenario #14 --- test/test_sams_hub.py | 86 ++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/test/test_sams_hub.py b/test/test_sams_hub.py index 08ef387..7750e46 100644 --- a/test/test_sams_hub.py +++ b/test/test_sams_hub.py @@ -4,6 +4,7 @@ from sams_classes.exceptions import AppNotExist from flask import Flask, Blueprint import sys, time from helper_classes import FlaskInThread +import copy def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) @@ -223,34 +224,45 @@ class CaseMinimalSAMSHub(unittest.TestCase): def test_hub_default_language_used(self): """The hub default_language is prefered instead of app default_language""" - wrong = 'Hello world!' - expected = 'Hallo Welt!' - self.hub.addApp( - SAMSApp( - name = 'test' - , manifest = { - 'default_language': 'en' - , 'views':[ - {'url': 'hello' - , 'function': 'views.hello'} - ] - } - , langDict = { - 'de': {'hello': expected} - , 'en': {'hello': wrong} - } - ) - ) - self.hub.flaskApp.config['DEBUG'] = True - client = self.hub.flaskApp.test_client(self) - response = client.get('/test/hello') - self.assertIs(response.status_code, 200) - self.assertEquals(response.data.decode('utf-8'), expected) + langDicts = { + 'de': {'hello': 'Hallo Welt!'}, + 'en': {'hello': 'Hello world!'} + } + for langCode, langDict in langDicts.items(): + with self.subTest(langCode): + hub = SAMSHub(name = 'test', config = {'default_language': 'de'}) + hub.addApp( + SAMSApp( + name = 'test' + , manifest = { + 'default_language': langCode + , 'views':[ + {'url': 'hello' + , 'function': 'views.hello'} + ] + } + , langDict = copy.deepcopy(langDicts) + ) + ) + hub.flaskApp.config['DEBUG'] = True + with hub.flaskApp.test_client(self) as client: + response = client.get('/test/hello') + self.assertIs(response.status_code, 200) + self.assertEquals(response.data.decode('utf-8'), langDict['hello']) def test_session_language_used(self): """use Session['language'] if possible""" - expected = 'Bonjour!' - self.hub.addApp( + langDict = { + 'de': {'hello': 'Hallo Welt!'}, + 'en': {'hello': 'Hello world!'}, + 'fr': {'hello': 'Bonjour tout le monde!'} + } + sessionLangs = ['de', 'en', 'fr'] + hub = SAMSHub( + name = 'test', + config = {'default_language': 'de'} + ) + hub.addApp( SAMSApp( name = 'test' , manifest = { @@ -260,19 +272,19 @@ class CaseMinimalSAMSHub(unittest.TestCase): , 'function': 'views.hello'} ] } - , langDict = { - 'de': {'hello': 'falsch'} - , 'en': {'hello': 'wrong'} - , 'fr': {'hello': expected} - } + , langDict = copy.deepcopy(langDict) ) ) - self.hub.flaskApp.config['DEBUG'] = True - with self.hub.flaskApp.test_client(self) as client: - with client.session_transaction() as session_simulation: - session_simulation['language'] = 'fr' - response = client.get('/test/hello') - self.assertIs(response.status_code, 200) - self.assertEquals(response.data.decode('utf-8'), expected) + for sessionLang in sessionLangs: + eprint(langDict) + with self.subTest(sessionLang): + hub.flaskApp.config['DEBUG'] = True + with hub.flaskApp.test_client(self) as client: + with client.session_transaction() as session_simulation: + session_simulation['language'] = sessionLang + response = client.get('/test/hello') + self.assertIs(response.status_code, 200) + self.assertEquals( + response.data.decode('utf-8'),langDict[sessionLang]['hello']) if __name__ == '__main__': unittest.main() \ No newline at end of file -- GitLab