示例#1
0
    def test_call(self):
        client = RPCClient(HOST, PORT)

        ret = client.call('echo', 'message')
        eq_('message', ret)

        ret = client.call('echo', 'message' * 100)
        eq_('message' * 100, ret)
示例#2
0
    def test_call_server_side_exception(self):
        client = RPCClient(HOST, PORT)

        try:
            ret = client.call('raise_error')
        except RPCError, e:
            eq_('error msg', e.message)
            raise
示例#3
0
    def test_open_with_timeout(self, mock_socket):
        mock_socket_ins = Mock()
        mock_socket.create_connection.return_value = mock_socket_ins

        client = RPCClient(HOST, PORT, timeout=5.0)

        mock_socket_ins.settimeout.assert_called_once_with(5.0)
        ok_(client.is_connected())
示例#4
0
    def test_open_with_timeout(self, mock_socket):
        mock_socket_ins = Mock()
        mock_socket.create_connection.return_value = mock_socket_ins

        client = RPCClient(HOST, PORT, timeout=5.0)

        mock_socket_ins.settimeout.assert_called_once_with(5.0)
        ok_(client.is_connected())
示例#5
0
    def test_call(self):
        client = RPCClient(HOST, PORT)

        ret = client.call('echo', 'message')
        eq_('message', ret)

        ret = client.call('echo', 'message' * 100)
        eq_('message' * 100, ret)
示例#6
0
    def test_open_unix_socket_with_timeout(self, mock_socket):
        mock_socket_ins = Mock()
        mock_socket.socket.return_value = mock_socket_ins

        client = RPCClient(unix_socket_path=UNIX_SOCK_PATH, timeout=5.0)

        mock_socket_ins.settimeout.assert_called_once_with(5.0)
        ok_(client.is_connected())
示例#7
0
    def test_call_server_side_exception(self):
        client = RPCClient(HOST, PORT)

        try:
            ret = client.call('raise_error')
        except RPCError as e:
            eq_('error msg', str(e))
            raise

        eq_('message', ret)
示例#8
0
    def test_call_server_side_exception(self):
        client = RPCClient(HOST, PORT)

        try:
            ret = client.call('raise_error')
        except RPCError as e:
            eq_('error msg', str(e))
            raise

        eq_('message', ret)
示例#9
0
    def test_open_and_close(self, mock_socket):
        mock_socket_ins = Mock()
        mock_socket.create_connection.return_value = mock_socket_ins

        client = RPCClient(HOST, PORT)

        ok_(client.is_connected())

        mock_socket.create_connection.assert_called_once_with((HOST, PORT))

        client.close()

        ok_(mock_socket_ins.close.called)
        ok_(not client.is_connected())
示例#10
0
    def test_open_and_close(self, mock_socket):
        mock_socket_ins = Mock()
        mock_socket.create_connection.return_value = mock_socket_ins

        client = RPCClient(HOST, PORT)

        ok_(client.is_connected())

        mock_socket.create_connection.assert_called_once_with((HOST, PORT))

        client.close()

        ok_(mock_socket_ins.close.called)
        ok_(not client.is_connected())
示例#11
0
    def test_open_and_close_unix_socket(self, mock_socket):
        mock_socket_ins = Mock()
        mock_socket.socket.return_value = mock_socket_ins

        client = RPCClient(unix_socket_path=UNIX_SOCK_PATH)
        mock_socket.socket.assert_called_once_with(mock_socket.AF_UNIX, mock_socket.SOCK_STREAM)

        ok_(client.is_connected())

        mock_socket_ins.connect.assert_called_once_with(UNIX_SOCK_PATH)

        client.close()

        ok_(mock_socket_ins.close.called)
        ok_(not client.is_connected())
示例#12
0
    def test_call_socket_timeout(self):
        client = RPCClient(HOST, PORT, timeout=0.1)

        client.call('echo_delayed', 'message', 1)
示例#13
0
    def test_call_socket_timeout(self):
        client = RPCClient(HOST, PORT, timeout=0.1)

        client.call('echo_delayed', 'message', 1)
示例#14
0
 def test_open_only_port(self):
     RPCClient(port=PORT)
示例#15
0
 def test_open_only_host(self):
     RPCClient(HOST)
示例#16
0
 def test_open_no_hostport_no_unix_socket(self):
     RPCClient()