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)
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
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())
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())
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)
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())
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())
def test_call_socket_timeout(self): client = RPCClient(HOST, PORT, timeout=0.1) client.call('echo_delayed', 'message', 1)
def test_open_only_port(self): RPCClient(port=PORT)
def test_open_only_host(self): RPCClient(HOST)
def test_open_no_hostport_no_unix_socket(self): RPCClient()