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

Function test_websocket_send_and_receive_json

tests/test_websockets.py:152–166  ·  tests/test_websockets.py::test_websocket_send_and_receive_json
(
    test_client_factory: TestClientFactory,
)

Source from the content-addressed store, hash-verified

150
151
152def test_websocket_send_and_receive_json(
153 test_client_factory: TestClientFactory,
154) -> None:
155 async def app(scope: Scope, receive: Receive, send: Send) -> None:
156 websocket = WebSocket(scope, receive=receive, send=send)
157 await websocket.accept()
158 data = await websocket.receive_json()
159 await websocket.send_json({class="st">"message": data})
160 await websocket.close()
161
162 client = test_client_factory(app)
163 with client.websocket_connect(class="st">"/") as websocket:
164 websocket.send_json({class="st">"hello": class="st">"world"})
165 data = websocket.receive_json()
166 assert data == {class="st">"message": {class="st">"hello": class="st">"world"}}
167
168
169def test_websocket_iter_text(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