Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def headers(self, headers=None, **kw):
"""
Defines a dictionary of arguments.
Header keys are case insensitive.
Arguments:
headers (dict): headers to match.
**headers (dict): headers to match as variadic keyword arguments.
Returns:
self: current Mock instance.
"""
headers = kw if kw else headers
self.add_matcher(matcher('HeadersMatcher', headers))
def body(self, body):
"""
Defines the body data to match.
``body`` argument can be a ``str``, ``binary`` or a regular expression.
Arguments:
body (str|binary|regex): body data to match.
Returns:
self: current Mock instance.
"""
self.add_matcher(matcher('BodyMatcher', body))
def jsonschema(self, schema):
"""
Defines a JSONSchema representation to be used for body matching.
Arguments:
schema (str|dict): dict or JSONSchema string to use.
Returns:
self: current Mock instance.
"""
self.add_matcher(matcher('JSONSchemaMatcher', schema))
def method(self, method):
"""
Defines the HTTP method to match.
Use ``*`` to match any method.
Arguments:
method (str): method value to match. E.g: ``GET``.
Returns:
self: current Mock instance.
"""
self._request.method = method
self.add_matcher(matcher('MethodMatcher', method))
def method(self, method):
"""
Defines the HTTP method to match.
Use ``*`` to match any method.
Arguments:
method (str): method value to match. E.g: ``GET``.
Returns:
self: current Mock instance.
"""
self.add_matcher(matcher('MethodMatcher', method))
Header keys are case insensitive.
Arguments:
*names (str): header or headers names to match.
Returns:
self: current Mock instance.
Example::
(pook.get('server.com/api')
.header_present('content-type'))
"""
for name in names:
headers = {name: re.compile('(.*)')}
self.add_matcher(matcher('HeadersMatcher', headers))
def jsonschema(self, schema):
"""
Defines a JSONSchema representation to be used for body matching.
Arguments:
schema (str|dict): dict or JSONSchema string to use.
Returns:
self: current Mock instance.
"""
self.add_matcher(matcher('JSONSchemaMatcher', schema))
- ``xml`` = ``application/xml``
- ``html`` = ``text/html``
- ``text`` = ``text/plain``
- ``urlencoded`` = ``application/x-www-form-urlencoded``
- ``form`` = ``application/x-www-form-urlencoded``
- ``form-data`` = ``application/x-www-form-urlencoded``
Arguments:
value (str): type alias or header value to match.
Returns:
self: current Mock instance.
"""
header = {'Content-Type': TYPES.get(value, value)}
self._request.headers = header
self.add_matcher(matcher('HeadersMatcher', header))