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

Function test_websocket_send_and_receive_bytes

tests/test_websockets.py:135–149  ·  view source on GitHub ↗
(
    test_client_factory: TestClientFactory,
)

Source from the content-addressed store, hash-verified

133
134
135def test_websocket_send_and_receive_bytes(
136 test_client_factory: TestClientFactory,
137) -> None:
138 async def app(scope: Scope, receive: Receive, send: Send) -> None:
139 websocket = WebSocket(scope, receive=receive, send=send)
140 await websocket.accept()
141 data = await websocket.receive_bytes()
142 await websocket.send_bytes(b"Message was: " + data)
143 await websocket.close()
144
145 client = test_client_factory(app)
146 with client.websocket_connect("/") as websocket:
147 websocket.send_bytes(b"Hello, world!")
148 data = websocket.receive_bytes()
149 assert data == b"Message was: Hello, world!"
150
151
152def test_websocket_send_and_receive_json(

Callers

nothing calls this directly

Calls 4

send_bytesMethod · 0.95
receive_bytesMethod · 0.95
test_client_factoryFunction · 0.85
websocket_connectMethod · 0.80

Tested by

no test coverage detected