Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sams-classes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
coding-at-fu
sams-classes
Commits
47bd8f54
Commit
47bd8f54
authored
8 years ago
by
Sebastian Lobinger
Browse files
Options
Downloads
Patches
Plain Diff
restructured TestCases in in test_sams_hub.py 30 lines saved
parent
d8c09d07
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_sams_hub.py
+138
-165
138 additions, 165 deletions
test/test_sams_hub.py
with
138 additions
and
165 deletions
test/test_sams_hub.py
+
138
−
165
View file @
47bd8f54
...
...
@@ -3,130 +3,213 @@ from sams_classes import SAMSHub, SAMSApp
from
sams_classes.exceptions
import
AppNotExist
from
flask
import
Flask
,
Blueprint
import
sys
from
pexpect.async
import
expect_async
def
eprint
(
*
args
,
**
kwargs
):
print
(
*
args
,
file
=
sys
.
stderr
,
**
kwargs
)
class
Test
SAMSHub
(
unittest
.
TestCase
):
class
Case
SAMSHub
WithMainApp
(
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
'
]
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
]}]
}
]
}
,
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
)
class
CaseSAMSHubInitExceptions
(
unittest
.
TestCase
):
def
test_missing_init_name
(
self
):
with
self
.
assertRaises
(
TypeError
):
hub
=
SAMSHub
(
config
=
{
'
default_language
'
:
'
de
'
})
SAMSHub
(
config
=
{
'
default_language
'
:
'
de
'
})
def
test_missing_init_config
(
self
):
with
self
.
assertRaises
(
TypeError
):
hub
=
SAMSHub
(
name
=
'
test
'
)
SAMSHub
(
name
=
'
test
'
)
def
test_missing_init_default_language
(
self
):
with
self
.
assertRaises
(
TypeError
):
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{})
SAMSHub
(
name
=
'
test
'
,
config
=
{})
class
CaseMinimalSAMSHub
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{
'
default_language
'
:
'
de
'
})
def
test_apps_addable
(
self
):
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{
'
default_language
'
:
'
de
'
})
self
.
assertIs
(
len
(
hub
.
appKeys
),
0
,
'
Precondition, hub has 0 appKeys
'
)
self
.
assertIs
(
len
(
self
.
hub
.
appKeys
),
0
,
'
Precondition, hub has 0 appKeys
'
)
with
self
.
assertRaises
(
AppNotExist
):
hub
.
app
(
'
test_app
'
)
hub
.
addApp
(
self
.
hub
.
app
(
'
test_app
'
)
self
.
hub
.
addApp
(
SAMSApp
(
name
=
'
test
'
,
manifest
=
{
'
default_language
'
:
'
en
'
}
,
langDict
=
{
'
en
'
:{}}
)
)
self
.
assertIs
(
len
(
hub
.
appKeys
),
1
,
'
Postcondition, hub has 1 appKey
'
)
self
.
assertIs
(
len
(
self
.
hub
.
appKeys
),
1
,
'
Postcondition, hub has 1 appKey
'
)
self
.
assertIsInstance
(
hub
.
app
(
'
test
'
)
self
.
hub
.
app
(
'
test
'
)
,
SAMSApp
,
'
Postcondition,
"
test_app
"
in hub is a SAMSApp
'
)
def
test_error_apps_add_wrong_type
(
self
):
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{
'
default_language
'
:
'
de
'
})
with
self
.
assertRaises
(
TypeError
):
hub
.
addApp
(
'
wrong
'
)
self
.
hub
.
addApp
(
'
wrong
'
)
def
test_has_flask_app
(
self
):
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{
'
default_language
'
:
'
de
'
})
self
.
assertIsInstance
(
hub
.
flaskApp
,
Flask
)
self
.
assertIsInstance
(
self
.
hub
.
flaskApp
,
Flask
)
def
test_flask_app_readonly
(
self
):
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{
'
default_language
'
:
'
de
'
})
with
self
.
assertRaises
(
AttributeError
):
hub
.
flaskApp
=
Flask
(
'
test
'
)
self
.
hub
.
flaskApp
=
Flask
(
'
test
'
)
def
test_add_app_registers_blueprint
(
self
):
"""
The blueprint of the addedApp is registered in flaskApp
"""
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{
'
default_language
'
:
'
de
'
})
self
.
assertEqual
(
hub
.
flaskApp
.
blueprints
.
get
(
'
test
'
)
self
.
hub
.
flaskApp
.
blueprints
.
get
(
'
test
'
)
,
None
,
'
Precondition, hub.flaskApp has not Blueprint
"
test
"'
)
hub
.
addApp
(
self
.
hub
.
addApp
(
SAMSApp
(
name
=
'
test
'
,
manifest
=
{
'
default_language
'
:
'
en
'
}
,
langDict
=
{
'
en
'
:{}}
)
)
self
.
assertIsInstance
(
hub
.
flaskApp
.
blueprints
.
get
(
'
test
'
)
self
.
hub
.
flaskApp
.
blueprints
.
get
(
'
test
'
)
,
Blueprint
,
'
Postcondition, hub.flaskApp has a Blueprint
"
test
"'
)
def
test_context_processor_app_lang
(
self
):
"""
The hub sets an app context processor that provides a app_lang dict
"""
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{
'
default_language
'
:
'
de
'
})
expected
=
'
Hallo Welt!
'
hub
.
addApp
(
self
.
hub
.
addApp
(
SAMSApp
(
name
=
'
test
'
,
manifest
=
{
'
default_language
'
:
'
de
'
,
'
views
'
:[
{
'
url
'
:
'
hello
'
,
'
function
'
:
'
views.hello
'
}
]
}
,
langDict
=
{
'
de
'
:
{
'
hello
'
:
expected
}
}
name
=
'
test
'
,
manifest
=
{
'
default_language
'
:
'
de
'
,
'
views
'
:[{
'
url
'
:
'
hello
'
,
'
function
'
:
'
views.hello
'
}]
},
langDict
=
{
'
de
'
:
{
'
hello
'
:
expected
}}
)
)
hub
.
flaskApp
.
config
[
'
DEBUG
'
]
=
True
client
=
hub
.
flaskApp
.
test_client
(
self
)
self
.
hub
.
flaskApp
.
config
[
'
DEBUG
'
]
=
True
client
=
self
.
hub
.
flaskApp
.
test_client
(
self
)
response
=
client
.
get
(
'
/test/hello
'
)
self
.
assertIs
(
response
.
status_code
,
200
)
self
.
assertEquals
(
response
.
data
.
decode
(
'
utf-8
'
),
expected
)
def
test_menu_list_provided
(
self
):
"""
The Hub provides a menu list via context_processor
"""
name
=
'
test
'
expected_names
=
[
'
Ebene 1: Eintrag 1
'
,
'
Eintrag 1 Ebene 2: Eintrag 1
'
,
'
Ebene 1: Eintrag 2
'
]
urls
=
[
'
1/1
'
,
'
2/1
'
,
'
1/2
'
]
name_vars
=
[
'
1_1
'
,
'
2_1
'
,
'
1_2
'
]
expected
=
''
.
join
((
"
<ul>
\n\n
<li><a href=
'
/
"
,
name
,
'
/
'
,
urls
[
0
],
"'
>
"
,
expected_names
[
0
],
"
</a>
\n\n
<ul>
\n\n
<li><a href=
'
/
"
,
name
,
'
/
'
,
urls
[
1
],
"'
>
"
,
expected_names
[
1
],
"
</a>
\n\n
</li>
\n\n
</ul>
\n\n
</li>
\n\n
<li><a href=
'
/
"
,
name
,
'
/
'
,
urls
[
2
],
"'
>
"
,
expected_names
[
2
],
'
</a>
\n\n
</li>
\n\n
</ul>
'
))
self
.
hub
.
addApp
(
SAMSApp
(
name
=
name
,
manifest
=
{
'
default_language
'
:
'
de
'
,
'
views
'
:
[{
'
url
'
:
'
test-menu
'
,
'
function
'
:
'
views.menu_test
'
}],
'
menu
'
:[
{
'
url
'
:
urls
[
0
],
'
name_string
'
:
name_vars
[
0
],
'
menu
'
:[
{
'
url
'
:
urls
[
1
],
'
name_string
'
:
name_vars
[
1
]}
]},
{
'
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
(
'
/test/test-menu
'
)
self
.
assertIs
(
response
.
status_code
,
200
)
self
.
assertEquals
(
response
.
data
.
decode
(
'
utf-8
'
),
expected
)
def
test_hub_default_language_used
(
self
):
"""
The hub default_language is prefered instead of app default_language
"""
wrong
=
'
Hallo Welt!
'
expected
=
'
Hello world!
'
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{
'
default_language
'
:
'
en
'
})
hub
.
addApp
(
wrong
=
'
Hello world!
'
expected
=
'
Hallo Welt!
'
self
.
hub
.
addApp
(
SAMSApp
(
name
=
'
test
'
,
manifest
=
{
'
default_language
'
:
'
d
e
'
'
default_language
'
:
'
e
n
'
,
'
views
'
:[
{
'
url
'
:
'
hello
'
,
'
function
'
:
'
views.hello
'
}
]
}
,
langDict
=
{
'
de
'
:
{
'
hello
'
:
wrong
}
,
'
en
'
:
{
'
hello
'
:
expected
}
'
de
'
:
{
'
hello
'
:
expected
}
,
'
en
'
:
{
'
hello
'
:
wrong
}
}
)
)
hub
.
flaskApp
.
config
[
'
DEBUG
'
]
=
True
client
=
hub
.
flaskApp
.
test_client
(
self
)
self
.
hub
.
flaskApp
.
config
[
'
DEBUG
'
]
=
True
client
=
self
.
hub
.
flaskApp
.
test_client
(
self
)
response
=
client
.
get
(
'
/test/hello
'
)
self
.
assertIs
(
response
.
status_code
,
200
)
self
.
assertEquals
(
response
.
data
.
decode
(
'
utf-8
'
),
expected
)
def
test_session_language_used
(
self
):
"""
use Session[
'
language
'
] if possible
"""
expected
=
'
Hallo Welt!
'
hub
=
SAMSHub
(
name
=
'
test
'
,
config
=
{
'
default_language
'
:
'
fr
'
})
hub
.
addApp
(
expected
=
'
Bonjour!
'
self
.
hub
.
addApp
(
SAMSApp
(
name
=
'
test
'
,
manifest
=
{
...
...
@@ -137,126 +220,16 @@ class TestSAMSHub(unittest.TestCase):
]
}
,
langDict
=
{
'
de
'
:
{
'
hello
'
:
expected
}
'
de
'
:
{
'
hello
'
:
'
falsch
'
}
,
'
en
'
:
{
'
hello
'
:
'
wrong
'
}
,
'
fr
'
:
{
'
hello
'
:
'
mal
'
}
,
'
fr
'
:
{
'
hello
'
:
expected
}
}
)
)
hub
.
flaskApp
.
config
[
'
DEBUG
'
]
=
True
with
hub
.
flaskApp
.
test_client
(
self
)
as
client
:
self
.
hub
.
flaskApp
.
config
[
'
DEBUG
'
]
=
True
with
self
.
hub
.
flaskApp
.
test_client
(
self
)
as
client
:
with
client
.
session_transaction
()
as
session_simulation
:
session_simulation
[
'
language
'
]
=
'
de
'
session_simulation
[
'
language
'
]
=
'
fr
'
response
=
client
.
get
(
'
/test/hello
'
)
self
.
assertIs
(
response
.
status_code
,
200
)
self
.
assertEquals
(
response
.
data
.
decode
(
'
utf-8
'
),
expected
)
def
test_menu_list_provided
(
self
):
"""
The Hub provides a menu list via context_processor
"""
name
=
'
test
'
hub
=
SAMSHub
(
name
=
name
,
config
=
{
'
default_language
'
:
'
de
'
})
expected_names
=
[
'
Ebene 1: Eintrag 1
'
,
'
Eintrag 1 Ebene 2: Eintrag 1
'
,
'
Ebene 1: Eintrag 2
'
]
urls
=
[
'
1/1
'
,
'
2/1
'
,
'
1/2
'
]
name_vars
=
[
'
1_1
'
,
'
2_1
'
,
'
1_2
'
]
expected
=
''
.
join
((
"
<ul>
\n\n
<li><a href=
'
/
"
,
name
,
'
/
'
,
urls
[
0
],
"'
>
"
,
expected_names
[
0
],
"
</a>
\n\n
<ul>
\n\n
<li><a href=
'
/
"
,
name
,
'
/
'
,
urls
[
1
],
"'
>
"
,
expected_names
[
1
],
"
</a>
\n\n
</li>
\n\n
</ul>
\n\n
</li>
\n\n
<li><a href=
'
/
"
,
name
,
'
/
'
,
urls
[
2
],
"'
>
"
,
expected_names
[
2
],
'
</a>
\n\n
</li>
\n\n
</ul>
'
))
hub
.
addApp
(
SAMSApp
(
name
=
name
,
manifest
=
{
'
default_language
'
:
'
de
'
,
'
views
'
:[
{
'
url
'
:
'
test-menu
'
,
'
function
'
:
'
views.menu_test
'
}
],
'
menu
'
:[
{
'
url
'
:
urls
[
0
],
'
name_string
'
:
name_vars
[
0
],
'
menu
'
:[
{
'
url
'
:
urls
[
1
],
'
name_string
'
:
name_vars
[
1
]
}
]
},
{
'
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
(
'
/test/test-menu
'
)
self
.
assertIs
(
response
.
status_code
,
200
)
self
.
assertEquals
(
response
.
data
.
decode
(
'
utf-8
'
),
expected
)
def
test_main_app
(
self
):
"""
It is possible to declare a main app where the urls have no prefix
"""
name
=
'
test
'
appname
=
'
test.app
'
hub
=
SAMSHub
(
name
=
name
,
config
=
{
'
default_language
'
:
'
de
'
,
'
main_app
'
:
'
test
'
})
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=
'
/
"
,
appname
,
'
/
'
,
urls
[
2
],
"'
>
"
,
expected_names
[
2
],
'
</a>
\n\n
</li>
\n\n
</ul>
'
))
hub
.
addApp
(
SAMSApp
(
name
=
name
,
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
))}
)
)
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
))}
)
)
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
(
'
/
'
+
appname
+
'
/
'
+
urls
[
2
])
self
.
assertIs
(
response
.
status_code
,
200
)
\ No newline at end of file
self
.
assertEquals
(
response
.
data
.
decode
(
'
utf-8
'
),
expected
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment