diff --git a/test/test_sams_hub.py b/test/test_sams_hub.py index 4911dc1108a5611dd0751b15bb5cfbe112f20257..6e2e94a759f41befe69c331ad806c75b1eece448 100644 --- a/test/test_sams_hub.py +++ b/test/test_sams_hub.py @@ -3,7 +3,7 @@ from sams_classes import SAMSHub, SAMSApp from sams_classes.exceptions import AppNotExist from flask import Flask, Blueprint import sys, time -from .helper_classes import FlaskInThread +from helper_classes import FlaskInThread def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) @@ -13,7 +13,7 @@ class CaseSAMSHubWithThreadedAPI(unittest.TestCase): def setUp(self): self.hub = SAMSHub( name = 'test', config = {'default_language': 'de', 'main_app' : 'test'}) - from .api_test_server import app as apiApp + from api_test_server import app as apiApp apiApp.config['TESTING'] = True thApi = FlaskInThread(apiApp, host="localhost", port=4711) thApi.start() @@ -41,62 +41,71 @@ class CaseSAMSHubWithThreadedAPI(unittest.TestCase): class CaseSAMSHubWithMainApp(unittest.TestCase): - def setUp(self): - self.hub = SAMSHub( - name = 'test', config = {'default_language': 'de', 'main_app' : 'test'}) - def test_main_app(self): """It is possible to declare a main app where the urls have no prefix""" - appname = 'test.app' - expected_names = [ - 'Hauptanwendung Punkt 1', 'Hauptanwendung Punkt 2', 'Zusatzanwendung 1' + szenarios = [ + {'main_app': 'test', 'extra_app': 'test.app'}, + {'main_app': 'test.app', 'extra_app': 'test'} ] - urls = ['', '2', 'app/1'] - name_vars = ['main_1', 'main_2', 'app_1'] - expected = ''.join(( - "<ul>\n\n<li><a href='/", urls[0], "'>", expected_names[0], - "</a>\n\n<ul>\n\n<li><a href='/", urls[1], "'>", expected_names[1], - "</a>\n\n</li>\n\n</ul>\n\n</li>\n\n<li><a href='/", appname, '/', urls[2], "'>", - expected_names[2], '</a>\n\n</li>\n\n</ul>' - )) - self.hub.addApp( - SAMSApp( - name = 'test', - manifest = { - 'default_language': 'de', - 'views':[ - {'url': urls[0], 'function': 'views.menu_test'}, - {'url': urls[1], 'function': 'views.do_nothing'} - ], - 'menu':[ - { - 'url': urls[0], 'name_string': name_vars[0], - 'menu': [{'url': urls[1], 'name_string': name_vars[1]}] + for szenario in szenarios: + main_app = szenario['main_app'] + extra_app = szenario['extra_app'] + with self.subTest(main_app = main_app, extra_app = extra_app): + hub = SAMSHub( + name = 'test', + config = {'default_language': 'de', 'main_app' : main_app} + ) + expected_names = [ + 'Hauptanwendung Punkt 1', 'Hauptanwendung Punkt 2', + 'Zusatzanwendung 1' + ] + urls = ['', '2', 'app/1'] + name_vars = ['main_1', 'main_2', 'app_1'] + expected = ''.join(( + "<ul>\n\n<li><a href='/", urls[0], "'>", expected_names[0], + "</a>\n\n<ul>\n\n<li><a href='/", urls[1], "'>", expected_names[1], + "</a>\n\n</li>\n\n</ul>\n\n</li>\n\n<li><a href='/", extra_app, '/', + urls[2], "'>", + expected_names[2], '</a>\n\n</li>\n\n</ul>' + )) + hub.addApp( + SAMSApp( + name = main_app, + manifest = { + 'default_language': 'de', + 'views':[ + {'url': urls[0], 'function': 'views.menu_test'}, + {'url': urls[1], 'function': 'views.do_nothing'} + ], + 'menu':[ + { + 'url': urls[0], 'name_string': name_vars[0], + 'menu': [{'url': urls[1], 'name_string': name_vars[1]}] + } + ] } - ] - } - , langDict = {'de': dict(zip(name_vars, expected_names))} - ) - ) - self.hub.addApp( - SAMSApp( - name = appname, - manifest = { - 'default_language': 'de', - 'views': [{'url': urls[2], 'function': 'views.do_nothing'}], - 'menu': [{'url': urls[2], 'name_string': name_vars[2]}] - }, langDict = {'de': dict(zip(name_vars, expected_names))} - ) - ) - self.hub.flaskApp.config['DEBUG'] = True - with self.hub.flaskApp.test_client(self) as client: - response = client.get('/') - self.assertIs(response.status_code, 200) - self.assertEquals(response.data.decode('utf-8'), expected) - response = client.get('/' + urls[1]) - self.assertIs(response.status_code, 200) - response = client.get('/' + appname + '/' + urls[2]) - self.assertIs(response.status_code, 200) + , langDict = {'de': dict(zip(name_vars, expected_names))} + ) + ) + hub.addApp( + SAMSApp( + name = extra_app, + manifest = { + 'default_language': 'de', + 'views': [{'url': urls[2], 'function': 'views.do_nothing'}], + 'menu': [{'url': urls[2], 'name_string': name_vars[2]}] + }, langDict = {'de': dict(zip(name_vars, expected_names))} + ) + ) + hub.flaskApp.config['DEBUG'] = True + with hub.flaskApp.test_client(self) as client: + response = client.get('/') + self.assertIs(response.status_code, 200) + self.assertEquals(response.data.decode('utf-8'), expected) + response = client.get('/' + urls[1]) + self.assertIs(response.status_code, 200) + response = client.get('/' + extra_app + '/' + urls[2]) + self.assertIs(response.status_code, 200) class CaseSAMSHubInitExceptions(unittest.TestCase): @@ -264,4 +273,6 @@ class CaseMinimalSAMSHub(unittest.TestCase): session_simulation['language'] = 'fr' response = client.get('/test/hello') self.assertIs(response.status_code, 200) - self.assertEquals(response.data.decode('utf-8'), expected) \ No newline at end of file + self.assertEquals(response.data.decode('utf-8'), expected) + +if __name__ == '__main__': unittest.main() \ No newline at end of file