MCPcopy Index your code
hub / github.com/python-websockets/websockets / alter_and_receive_response

Function alter_and_receive_response

tests/test_client.py:303–324  ·  view source on GitHub ↗

Generate a handshake response that can be altered for testing.

(client)

Source from the content-addressed store, hash-verified

301
302@contextlib.contextmanager
303def alter_and_receive_response(client):
304 """Generate a handshake response that can be altered for testing."""
305 # We could start by sending a handshake request, i.e.:
306 # request = client.connect()
307 # client.send_request(request)
308 # However, in the current implementation, these calls have no effect on the
309 # state of the client. Therefore, they're unnecessary and can be skipped.
310 response = Response(
311 status_code=101,
312 reason_phrase="Switching Protocols",
313 headers=Headers(
314 {
315 "Upgrade": "websocket",
316 "Connection": "Upgrade",
317 "Sec-WebSocket-Accept": accept_key(client.key),
318 }
319 ),
320 )
321 yield response
322 client.receive_data(response.serialize())
323 [parsed_response] = client.events_received()
324 assert response == dataclasses.replace(parsed_response, _exception=None)
325
326
327class HandshakeTests(unittest.TestCase):

Callers 15

test_basicMethod · 0.85
test_missing_upgradeMethod · 0.85
test_invalid_upgradeMethod · 0.85
test_missing_acceptMethod · 0.85
test_multiple_acceptMethod · 0.85
test_invalid_acceptMethod · 0.85
test_no_extensionsMethod · 0.85
test_enable_extensionMethod · 0.85

Calls 6

serializeMethod · 0.95
ResponseClass · 0.90
HeadersClass · 0.90
accept_keyFunction · 0.90
receive_dataMethod · 0.80
events_receivedMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…