(
test_client_factory: TestClientFactory,
)
| 107 | |
| 108 | |
| 109 | def test_websocket_endpoint_on_receive_json( |
| 110 | test_client_factory: TestClientFactory, |
| 111 | ) -> None: |
| 112 | class WebSocketApp(WebSocketEndpoint): |
| 113 | encoding = "json" |
| 114 | |
| 115 | async def on_receive(self, websocket: WebSocket, data: str) -> None: |
| 116 | await websocket.send_json({"message": data}) |
| 117 | |
| 118 | client = test_client_factory(WebSocketApp) |
| 119 | with client.websocket_connect("/ws") as websocket: |
| 120 | websocket.send_json({"hello": "world"}) |
| 121 | data = websocket.receive_json() |
| 122 | assert data == {"message": {"hello": "world"}} |
| 123 | |
| 124 | with pytest.raises(RuntimeError): |
| 125 | with client.websocket_connect("/ws") as websocket: |
| 126 | websocket.send_text("Hello world") |
| 127 | |
| 128 | |
| 129 | def test_websocket_endpoint_on_receive_json_binary( |
nothing calls this directly
no test coverage detected