Exemple #1
0
    def test_peername_return_str_when_connection_was_made(
            self, transport: Mock) -> None:
        server = WebSocketServer()

        server.connection_made(transport)

        assert server.peername == "test-peer"
Exemple #2
0
    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
Exemple #3
0
    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()
Exemple #4
0
    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
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
    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()
Exemple #8
0
    def test_finalise_handshake_when_transport_is_none(self) -> None:
        server = WebSocketServer()

        server.finalise_handshake(b"12345")

        assert server.initialised is False
Exemple #9
0
    def test_peername_return_none(self) -> None:
        server = WebSocketServer()

        assert server.peername is None