def test_serve_expects_handler_for_given_route(self): self.setUpBind() self.socket.recv = mock.MagicMock(side_effect=results('route', 'msg')) z = Zmq(context=self.ctx) self.assertRaises(KeyError, z.serve) expected = [mock.call(), mock.call()] self.assertEqual(self.socket.recv.call_args_list, expected)
def test_serve_expects_zmq_messages_consisted_on_2_parts(self): self.setUpBind() c = mock.MagicMock(return_value=self.deferred) self.socket.recv = mock.MagicMock(side_effect=results('route', 'msg')) self.deferred.done = mock.MagicMock(side_effect=KeyboardInterrupt) z = Zmq(context=self.ctx) z.attach_listener('route', c) self.assertRaises(KeyboardInterrupt, z.serve) c.assert_called_once_with(IsA(str))
def test_serve_expects_deferred_instance_returned_from_handler(self): self.setUpBind() c = mock.MagicMock(return_value=self.deferred) self.socket.recv = mock.MagicMock(side_effect=results('route', 'msg', KeyboardInterrupt())) z = Zmq(context=self.ctx) z.attach_listener('route', c) self.assertRaises(KeyboardInterrupt, z.serve) c.assert_called_once_with(IsA(str)) self.deferred.done.assert_called_once_with(IsCallable())