Ejemplo n.º 1
0
    def test_can_ack_messages(self):

        raw_message = amqp.Message(
            ProfileRequest(0, '', '').json(),
            content_type='application/json',
        )
        self._channel.basic_publish(raw_message, routing_key=self._test_id)

        trans = AmqpTransport(
            host='localhost',
            username='******',
            password='******',
            queue=self._test_id,
        )

        message = trans.fetch()
        trans.complete(message)

        self.assertTrue(trans.fetch() is None)
Ejemplo n.º 2
0
    def test_can_ack_messages(self):

        raw_message = amqp.Message(
            ProfileRequest(0, '', '').json(),
            content_type='application/json',
        )
        self._channel.basic_publish(raw_message, routing_key=self._test_id)

        trans = AmqpTransport(
            host='localhost',
            username='******',
            password='******',
            queue=self._test_id,
        )

        message = trans.fetch()
        trans.complete(message)

        self.assertTrue(trans.fetch() is None)
Ejemplo n.º 3
0
    def test_raises_value_error_on_unknown_message(self):

        raw_message = amqp.Message(
            '{"fake": true}',
            content_type='application/json',
        )
        self._channel.basic_publish(raw_message, routing_key=self._test_id)

        trans = AmqpTransport(
            host='localhost',
            username='******',
            password='******',
            queue=self._test_id,
        )

        with self.assertRaises(ValueError):

            trans.fetch()

        # Close the connection and force requeue of the message.
        trans.close()

        raw_message = self._channel.basic_get(self._test_id)
        self._channel.basic_ack(raw_message.delivery_tag)
Ejemplo n.º 4
0
    def test_raises_value_error_on_unknown_message(self):

        raw_message = amqp.Message(
            '{"fake": true}',
            content_type='application/json',
        )
        self._channel.basic_publish(raw_message, routing_key=self._test_id)

        trans = AmqpTransport(
            host='localhost',
            username='******',
            password='******',
            queue=self._test_id,
        )

        with self.assertRaises(ValueError):

            trans.fetch()

        # Close the connection and force requeue of the message.
        trans.close()

        raw_message = self._channel.basic_get(self._test_id)
        self._channel.basic_ack(raw_message.delivery_tag)
Ejemplo n.º 5
0
    def test_can_fetch_message_from_queue(self):

        secret = str(uuid.uuid4())

        raw_message = amqp.Message(
            ProfileRequest(0, secret, secret).json(),
            content_type='application/json',
        )
        self._channel.basic_publish(raw_message, routing_key=self._test_id)

        trans = AmqpTransport(
            host='localhost',
            username='******',
            password='******',
            queue=self._test_id,
        )

        message = trans.fetch()
        self.assertTrue(message.code == secret)
        self._channel.basic_ack(trans._message_map[message].delivery_tag)
Ejemplo n.º 6
0
    def test_can_fetch_message_from_queue(self):

        secret = str(uuid.uuid4())

        raw_message = amqp.Message(
            ProfileRequest(0, secret, secret).json(),
            content_type='application/json',
        )
        self._channel.basic_publish(raw_message, routing_key=self._test_id)

        trans = AmqpTransport(
            host='localhost',
            username='******',
            password='******',
            queue=self._test_id,
        )

        message = trans.fetch()
        self.assertTrue(message.code == secret)
        self._channel.basic_ack(trans._message_map[message].delivery_tag)