MCPcopy
hub / github.com/encode/uvicorn / test_request_logging

Function test_request_logging

tests/protocols/test_http.py:346–358  ·  view source on GitHub ↗
(path: str, http_protocol_cls: type[HTTPProtocol], caplog: pytest.LogCaptureFixture)

Source from the content-addressed store, hash-verified

344
345@pytest.mark.parametrize("path", ["/", "/?foo", "/?foo=bar", "/?foo=bar&baz=1"])
346async def test_request_logging(path: str, http_protocol_cls: type[HTTPProtocol], caplog: pytest.LogCaptureFixture):
347 get_request_with_query_string = b"\r\n".join(
348 [f"GET {path} HTTP/1.1".encode("ascii"), b"Host: example.org", b"", b""]
349 )
350 caplog.set_level(logging.INFO, logger="uvicorn.access")
351 logging.getLogger("uvicorn.access").propagate = True
352
353 app = Response("Hello, world", media_type="text/plain")
354
355 protocol = get_connected_protocol(app, http_protocol_cls, log_config=None)
356 protocol.data_received(get_request_with_query_string)
357 await protocol.loop.run_one()
358 assert f'"GET {path} HTTP/1.1" 200' in caplog.records[0].message
359
360
361async def test_head_request(http_protocol_cls: type[HTTPProtocol]):

Callers

nothing calls this directly

Calls 5

ResponseClass · 0.90
joinMethod · 0.80
get_connected_protocolFunction · 0.70
data_receivedMethod · 0.45
run_oneMethod · 0.45

Tested by

no test coverage detected