Example #1
0
    def test_consume(self):
        """The consume helper should direct all incoming messages matching the
        specified routing_key, queue_name & exchange to the given callback"""

        message = fake_amq_message({"key": "value"})
        worker = get_stubbed_worker(Worker)

        # buffer to check messages consumed
        log = [Message.from_json(message.content.body)]
        # consume all messages on the given routing key and append
        # them to the log
        worker.consume('test.routing.key', lambda msg: log.append(msg))
        # if all works well then the consume method should funnel the test
        # message straight to the callback, the callback will apend it to the
        # log and we can test it.
        worker._amqp_client.broker.basic_publish('vumi', 'test.routing.key',
                                                 message.content)
        self.assertEquals(log, [Message(key="value")])