Skip to content

Commit

Permalink
test: Add tests for custom request and websocket classes examples in …
Browse files Browse the repository at this point in the history
…docs
  • Loading branch information
kedod committed Mar 9, 2024
1 parent 84af179 commit 87f559f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/examples/test_request_data.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
12 changes: 12 additions & 0 deletions tests/examples/test_websockets.py
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 87f559f

Please sign in to comment.