def test_tfsm_search(monkeypatch): monkeypatch.setenv("NETPALM_TXTFSM_INDEX_FILE", "backend/plugins/extensibles/DOESNOTEXIT/index") config = confload.initialize_config(search_tfsm=False) config.setup_logging(max_debug=True) index_file_path = Path(config.txtfsm_index_file).absolute() assert not index_file_path.exists() config = confload.initialize_config() # search_tfsm must default to True index_file_path = Path(config.txtfsm_index_file).absolute() assert index_file_path.exists()
def test_netpalm_config_honors_envvar(): with pytest.raises(FileNotFoundError): config = confload.Config("DOES NOT EXIST.json") with pytest.raises(FileNotFoundError): os.environ["NETPALM_CONFIG"] = "DOES NOT EXIST.JSON" config = confload.initialize_config() # with pytest.raises(FileNotFoundError): # this depends on the fact that you're running pytest from the tests directory # del os.environ["NETPALM_CONFIG"] # but we're not doing that anymore and it's okay really # config = confload.initialize_config() config = confload.Config(ACTUAL_CONFIG_PATH) os.environ["NETPALM_CONFIG"] = str(ACTUAL_CONFIG_PATH) config = confload.initialize_config()
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 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 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
def test_template_object(): config = confload.initialize_config() template_obj = FSMTemplate() result = template_obj.get_template_list() assert 'Errno' not in result.get('data', '') assert result['status'] != 'error'
def clean_log(): config = confload.initialize_config() extn_log = ExtnUpdateLog(reds.base_connection, config.redis_update_log, create=False) extn_log.clear()