예제 #1
0
    def test_correct_callback_called(self):
        socket = Mock()
        data = service_call.encode_call('bar', [10])
        socket.recv = Mock(return_value=data)

        service_call.handle_connection(self.handlers, socket)
        self.handlers['bar'].assert_any_call([10])
예제 #2
0
    def test_correct_callback_called(self):
        socket = Mock()
        data = service_call.encode_call('bar', [10])
        socket.recv = Mock(return_value=data)

        service_call.handle_connection(self.handlers, socket)
        self.handlers['bar'].assert_any_call([10])
예제 #3
0
    def test_decoding_method(self):
        """
        Checks that we can decode a method.
        """
        data = service_call.encode_call("foo", [42])
        name, params = service_call.decode_call(data)

        self.assertEqual(name, "foo")
        self.assertEqual(params, [42])
예제 #4
0
    def test_float_single_precision(self):
        """
        Checks that floats are single precision.
        """
        data = service_call.encode_call("foo", 1. + 1e-8)
        name, args = service_call.decode_call(data)

        # Check that we have the marker for single precision float
        self.assertEqual(1., args)
예제 #5
0
    def test_decoding_method(self):
        """
        Checks that we can decode a method.
        """
        data = service_call.encode_call("foo", [42])
        name, params = service_call.decode_call(data)

        self.assertEqual(name, "foo")
        self.assertEqual(params, [42])
예제 #6
0
    def test_float_single_precision(self):
        """
        Checks that floats are single precision.
        """
        data = service_call.encode_call("foo", 1. + 1e-8)
        name, args = service_call.decode_call(data)

        # Check that we have the marker for single precision float
        self.assertEqual(1., args)
예제 #7
0
    def test_float_single_precision(self):
        """
        Checks that floats are single precision.
        """
        data = service_call.encode_call("foo", [1.])
        data = serial_datagram.decode(data)

        # Check that we have the marker for single precision float
        self.assertEqual(data[1 + 3 + 1], 0xca)
예제 #8
0
    def test_callback_writeback(self):
        socket = Mock()
        self.handlers['bar'].return_value = 1
        data = service_call.encode_call('bar', [10])
        socket.recv = Mock(return_value=data)

        service_call.handle_connection(self.handlers, socket)

        expected_data = msgpack.packb(1)
        socket.send.assert_any_call(expected_data)
예제 #9
0
    def test_callback_writeback(self):
        socket = Mock()
        self.handlers['bar'].return_value = 1
        data = service_call.encode_call('bar', [10])
        socket.recv = Mock(return_value=data)

        service_call.handle_connection(self.handlers, socket)

        expected_data = msgpack.packb(1)
        socket.send.assert_any_call(expected_data)
예제 #10
0
    def test_encoding_method_name(self):
        """
        Checks that encoding method works as expected.
        """
        data = service_call.encode_call("foo", [1, 2, 3])
        data = serial_datagram.decode(data)

        u = msgpack.Unpacker(encoding='ascii')
        u.feed(data)
        command = next(u)

        self.assertEqual(command, ['foo', [1, 2, 3]])
예제 #11
0
    def test_multiple_segments(self):
        """
        This tests checks what happens if the data is split between several TCP
        MSS (recv does not return all data in one piece.
        """
        socket = Mock()
        data = service_call.encode_call('bar', [10])
        socket.recv = Mock()
        socket.recv.side_effect = [data[:3], data[3:]]

        service_call.handle_connection(self.handlers, socket)
        self.handlers['bar'].assert_any_call([10])
예제 #12
0
    def test_encoding_method_name(self):
        """
        Checks that encoding method works as expected.
        """
        data = service_call.encode_call("foo", [1, 2, 3])
        data = serial_datagram.decode(data)

        u = msgpack.Unpacker(encoding='ascii')
        u.feed(data)
        command = next(u)

        self.assertEqual(command, ['foo', [1, 2, 3]])
예제 #13
0
    def test_multiple_segments(self):
        """
        This tests checks what happens if the data is split between several TCP
        MSS (recv does not return all data in one piece.
        """
        socket = Mock()
        data = service_call.encode_call('bar', [10])
        socket.recv = Mock()
        socket.recv.side_effect = [data[:3], data[3:]]

        service_call.handle_connection(self.handlers, socket)
        self.handlers['bar'].assert_any_call([10])
예제 #14
0
    def test_service_call(self, create_connection):
        """
        Check that we correctly send the call.
        """
        create_connection.return_value = Mock()
        create_connection.return_value.recv = Mock(return_value=b'')

        adress = ('127.0.0.1', 20001)
        method_name = 'foo'
        method_params = [12]

        expected_data = service_call.encode_call(method_name, method_params)

        service_call.call(adress, method_name, method_params)

        create_connection.assert_any_call(adress)
        create_connection.return_value.sendall.assert_any_call(expected_data)
예제 #15
0
    def test_service_call(self, create_connection):
        """
        Check that we correctly send the call.
        """
        create_connection.return_value = Mock()
        create_connection.return_value.recv = Mock(
            return_value=msgpack.packb(None))

        adress = ('127.0.0.1', 20001)
        method_name = 'foo'
        method_params = [12]

        expected_data = service_call.encode_call(method_name, method_params)

        service_call.call(adress, method_name, method_params)

        create_connection.assert_any_call(adress)
        create_connection.return_value.sendall.assert_any_call(expected_data)