async def test_connect_stores_pool(self): with patch("aiocache.backends.redis.aioredis.create_pool") as create_pool: pool = FakePool() create_pool.return_value = pool redis = RedisBackend() await redis._connect() assert RedisBackend.pools[redis.get_pool()[0]] is pool
def test_setup_default_settings(self, set_settings): redis_backend = RedisBackend() assert redis_backend.endpoint == "endpoint" assert redis_backend.port == "port" assert redis_backend.db == 2 assert redis_backend.password == "pass"
def test_setup_override(self): redis_backend = RedisBackend(db=2, password="******") assert redis_backend.endpoint == "127.0.0.1" assert redis_backend.port == 6379 assert redis_backend.db == 2 assert redis_backend.password == "pass"
def test_setup_default_ignored_wrong_class(self, set_settings): settings._CACHE = str redis_backend = RedisBackend() assert redis_backend.endpoint == "127.0.0.1" assert redis_backend.port == 6379 assert redis_backend.db == 0 assert redis_backend.password is None
def test_setup(self): redis_backend = RedisBackend() assert redis_backend.endpoint == "127.0.0.1" assert redis_backend.port == 6379 assert redis_backend.db == 0 assert redis_backend.password is None assert redis_backend.pool_min_size == 1 assert redis_backend.pool_max_size == 10
def test_setup_default_settings_kwargs_override(self, set_settings): redis_backend = RedisBackend(endpoint="a", port=123, db=1, pool_min_size=5, pool_max_size=6) assert redis_backend.endpoint == "a" assert redis_backend.port == 123 assert redis_backend.db == 1 assert redis_backend.password == "pass" assert redis_backend.pool_min_size == 5 assert redis_backend.pool_max_size == 6
async def test_connect_calls_create_pool(self): with patch("aiocache.backends.redis.aioredis.create_pool") as create_pool: pool = FakePool() create_pool.return_value = pool redis = RedisBackend() await redis._connect() create_pool.assert_called_with( (redis.endpoint, redis.port), db=redis.db, password=redis.password, loop=redis._loop, encoding=getattr(redis, "encoding", None), minsize=redis.pool_min_size, maxsize=redis.pool_max_size)
def redis(event_loop): redis = RedisBackend() pool = FakePool() redis._connect = pool yield redis, pool
async def test_connect_with_pool(self): redis = RedisBackend() pool = FakePool() redis.get_pool = MagicMock(return_value=["key", pool]) assert await redis._connect() == pool
def test_get_pool(self): redis = RedisBackend() pool_key, pool = redis.get_pool() assert pool_key == "{}{}{}{}{}{}".format( redis.endpoint, redis.port, getattr(redis, "encoding", None), redis.db, redis.password, id(redis._loop))
def get_backend(self, *args, **kwargs): return RedisBackend(*args, **kwargs)