def test_cache_prefix_is_set(monkeypatch): monkeypatch.setenv("NETPALM_REDIS_CACHE_KEY_PREFIX", "RCK") config = confload.initialize_config() redis_helper = rediz.Rediz(config) assert redis_helper.cache.key_prefix == "RCK" config.redis_cache_key_prefix = '' redis_helper = rediz.Rediz(config) assert redis_helper.cache.key_prefix == "NOPREFIX" config.redis_cache_key_prefix = ' ' redis_helper = rediz.Rediz(config) assert redis_helper.cache.key_prefix == "NOPREFIX" config.redis_cache_key_prefix = None redis_helper = rediz.Rediz(config) assert redis_helper.cache.key_prefix == "None"
def test_cache_disabled(monkeypatch): monkeypatch.setenv("NETPALM_REDIS_CACHE_ENABLED", "FALSE") config = confload.initialize_config() redis_helper = rediz.Rediz(config) cache = redis_helper.cache assert redis_helper.cache_enabled == False assert isinstance(cache, rediz.DisabledCache) assert cache.get('key') is None assert cache.set('key', 'value') is None assert cache.get('key') is None
def clean_cache_redis_helper(monkeypatch): monkeypatch.setenv("NETPALM_REDIS_CACHE_ENABLED", "TRUE") config = confload.initialize_config() redis_helper = rediz.Rediz(config) redis_helper.cache.clear() return redis_helper