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):
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"}
@multi_cached("keys")
async def bar():
pass
@multi_cached(keys_from_attr="keys")
async def what(self, keys=None, what=1):
return "1"
def test_alias_takes_precedence(self, mock_cache):
with patch(
"aiocache.decorators.caches.get", MagicMock(return_value=mock_cache)
) as mock_get:
mc = multi_cached(
keys_from_attr="keys", alias="default", cache=SimpleMemoryCache, namespace="test"
)
mc(stub_dict)
mock_get.assert_called_with("default")
assert mc.cache is mock_cache
def decorator(self, mocker, mock_cache):
with patch("aiocache.decorators._get_cache", return_value=mock_cache):
yield multi_cached(keys_from_attr="keys")
@multi_cached(wrong_param=1)
async def fn(n):
return n
@multi_cached(keys_from_attr="keys", key_builder=build_key)
async def fn(self, keys, market="ES"):
return {pytest.KEY: 1, pytest.KEY_1: 2}
@multi_cached("ids", cache=Cache.REDIS, namespace="main")
async def multi_cached_ids(ids=None):
return {id_: DICT[id_] for id_ in ids}