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

update test_sams_Hub.py to make a reflect the exampleApp szenario #14

parent a949d126
No related branches found
No related tags found
1 merge request!8Resolve "Ändern der Sprache in ExampleApp muss in beiden Sprachen funtkionieren"
...@@ -4,6 +4,7 @@ from sams_classes.exceptions import AppNotExist ...@@ -4,6 +4,7 @@ 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
import copy
def eprint(*args, **kwargs): def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs) print(*args, file=sys.stderr, **kwargs)
...@@ -223,34 +224,45 @@ class CaseMinimalSAMSHub(unittest.TestCase): ...@@ -223,34 +224,45 @@ class CaseMinimalSAMSHub(unittest.TestCase):
def test_hub_default_language_used(self): def test_hub_default_language_used(self):
"""The hub default_language is prefered instead of app default_language""" """The hub default_language is prefered instead of app default_language"""
wrong = 'Hello world!' langDicts = {
expected = 'Hallo Welt!' 'de': {'hello': 'Hallo Welt!'},
self.hub.addApp( '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( SAMSApp(
name = 'test' name = 'test'
, manifest = { , manifest = {
'default_language': 'en' 'default_language': langCode
, 'views':[ , 'views':[
{'url': 'hello' {'url': 'hello'
, 'function': 'views.hello'} , 'function': 'views.hello'}
] ]
} }
, langDict = { , langDict = copy.deepcopy(langDicts)
'de': {'hello': expected}
, 'en': {'hello': wrong}
}
) )
) )
self.hub.flaskApp.config['DEBUG'] = True hub.flaskApp.config['DEBUG'] = True
client = self.hub.flaskApp.test_client(self) with hub.flaskApp.test_client(self) as client:
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'), langDict['hello'])
def test_session_language_used(self): def test_session_language_used(self):
"""use Session['language'] if possible""" """use Session['language'] if possible"""
expected = 'Bonjour!' langDict = {
self.hub.addApp( '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( SAMSApp(
name = 'test' name = 'test'
, manifest = { , manifest = {
...@@ -260,19 +272,19 @@ class CaseMinimalSAMSHub(unittest.TestCase): ...@@ -260,19 +272,19 @@ class CaseMinimalSAMSHub(unittest.TestCase):
, 'function': 'views.hello'} , 'function': 'views.hello'}
] ]
} }
, langDict = { , langDict = copy.deepcopy(langDict)
'de': {'hello': 'falsch'}
, 'en': {'hello': 'wrong'}
, 'fr': {'hello': expected}
}
) )
) )
self.hub.flaskApp.config['DEBUG'] = True for sessionLang in sessionLangs:
with self.hub.flaskApp.test_client(self) as client: 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: with client.session_transaction() as session_simulation:
session_simulation['language'] = 'fr' session_simulation['language'] = sessionLang
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'),langDict[sessionLang]['hello'])
if __name__ == '__main__': unittest.main() 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