Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_cache_class_no_alias(self):
cache = caches.create(cache=RedisCache)
assert isinstance(cache, RedisCache)
assert cache.endpoint == "127.0.0.1"
assert cache.port == 6379
def test_create_deprecated(self):
with patch("aiocache.factory.warnings.warn") as mock:
caches.create(cache="aiocache.SimpleMemoryCache")
mock.assert_called_once_with(
"Creating a cache with an explicit config is deprecated, use 'aiocache.Cache'",
DeprecationWarning,
)
def test_get_wrong_alias(self):
with pytest.raises(KeyError):
caches.get("wrong_cache")
with pytest.raises(KeyError):
caches.create("wrong_cache")
caches.set_config(
{
"default": {
"cache": "aiocache.RedisCache",
"plugins": [
{"class": "aiocache.plugins.HitMissRatioPlugin"},
{"class": "aiocache.plugins.TimingPlugin"},
],
}
}
)
cache = caches.get("default")
assert isinstance(cache.plugins[0], HitMissRatioPlugin)
cache = caches.create("default")
assert isinstance(cache.plugins[0], HitMissRatioPlugin)
def test_create_cache_str_no_alias(self):
cache = caches.create(cache="aiocache.RedisCache")
assert isinstance(cache, RedisCache)
assert cache.endpoint == "127.0.0.1"
assert cache.port == 6379
def test_create_cache_ensure_alias_or_cache(self):
with pytest.raises(TypeError):
caches.create()