This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_org_config.py
102 lines (88 loc) · 2.75 KB
/
test_org_config.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from contextlib import contextmanager
from typing import Any, ContextManager, Iterator
import pytest
from pydantic import ValidationError
from pytest_mock import MockerFixture
from org_config import OrgConfig, load_org_config
@contextmanager
def does_not_raise() -> Iterator[None]:
yield
def test_load_config_reads_toml(mocker: MockerFixture) -> None:
mocker.patch(
"org_config.open",
mocker.mock_open(
read_data=(
b'organization_name = "org1"\n'
b'management_profile = "profile1"\n'
b'regions = ["eu-west-1"]\n'
)
),
)
load_org_config()
import org_config
org_config.open.assert_called_once_with("org_config.toml", mode=mocker.ANY) # type: ignore[attr-defined]
@pytest.mark.parametrize(
"parsed_input, expected_exception",
[
pytest.param(None, pytest.raises(TypeError), id="None"),
pytest.param({}, pytest.raises(ValidationError), id="empty dict"),
pytest.param(
{
"organization_name": "",
"management_profile": "profile1",
"regions": ["eu-west-1"],
},
pytest.raises(ValidationError),
id="empty organization_name",
),
pytest.param(
{
"organization_name": "org1",
"management_profile": "",
"regions": ["eu-west-1"],
},
pytest.raises(ValidationError),
id="empty management_profile",
),
pytest.param(
{
"organization_name": "org1",
"management_profile": "profile1",
"regions": [],
},
pytest.raises(ValidationError),
id="empty regions",
),
pytest.param(
{
"organization_name": "org1",
"management_profile": "profile1",
"regions": ["eu-west-1", "eu-toybox-1"],
},
pytest.raises(ValidationError),
id="invalid region",
),
],
)
def test_invalid_input(
parsed_input: Any, expected_exception: ContextManager[Exception]
) -> None:
with expected_exception:
OrgConfig(**parsed_input)
@pytest.mark.parametrize(
"loaded_config",
[
pytest.param(
{
"organization_name": "org1",
"management_profile": "profile1",
"regions": ["eu-west-1"],
}
)
],
)
def test_valid_config(loaded_config: Any) -> None:
actual_config = OrgConfig(**loaded_config)
assert actual_config.organization_name == "org1"
assert actual_config.management_profile == "profile1"
assert actual_config.regions == ["eu-west-1"]