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
aab76a26
Commit
aab76a26
authored
8 years ago
by
Sebastian Lobinger
Browse files
Options
Downloads
Patches
Plain Diff
add new root url rule to tests in test_sams_proxy.py to fit needs
#20
parent
8f30db18
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!15
Resolve "Basis-Pfad (/) bei API über Proxy nicht aufrufbar"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_sams_proxy.py
+29
-21
29 additions, 21 deletions
test/test_sams_proxy.py
with
29 additions
and
21 deletions
test/test_sams_proxy.py
+
29
−
21
View file @
aab76a26
...
...
@@ -68,6 +68,9 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
time
.
sleep
(
0.01
)
self
.
proxyApp
=
Flask
(
'
test
'
)
self
.
proxyApp
.
config
[
'
TESTING
'
]
=
True
self
.
basic_url_rule_params
=
{
'
endpoint
'
:
'
proxy
'
,
'
methods
'
:
[
'
GET
'
,
'
POST
'
,
'
PUT
'
,
'
UPDATE
'
,
'
PATCH
'
,
'
DELETE
'
,
'
OPTIONS
'
]}
self
.
url_rule_properties
=
[
'
rootUrlRule
'
,
'
urlRule
'
]
def
tearDown
(
self
):
response
=
requests
.
get
(
'
http://localhost:4711/shutdown
'
)
...
...
@@ -78,9 +81,9 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
"""
The proxy passes json data
"""
proxy
=
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/proxy
'
,
'
out
'
:
'
http://localhost:4711
'
})
self
.
proxyApp
.
add_
url
_r
ule
(
rule
=
proxy
.
url
R
ule
,
endpoint
=
'
proxy
'
,
view_func
=
proxy
.
proxy
,
methods
=
[
'
GET
'
,
'
POST
'
,
'
PUT
'
,
'
UPDATE
'
,
'
PATCH
'
,
'
DELETE
'
,
'
OPTIONS
'
]
)
for
url
R
ule
Prop
in
self
.
url
_r
ule
_properties
:
self
.
proxyApp
.
add_url_rule
(
rule
=
getattr
(
proxy
,
urlRuleProp
)
,
view_func
=
proxy
.
proxy
,
**
self
.
basic_url_rule_params
)
thProxyApp
=
FlaskInThread
(
self
.
proxyApp
,
host
=
"
localhost
"
,
port
=
5000
)
thProxyApp
.
start
()
time
.
sleep
(
0.01
)
...
...
@@ -99,9 +102,9 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
'
user
'
:
{
'
name
'
:
'
u
'
,
'
param-type
'
:
'
url
'
},
'
group
'
:
{
'
name
'
:
'
g
'
,
'
param-type
'
:
'
body
'
},
'
language
'
:
{
'
name
'
:
'
Lang
'
,
'
param-type
'
:
'
header
'
}}}})
self
.
proxyApp
.
add_
url
_r
ule
(
rule
=
proxy
.
url
R
ule
,
endpoint
=
'
proxy
'
,
view_func
=
proxy
.
proxy
,
methods
=
[
'
GET
'
,
'
POST
'
,
'
PUT
'
,
'
UPDATE
'
,
'
PATCH
'
,
'
DELETE
'
,
'
OPTIONS
'
]
)
for
url
R
ule
Prop
in
self
.
url
_r
ule
_properties
:
self
.
proxyApp
.
add_url_rule
(
rule
=
getattr
(
proxy
,
urlRuleProp
)
,
view_func
=
proxy
.
proxy
,
**
self
.
basic_url_rule_params
)
self
.
proxyApp
.
secret_key
=
'
A0Zr98j/3yX R~XHH!jmN]LWX/,?RT
'
with
self
.
proxyApp
.
test_client
(
self
)
as
client
:
with
client
.
session_transaction
()
as
sess
:
...
...
@@ -125,9 +128,9 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
'
user
'
:
{
'
name
'
:
'
u
'
,
'
param-type
'
:
'
url
'
},
'
group
'
:
{
'
name
'
:
'
g
'
,
'
param-type
'
:
'
body
'
},
'
language
'
:
{
'
name
'
:
'
lang
'
,
'
param-type
'
:
'
header
'
}}}})
self
.
proxyApp
.
add_
url
_r
ule
(
rule
=
proxy
.
url
R
ule
,
endpoint
=
'
proxy
'
,
view_func
=
proxy
.
proxy
,
methods
=
[
'
GET
'
,
'
POST
'
,
'
PUT
'
,
'
UPDATE
'
,
'
PATCH
'
,
'
DELETE
'
,
'
OPTIONS
'
]
)
for
url
R
ule
Prop
in
self
.
url
_r
ule
_properties
:
self
.
proxyApp
.
add_url_rule
(
rule
=
getattr
(
proxy
,
urlRuleProp
)
,
view_func
=
proxy
.
proxy
,
**
self
.
basic_url_rule_params
)
self
.
proxyApp
.
secret_key
=
'
A0Zr98j/3yX R~XHH!jmN]LWX/,?RT
'
with
self
.
proxyApp
.
test_client
(
self
)
as
client
:
with
client
.
session_transaction
()
as
sess
:
...
...
@@ -152,9 +155,9 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
'
user
'
:
{
'
name
'
:
'
u
'
,
'
param-type
'
:
'
url
'
},
'
group
'
:
{
'
name
'
:
'
g
'
,
'
param-type
'
:
'
body
'
},
'
language
'
:
{
'
name
'
:
'
lang
'
,
'
param-type
'
:
'
header
'
}}}})
self
.
proxyApp
.
add_
url
_r
ule
(
rule
=
proxy
.
url
R
ule
,
endpoint
=
'
proxy
'
,
view_func
=
proxy
.
proxy
,
methods
=
[
'
GET
'
,
'
POST
'
,
'
PUT
'
,
'
UPDATE
'
,
'
PATCH
'
,
'
DELETE
'
,
'
OPTIONS
'
]
)
for
url
R
ule
Prop
in
self
.
url
_r
ule
_properties
:
self
.
proxyApp
.
add_url_rule
(
rule
=
getattr
(
proxy
,
urlRuleProp
)
,
view_func
=
proxy
.
proxy
,
**
self
.
basic_url_rule_params
)
self
.
proxyApp
.
secret_key
=
'
A0Zr98j/3yX R~XHH!jmN]LWX/,?RT
'
with
self
.
proxyApp
.
test_client
(
self
)
as
client
:
with
client
.
session_transaction
()
as
sess
:
...
...
@@ -171,23 +174,25 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
"""
The proxy forwards a request to test flaskapp and returns
'
hello
'
"""
proxy
=
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/proxy
'
,
'
out
'
:
'
http://localhost:4711
'
})
self
.
proxyApp
.
add_
url
_r
ule
(
rule
=
proxy
.
url
R
ule
,
endpoint
=
'
proxy
'
,
view_func
=
proxy
.
proxy
,
methods
=
[
'
GET
'
,
'
POST
'
,
'
PUT
'
,
'
UPDATE
'
,
'
PATCH
'
,
'
DELETE
'
,
'
OPTIONS
'
]
)
for
url
R
ule
Prop
in
self
.
url
_r
ule
_properties
:
self
.
proxyApp
.
add_url_rule
(
rule
=
getattr
(
proxy
,
urlRuleProp
)
,
view_func
=
proxy
.
proxy
,
**
self
.
basic_url_rule_params
)
with
self
.
proxyApp
.
test_client
(
self
)
as
client
:
eprint
(
self
.
proxyApp
.
url_map
)
for
method
in
[
'
get
'
,
'
post
'
,
'
put
'
,
'
update
'
,
'
patch
'
,
'
delete
'
,
'
options
'
]:
response
=
client
.
open
(
path
=
'
/proxy/hello
'
,
method
=
method
.
upper
())
self
.
assertIs
(
response
.
status_code
,
200
,
method
)
self
.
assertEqual
(
response
.
data
.
decode
(
'
utf-8
'
),
method
+
'
hello
'
)
for
path
in
(
'
/proxy/hello
'
,
'
/proxy/
'
):
response
=
client
.
open
(
path
=
path
,
method
=
method
.
upper
())
with
self
.
subTest
(
'
method
'
+
method
+
'
path
'
+
path
):
self
.
assertIs
(
response
.
status_code
,
200
,
method
)
def
test_param_passthrough
(
self
):
"""
The proxy passes headers, form / data and url params
"""
proxy
=
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/proxy
'
,
'
out
'
:
'
http://localhost:4711
'
})
self
.
proxyApp
.
add_
url
_r
ule
(
rule
=
proxy
.
url
R
ule
,
endpoint
=
'
proxy
'
,
view_func
=
proxy
.
proxy
,
methods
=
[
'
GET
'
,
'
POST
'
,
'
PUT
'
,
'
UPDATE
'
,
'
PATCH
'
,
'
DELETE
'
,
'
OPTIONS
'
]
)
for
url
R
ule
Prop
in
self
.
url
_r
ule
_properties
:
self
.
proxyApp
.
add_url_rule
(
rule
=
getattr
(
proxy
,
urlRuleProp
)
,
view_func
=
proxy
.
proxy
,
**
self
.
basic_url_rule_params
)
with
self
.
proxyApp
.
test_client
(
self
)
as
client
:
res
=
client
.
get
(
path
=
'
/proxy/passthrough
'
,
query_string
=
{
'
u
'
:
'
foo
'
},
data
=
{
'
g
'
:
'
bar
'
},
headers
=
{
'
lang
'
:
'
klingon
'
})
...
...
@@ -214,6 +219,9 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
proxyApp
.
add_url_rule
(
rule
=
proxy
.
urlRule
,
endpoint
=
'
proxy
'
,
view_func
=
proxy
.
proxy
,
methods
=
[
'
GET
'
,
'
POST
'
,
'
PUT
'
,
'
UPDATE
'
,
'
PATCH
'
,
'
DELETE
'
,
'
OPTIONS
'
])
proxyApp
.
add_url_rule
(
rule
=
proxy
.
rootUrlRule
,
endpoint
=
'
proxy
'
,
view_func
=
proxy
.
proxy
,
methods
=
[
'
GET
'
,
'
POST
'
,
'
PUT
'
,
'
UPDATE
'
,
'
PATCH
'
,
'
DELETE
'
,
'
OPTIONS
'
])
with
proxyApp
.
test_client
(
self
)
as
client
:
res
=
client
.
get
(
path
=
'
/proxy/passthrough
'
,
query_string
=
{
'
u
'
:
'
foo
'
},
data
=
{
'
g
'
:
'
bar
'
},
...
...
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