MCPcopy Create free account
hub / github.com/encode/starlette / test_websocket_endpoint_on_receive_bytes

Function test_websocket_endpoint_on_receive_bytes

tests/test_endpoints.py:89–106  ·  view source on GitHub ↗
(
    test_client_factory: TestClientFactory,
)

Source from the content-addressed store, hash-verified

87
88
89def test_websocket_endpoint_on_receive_bytes(
90 test_client_factory: TestClientFactory,
91) -> None:
92 class WebSocketApp(WebSocketEndpoint):
93 encoding = "bytes"
94
95 async def on_receive(self, websocket: WebSocket, data: bytes) -> None:
96 await websocket.send_bytes(b"Message bytes was: " + data)
97
98 client = test_client_factory(WebSocketApp)
99 with client.websocket_connect("/ws") as websocket:
100 websocket.send_bytes(b"Hello, world!")
101 _bytes = websocket.receive_bytes()
102 assert _bytes == b"Message bytes was: Hello, world!"
103
104 with pytest.raises(RuntimeError):
105 with client.websocket_connect("/ws") as websocket:
106 websocket.send_text("Hello world")
107
108
109def test_websocket_endpoint_on_receive_json(

Callers

nothing calls this directly

Calls 5

test_client_factoryFunction · 0.85
websocket_connectMethod · 0.80
send_bytesMethod · 0.45
receive_bytesMethod · 0.45
send_textMethod · 0.45

Tested by

no test coverage detected