Server selects a subprotocol with the select_subprotocol callable.
(self)
| 70 | self.assertEval(client, "ws.protocol.state.name", "OPEN") |
| 71 | |
| 72 | def test_select_subprotocol(self): |
| 73 | """Server selects a subprotocol with the select_subprotocol callable.""" |
| 74 | |
| 75 | def select_subprotocol(ws, subprotocols): |
| 76 | ws.select_subprotocol_ran = True |
| 77 | assert "chat" in subprotocols |
| 78 | return "chat" |
| 79 | |
| 80 | with run_server( |
| 81 | subprotocols=["chat"], |
| 82 | select_subprotocol=select_subprotocol, |
| 83 | ) as server: |
| 84 | with connect(get_uri(server), subprotocols=["chat"]) as client: |
| 85 | self.assertEval(client, "ws.select_subprotocol_ran", "True") |
| 86 | self.assertEval(client, "ws.subprotocol", "chat") |
| 87 | |
| 88 | def test_select_subprotocol_rejects_handshake(self): |
| 89 | """Server rejects handshake if select_subprotocol raises NegotiationError.""" |
nothing calls this directly
no test coverage detected