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.
- _munge()#
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.
- custom_204(resp)#
Render response with status 204.
- custom_304(resp)#
Render response with status 304.
- err_before_read(resp)#
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 Controller.stream>, '/upload': <function Controller.upload>, '/wrong_cl_buffered': <function Controller.wrong_cl_buffered>, '/wrong_cl_unbuffered': <function Controller.wrong_cl_unbuffered>}#
- hello(resp)#
Render Hello world.
- one_megabyte_of_a(resp)#
Render 1MB response.
- pov(resp)#
Render
pov
value.
- stream(resp)#
Render streaming response.
- upload(resp)#
Process file upload and render thank.
- wrong_cl_buffered(resp)#
Render buffered response with invalid length value.
- wrong_cl_unbuffered(resp)#
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
- _asdict()#
Return a new dict which maps field names to their values.
- _field_defaults = {}#
- _fields = ('msg', 'level', 'traceback')#
- classmethod _make(iterable)#
Make a new ErrorLogCall object from a sequence or iterable
- _replace(**kwds)#
Return a new ErrorLogCall object replacing specified fields with new values
- level#
Alias for field number 1
- msg#
Alias for field number 0
- 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 selector.select 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.
- cheroot.test.test_conn.raw_testing_server(wsgi_server_client)#
Attach a WSGI app to the given server and preconfigure it.
- cheroot.test.test_conn.test_100_Continue(test_client)#
Test 100-continue header processing.
- cheroot.test.test_conn.test_598(test_client)#
Test serving large file with a read timeout in place.
- cheroot.test.test_conn.test_Chunked_Encoding(test_client)#
Test HTTP uploads with chunked transfer-encoding.
- cheroot.test.test_conn.test_Content_Length_in(test_client)#
Try a non-chunked request where Content-Length exceeds limit.
(server.max_request_body_size). Assert error before body send.
- cheroot.test.test_conn.test_Content_Length_not_int(test_client)#
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.
- cheroot.test.test_conn.test_HTTP11_Timeout_after_request(test_client)#
Check timeout after at least one request has succeeded.
The server should close the connection without 408.
- cheroot.test.test_conn.test_HTTP11_persistent_connections(test_client)#
Test persistent HTTP/1.1 connections.
- cheroot.test.test_conn.test_HTTP11_pipelining(test_client)#
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.
- cheroot.test.test_conn.test_No_Message_Body(test_client)#
Test HTTP queries with an empty response body.
- cheroot.test.test_conn.test_broken_connection_during_tcp_fin(error_number, exception_leaks, mocker, monkeypatch, simulated_exception, test_client)#
Test there’s no traceback on broken connection during close.
It artificially causes
ECONNRESET
/EPIPE
/ESHUTDOWN
/ENOTCONN
as well as unrelatedRuntimeError
andsocket.error(-1)
on the server socket whensocket.shutdown()
is called. It’s triggered by closing the client socket before the server had a chance to respond.The expectation is that only
RuntimeError
and asocket.error
with an unusual error code would leak.With the
None
-parameter, a real non-simulatedOSError(107, 'Transport endpoint is not connected')
happens.
- cheroot.test.test_conn.test_client(testing_server)#
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.
- cheroot.test.test_conn.test_keepalive_conn_management(test_client)#
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.