Expectations for Behave¶
Expectation helper functions are receiving response object (for example from requests lib) as first argument. These helpers make testing API response bodies and headers easy with minimal time and effort.
- wooper.expect.expect_body_contains(response, text)[source]¶
checks if response body contains some text
- Parameters:
text (str) – Expected text
- wooper.expect.expect_headers(response, headers, partly=False)[source]¶
checks if response headers values are equal to given
- Parameters:
headers (dict) – Dict with headers and their values, like { “Header1”: “ExpectedValue1” }
partly (bool, optional) – Compare full header value or check if the value includes expected one.
- wooper.expect.expect_headers_contain(response, header, value=None)[source]¶
checks if response headers contain a given header
- Parameters:
header (str) – Expected header name.
value (str, optional) – Expected header value.
- wooper.expect.expect_json(response, expected_json, path=None)[source]¶
checks if json response equals some json,
- Parameters:
expected_json (str, list, dict) – JSON object to compare with
path (str, optional) – Path inside response json, separated by slashes, ie ‘foo/bar/spam’, ‘foo/[0]/bar’
- wooper.expect.expect_json_contains(response, expected_json, path=None, reverse_expectation=False)[source]¶
checks if json response contains some json subset,
- Parameters:
expected_json (str, list, dict) – JSON object to compare with
path (str, optional) – Path inside response json, separated by slashes, ie ‘foo/bar/spam’, ‘foo/[0]/bar’
- wooper.expect.expect_json_length(response, length, path=None)[source]¶
checks if count of objects in json response equals provided length,
- Parameters:
length (int) – Expected number of objects inside json or length of the string
path (str, optional) – Path inside response json, separated by slashes, ie ‘foo/bar/spam’, ‘foo/[0]/bar’
- wooper.expect.expect_json_match(response, expected_json, path=None)[source]¶
checks if json response partly matches some json,
- Parameters:
expected_json (str, list, dict) – JSON object to compare with
path (str, optional) – Path inside response json, separated by slashes, ie ‘foo/bar/spam’, ‘foo/[0]/bar’
- wooper.expect.expect_json_not_contains(response, expected_json, path=None)[source]¶
checks if json response not contains some json subset,
- Parameters:
expected_json (str, list, dict) – JSON object to compare with
path (str, optional) – Path inside response json, separated by slashes, ie ‘foo/bar/spam’, ‘foo/[0]/bar’