Ejemplo n.º 1
0
    def test_send_reply(self):
        req = Mock()
        req.content_type = 'application/json'
        req.content_encoding = 'binary'
        req.properties = {'reply_to': 'hello',
                          'correlation_id': 'world'}
        channel = Mock()
        exchange = Mock()
        exchange.is_bound = True
        exchange.channel = channel
        producer = Mock()
        producer.channel = channel
        producer.channel.connection.client.declared_entities = set()
        send_reply(exchange, req, {'hello': 'world'}, producer)

        assert producer.publish.call_count
        args = producer.publish.call_args
        assert args[0][0] == {'hello': 'world'}
        assert args[1] == {
            'exchange': exchange,
            'routing_key': 'hello',
            'correlation_id': 'world',
            'serializer': 'json',
            'retry': False,
            'retry_policy': None,
            'content_encoding': 'binary',
        }
Ejemplo n.º 2
0
 def test_release(self):
     p = Mock()
     p.channel = Mock()
     p.__connection__ = Mock()
     self.pool.release(p)
     p.__connection__.release.assert_called_with()
     assert p.channel is None
Ejemplo n.º 3
0
    def test_with_retry(self):
        channel = Mock()
        client = channel.connection.client = Mock()
        client.declared_entities = set()
        entity = Mock()
        entity.can_cache_declaration = True
        entity.is_bound = True
        entity.channel = channel

        maybe_declare(entity, channel, retry=True)
        assert channel.connection.client.ensure.call_count
Ejemplo n.º 4
0
    def test_cacheable(self):
        channel = Mock()
        client = channel.connection.client = Mock()
        client.declared_entities = set()
        entity = Mock()
        entity.can_cache_declaration = True
        entity.auto_delete = False
        entity.is_bound = True
        entity.channel = channel

        maybe_declare(entity, channel)
        assert entity.declare.call_count == 1
        assert hash(entity) in channel.connection.client.declared_entities

        maybe_declare(entity, channel)
        assert entity.declare.call_count == 1

        entity.channel.connection = None
        with pytest.raises(RecoverableConnectionError):
            maybe_declare(entity)