def test_send(self): # Send auto ACK response = rpc.RPCResponse(self.connection, 'addTwo', '123') self.io_loop.call_later(1, self.stop) self.wait() self.handler.assert_called_with(msg('P|A|REQ|addTwo|123+')) # Send response response.send(14) self.handler.assert_called_with(msg('P|RES|addTwo|123|N14+'))
def test_send_no_autoack(self): # Create response but disable autoack response = rpc.RPCResponse(self.connection, 'addTwo', '123') response.auto_ack = False self.handler.assert_not_called() # Send the ack response.ack() self.handler.assert_called_with(msg('P|A|REQ|addTwo|123+')) # Do not send multiple ack messages self.handler.reset_mock() response.ack() self.handler.assert_not_called()
def test_error(self): response = rpc.RPCResponse(self.connection, 'addTwo', '123') response.error('Error message') self.handler.assert_called_with(msg('P|E|Error message|addTwo|123+')) self.assertRaises(ValueError, functools.partial(response.send, 'abc'))
def test_reject(self): response = rpc.RPCResponse(self.connection, 'addTwo', '123') response.reject() self.handler.assert_called_with(msg('P|REJ|addTwo|123+')) self.assertRaises(ValueError, functools.partial(response.send, 'abc'))