(
test_client_factory: TestClientFactory,
)
| 96 | |
| 97 | |
| 98 | def test_websocket_endpoint_on_receive_json( |
| 99 | test_client_factory: TestClientFactory, |
| 100 | ) -> None: |
| 101 | class WebSocketApp(WebSocketEndpoint): |
| 102 | encoding = "json" |
| 103 | |
| 104 | async def on_receive(self, websocket: WebSocket, data: str) -> None: |
| 105 | await websocket.send_json({"message": data}) |
| 106 | |
| 107 | client = test_client_factory(WebSocketApp) |
| 108 | with client.websocket_connect("/ws") as websocket: |
| 109 | websocket.send_json({"hello": "world"}) |
| 110 | data = websocket.receive_json() |
| 111 | assert data == {"message": {"hello": "world"}} |
| 112 | |
| 113 | with pytest.raises(RuntimeError): |
| 114 | with client.websocket_connect("/ws") as websocket: |
| 115 | websocket.send_text("Hello world") |
| 116 | |
| 117 | |
| 118 | def test_websocket_endpoint_on_receive_json_binary( |
nothing calls this directly
no test coverage detected