pook.matchers package¶
Submodules¶
pook.matchers.api module¶
- class pook.matchers.api.BaseMatcher(expectation, negate=False)[source]¶
Bases:
object
BaseMatcher implements the basic HTTP request matching interface.
- compare(value, expectation, regex_expr=False)[source]¶
Compares two values with regular expression matching support.
- Parameters:
value (mixed) – value to compare.
expectation (mixed) – value to match.
regex_expr (bool, optional) – enables string based regex matching.
- Returns:
bool
- property expectation¶
- abstract match(request)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- property name¶
- negate = False¶
- class pook.matchers.api.BodyMatcher(*args, **kwargs)[source]¶
Bases:
BaseMatcher
BodyMatchers matches the request body via strict value comparison or regular expression based matching.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- class pook.matchers.api.HeadersMatcher(headers)[source]¶
Bases:
BaseMatcher
Headers HTTP request matcher.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- class pook.matchers.api.JSONMatcher(data)[source]¶
Bases:
BaseMatcher
JSONMatcher implements a JSON body matcher supporting strict structure and regular expression based comparisons.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- class pook.matchers.api.JSONSchemaMatcher(schema)[source]¶
Bases:
BaseMatcher
JSONSchema matcher validates a request body against a given JSONSchema definition schema.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- class pook.matchers.api.MethodMatcher(expectation, negate=False)[source]¶
Bases:
BaseMatcher
MethodMatcher implements.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- class pook.matchers.api.PathMatcher(expectation, negate=False)[source]¶
Bases:
BaseMatcher
PathMatcher implements an URL path matcher.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- class pook.matchers.api.QueryMatcher(expectation, negate=False)[source]¶
Bases:
BaseMatcher
QueryMatcher implements an URL query params matcher.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- class pook.matchers.api.URLMatcher(url)[source]¶
Bases:
BaseMatcher
URLMatcher implements an URL schema matcher.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- regex = False¶
- class pook.matchers.api.XMLMatcher(data)[source]¶
Bases:
BaseMatcher
XMLMatcher implements a XML body matcher supporting both strict structure comparison and regular expression.
- compare(data)[source]¶
Compares two values with regular expression matching support.
- Parameters:
value (mixed) – value to compare.
expectation (mixed) – value to match.
regex_expr (bool, optional) – enables string based regex matching.
- Returns:
bool
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- pook.matchers.api.add(*matcher)[source]¶
Registers one or multiple matchers to be used by default from mocking engine.
- Parameters:
*matcher (list[pook.BaseMatcher]) – variadic matchers to add.
- pook.matchers.api.get(name)[source]¶
Returns a matcher instance by class or alias name.
- Parameters:
name (str) – matcher class name or alias.
- Returns:
found matcher instance, otherwise
None
.- Return type:
matcher
- pook.matchers.api.init(name, *args, **kwargs)[source]¶
Initializes a matcher instance passing variadic arguments to its constructor. Acts as a delegator proxy.
- Parameters:
- Returns:
matcher instance.
- Return type:
matcher
- Raises:
ValueError – if matcher was not found.
pook.matchers.base module¶
- class pook.matchers.base.BaseMatcher(expectation, negate=False)[source]¶
Bases:
object
BaseMatcher implements the basic HTTP request matching interface.
- compare(value, expectation, regex_expr=False)[source]¶
Compares two values with regular expression matching support.
- Parameters:
value (mixed) – value to compare.
expectation (mixed) – value to match.
regex_expr (bool, optional) – enables string based regex matching.
- Returns:
bool
- property expectation¶
- abstract match(request)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- property name¶
- negate = False¶
- class pook.matchers.base.ExistsMatcher(expectation, negate=False)[source]¶
Bases:
BaseMatcher
Base class for matchers that only check for existence.
- get_request_attribute(request)[source]¶
Retrieve attribute from the request in which existence should be checked.
- match(request)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- abstract property request_attr¶
The attribute from the request in which to check for existence of the expectation.
pook.matchers.body module¶
- class pook.matchers.body.BodyMatcher(*args, **kwargs)[source]¶
Bases:
BaseMatcher
BodyMatchers matches the request body via strict value comparison or regular expression based matching.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
pook.matchers.headers module¶
- class pook.matchers.headers.HeaderExistsMatcher(expectation, negate=False)[source]¶
Bases:
ExistsMatcher
- request_attr = 'headers'¶
- class pook.matchers.headers.HeadersMatcher(headers)[source]¶
Bases:
BaseMatcher
Headers HTTP request matcher.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
pook.matchers.json module¶
- class pook.matchers.json.JSONMatcher(data)[source]¶
Bases:
BaseMatcher
JSONMatcher implements a JSON body matcher supporting strict structure and regular expression based comparisons.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
pook.matchers.json_schema module¶
- class pook.matchers.json_schema.JSONSchemaMatcher(schema)[source]¶
Bases:
BaseMatcher
JSONSchema matcher validates a request body against a given JSONSchema definition schema.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
pook.matchers.method module¶
- class pook.matchers.method.MethodMatcher(expectation, negate=False)[source]¶
Bases:
BaseMatcher
MethodMatcher implements.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
pook.matchers.path module¶
- class pook.matchers.path.PathMatcher(expectation, negate=False)[source]¶
Bases:
BaseMatcher
PathMatcher implements an URL path matcher.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
pook.matchers.query module¶
- class pook.matchers.query.QueryMatcher(expectation, negate=False)[source]¶
Bases:
BaseMatcher
QueryMatcher implements an URL query params matcher.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- class pook.matchers.query.QueryParameterExistsMatcher(expectation, allow_empty, negate=False)[source]¶
Bases:
ExistsMatcher
- is_empty(value)[source]¶
Check for empty query parameter values.
urllib.parse.parse_qs returns a value of [‘’] for parameters that are present but without value.
- match(request)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- request_attr = 'query'¶
pook.matchers.url module¶
- class pook.matchers.url.URLMatcher(url)[source]¶
Bases:
BaseMatcher
URLMatcher implements an URL schema matcher.
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.
- regex = False¶
pook.matchers.xml module¶
- class pook.matchers.xml.XMLMatcher(data)[source]¶
Bases:
BaseMatcher
XMLMatcher implements a XML body matcher supporting both strict structure comparison and regular expression.
- compare(data)[source]¶
Compares two values with regular expression matching support.
- Parameters:
value (mixed) – value to compare.
expectation (mixed) – value to match.
regex_expr (bool, optional) – enables string based regex matching.
- Returns:
bool
- match(req)[source]¶
Match performs the value matching. This is an abstract method that must be implemented by child classes.
- Parameters:
request (pook.Request) – request object to match.