Пример #1
0
def test_execute_purge_no_backend():
    @pretend.call_recorder
    def find_service_factory(interface):
        raise ValueError

    config = pretend.stub(find_service_factory=find_service_factory)
    session = pretend.stub(info={
        "warehouse.cache.origin.purges": {"type_1", "type_2", "foobar"},
    }, )

    origin.execute_purge(config, session)

    assert find_service_factory.calls == [pretend.call(origin.IOriginCache)]
    assert "warehouse.cache.origin.purges" not in session.info
Пример #2
0
def test_execute_purge_success(app_config):
    cacher = pretend.stub(purge=pretend.call_recorder(lambda purges: None))
    factory = pretend.call_recorder(lambda ctx, config: cacher)
    app_config.register_service_factory(factory, IOriginCache)
    app_config.commit()
    session = pretend.stub(
        info={"warehouse.cache.origin.purges": {"type_1", "type_2", "foobar"}}
    )

    origin.execute_purge(app_config, session)

    assert factory.calls == [pretend.call(None, app_config)]
    assert cacher.purge.calls == [pretend.call({"type_1", "type_2", "foobar"})]
    assert "warehouse.cache.origin.purges" not in session.info
Пример #3
0
def test_execute_purge_no_backend():
    @pretend.call_recorder
    def find_service_factory(interface):
        raise LookupError

    config = pretend.stub(find_service_factory=find_service_factory)
    session = pretend.stub(
        info={"warehouse.cache.origin.purges": {"type_1", "type_2", "foobar"}}
    )

    origin.execute_purge(config, session)

    assert find_service_factory.calls == [pretend.call(origin.IOriginCache)]
    assert "warehouse.cache.origin.purges" not in session.info
Пример #4
0
def test_execute_purge_success(app_config):
    cacher = pretend.stub(purge=pretend.call_recorder(lambda purges: None))
    factory = pretend.call_recorder(lambda ctx, config: cacher)
    app_config.register_service_factory(factory, IOriginCache)
    app_config.commit()
    session = pretend.stub(
        info={"warehouse.cache.origin.purges": {"type_1", "type_2", "foobar"}}
    )

    origin.execute_purge(app_config, session)

    assert factory.calls == [pretend.call(None, app_config)]
    assert cacher.purge.calls == [pretend.call({"type_1", "type_2", "foobar"})]
    assert "warehouse.cache.origin.purges" not in session.info
Пример #5
0
def test_execute_purge_success():
    cacher = pretend.stub(purge=pretend.call_recorder(lambda purges: None))
    factory = pretend.call_recorder(lambda ctx, config: cacher)
    config = pretend.stub(
        find_service_factory=pretend.call_recorder(lambda i: factory), )
    session = pretend.stub(info={
        "warehouse.cache.origin.purges": {"type_1", "type_2", "foobar"},
    }, )

    origin.execute_purge(config, session)

    assert config.find_service_factory.calls == [
        pretend.call(origin.IOriginCache),
    ]
    assert factory.calls == [pretend.call(None, config)]
    assert cacher.purge.calls == [pretend.call({"type_1", "type_2", "foobar"})]
    assert "warehouse.cache.origin.purges" not in session.info
Пример #6
0
def test_execute_purge_success():
    cacher = pretend.stub(purge=pretend.call_recorder(lambda purges: None))
    factory = pretend.call_recorder(lambda ctx, config: cacher)
    config = pretend.stub(
        find_service_factory=pretend.call_recorder(lambda i: factory),
    )
    session = pretend.stub(
        info={
            "warehouse.cache.origin.purges": {"type_1", "type_2", "foobar"},
        },
    )

    origin.execute_purge(config, session)

    assert config.find_service_factory.calls == [
        pretend.call(origin.IOriginCache),
    ]
    assert factory.calls == [pretend.call(None, config)]
    assert cacher.purge.calls == [pretend.call({"type_1", "type_2", "foobar"})]
    assert "warehouse.cache.origin.purges" not in session.info