pook.matchers package¶
Submodules¶
pook.matchers.api module¶
- class pook.matchers.api.BaseMatcher(expectation, negate=False)[source]¶
Bases:
objectBaseMatcher 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(expectation, negate=False)[source]¶
Bases:
BaseMatcherBodyMatchers 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:
BaseMatcherHeaders 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:
BaseMatcherMatch JSON documents of equivalent value.
JSON documents are matched on the structured data in the document, rather than on the strict organisation of the document.
The following two JSON snippets are treated as identical by this matcher:
{“a”: “one”, “b”: [“two”]}
… is considered idential to …
{“b”: [“two”], “a”: “one”}
In other words, the order does not matter in comparison.
Use
BodyMatcherto strictly match the exact textual structure.- 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:
BaseMatcherJSONSchema 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:
BaseMatcherMethodMatcher 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:
BaseMatcherPathMatcher 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:
BaseMatcherQueryMatcher 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:
BaseMatcherURLMatcher 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:
BaseMatcherMatch XML documents of equivalent structural value.
XML documents are matched on the structured data in the document, rather than on the strict organisation of the document.
The following two XML snippets are treated as identical by this matcher:
<a value=”one”></a> <b>two</b>
… is considered idential to …
<b>two</b> <a value=”one”></a>
In other words, the order does not matter in comparison.
Use
BodyMatcherto strictly match the exact textual structure.- 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:
objectBaseMatcher 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:
BaseMatcherBase 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(expectation, negate=False)[source]¶
Bases:
BaseMatcherBodyMatchers 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:
BaseMatcherHeaders 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:
BaseMatcherMatch JSON documents of equivalent value.
JSON documents are matched on the structured data in the document, rather than on the strict organisation of the document.
The following two JSON snippets are treated as identical by this matcher:
{“a”: “one”, “b”: [“two”]}
… is considered idential to …
{“b”: [“two”], “a”: “one”}
In other words, the order does not matter in comparison.
Use
BodyMatcherto strictly match the exact textual structure.- 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:
BaseMatcherJSONSchema 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:
BaseMatcherMethodMatcher 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:
BaseMatcherPathMatcher 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:
BaseMatcherQueryMatcher 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:
BaseMatcherURLMatcher 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:
BaseMatcherMatch XML documents of equivalent structural value.
XML documents are matched on the structured data in the document, rather than on the strict organisation of the document.
The following two XML snippets are treated as identical by this matcher:
<a value=”one”></a> <b>two</b>
… is considered idential to …
<b>two</b> <a value=”one”></a>
In other words, the order does not matter in comparison.
Use
BodyMatcherto strictly match the exact textual structure.- 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.