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_should_raise_exception(self):
with pytest.raises(FileFormatNotSupportedError) as excinfo:
load_config_file("tests/data/api_wrong_format_include.yaml")
assert (
str(excinfo.value)
== "The format .txt is not supported. Supported formats: '.yaml', '.yml', '.json'. "
"File path: 'tests/data/include.txt'."
def test_should_raise_exception(self):
with pytest.raises(FileNotFoundError) as excinfo:
load_config_file("tests/data/api_invalid_path_include.yaml")
assert "[Errno 2] No such file or directory: " in str(excinfo.value)
assert "tests/data/invalid_path/include.yaml'" in str(excinfo.value)
def test_should_load(self):
data = load_config_file("tests/data/jsonfile.json")
assert data == {
"api": {
"endpoints": [
{
"name": "scanapi-demo",
"path": "${BASE_URL}",
"requests": [{"name": "health", "path": "/health/"}],
}
def test_should_raise_exception(self):
with pytest.raises(FileFormatNotSupportedError) as excinfo:
load_config_file("tests/data/not_supported_format.txt")
assert (
str(excinfo.value)
== "The format .txt is not supported. Supported formats: '.yaml', '.yml', '.json'. "
"File path: 'tests/data/not_supported_format.txt'."
def test_should_raise_exception(self):
with pytest.raises(EmptyConfigFileError) as excinfo:
load_config_file("tests/data/empty.yaml")
assert str(excinfo.value) == "File 'tests/data/empty.yaml' is empty."
def test_should_load(self):
data = load_config_file("tests/data/api.yaml")
assert data == {
"api": {
"endpoints": [
{
"name": "scanapi-demo",
"path": "${BASE_URL}",
"requests": [{"name": "health", "path": "/health/"}],
}
def save_config_file_preferences(self, config_path=None):
if not config_path and not self.has_default_config_file:
return
if not config_path:
user_config = load_config_file(DEFAULT_CONFIG_PATH)
self["config_path"] = DEFAULT_CONFIG_PATH
self.update(**user_config)
return
user_config = load_config_file(config_path)
self.update(**user_config)
def save_config_file_preferences(self, config_path=None):
if not config_path and not self.has_default_config_file:
return
if not config_path:
user_config = load_config_file(DEFAULT_CONFIG_PATH)
self["config_path"] = DEFAULT_CONFIG_PATH
self.update(**user_config)
return
user_config = load_config_file(config_path)
self.update(**user_config)