MCPcopy
hub / github.com/encode/starlette / test_websocket_binary_json

Function test_websocket_binary_json

tests/test_websockets.py:31–43  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

29
30
31def test_websocket_binary_json(test_client_factory: TestClientFactory) -> None:
32 async def app(scope: Scope, receive: Receive, send: Send) -> None:
33 websocket = WebSocket(scope, receive=receive, send=send)
34 await websocket.accept()
35 message = await websocket.receive_json(mode="binary")
36 await websocket.send_json(message, mode="binary")
37 await websocket.close()
38
39 client = test_client_factory(app)
40 with client.websocket_connect("/123?a=abc") as websocket:
41 websocket.send_json({"test": "data"}, mode="binary")
42 data = websocket.receive_json(mode="binary")
43 assert data == {"test": "data"}
44
45
46def test_websocket_ensure_unicode_on_send_json(

Callers

nothing calls this directly

Calls 4

send_jsonMethod · 0.95
receive_jsonMethod · 0.95
test_client_factoryFunction · 0.85
websocket_connectMethod · 0.80

Tested by

no test coverage detected