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
84e849ed
Commit
84e849ed
authored
8 years ago
by
slobinger
Browse files
Options
Downloads
Plain Diff
Merge branch '7-SAMSApp-urlrules-for-proxies' into 'master'
Resolve "SAMSApp fügt urlRules für SAMSProxies hinzu" Closes
#7
See merge request
!3
parents
5113e889
8fe48f64
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!3
Resolve "SAMSApp fügt urlRules für SAMSProxies hinzu"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sams_classes/sams_app.py
+10
-0
10 additions, 0 deletions
sams_classes/sams_app.py
test/test_sams_app.py
+38
-2
38 additions, 2 deletions
test/test_sams_app.py
test/test_sams_proxy.py
+7
-8
7 additions, 8 deletions
test/test_sams_proxy.py
with
55 additions
and
10 deletions
sams_classes/sams_app.py
+
10
−
0
View file @
84e849ed
...
...
@@ -25,6 +25,7 @@ class SAMSApp:
,
dict
):
raise
DefaultLanguageDictMissing
()
self
.
__add_urls
()
self
.
__add_proxy_urls
()
@property
def
module
(
self
):
...
...
@@ -48,6 +49,15 @@ class SAMSApp:
rule
=
self
.
_generate_url
(
view
.
get
(
'
url
'
)),
endpoint
=
endpoint
,
view_func
=
view_func
)
def
__add_proxy_urls
(
self
):
i
=
0
for
proxy
in
self
.
proxies
:
self
.
__blueprint
.
add_url_rule
(
rule
=
self
.
_generate_url
(
proxy
.
urlRule
),
endpoint
=
self
.
__blueprint
.
name
+
'
_proxy_
'
+
str
(
i
),
view_func
=
proxy
.
proxy
)
i
+=
1
@staticmethod
def
_get_attr
(
thing
,
attrString
):
try
:
...
...
This diff is collapsed.
Click to expand it.
test/test_sams_app.py
+
38
−
2
View file @
84e849ed
import
unittest
import
unittest
,
time
from
sams_classes
import
SAMSApp
,
SAMSProxy
import
sys
from
types
import
ModuleType
...
...
@@ -7,6 +7,8 @@ from sams_classes.exceptions import (
,
DefaultLanguageDictMissing
)
from
flask
import
Blueprint
,
Flask
from
.helper_classes
import
FlaskInThread
import
requests
def
eprint
(
*
args
,
**
kwargs
):
print
(
*
args
,
file
=
sys
.
stderr
,
**
kwargs
)
...
...
@@ -65,7 +67,7 @@ class TestSAMSApp(unittest.TestCase):
,
langDict
=
{
'
en
'
:{}})
flaskApp
=
Flask
(
__name__
)
flaskApp
.
register_blueprint
(
app
.
blueprint
)
self
.
assertGreater
(
len
(
list
(
flaskApp
.
url_map
.
iter_rules
())),
0
)
self
.
assertGreater
(
len
(
list
(
flaskApp
.
url_map
.
iter_rules
())),
1
)
client
=
flaskApp
.
test_client
(
self
)
response
=
client
.
get
(
'
/test/do_nothing
'
)
self
.
assertIs
(
response
.
status_code
,
200
)
...
...
@@ -161,6 +163,40 @@ class TestSAMSApp(unittest.TestCase):
self
.
assertIs
(
len
(
app
.
proxies
),
len
(
app
.
manifest
.
get
(
'
proxies
'
)))
for
element
in
app
.
proxies
:
self
.
assertIsInstance
(
element
,
SAMSProxy
)
class
TestSAMSAppWithThreadedApi
(
unittest
.
TestCase
):
"""
Class to test SAMSApp with a threaded API App as backend
This TestCase provides a setup and tearDown for a API App in a separate
thread which is reachable at http://localhost:4711.
"""
def
setUp
(
self
):
from
.api_test_server
import
app
as
apiApp
thApi
=
FlaskInThread
(
apiApp
,
host
=
"
localhost
"
,
port
=
4711
)
thApi
.
start
()
time
.
sleep
(
0.01
)
self
.
flaskApp
=
Flask
(
'
test
'
)
self
.
flaskApp
.
config
[
'
TESTING
'
]
=
True
def
tearDown
(
self
):
response
=
requests
.
get
(
'
http://localhost:4711/shutdown
'
)
print
(
response
.
content
.
decode
(
'
utf-8
'
))
time
.
sleep
(
0.01
)
def
test_app_proxy_registered
(
self
):
"""
SAMSApp registers the needed url rue for proxy in its bluebprint
"""
testApp
=
SAMSApp
(
name
=
'
test
'
,
langDict
=
{
'
de
'
:
{}},
manifest
=
{
'
default_language
'
:
'
de
'
,
'
proxies
'
:
[
{
'
in
'
:
'
api
'
,
'
out
'
:
'
http://localhost:4711
'
}]
}
)
self
.
flaskApp
.
register_blueprint
(
testApp
.
blueprint
)
self
.
assertGreater
(
len
(
list
(
self
.
flaskApp
.
url_map
.
iter_rules
())),
1
)
eprint
(
self
.
flaskApp
.
url_map
)
with
self
.
flaskApp
.
test_client
(
self
)
as
client
:
response
=
client
.
get
(
'
/api/hello
'
)
self
.
assertIs
(
response
.
status_code
,
200
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/test_sams_proxy.py
+
7
−
8
View file @
84e849ed
...
...
@@ -17,12 +17,12 @@ class TestSAMSHub(unittest.TestCase):
#apiApp.config['TESTING'] = True
thApi
=
FlaskInThread
(
apiApp
,
host
=
"
localhost
"
,
port
=
4711
)
thApi
.
start
()
time
.
sleep
(
1
)
time
.
sleep
(
0.0
1
)
def
tearDown
(
self
):
response
=
requests
.
get
(
'
http://localhost:4711/shutdown
'
)
print
(
response
.
content
.
decode
(
'
utf-8
'
))
time
.
sleep
(
1
)
time
.
sleep
(
0.0
1
)
def
test_proxy_spec_mandatory
(
self
):
"""
SAMSProxy needs a proxy_spec dict, raies error if not supplied
"""
...
...
@@ -187,11 +187,10 @@ class TestSAMSHub(unittest.TestCase):
thProxyApp
=
FlaskInThread
(
proxyApp
,
host
=
"
localhost
"
,
port
=
5000
)
thProxyApp
.
start
()
time
.
sleep
(
1
)
with
proxyApp
.
test_client
(
self
)
as
client
:
res
=
requests
.
post
(
url
=
'
http://localhost:5000/proxy/passthrough
'
,
json
=
{
'
g
'
:
'
bar
'
})
resDict
=
json
.
loads
(
res
.
content
.
decode
(
'
utf-8
'
))
eprint
(
'
resDict:
'
+
str
(
resDict
)
+
'
\n
'
)
self
.
assertEqual
(
resDict
[
'
body
'
][
'
g
'
],
'
bar
'
)
res
=
requests
.
post
(
url
=
'
http://localhost:5000/proxy/passthrough
'
,
json
=
{
'
g
'
:
'
bar
'
})
resDict
=
json
.
loads
(
res
.
content
.
decode
(
'
utf-8
'
))
eprint
(
'
resDict:
'
+
str
(
resDict
)
+
'
\n
'
)
self
.
assertEqual
(
resDict
[
'
body
'
][
'
g
'
],
'
bar
'
)
requests
.
get
(
'
http://localhost:5000/shutdown
'
)
time
.
sleep
(
1
)
\ 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