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.Sessionclass to provide logging facilities for lemoncheesecake. The actual logging is performed through theLoggerinstance which is associated to the session.The following
requestsmethods, performing an actual HTTP request:request()get()options()head()post()put()patch()delete()
are overridden, they all:
take an optional extra
loggerargument that is used over the session-wideloggerfor 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.
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.Sessionobject.- max_inlined_body_size: Optional[int]¶
If a serialized request/response body size is greater than
max_inlined_body_sizethen it will be logged as an attachment. If it is set toNone, the body will be logged directly whatever his size.
- classmethod on(debug=False)¶
Create a logger with every request/response details enabled.
- Return type:
- classmethod off()¶
Create a logger with every request/response details disabled.
- Return type:
- classmethod no_headers(debug=False)¶
Create a logger with every request/response details enabled except headers.
- Return type:
Response¶
- class lemoncheesecake_requests.Response¶
The Response class.
It inherits
requests.Responseand provides extra methods that deal with status code verification.- check_status_code(expected)¶
Check the status code using the
lemoncheesecake.matching.check_that()function.
- check_ok()¶
Check that the status code is 2xx using the
lemoncheesecake.matching.check_that()function.- Return type:
- require_status_code(expected)¶
Check the status code using the
lemoncheesecake.matching.require_that()function.
- require_ok()¶
Check that the status code is 2xx using the
lemoncheesecake.matching.require_that()function.- Return type:
- assert_status_code(expected)¶
Check the status code using the
lemoncheesecake.matching.assert_that()function.
- assert_ok()¶
Check that the status code is 2xx using the
lemoncheesecake.matching.assert_that()function.- Return type:
- raise_unless_status_code(expected)¶
Raise a
StatusCodeMismatchexception unless the status code expected condition is met.- Raises:
- Parameters:
- Return type:
- raise_unless_ok()¶
Raise a
StatusCodeMismatchexception unless the status code is 2xx.- Raises:
- Return type:
- check_headers(expected)¶
Check response headers using the
lemoncheesecake.matching.check_that_in()function.New in version 0.4.0.
- require_headers(expected)¶
Check response headers using the
lemoncheesecake.matching.require_that_in()function.New in version 0.4.0.
- assert_headers(expected)¶
Check response headers using the
lemoncheesecake.matching.assert_that_in()function.New in version 0.4.0.
- check_header(name, expected)¶
Check response headers using the
lemoncheesecake.matching.check_that_in()function.New in version 0.4.0.
- require_header(name, expected)¶
Check response headers using the
lemoncheesecake.matching.require_that_in()function.New in version 0.4.0.
- assert_header(name, expected)¶
Check response headers using the
lemoncheesecake.matching.assert_that_in()function.New in version 0.4.0.
- check_json(expected)¶
Check the response JSON using the
lemoncheesecake.matching.check_that_in()function.New in version 0.4.0.
- require_json(expected)¶
Check the response JSON using the
lemoncheesecake.matching.require_that_in()function.New in version 0.4.0.
- assert_json(expected)¶
Check the response JSON using the
lemoncheesecake.matching.assert_that_in()function.New in version 0.4.0.
Matchers¶
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:
response (Response) –
matcher (Matcher) –
match_result (MatchResult) –