Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
api-tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
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
Miguel Angel Reina Ortega
api-tests
Commits
1c61c526
Commit
1c61c526
authored
6 years ago
by
Giacomo Bernini
Browse files
Options
Downloads
Patches
Plain Diff
added mock server library patch
parent
01626a42
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
extensions/mockserverlibrary.patch
+75
-0
75 additions, 0 deletions
extensions/mockserverlibrary.patch
with
75 additions
and
0 deletions
extensions/mockserverlibrary.patch
0 → 100644
+
75
−
0
View file @
1c61c526
diff --git a/src/MockServerLibrary/library.py b/src/MockServerLibrary/library.py
index a9e6227..7208e61 100644
--- a/src/MockServerLibrary/library.py
+++ b/src/MockServerLibrary/library.py
@@ -68,6 +68,31 @@
class MockServerLibrary(object):
return req
+ def create_mock_request_matcher_schema(self, method, path, body_type='JSON_SCHEMA', body=None):
+ """Creates a mock request matcher to be used by mockserver.
+
+ Returns the request matcher in a dictionary format.
+
+ `method` is the HTTP method of the mocked endpoint
+
+ `path` is the url of the mocked endpoint, e.g. /api
+
+ `body_type` is the type of the request body, e.g. JSON
+
+ `body` is a dictionary of the json attribute(s) to match
+
+ `exact` is a boolean value which specifies whether the body should match fully (=true),
+ or if only specified fields should match (=false)
+ """
+ req = {}
+ req['method'] = method
+ req['path'] = path
+
+ req['body'] = {'type': body_type, 'jsonSchema': json.dumps(body)}
+
+ return req
+
+
def create_mock_response(self, status_code, headers=None, body_type='JSON', body=None):
"""Creates a mock response to be used by mockserver.
@@ -97,6 +122,37 @@
class MockServerLibrary(object):
return rsp
+
+ def create_mock_response_schema(self, status_code, headers=None, body_type='JSON_SCHEMA', body=None):
+ """Creates a mock response to be used by mockserver.
+
+ Returns the response in a dictionary format.
+
+ `status_code` is the HTTP status code of the response
+
+ `headers` is a dictionary of headers to be added to the response
+
+ `body_type` is the type of the response body, e.g. JSON
+
+ `body` is a dictonary of JSON attribute(s) to be added to the response body
+ """
+ rsp = {}
+ rsp['statusCode'] = int(status_code)
+
+ if headers:
+ rsp['headers'] = []
+
+ for key, value in headers.items():
+ header = {'name': key, 'values': value.split(",")}
+ rsp['headers'].append(header)
+ logger.debug("Add header - header: {}".format(header))
+
+ if body_type is 'JSON_SCHEMA' and body:
+ rsp['body'] = json.dumps(body)
+
+ return rsp
+
+
def create_mock_expectation(self, request, response, count=1, unlimited=True):
"""Creates a mock expectation to be used by mockserver.
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