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

Function test_websocket_iter_json

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

Source from the content-addressed store, hash-verified

195
196
197def test_websocket_iter_json(test_client_factory: TestClientFactory) -> None:
198 async def app(scope: Scope, receive: Receive, send: Send) -> None:
199 websocket = WebSocket(scope, receive=receive, send=send)
200 await websocket.accept()
201 async for data in websocket.iter_json():
202 await websocket.send_json({"message": data})
203
204 client = test_client_factory(app)
205 with client.websocket_connect("/") as websocket:
206 websocket.send_json({"hello": "world"})
207 data = websocket.receive_json()
208 assert data == {"message": {"hello": "world"}}
209
210
211def test_websocket_concurrency_pattern(test_client_factory: TestClientFactory) -> None:

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