cheroot.test.test_conn module

Tests for TCP connection handling, including proper and timely close.

class cheroot.test.test_conn.Controller

Bases: cheroot.test.helper.Controller

Controller for serving WSGI apps.


Encode PATH_INFO correctly depending on Python version.

WSGI 1.0 is a mess around unicode. Create endpoints that match the PATH_INFO that it produces.


Render response with status 204.


Render response with status 304.


Render response with status 500.

handlers = {'/custom/204': <function Controller.custom_204>, '/custom/304': <function Controller.custom_304>, '/err_before_read': <function Controller.err_before_read>, '/hello': <function Controller.hello>, '/one_megabyte_of_a': <function Controller.one_megabyte_of_a>, '/page1': <function Controller.pov>, '/page2': <function Controller.pov>, '/page3': <function Controller.pov>, '/pov': <function Controller.pov>, '/stream': <function>, '/upload': <function Controller.upload>, '/wrong_cl_buffered': <function Controller.wrong_cl_buffered>, '/wrong_cl_unbuffered': <function Controller.wrong_cl_unbuffered>}

Render Hello world.


Render 1MB response.


Render pov value.


Render streaming response.


Process file upload and render thank.


Render buffered response with invalid length value.


Render unbuffered response with invalid length value.

class cheroot.test.test_conn.ErrorLogMonitor

Bases: object

Mock class to access the server error_log calls made by the server.

class ErrorLogCall(msg, level, traceback)

Bases: tuple


Return a new OrderedDict which maps field names to their values.

_fields = ('msg', 'level', 'traceback')
_fields_defaults = {}
classmethod _make(iterable)

Make a new ErrorLogCall object from a sequence or iterable


Return a new ErrorLogCall object replacing specified fields with new values

property level

Alias for field number 1

property msg

Alias for field number 0

property traceback

Alias for field number 2

class cheroot.test.test_conn.FaultyGetMap(original_get_map)

Bases: object

Mock class to insert errors in the selector.get_map method.

class cheroot.test.test_conn.FaultySelect(original_select)

Bases: object

Mock class to insert errors in the method.

cheroot.test.test_conn.header_exists(header_name, headers)

Check that a header is present.

cheroot.test.test_conn.header_has_value(header_name, header_value, headers)

Check that a header with a given value is present.


Attach a WSGI app to the given server and preconfigure it.


Test 100-continue header processing.


Test serving large file with a read timeout in place.


Test HTTP uploads with chunked transfer-encoding.


Try a non-chunked request where Content-Length exceeds limit.

(server.max_request_body_size). Assert error before body send.


Test that malicious Content-Length header returns 400.

cheroot.test.test_conn.test_Content_Length_out(test_client, uri, expected_resp_status, expected_resp_body)

Test response with Content-Length less than the response body.

(non-chunked response)

cheroot.test.test_conn.test_HTTP11_Timeout(test_client, timeout_before_headers)

Check timeout without sending any data.

The server will close the connection with a 408.


Check timeout after at least one request has succeeded.

The server should close the connection without 408.


Test persistent HTTP/1.1 connections.


Test HTTP/1.1 pipelining.

http.client doesn’t support this directly.

cheroot.test.test_conn.test_No_CRLF(test_client, invalid_terminator)

Test HTTP queries with no valid CRLF terminators.


Test HTTP queries with an empty response body.


Get and return a test client out of the given server.

cheroot.test.test_conn.test_invalid_selected_connection(test_client, monkeypatch)

Test the error handling segment of HTTP connection selection.

See cheroot.connections.ConnectionManager.get_conn().

cheroot.test.test_conn.test_keepalive(test_client, http_server_protocol)

Test Keep-Alive enabled connections.


Test management of Keep-Alive connections.

cheroot.test.test_conn.test_readall_or_close(test_client, max_request_body_size)

Test a max_request_body_size of 0 (the default) and 1001.

cheroot.test.test_conn.test_streaming_10(test_client, set_cl)

Test serving of streaming responses with HTTP/1.0 protocol.

cheroot.test.test_conn.test_streaming_11(test_client, set_cl)

Test serving of streaming responses with HTTP/1.1 protocol.

cheroot.test.test_conn.testing_server(raw_testing_server, monkeypatch)

Modify the “raw” base server to monitor the error_log messages.

If you need to ignore a particular error message use the property testing_server.error_log.ignored_msgs by appending to the list the expected error messages.