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

Function test_websocket_ensure_unicode_on_send_json

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

Source from the content-addressed store, hash-verified

44
45
46def test_websocket_ensure_unicode_on_send_json(
47 test_client_factory: TestClientFactory,
48) -> None:
49 async def app(scope: Scope, receive: Receive, send: Send) -> None:
50 websocket = WebSocket(scope, receive=receive, send=send)
51
52 await websocket.accept()
53 message = await websocket.receive_json(mode="text")
54 await websocket.send_json(message, mode="text")
55 await websocket.close()
56
57 client = test_client_factory(app)
58 with client.websocket_connect("/123?a=abc") as websocket:
59 websocket.send_json({"test": "数据"}, mode="text")
60 data = websocket.receive_text()
61 assert data == '{"test":"数据"}'
62
63
64def test_websocket_query_params(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 4

send_jsonMethod · 0.95
receive_textMethod · 0.95
test_client_factoryFunction · 0.85
websocket_connectMethod · 0.80

Tested by

no test coverage detected