예제 #1
0
 def test_string_received(self):
     """
     Ensure the string_received method works as expected.
     """
     transport = mock.MagicMock()
     addr = ('192.168.0.1', 9999)
     transport.get_extra_info = mock.MagicMock(return_value=addr)
     connector = mock.MagicMock()
     connector.receive = mock.MagicMock()
     node = mock.MagicMock()
     p = NetstringProtocol(connector, node)
     p.connection_made(transport)
     p.string_received('hello world')
     connector.receive.assert_called_once_with('hello world', '192.168.0.1',
                                               node, p)
예제 #2
0
 def test_data_received_containing_weird_unicode(self):
     """
     Ensure the netstring is re-constructed correctly if it contains weird
     unicode characters and a non-obvious length.
     """
     p = NetstringProtocol('foo', 'bar')
     p.connection_made(mock.MagicMock())
     p.string_received = mock.MagicMock()
     p.data_received('15:zɐq ɹɐq ooɟ,'.encode('utf-8'))
     p.string_received.assert_called_once_with('zɐq ɹɐq ooɟ')
예제 #3
0
 def test_data_received_in_chunks(self):
     """
     Ensure the netstring is re-constructed correctly if it is received
     over several calls to data_received (i.e. ensure the FSM is working).
     """
     p = NetstringProtocol('foo', 'bar')
     p.connection_made(mock.MagicMock())
     p.string_received = mock.MagicMock()
     p.data_received('11:hello '.encode('utf-8'))
     p.data_received('world,'.encode('utf-8'))
     p.string_received.assert_called_once_with('hello world')
예제 #4
0
 def test_data_received_more_data(self):
     """
     Ensure that sequences of netstring from the remote peer are correctly
     handled.
     """
     p = NetstringProtocol('foo', 'bar')
     p.connection_made(mock.MagicMock())
     p.string_received = mock.MagicMock()
     p.data_received('11:hello world,'.encode('utf-8'))
     p.data_received('11:hello world,'.encode('utf-8'))
     self.assertEqual(2, p.string_received.call_count)
예제 #5
0
    def test_data_received(self):
        """
        Ensure that good data results in the expected results:

        * No errors.
        * The correct call to string received.
        """
        p = NetstringProtocol('foo', 'bar')
        p.connection_made(mock.MagicMock())
        p.string_received = mock.MagicMock()
        p.data_received('11:hello world,'.encode('utf-8'))
        p.string_received.assert_called_once_with('hello world')