Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PPP-libmodule-Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
PPP-libmodule-Python
Commits
74cac7a5
Commit
74cac7a5
authored
10 years ago
by
Valentin Lorentz
Browse files
Options
Downloads
Patches
Plain Diff
Make PPPTestCase methods more usable.
parent
7413dc75
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ppp_libmodule/tests.py
+26
-6
26 additions, 6 deletions
ppp_libmodule/tests.py
with
26 additions
and
6 deletions
ppp_libmodule/tests.py
+
26
−
6
View file @
74cac7a5
...
...
@@ -9,6 +9,17 @@ from webtest import TestApp
from
unittest
import
TestCase
from
ppp_datamodel.communication
import
Request
,
Response
def
arg_to_dict
(
f
):
"""
Converts the first argument to the function to a dict
(assuming it
'
s either a json-encoding string or a Request object).
"""
def
newf
(
self
,
obj
,
*
args
,
**
kwargs
):
if
isinstance
(
obj
,
Request
):
obj
=
obj
.
as_dict
()
elif
isinstance
(
obj
,
str
):
obj
=
json
.
loads
(
obj
)
return
f
(
self
,
obj
,
*
args
,
**
kwargs
)
return
newf
def
PPPTestCase
(
app
):
class
_PPPTestCase
(
TestCase
):
config_var
=
None
...
...
@@ -30,23 +41,32 @@ def PPPTestCase(app):
del
self
.
config_file
super
(
_PPPTestCase
,
self
).
tearDown
()
@arg_to_dict
def
request
(
self
,
obj
):
if
isinstance
(
obj
,
Request
):
obj
=
obj
.
as_dict
()
elif
isinstance
(
obj
,
str
):
obj
=
json
.
loads
(
obj
)
j
=
self
.
app
.
post_json
(
'
/
'
,
obj
).
json
"""
Make a request and return the answers.
"""
return
list
(
map
(
Response
.
from_dict
,
j
))
@arg_to_dict
def
assertResponse
(
self
,
request
,
response
):
"""
Makes a request and asserts the response is the expected one.
"""
self
.
assertEqual
(
self
.
request
(
request
),
response
)
@arg_to_dict
def
assertResponsesIn
(
self
,
request
,
expected
):
"""
Makes a request and asserts the response is among a set
of expected ones.
"""
responses
=
self
.
request
(
request
)
self
.
assertTrue
(
all
(
x
in
expected
for
x
in
responses
),
'
Not all of:
\n
%r
\n
are in:
\n
%r
'
%
(
responses
,
expected
))
@arg_to_dict
def
assertResponsesCount
(
self
,
request
,
count
):
"""
Makes a request and asserts the number of responses is
a given number.
"""
self
.
assertEqual
(
len
(
self
.
request
(
request
)),
count
)
def
assertStatusInt
(
self
,
request
,
status
):
res
=
self
.
app
.
post_json
(
'
/
'
,
request
,
status
=
'
*
'
)
@arg_to_dict
def
assertStatusInt
(
self
,
obj
,
status
):
"""
Makes a request and asserts the HTTP status code is
the one that is expected.
"""
res
=
self
.
app
.
post_json
(
'
/
'
,
obj
,
status
=
'
*
'
)
self
.
assertEqual
(
res
.
status_int
,
status
)
return
_PPPTestCase
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