Esempio n. 1
0
def test_registry_should_raise_error_on_dublicate_cache_key(
        cache_registry: CacheRegistry) -> None:
    cache = BaseCacheBackend()
    cache_registry.set(CACHE_KEY, cache)

    with pytest.raises(NameError,
                       match='Cache with the same name already registered'):
        cache_registry.set(CACHE_KEY, cache)
Esempio n. 2
0
def test_retrieve_all_registered_caches_from_registry(
        cache_registry: CacheRegistry) -> None:
    cache = BaseCacheBackend()

    cache_registry.set(CACHE_KEY, cache)
    cache_registry.set('OTHER_CACHE_KEY', cache)

    assert cache_registry.all() == (cache, cache)
Esempio n. 3
0
def test_flush_should_remove_all_registered_cashes(
        cache_registry: CacheRegistry) -> None:
    cache = BaseCacheBackend()

    cache_registry.set(CACHE_KEY, cache)
    cache_registry.set('OTHER_CACHE_KEY', cache)

    cache_registry.flush()

    assert cache_registry.get(CACHE_KEY) is None
    assert cache_registry.get('OTHER_CACHE_KEY') is None
Esempio n. 4
0
def cache_registry() -> CacheRegistry:
    registry = CacheRegistry()
    yield registry
    registry.flush()
Esempio n. 5
0
def test_remove_cache_from_registry_should_raise_error_if_cache_not_register(
        cache_registry: CacheRegistry) -> None:
    with pytest.raises(NameError,
                       match='Cache with the same name not registered'):
        cache_registry.remove(CACHE_KEY)
Esempio n. 6
0
def test_remove_cache_from_registry(cache_registry: CacheRegistry) -> None:
    cache = BaseCacheBackend()
    cache_registry.set(CACHE_KEY, cache)
    cache_registry.remove(CACHE_KEY)

    assert cache_registry.get(CACHE_KEY) is None
Esempio n. 7
0
def test_get_from_registry_should_return_cache_instance(
        cache_registry: CacheRegistry) -> None:
    cache = BaseCacheBackend()
    cache_registry.set(CACHE_KEY, cache)

    assert cache_registry.get(CACHE_KEY) == cache
Esempio n. 8
0
def test_get_from_registry_should_return_none_if_cache_not_registered(
        cache_registry: CacheRegistry) -> None:
    assert cache_registry.get('') is None