Example #1
0
    def test_purges_fails(self, monkeypatch, exception_type):
        exc = exception_type()

        class Cache:
            @staticmethod
            @pretend.call_recorder
            def purge(key):
                raise exc

        class Task:
            @staticmethod
            @pretend.call_recorder
            def retry(exc):
                raise celery.exceptions.Retry

        task = Task()
        service = Cache()
        request = pretend.stub(
            find_service=pretend.call_recorder(lambda iface: service),
            log=pretend.stub(
                info=pretend.call_recorder(lambda *args, **kwargs: None),
                error=pretend.call_recorder(lambda *args, **kwargs: None),
            ),
        )

        with pytest.raises(celery.exceptions.Retry):
            services.purge_tag(task, request, "foo")

        assert request.find_service.calls == [pretend.call(IXMLRPCCache)]
        assert service.purge.calls == [pretend.call("foo")]
        assert task.retry.calls == [pretend.call(exc=exc)]
        assert request.log.info.calls == [pretend.call("Purging %s", "foo")]
        assert request.log.error.calls == [
            pretend.call("Error purging %s: %s", "foo", str(exception_type()))
        ]
Example #2
0
    def test_purges_fails(self, monkeypatch, exception_type):
        exc = exception_type()

        class Cache:
            @staticmethod
            @pretend.call_recorder
            def purge(key):
                raise exc

        class Task:
            @staticmethod
            @pretend.call_recorder
            def retry(exc):
                raise celery.exceptions.Retry

        task = Task()
        service = Cache()
        request = pretend.stub(
            find_service=pretend.call_recorder(lambda iface: service),
            log=pretend.stub(
                info=pretend.call_recorder(lambda *args, **kwargs: None),
                error=pretend.call_recorder(lambda *args, **kwargs: None),
            ),
        )

        with pytest.raises(celery.exceptions.Retry):
            services.purge_tag(task, request, "foo")

        assert request.find_service.calls == [pretend.call(IXMLRPCCache)]
        assert service.purge.calls == [pretend.call("foo")]
        assert task.retry.calls == [pretend.call(exc=exc)]
        assert request.log.info.calls == [pretend.call("Purging %s", "foo")]
        assert request.log.error.calls == [
            pretend.call("Error purging %s: %s", "foo", str(exception_type()))
        ]
Example #3
0
    def test_purges_successfully(self, monkeypatch):
        task = pretend.stub()
        service = pretend.stub(purge=pretend.call_recorder(lambda k: None))
        request = pretend.stub(
            find_service=pretend.call_recorder(lambda iface: service),
            log=pretend.stub(info=pretend.call_recorder(lambda *args, **kwargs: None)),
        )

        services.purge_tag(task, request, "foo")

        assert request.find_service.calls == [pretend.call(IXMLRPCCache)]
        assert service.purge.calls == [pretend.call("foo")]
        assert request.log.info.calls == [pretend.call("Purging %s", "foo")]
Example #4
0
    def test_purges_successfully(self, monkeypatch):
        task = pretend.stub()
        service = pretend.stub(purge=pretend.call_recorder(lambda k: None))
        request = pretend.stub(
            find_service=pretend.call_recorder(lambda iface: service),
            log=pretend.stub(info=pretend.call_recorder(lambda *args, **kwargs: None)),
        )

        services.purge_tag(task, request, "foo")

        assert request.find_service.calls == [pretend.call(IXMLRPCCache)]
        assert service.purge.calls == [pretend.call("foo")]
        assert request.log.info.calls == [pretend.call("Purging %s", "foo")]