From 87f559fb074b9f4dcb2e908c1a581786e350081d Mon Sep 17 00:00:00 2001 From: kedod Date: Sat, 9 Mar 2024 19:48:55 +0100 Subject: [PATCH] test: Add tests for custom request and websocket classes examples in docs --- tests/examples/test_request_data.py | 7 +++++++ tests/examples/test_websockets.py | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/examples/test_websockets.py diff --git a/tests/examples/test_request_data.py b/tests/examples/test_request_data.py index f86d20a94b..2c03e08bbe 100644 --- a/tests/examples/test_request_data.py +++ b/tests/examples/test_request_data.py @@ -1,3 +1,4 @@ +from docs.examples.request_data.custom_request import app as custom_request_class_app from docs.examples.request_data.msgpack_request import app as msgpack_app from docs.examples.request_data.request_data_1 import app from docs.examples.request_data.request_data_2 import app as app_2 @@ -99,3 +100,9 @@ def test_msgpack_app() -> None: with TestClient(app=msgpack_app) as client: response = client.post("/", content=encode_msgpack(test_data)) assert response.json() == test_data + + +def test_custom_request_app() -> None: + with TestClient(app=custom_request_class_app) as client: + response = client.get("/kitten-name") + assert response.content == b"Whiskers" diff --git a/tests/examples/test_websockets.py b/tests/examples/test_websockets.py new file mode 100644 index 0000000000..c2898aa117 --- /dev/null +++ b/tests/examples/test_websockets.py @@ -0,0 +1,12 @@ +from docs.examples.websockets.custom_websocket import app as custom_websocket_class_app + +from litestar.testing.client.sync_client import TestClient + + +def test_custom_websocket_class(): + client = TestClient(app=custom_websocket_class_app) + + with client.websocket_connect("/") as ws: + ws.send({"data": "I should not be in response"}) + data = ws.receive() + assert data["text"] == "Fixed response"