Generate a handshake response that can be altered for testing.
(client)
| 301 | |
| 302 | @contextlib.contextmanager |
| 303 | def 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 | |
| 327 | class HandshakeTests(unittest.TestCase): |
no test coverage detected
searching dependent graphs…