def checkMessage(self, msg, **kwargs): """ Ensures that the supplied msg is formatted as a onStatus invoke. @param msg: The L{message.IMessage} to check. @param kwargs: Optional parameters to check. Valid keys are 'command', 'level, 'code', 'description' and 'extra'. """ sentinel = object() def check(a, b): c = kwargs.pop(b, sentinel) if c is sentinel: return self.assertEqual(a, c) self.assertTrue(message.typeByClass(msg), message.Invoke) self.assertEqual(msg.name, 'onStatus') self.assertEqual(msg.id, 0) cmd, s = msg.argv check(cmd, 'command') check(s.level, 'level') check(s.code, 'code') check(s.description, 'description') check(s.getExtraContext(), 'extra') # sanity check self.assertEqual(kwargs, {}, msg='improper use of checkMessage')
def test_command_callback(self): """ Test a command result and the message that is generated. """ ret = yield self.makeCall('command_result') self.assertEqual(ret, 'foo') m = self.messages self.assertEqual(len(m), 1) msg = self.messages.pop() self.assertTrue(message.typeByClass(msg), message.Invoke) self.assertEqual(msg.name, '_result') self.assertEqual(msg.argv, [{'one': 'two'}, 'foo']) self.assertEqual(msg.id, 2)
def test_successful_call(self): """ Test a successful RPC call. """ ret = yield self.makeCall('known_return') self.assertEqual(ret, 'foo') m = self.messages self.assertEqual(len(m), 1) msg = self.messages.pop() self.assertTrue(message.typeByClass(msg), message.Invoke) self.assertEqual(msg.name, '_result') self.assertEqual(msg.argv, [None, 'foo']) self.assertEqual(msg.id, 2)
def test_successful_call(self): """ Test a successful RPC call. """ ret = yield self.makeCall('known_return') self.assertEqual(ret, 'foo') m = self.messages self.assertEqual(len(m), 1) msg = self.messages.pop() self.assertTrue(message.typeByClass(msg), message.Invoke) self.assertEqual(msg.name, '_result') self.assertEqual(msg.argv, [None, 'foo']) self.assertEqual(msg.id, 1)
def test_command_callback(self): """ Test a command result and the message that is generated. """ ret = yield self.makeCall('command_result') self.assertEqual(ret, 'foo') m = self.messages self.assertEqual(len(m), 1) msg = self.messages.pop() self.assertTrue(message.typeByClass(msg), message.Invoke) self.assertEqual(msg.name, '_result') self.assertEqual(msg.argv, [{'one': 'two'}, 'foo']) self.assertEqual(msg.id, 1)
def test_call_command(self): """ Ensure L{execute} accepts a C{command} kwarg and that it is set on the message appropriately. """ cmd = {'foo': 'bar'} i, m = self.invoker, self.messages ret = i.call('remote_method', command=cmd) self.assertEqual(ret, None) self.assertEqual(len(m), 1) msg = m.pop() self.assertEqual(message.typeByClass(msg), message.INVOKE) self.assertEqual(msg.id, 0) self.assertEqual(msg.name, 'remote_method') self.assertEqual(msg.argv, [cmd])
def test_call_message(self): """ Check the context of the message sent when L{callWithoutResult} is executed. """ i = self.invoker m = self.messages ret = i.call('remote_method', 1, 2, 3, 'foo') self.assertEqual(ret, None) self.assertEqual(len(m), 1) msg = m.pop() self.assertEqual(message.typeByClass(msg), message.INVOKE) self.assertEqual(msg.id, 0) self.assertEqual(msg.name, 'remote_method') self.assertEqual(msg.argv, [None, 1, 2, 3, 'foo'])
def test_command(self): """ Ensure L{call} accepts a C{command} kwarg and that it is set on the sent message appropriately. """ cmd = {'foo': 'bar'} i, m = self.invoker, self.messages d = i.call('remote_method', command=cmd, notify=True) self.assertTrue(isinstance(d, defer.Deferred)) self.assertEqual(len(m), 1) msg = m.pop() self.assertEqual(message.typeByClass(msg), message.INVOKE) self.assertEqual(msg.id, 1) self.assertEqual(msg.name, 'remote_method') self.assertEqual(msg.argv, [cmd]) callContext = i.getCallContext(msg.id) self.assertEqual(callContext, (d, 'remote_method', (), cmd))
def test_command(self): """ Ensure L{call} accepts a C{command} kwarg and that it is set on the sent message appropriately. """ cmd = {'foo': 'bar'} i, m = self.invoker, self.messages d = i.call('remote_method', command=cmd, notify=True) self.assertTrue(isinstance(d, defer.Deferred)) self.assertEqual(len(m), 1) msg = m.pop() self.assertEqual(message.typeByClass(msg), message.INVOKE) self.assertEqual(msg.id, 2) self.assertEqual(msg.name, 'remote_method') self.assertEqual(msg.argv, [cmd]) callContext = i.getCallContext(msg.id) self.assertEqual(callContext, (d, 'remote_method', (), cmd))
def test_call(self): """ Check the context of the message sent when L{call} is executed. """ i = self.invoker m = self.messages d = i.call('remote_method', 1, 2, 3, 'foo', notify=True) self.assertTrue(isinstance(d, defer.Deferred)) self.assertEqual(len(m), 1) msg = m.pop() self.assertEqual(message.typeByClass(msg), message.INVOKE) self.assertEqual(msg.id, 2) self.assertEqual(msg.name, 'remote_method') self.assertEqual(msg.argv, [None, 1, 2, 3, 'foo']) callContext = i.getCallContext(msg.id) self.assertEqual(callContext, (d, 'remote_method', (1, 2, 3, 'foo'), None))
def test_call(self): """ Check the context of the message sent when L{call} is executed. """ i = self.invoker m = self.messages d = i.call('remote_method', 1, 2, 3, 'foo', notify=True) self.assertTrue(isinstance(d, defer.Deferred)) self.assertEqual(len(m), 1) msg = m.pop() self.assertEqual(message.typeByClass(msg), message.INVOKE) self.assertEqual(msg.id, 1) self.assertEqual(msg.name, 'remote_method') self.assertEqual(msg.argv, [None, 1, 2, 3, 'foo']) callContext = i.getCallContext(msg.id) self.assertEqual(callContext, (d, 'remote_method', (1, 2, 3, 'foo'), None))
self.receiver.initiateCall(callId=callId) try: yield self.makeCall('foo', callId) except exc.CallFailed, e: pass else: self.fail('exc.CallFailed not raised') self.assertEqual(str(e), 'Unable to initiate an already active call 2') m = self.messages self.assertEqual(len(m), 1) msg = self.messages.pop() self.assertTrue(message.typeByClass(msg), message.Invoke) self.assertEqual(msg.name, '_error') self.assertEqual(msg.argv, [None, { 'code': 'NetConnection.Call.Failed', 'description': 'Unable to initiate an already active call 2', 'level': 'error' }]) self.assertEqual(msg.id, callId) @defer.inlineCallbacks def test_call_exposed(self): """ Call an exposed method on the faciliator. """ ret = yield self.receiver.callExposedMethod('exposed', 1, 2, 3)
self.receiver.initiateCall(callId=callId) try: yield self.makeCall('foo', callId) except exc.CallFailed, e: pass else: self.fail('exc.CallFailed not raised') self.assertEqual(str(e), 'Unable to initiate an already active call 1') m = self.messages self.assertEqual(len(m), 1) msg = self.messages.pop() self.assertTrue(message.typeByClass(msg), message.Invoke) self.assertEqual(msg.name, '_error') self.assertEqual(msg.argv, [ None, { 'code': 'NetConnection.Call.Failed', 'description': 'Unable to initiate an already active call 1', 'level': 'error' } ]) self.assertEqual(msg.id, callId) @defer.inlineCallbacks def test_call_exposed(self): """ Call an exposed method on the faciliator. """