Skip to content
Snippets Groups Projects
Commit a518e7b3 authored by slobinger's avatar slobinger
Browse files

Merge branch '12-sams_hub_main_app_bugfix' into 'master'

update tes_main_app to test main apps with dots in its name #12

Closes #12

See merge request !6
parents 97502a95 93b0e0b1
No related branches found
No related tags found
1 merge request!6update tes_main_app to test main apps with dots in its name #12
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment