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

Function test_websocket_endpoint_on_receive_text

tests/test_endpoints.py:134–151  ·  tests/test_endpoints.py::test_websocket_endpoint_on_receive_text
(
    test_client_factory: TestClientFactory,
)

Source from the content-addressed store, hash-verified

132
133
134def test_websocket_endpoint_on_receive_text(
135 test_client_factory: TestClientFactory,
136) -> None:
137 class WebSocketApp(WebSocketEndpoint):
138 encoding = class="st">"text"
139
140 async def on_receive(self, websocket: WebSocket, data: str) -> None:
141 await websocket.send_text(fclass="st">"Message text was: {data}")
142
143 client = test_client_factory(WebSocketApp)
144 with client.websocket_connect(class="st">"/ws") as websocket:
145 websocket.send_text(class="st">"Hello, world!")
146 _text = websocket.receive_text()
147 assert _text == class="st">"Message text was: Hello, world!"
148
149 with pytest.raises(RuntimeError):
150 with client.websocket_connect(class="st">"/ws") as websocket:
151 websocket.send_bytes(bclass="st">"Hello world")
152
153
154def test_websocket_endpoint_on_default(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected