def test_peername_return_str_when_connection_was_made( self, transport: Mock) -> None: server = WebSocketServer() server.connection_made(transport) assert server.peername == "test-peer"
def test_connection_lost_transport_and_future_are_none(self) -> None: server = WebSocketServer() server.connection_lost(Exception()) assert server._future is None assert server.transport is None
def test_data_received_initialised(self) -> None: server = WebSocketServer() server.initialised = True with patch.object(server, "finalise_handshake") as mock_finalise_handshake: server.data_received(b"12345") mock_finalise_handshake.assert_not_called()
def test_connection_made(self, transport: Mock) -> None: server = WebSocketServer() server.connection_made(transport) assert server.initialised is False assert server.transport == transport assert server._future is None
def test_data_received_not_initialised(self) -> None: server = WebSocketServer() server.initialised = False data = b"12345" with patch.object(server, "finalise_handshake") as mock_finalise_handshake: server.data_received(data) mock_finalise_handshake.assert_called_once_with(data)
def test_finalise_handshake(self, handshake_response: Mock, transport: Mock) -> None: server = WebSocketServer() server.transport = transport server.finalise_handshake(b"12345") assert server.initialised is True transport.write.assert_called_once_with(handshake_response)
def test_connection_lost(self, future: Mock, transport: Mock) -> None: server = WebSocketServer() server._future = future server.transport = transport server.connection_lost(Exception()) future.cancel.assert_called_once() transport.close.assert_called_once()
def test_finalise_handshake_when_transport_is_none(self) -> None: server = WebSocketServer() server.finalise_handshake(b"12345") assert server.initialised is False
def test_peername_return_none(self) -> None: server = WebSocketServer() assert server.peername is None