Test class for UnitTest

class wooper.test_class.ApiMixin[source]

This class can be used as a mixin to unittest.TestCase to provide additional methods for requesting, inspecting and testing REST API services.

server_url

Server URL. Will be used for constructing URL for responses.

DELETE(*args, **kwargs)[source]

make a DELETE request to some URI

Parameters

uri (str) – URI

rest of args is the same as in requests.delete()

GET(*args, **kwargs)[source]

make a GET request to some URI

Parameters

uri (str) – URI

rest of args is the same as in requests.get()

PATCH(*args, **kwargs)[source]

make a PATCH request to some URI

Parameters
  • uri (str) – URI

  • data (str, list, dict) – request payload

rest of args is the same as in requests.patch()

POST(*args, **kwargs)[source]

make a POST request to some URI

Parameters
  • uri (str) – URI

  • data (str, list, dict) – request payload

rest of args is the same as in requests.post()

PUT(*args, **kwargs)[source]

make a PUT request to some URI

Parameters
  • uri (str) – URI

  • data (str, list, dict) – request payload

rest of args is the same as in requests.put()

enable_ssl_verification = True

Enable SSL certificates’ verification (default: True)

expect_body_contains(text)[source]

checks if response body contains some text

Parameters

text (str) – Expected text

expect_headers(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.

expect_headers_contain(header, value=None)[source]

checks if response headers contain a given header

Parameters
  • header (str) – Expected header name.

  • value (str, optional) – Expected header value.

expect_json(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’

expect_json_contains(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’

expect_json_length(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’

expect_json_match(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’

expect_json_not_contains(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’

expect_status(code)[source]

checks if response status equals given code

Parameters

code (int) – Expected status code

expect_status_in(codes)[source]

checks if response status equals to one of the provided

Parameters

codes (list) – List of valid status codes

property json_response
Returns

response as json

Throws ValueError

if response is not a valid json

print_headers = False

Print requests’ headers during test run

print_payload = False

Print payload sent to the server during test run

print_url = False

Print URLs during test run