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_default_serializer(self):
assert isinstance(RedisCache().serializer, JsonSerializer)
def test_class_from_string():
assert _class_from_string("aiocache.RedisCache") == RedisCache
def test_cache_settings(self):
settings.set_cache(
RedisCache, endpoint="127.0.0.1", port=6379, timeout=10, db=1)
cache = RedisCache(db=0)
assert cache.endpoint == "127.0.0.1"
assert cache.port == 6379
assert cache.timeout == 10
assert cache.db == 0
def test_get_cache_overrides(self):
cache = get_cache(
cache=RedisCache, namespace="default", serializer=PickleSerializer(),
plugins=BasePlugin(), endpoint="http://...", port=123)
assert isinstance(cache, RedisCache)
assert cache.endpoint == "http://..."
assert cache.port == 123
assert cache.namespace == "default"
assert isinstance(cache.serializer, PickleSerializer)
assert isinstance(cache.plugins, BasePlugin)
"endpoint": "127.0.0.10",
"port": 6378,
"serializer": {"class": "aiocache.serializers.PickleSerializer"},
"plugins": [
{"class": "aiocache.plugins.HitMissRatioPlugin"},
{"class": "aiocache.plugins.TimingPlugin"},
],
},
"alt": {"cache": "aiocache.SimpleMemoryCache"},
}
)
default = caches.get("default")
alt = caches.get("alt")
assert isinstance(default, RedisCache)
assert default.endpoint == "127.0.0.10"
assert default.port == 6378
assert isinstance(default.serializer, PickleSerializer)
assert len(default.plugins) == 2
assert isinstance(alt, SimpleMemoryCache)
def test_get_cache_value_with_fallbacks_with_settings():
settings.set_cache(RedisCache, fake_key="random")
assert get_cache_value_with_fallbacks(None, "fake_key", "DEFAULT", cls=RedisCache) == "random"
@cached(cache=RedisCache, ttl=10, key="key")
async def decorator():
return Result("content", 200)
def test_default_cache():
loop = asyncio.get_event_loop()
loop.run_until_complete(decorator())
loop.run_until_complete(global_cache())
loop.run_until_complete(RedisCache(namespace="main").delete("key"))