Exemplo n.º 1
0
    def test_when_receiving_a_message_then_message_length_and_encoding_is_received(
            self) -> None:
        message_data = self.test_message.encode()
        self.socket.recv.side_effect = [
            struct.pack('!I', len(message_data)), message_data
        ]

        self.socket_connection.recv_msg()

        calls = self.socket.method_calls
        expected_calls = [call.recv(4), call.recv(len(message_data))]
        self.assertListEqual(expected_calls, calls)
Exemplo n.º 2
0
    def test_too_many(self):
        source = unittest.mock.MagicMock()
        dest = unittest.mock.MagicMock()
        source.recv.side_effect = b'fubar'

        OneWayThread(source, dest, limit=2).run()

        source.sendall.assert_has_calls = [call.recv(4096), \
            call.recv(4096), call.close()]
        dest.sendall.assert_has_calls = [ \
            call.sendall('f'), \
            call.sendall('u'), \
            call.close()]
Exemplo n.º 3
0
    def test_too_many(self):
        source = unittest.mock.MagicMock()
        dest = unittest.mock.MagicMock()
        source.recv.side_effect = b'fubar'

        OneWayThread(source, dest, limit=2).run()

        source.sendall.assert_has_calls = [call.recv(4096), \
            call.recv(4096), call.close()]
        dest.sendall.assert_has_calls = [ \
            call.sendall('f'), \
            call.sendall('u'), \
            call.close()]
Exemplo n.º 4
0
    def test_no_data(self):
        source = unittest.mock.Mock()
        dest = unittest.mock.Mock()
        source.recv.side_effect = ""

        OneWayThread(source, dest).run()

        source.sendall.assert_has_calls = [call.recv(4096), call.close()]
        dest.sendall.assert_has_calls = [call.close()]
Exemplo n.º 5
0
    def test_no_data(self):
        source = unittest.mock.Mock()
        dest = unittest.mock.Mock()
        source.recv.side_effect = ""

        OneWayThread(source, dest).run()

        source.sendall.assert_has_calls = [call.recv(4096), call.close()]
        dest.sendall.assert_has_calls = [call.close()]
Exemplo n.º 6
0
    def test_simple_data(self):
        source = unittest.mock.Mock()
        dest = unittest.mock.Mock()
        source.recv.side_effect = b'fubar'

        OneWayThread(source, dest).run()

        source.sendall.assert_has_calls = [call.recv(4096), call.close()]
        dest.sendall.assert_has_calls = [ \
            call.sendall('f'), \
            call.sendall('u'), \
            call.sendall('b'), \
            call.sendall('a'), \
            call.sendall('r'), \
            call.close()]
Exemplo n.º 7
0
    def test_simple_data(self):
        source = unittest.mock.Mock()
        dest = unittest.mock.Mock()
        source.recv.side_effect = b'fubar'

        OneWayThread(source, dest).run()

        source.sendall.assert_has_calls = [call.recv(4096), call.close()]
        dest.sendall.assert_has_calls = [ \
            call.sendall('f'), \
            call.sendall('u'), \
            call.sendall('b'), \
            call.sendall('a'), \
            call.sendall('r'), \
            call.close()]
Exemplo n.º 8
0
def sent_recved(sent):
    return [call.send(sent), call.recv()]