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
Branches
Tags
1 merge request!8Resolve "Ändern der Sprache in ExampleApp muss in beiden Sprachen funtkionieren"
This commit is part of merge request !8. Comments created here will be created in the context of that merge request.
...@@ -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!'}
SAMSApp( }
name = 'test' for langCode, langDict in langDicts.items():
, manifest = { with self.subTest(langCode):
'default_language': 'en' hub = SAMSHub(name = 'test', config = {'default_language': 'de'})
, 'views':[ hub.addApp(
{'url': 'hello' SAMSApp(
, 'function': 'views.hello'} name = 'test'
] , manifest = {
} 'default_language': langCode
, langDict = { , 'views':[
'de': {'hello': expected} {'url': 'hello'
, 'en': {'hello': wrong} , 'function': 'views.hello'}
} ]
) }
) , langDict = copy.deepcopy(langDicts)
self.hub.flaskApp.config['DEBUG'] = True )
client = self.hub.flaskApp.test_client(self) )
response = client.get('/test/hello') hub.flaskApp.config['DEBUG'] = True
self.assertIs(response.status_code, 200) with hub.flaskApp.test_client(self) as client:
self.assertEquals(response.data.decode('utf-8'), expected) 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): 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 client.session_transaction() as session_simulation: with self.subTest(sessionLang):
session_simulation['language'] = 'fr' hub.flaskApp.config['DEBUG'] = True
response = client.get('/test/hello') with hub.flaskApp.test_client(self) as client:
self.assertIs(response.status_code, 200) with client.session_transaction() as session_simulation:
self.assertEquals(response.data.decode('utf-8'), expected) 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() 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