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

Function test_websocket_binary_json

tests/test_websockets.py:31–43  ·  tests/test_websockets.py::test_websocket_binary_json
(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=class="st">"binary")
36 await websocket.send_json(message, mode=class="st">"binary")
37 await websocket.close()
38
39 client = test_client_factory(app)
40 with client.websocket_connect(class="st">"/123?a=abc") as websocket:
41 websocket.send_json({class="st">"test": class="st">"data"}, mode=class="st">"binary")
42 data = websocket.receive_json(mode=class="st">"binary")
43 assert data == {class="st">"test": class="st">"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