Smarter tests for logging
@@ -63,10 +63,6 @@ GET_REQUEST_WITH_RAW_PATH = b"\r\n".join(
[b"GET /one%2Ftwo HTTP/1.1", b"Host: example.org", b"", b""]
)
-GET_REQUEST_WITH_QUERY_STRING = b"\r\n".join(
- [b"GET /search?q=hello HTTP/1.1", b"Host: example.org", b"", b""]
-)
-
UPGRADE_REQUEST = b"\r\n".join(
[
b"GET / HTTP/1.1",
@@ -161,8 +157,7 @@ def get_connected_protocol(app, protocol_cls, **kwargs):
@pytest.mark.parametrize("protocol_cls", HTTP_PROTOCOLS)
-def test_get_request(protocol_cls, caplog):
- caplog.set_level(logging.INFO, logger="uvicorn")
+def test_get_request(protocol_cls):
app = Response("Hello, world", media_type="text/plain")
protocol = get_connected_protocol(app, protocol_cls)
@@ -172,7 +167,21 @@ def test_get_request(protocol_cls, caplog):
assert b"HTTP/1.1 200 OK" in protocol.transport.buffer
assert b"Hello, world" in protocol.transport.buffer
- assert '"GET / HTTP/1.1" 200' in caplog.records[0].message
+
+@pytest.mark.parametrize("protocol_cls", HTTP_PROTOCOLS)
+@pytest.mark.parametrize("path", ["/", "/?foo", "/?foo=bar", "/?foo=bar&baz=1"])
+def test_request_logging(protocol_cls, path, caplog):
+ get_request_with_query_string = b"\r\n".join(
+ ["GET {} HTTP/1.1".format(path).encode("ascii"), b"Host: example.org", b"", b""]
+ )
+ caplog.set_level(logging.INFO, logger="uvicorn")
+ app = Response("Hello, world", media_type="text/plain")
+
+ protocol = get_connected_protocol(app, protocol_cls)
+ protocol.data_received(get_request_with_query_string)
+ protocol.loop.run_one()
+
+ assert '"GET {} HTTP/1.1" 200'.format(path) in caplog.records[0].message
@pytest.mark.parametrize("protocol_cls", HTTP_PROTOCOLS)
