-
-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathtest_config_loader.py
More file actions
74 lines (60 loc) · 2.5 KB
/
test_config_loader.py
File metadata and controls
74 lines (60 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from pytest import mark, raises
from scanapi.config_loader import load_config_file
from scanapi.errors import BadConfigIncludeError, EmptyConfigFileError
@mark.describe("config loader")
@mark.describe("load_config_file")
class TestLoadConfigFile:
@mark.context("when it is an YAML file")
@mark.it("should load")
def test_should_load_yaml(self):
data = load_config_file("tests/data/scanapi.yaml")
assert data == {
"endpoints": [
{
"name": "scanapi-demo",
"path": "${BASE_URL}",
"requests": [{"name": "health", "path": "/health/"}],
}
]
}
@mark.context("when it is a JSON file")
@mark.it("should load")
def test_should_load_json(self):
data = load_config_file("tests/data/jsonfile.json")
assert data == {
"endpoints": [
{
"name": "scanapi-demo",
"path": "${BASE_URL}",
"requests": [{"name": "health", "path": "/health/"}],
}
]
}
@mark.context("file does not exist")
@mark.it("should raise an exception")
def test_should_raise_exception(self):
with raises(FileNotFoundError) as excinfo:
load_config_file("invalid/path.yaml")
assert (
str(excinfo.value)
== "[Errno 2] No such file or directory: 'invalid/path.yaml'"
)
@mark.context("file is empty")
@mark.it("should raise an exception")
def test_should_raise_exception_2(self):
with raises(EmptyConfigFileError) as excinfo:
load_config_file("tests/data/empty.yaml")
assert str(excinfo.value) == "File 'tests/data/empty.yaml' is empty."
@mark.context("include file does not exist")
@mark.it("should raise an exception")
def test_should_raise_exception_3(self):
with 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)
@mark.context("include value is not a scalar")
@mark.it("should raise an exception")
def test_should_raise_exception_4(self):
with raises(BadConfigIncludeError) as excinfo:
load_config_file("tests/data/api_non_scalar_include.yaml")
assert "Include tag value is not a scalar" in str(excinfo.value)