API Reference

API compatibility / stability

lemoncheesecake-requests follows the well know Semantic Versioning for its public API. Since lemoncheesecake-requests is still on 0.y.z major version, API breaking changes might occur; it is then advised to pin the version.

What is considered as “public” is everything documented on https://lemoncheesecake-requests.readthedocs.io. Everything else is internal and is subject to changes at anytime.

Session

class lemoncheesecake_requests.Session(base_url='', logger=None, hint=None)

The Session class.

It inherits the requests.Session class to provide logging facilities for lemoncheesecake. The actual logging is performed through the Logger instance which is associated to the session.

The following requests methods, performing an actual HTTP request:

  • request()

  • get()

  • options()

  • head()

  • post()

  • put()

  • patch()

  • delete()

are overridden, they all:

  • take an optional extra logger argument that is used over the session-wide logger for that call:

    session.get("/foo", logger=Logger.off())
    
  • return an instance of lemoncheesecake_requests.Response

base_url: str

The base_url will be concatenated to the URL passed to methods such as get(), post() etc.. to form the complete URL (let the string empty if there is no base_url).

logger: Logger

The logger to be used by default for the session logging, if not provided, Logger.on() is used.

hint: Optional[str]

An optional string value to be logged to provide more context to the report reader.

Logger

class lemoncheesecake_requests.Logger(request_line_logging=True, request_headers_logging=True, request_body_logging=True, response_code_logging=True, response_headers_logging=True, response_body_logging=True, debug=False, max_inlined_body_size=2048)

The Logger class.

It provides lemoncheesecake logging facilities for a lemoncheesecake_requests.Session object.

request_line_logging: bool

Whether or not the request line must be logged.

request_headers_logging: bool

Whether or not the request headers must be logged.

request_body_logging: bool

Whether or not the request body must be logged.

response_code_logging: bool

Whether or not the response body must be logged.

response_headers_logging: bool

Whether or not the response headers must be logged.

response_body_logging: bool

Whether or not the response body must be logged.

debug: bool

Whether or not the logger should log as debug instead of info

max_inlined_body_size: Optional[int]

If a serialized request/response body size is greater than max_inlined_body_size then it will be logged as an attachment. If it is set to None, the body will be logged directly whatever his size.

classmethod on(debug=False)

Create a logger with every request/response details enabled.

Return type:

Logger

classmethod off()

Create a logger with every request/response details disabled.

Return type:

Logger

classmethod no_headers(debug=False)

Create a logger with every request/response details enabled except headers.

Return type:

Logger

classmethod no_response_body(debug=False)

Create a logger with every request/response details enabled except the response body.

Return type:

Logger

Response

class lemoncheesecake_requests.Response

The Response class.

It inherits requests.Response and provides extra methods that deal with status code verification.

check_status_code(expected)

Check the status code using the lemoncheesecake.matching.check_that() function.

Parameters:

expected (Union[Matcher, int]) –

Return type:

Response

check_ok()

Check that the status code is 2xx using the lemoncheesecake.matching.check_that() function.

Return type:

Response

require_status_code(expected)

Check the status code using the lemoncheesecake.matching.require_that() function.

Parameters:

expected (Union[Matcher, int]) –

Return type:

Response

require_ok()

Check that the status code is 2xx using the lemoncheesecake.matching.require_that() function.

Return type:

Response

assert_status_code(expected)

Check the status code using the lemoncheesecake.matching.assert_that() function.

Parameters:

expected (Union[Matcher, int]) –

Return type:

Response

assert_ok()

Check that the status code is 2xx using the lemoncheesecake.matching.assert_that() function.

Return type:

Response

raise_unless_status_code(expected)

Raise a StatusCodeMismatch exception unless the status code expected condition is met.

Raises:

StatusCodeMismatch

Parameters:

expected (Union[Matcher, int]) –

Return type:

Response

raise_unless_ok()

Raise a StatusCodeMismatch exception unless the status code is 2xx.

Raises:

StatusCodeMismatch

Return type:

Response

check_headers(expected)

Check response headers using the lemoncheesecake.matching.check_that_in() function.

New in version 0.4.0.

Parameters:

expected (dict) –

Return type:

Response

require_headers(expected)

Check response headers using the lemoncheesecake.matching.require_that_in() function.

New in version 0.4.0.

Parameters:

expected (dict) –

Return type:

Response

assert_headers(expected)

Check response headers using the lemoncheesecake.matching.assert_that_in() function.

New in version 0.4.0.

Parameters:

expected (dict) –

Return type:

Response

check_header(name, expected)

Check response headers using the lemoncheesecake.matching.check_that_in() function.

New in version 0.4.0.

Parameters:

expected (Union[Matcher, str]) –

Return type:

Response

require_header(name, expected)

Check response headers using the lemoncheesecake.matching.require_that_in() function.

New in version 0.4.0.

Parameters:

expected (Union[Matcher, str]) –

Return type:

Response

assert_header(name, expected)

Check response headers using the lemoncheesecake.matching.assert_that_in() function.

New in version 0.4.0.

Parameters:

expected (Union[Matcher, str]) –

Return type:

Response

check_json(expected)

Check the response JSON using the lemoncheesecake.matching.check_that_in() function.

New in version 0.4.0.

Parameters:

expected (dict) –

Return type:

Response

require_json(expected)

Check the response JSON using the lemoncheesecake.matching.require_that_in() function.

New in version 0.4.0.

Parameters:

expected (dict) –

Return type:

Response

assert_json(expected)

Check the response JSON using the lemoncheesecake.matching.assert_that_in() function.

New in version 0.4.0.

Parameters:

expected (dict) –

Return type:

Response

Matchers

lemoncheesecake_requests.is_2xx()

Test if the value is between 200 and 299.

Return type:

Matcher

lemoncheesecake_requests.is_3xx()

Test if the value is between 300 and 399.

Return type:

Matcher

lemoncheesecake_requests.is_4xx()

Test if the value is between 400 and 499.

Return type:

Matcher

lemoncheesecake_requests.is_5xx()

Test if the value is between 500 and 599.

Return type:

Matcher

Exceptions

exception lemoncheesecake_requests.LemoncheesecakeRequestsException

Base exception class for lemoncheesecake-requests.

exception lemoncheesecake_requests.StatusCodeMismatch(response, matcher, match_result)

This exception is raised by raise_unless_* methods.

Parameters: