예제 #1
0
 def test_signal_task_received(self):
     callback = Mock()
     with self._context(self.add.s(2, 2)) as C:
         signals.task_received.connect(callback)
         C()
         callback.assert_called_once_with(sender=C.consumer,
                                          request=ANY,
                                          signal=signals.task_received)
예제 #2
0
 def test_call_ignore_result(self):
     fun = Mock(name='fun')
     callback = Mock(name='callback')
     a = promise(fun=fun, ignore_result=True)
     a.then(callback)
     a()
     fun.assert_called_once_with()
     callback.assert_called_once_with()
예제 #3
0
파일: test_rmq.py 프로젝트: celery/py-amqp
    def test_publish_consume(self, publish_method, mandatory, immediate):
        callback = Mock()
        self.channel.queue_declare(
            queue='py-amqp-unittest', durable=False, exclusive=True
        )
        # RabbitMQ 3 removed the support for the immediate flag
        # Since we confirm the message, RabbitMQ complains
        # See
        # http://www.rabbitmq.com/blog/2012/11/19/breaking-things-with-rabbitmq-3-0/
        if immediate and publish_method == "basic_publish_confirm":
            with pytest.raises(amqp.exceptions.AMQPNotImplementedError) as exc:
                getattr(self.channel, publish_method)(
                    amqp.Message('Unittest'),
                    routing_key='py-amqp-unittest',
                    mandatory=mandatory,
                    immediate=immediate
                )

            assert exc.value.reply_code == 540
            assert exc.value.method_name == 'Basic.publish'
            assert exc.value.reply_text == 'NOT_IMPLEMENTED - immediate=true'

            return
        else:
            getattr(self.channel, publish_method)(
                amqp.Message('Unittest'),
                routing_key='py-amqp-unittest',
                mandatory=mandatory,
                immediate=immediate
            )
        # RabbitMQ 3 removed the support for the immediate flag
        # See
        # http://www.rabbitmq.com/blog/2012/11/19/breaking-things-with-rabbitmq-3-0/
        if immediate:
            with pytest.raises(amqp.exceptions.AMQPNotImplementedError) as exc:
                self.channel.basic_consume(
                    queue='py-amqp-unittest',
                    callback=callback,
                    consumer_tag='amq.ctag-PCmzXGkhCw_v0Zq7jXyvkg'
                )
            assert exc.value.reply_code == 540
            assert exc.value.method_name == 'Basic.publish'
            assert exc.value.reply_text == 'NOT_IMPLEMENTED - immediate=true'

            return
        else:
            self.channel.basic_consume(
                queue='py-amqp-unittest',
                callback=callback,
                consumer_tag='amq.ctag-PCmzXGkhCw_v0Zq7jXyvkg'
            )
        self.connection.drain_events()
        callback.assert_called_once_with(ANY)
        msg = callback.call_args[0][0]
        assert isinstance(msg, amqp.Message)
        assert msg.body_size == len('Unittest')
        assert msg.body == 'Unittest'
        assert msg.frame_method == amqp.spec.Basic.Deliver
        assert msg.delivery_tag == 1
        assert msg.ready is True
        assert msg.delivery_info == {
            'consumer_tag': 'amq.ctag-PCmzXGkhCw_v0Zq7jXyvkg',
            'delivery_tag': 1,
            'redelivered': False,
            'exchange': '',
            'routing_key': 'py-amqp-unittest'
        }
        assert msg.properties == {'content_encoding': 'utf-8'}

        self.channel.basic_ack(msg.delivery_tag)
예제 #4
0
 def test_call_ignore_result_callback_kwarg(self):
     fun = Mock(name='fun')
     callback = Mock(name='callback')
     a = promise(fun=fun, ignore_result=True, callback=callback)
     a()
     callback.assert_called_once_with()
예제 #5
0
 def test_signal_callback_kwargs(self):
     callback = Mock(name='callback')
     a = promise(callback=callback)
     a(42)
     callback.assert_called_once_with(42)
예제 #6
0
 def test_signal(self):
     callback = Mock(name='callback')
     a = promise()
     a.then(callback)
     a(42)
     callback.assert_called_once_with(42)