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_init(self):
serializer = PickleSerializer()
assert isinstance(serializer, BaseSerializer)
assert serializer.DEFAULT_ENCODING is None
assert serializer.encoding is None
def test_init(self):
serializer = JsonSerializer()
assert isinstance(serializer, BaseSerializer)
assert serializer.DEFAULT_ENCODING == "utf-8"
assert serializer.encoding == "utf-8"
def test_init(self):
mc = multi_cached(
keys_from_attr="keys",
key_builder=None,
ttl=1,
cache=SimpleMemoryCache,
plugins=None,
alias=None,
namespace="test",
)
assert mc.ttl == 1
assert mc.key_builder("key", lambda x: x) == "key"
assert mc.keys_from_attr == "keys"
assert mc.cache is None
assert mc._cache == SimpleMemoryCache
assert mc._serializer is None
assert mc._kwargs == {"namespace": "test"}
def test_init(self):
serializer = MsgPackSerializer()
assert isinstance(serializer, BaseSerializer)
assert serializer.DEFAULT_ENCODING == "utf-8"
assert serializer.encoding == "utf-8"
def test_new_invalid_cache_raises(self):
with pytest.raises(InvalidCacheType) as e:
Cache(object)
assert str(e.value) == "Invalid cache type, you can only use {}".format(
list(AIOCACHE_CACHES.keys())
)
import asyncio
import argparse
import logging
import uuid
from aiocache import Cache
from aiohttp import web
logging.getLogger("aiohttp.access").propagate = False
AIOCACHE_BACKENDS = {
"memory": Cache(Cache.MEMORY),
"redis": Cache(Cache.REDIS),
"memcached": Cache(Cache.MEMCACHED),
}
class CacheManager:
def __init__(self, backend):
self.cache = AIOCACHE_BACKENDS.get(backend)
async def get(self, key):
return await self.cache.get(key, timeout=0.1)
async def set(self, key, value):
return await self.cache.set(key, value, timeout=0.1)
async def handler_get(req):
try:
@cached(wrong_param=1)
async def fn(n):
return n
def test_inheritance(self):
assert isinstance(cached_stampede(), cached)
async def test_multi_set_multi_get_types(self, cache, obj):
cache.serializer = PickleSerializer()
assert await cache.multi_set([(pytest.KEY, obj)]) is True
assert await cache.multi_get([pytest.KEY]) == [pickle.loads(pickle.dumps(obj))]
def test_dumps(self):
assert PickleSerializer().dumps("hi") == b"\x80\x03X\x02\x00\x00\x00hiq\x00."