Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tests_api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
hive
tests_api
Commits
952b0b37
Commit
952b0b37
authored
4 years ago
by
Dariusz Kędzierski
Browse files
Options
Downloads
Patches
Plain Diff
Validator will now save also response if differences are detected
parent
1bdee7b8
No related branches found
No related tags found
1 merge request
!15
Set of tests for hivemind using tavern library
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hivemind/tavern/validate_response.py
+9
-1
9 additions, 1 deletion
hivemind/tavern/validate_response.py
with
9 additions
and
1 deletion
hivemind/tavern/validate_response.py
+
9
−
1
View file @
952b0b37
...
...
@@ -3,7 +3,7 @@ class PatternDiffException(Exception):
def
json_pretty_string
(
json_obj
):
from
json
import
dumps
return
dumps
(
json_obj
,
sort_keys
=
True
,
indent
=
4
)
return
dumps
(
json_obj
,
sort_keys
=
True
,
indent
=
2
)
def
save_diff
(
name
,
diff
):
"""
Save diff to a file
"""
...
...
@@ -11,6 +11,11 @@ def save_diff(name, diff):
f
.
write
(
str
(
diff
))
f
.
write
(
"
\n
"
)
def
save_response
(
file_name
,
response_json
):
"""
Save response to file
"""
with
open
(
file_name
,
'
w
'
)
as
f
:
f
.
writelines
(
json_pretty_string
(
response_json
))
def
validate_response
(
response
):
"""
Make sure that there is no error field in response json and there is a result field in response
"""
...
...
@@ -19,6 +24,7 @@ def validate_response(response):
assert
error
is
None
,
"
Error detected in response: {}
"
.
format
(
error
[
"
message
"
])
assert
result
is
not
None
,
"
Error detected in response: result is null, json object was expected
"
RESPONSE_FILE_EXT
=
"
.out.json
"
PATTERN_FILE_EXT
=
"
.pat.json
"
DIFF_FILE_EXT
=
"
.diff.json
"
def
load_pattern
(
name
):
...
...
@@ -42,6 +48,8 @@ def compare_response_with_pattern(response, method=None, directory=None):
pattern_resp_diff
=
jsondiff
.
diff
(
pattern
,
result
)
if
pattern_resp_diff
:
fname
=
directory
+
"
/
"
+
method
+
DIFF_FILE_EXT
response_fname
=
directory
+
"
/
"
+
method
+
RESPONSE_FILE_EXT
save_diff
(
fname
,
pattern_resp_diff
)
save_response
(
response_fname
,
result
)
msg
=
"
Differences detected between response and pattern. Diff saved to {}
\n\n
Diff:
\n
{}
"
.
format
(
fname
,
pattern_resp_diff
)
raise
PatternDiffException
(
msg
)
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