Skip to content
Snippets Groups Projects
Commit f900771b authored by Sebastian Lobinger's avatar Sebastian Lobinger
Browse files

Merge branch 'master' into 11-write-example-app

parents 9dd923a2 a518e7b3
No related branches found
No related tags found
1 merge request!10Resolve "Example App schreiben"
...@@ -3,7 +3,7 @@ from sams_classes import SAMSHub, SAMSApp ...@@ -3,7 +3,7 @@ from sams_classes import SAMSHub, SAMSApp
from sams_classes.exceptions import AppNotExist from sams_classes.exceptions import AppNotExist
from flask import Flask, Blueprint from flask import Flask, Blueprint
import sys, time import sys, time
from .helper_classes import FlaskInThread from helper_classes import FlaskInThread
def eprint(*args, **kwargs): def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs) print(*args, file=sys.stderr, **kwargs)
...@@ -13,7 +13,7 @@ class CaseSAMSHubWithThreadedAPI(unittest.TestCase): ...@@ -13,7 +13,7 @@ class CaseSAMSHubWithThreadedAPI(unittest.TestCase):
def setUp(self): def setUp(self):
self.hub = SAMSHub( self.hub = SAMSHub(
name = 'test', config = {'default_language': 'de', 'main_app' : 'test'}) 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 apiApp.config['TESTING'] = True
thApi = FlaskInThread(apiApp, host="localhost", port=4711) thApi = FlaskInThread(apiApp, host="localhost", port=4711)
thApi.start() thApi.start()
...@@ -41,27 +41,36 @@ class CaseSAMSHubWithThreadedAPI(unittest.TestCase): ...@@ -41,27 +41,36 @@ class CaseSAMSHubWithThreadedAPI(unittest.TestCase):
class CaseSAMSHubWithMainApp(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): def test_main_app(self):
"""It is possible to declare a main app where the urls have no prefix""" """It is possible to declare a main app where the urls have no prefix"""
appname = 'test.app' szenarios = [
{'main_app': 'test', 'extra_app': 'test.app'},
{'main_app': 'test.app', 'extra_app': 'test'}
]
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 = [ expected_names = [
'Hauptanwendung Punkt 1', 'Hauptanwendung Punkt 2', 'Zusatzanwendung 1' 'Hauptanwendung Punkt 1', 'Hauptanwendung Punkt 2',
'Zusatzanwendung 1'
] ]
urls = ['', '2', 'app/1'] urls = ['', '2', 'app/1']
name_vars = ['main_1', 'main_2', 'app_1'] name_vars = ['main_1', 'main_2', 'app_1']
expected = ''.join(( expected = ''.join((
"<ul>\n\n<li><a href='/", urls[0], "'>", expected_names[0], "<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<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], "'>", "</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>' expected_names[2], '</a>\n\n</li>\n\n</ul>'
)) ))
self.hub.addApp( hub.addApp(
SAMSApp( SAMSApp(
name = 'test', name = main_app,
manifest = { manifest = {
'default_language': 'de', 'default_language': 'de',
'views':[ 'views':[
...@@ -78,9 +87,9 @@ class CaseSAMSHubWithMainApp(unittest.TestCase): ...@@ -78,9 +87,9 @@ class CaseSAMSHubWithMainApp(unittest.TestCase):
, langDict = {'de': dict(zip(name_vars, expected_names))} , langDict = {'de': dict(zip(name_vars, expected_names))}
) )
) )
self.hub.addApp( hub.addApp(
SAMSApp( SAMSApp(
name = appname, name = extra_app,
manifest = { manifest = {
'default_language': 'de', 'default_language': 'de',
'views': [{'url': urls[2], 'function': 'views.do_nothing'}], 'views': [{'url': urls[2], 'function': 'views.do_nothing'}],
...@@ -88,14 +97,14 @@ class CaseSAMSHubWithMainApp(unittest.TestCase): ...@@ -88,14 +97,14 @@ class CaseSAMSHubWithMainApp(unittest.TestCase):
}, langDict = {'de': dict(zip(name_vars, expected_names))} }, langDict = {'de': dict(zip(name_vars, expected_names))}
) )
) )
self.hub.flaskApp.config['DEBUG'] = True hub.flaskApp.config['DEBUG'] = True
with self.hub.flaskApp.test_client(self) as client: with hub.flaskApp.test_client(self) as client:
response = client.get('/') response = client.get('/')
self.assertIs(response.status_code, 200) self.assertIs(response.status_code, 200)
self.assertEquals(response.data.decode('utf-8'), expected) self.assertEquals(response.data.decode('utf-8'), expected)
response = client.get('/' + urls[1]) response = client.get('/' + urls[1])
self.assertIs(response.status_code, 200) self.assertIs(response.status_code, 200)
response = client.get('/' + appname + '/' + urls[2]) response = client.get('/' + extra_app + '/' + urls[2])
self.assertIs(response.status_code, 200) self.assertIs(response.status_code, 200)
class CaseSAMSHubInitExceptions(unittest.TestCase): class CaseSAMSHubInitExceptions(unittest.TestCase):
...@@ -261,3 +270,5 @@ class CaseMinimalSAMSHub(unittest.TestCase): ...@@ -261,3 +270,5 @@ class CaseMinimalSAMSHub(unittest.TestCase):
response = client.get('/test/hello') response = client.get('/test/hello')
self.assertIs(response.status_code, 200) self.assertIs(response.status_code, 200)
self.assertEquals(response.data.decode('utf-8'), expected) 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