curia.mock.server module

curia.mock.server.parse_content_type_header(header)

Parse a content-type header into a tuple of the content type and a dictionary of parameters. :param header: the content-type header to parse :return: a tuple of the content type and a dictionary of parameters

See https://docs.python.org/3/library/cgi.html#functions-in-cgi-module for why we are using EmailMessage here instead of the cgi module.

curia.mock.server.parse_multipart(rfile, post_dict)

Parses a multipart/form-data request body into a dictionary of lists of strings, replicating the behavior of cgi.parse_multipart. :param rfile: the file-like object to read the request body from :param post_dict: contains additional parameters from the content-type header :return: the populated dictionary

exception curia.mock.server.ServerFailedToStartException

Bases: Exception

curia.mock.server.using_test_server(port=3000, response_map=None, log_dir='temp/', response_map_metadata: Any | None = None)
curia.mock.server.run_test_server(port=3000, response_map=None, log_dir='temp/', response_map_metadata: Any | None = None)
class curia.mock.server.ParseAndExtractDataSummary(method: str, path: str, url_qs: dict, content_qs: dict, content_type: str)

Bases: object

ParseAndExtractDataSummary(method: str, path: str, url_qs: dict, content_qs: dict, content_type: str)

method: str
path: str
url_qs: dict
content_qs: dict
content_type: str
curia.mock.server.default_encoder(obj)
exception curia.mock.server.Exception404

Bases: Exception

class curia.mock.server.TestServer(port=3000, shutdown_poll_freq=50, response_map=None, log_dir='temp/', response_map_metadata: Any | None = None)

Bases: HTTPServer

Constructor. May be extended, do not override.

class ResponseConfig(accepted_methods: List[str] | str, content_type: str, content: bytes)

Bases: object

ResponseConfig(accepted_methods: Union[List[str], str], content_type: str, content: bytes)

accepted_methods: List[str] | str
content_type: str
content: bytes
accepts_method(method)
add_data(handler)
class RequestHandler(request, client_address, server)

Bases: BaseHTTPRequestHandler

server: TestServer
do_GET()
do_POST()
do_PATCH()
do_PUT()
do_DELETE()
parse_and_extract(method: str)
map_to_response_auto(method)
use_response_map_callable(parse_extract_summary: ParseAndExtractDataSummary)
use_response_map_map(method: str, parse_extract_summary: ParseAndExtractDataSummary)
map_to_response(method)
infer_type_and_add_data(response_value)
add_debug_logs()
add_404(e: Exception | None = None)
add_500(e: Exception | None = None, tb: str | None = None)
add_405()
add_healthcheck()
add_teapot()
log(method, path, summary: ParseAndExtractDataSummary)
static debug_logs(port)

Accesses debug logs of a test server running on a given port