generated from Hochfrequenz/python_template_repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ahbreader.py
167 lines (148 loc) · 5.41 KB
/
test_ahbreader.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from datetime import date
from pathlib import Path
import pytest
from fundamend.models.anwendungshandbuch import Anwendungsfall, Anwendungshandbuch, Bedingung, Paket, UbBedingung
from fundamend.reader import AhbReader
from .example_ahb_utilts_11c import ahb_utilts_11c
from .example_ahb_utilts_11d import ahb_utilts_11d
@pytest.mark.parametrize(
"ahb_xml_file_path, expected_date",
[
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml",
date(2023, 10, 24),
),
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02.xml",
date(2024, 4, 2),
),
],
)
def test_get_publishing_date(ahb_xml_file_path: Path, expected_date: date) -> None:
reader = AhbReader(ahb_xml_file_path)
actual = reader.get_publishing_date()
assert actual == expected_date
@pytest.mark.parametrize(
"ahb_xml_file_path, expected",
[
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml", "BDEW"
),
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02.xml", "BDEW"
),
],
)
def test_get_author(ahb_xml_file_path: Path, expected: str) -> None:
reader = AhbReader(ahb_xml_file_path)
actual = reader.get_author()
assert actual == expected
@pytest.mark.parametrize(
"ahb_xml_file_path, expected",
[
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml", "1.1c"
),
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02.xml", "1.1d"
),
],
)
def test_get_version(ahb_xml_file_path: Path, expected: str) -> None:
reader = AhbReader(ahb_xml_file_path)
actual = reader.get_version()
assert actual == expected
@pytest.mark.parametrize(
"ahb_xml_file_path, expected_length",
[
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml", 88
),
],
)
def test_get_bedingungen(ahb_xml_file_path: Path, expected_length: int) -> None:
reader = AhbReader(ahb_xml_file_path)
actual = reader.get_bedingungen()
assert len(actual) == expected_length
assert all(isinstance(x, Bedingung) for x in actual)
@pytest.mark.parametrize(
"ahb_xml_file_path, expected_length",
[
pytest.param(Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml", 1),
],
)
def test_get_ub_bedingungen(ahb_xml_file_path: Path, expected_length: int) -> None:
reader = AhbReader(ahb_xml_file_path)
actual = reader.get_ub_bedingungen()
assert len(actual) == expected_length
assert all(isinstance(x, UbBedingung) for x in actual)
@pytest.mark.parametrize(
"ahb_xml_file_path, expected_length",
[
pytest.param(Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml", 1),
],
)
def test_get_pakete(ahb_xml_file_path: Path, expected_length: int) -> None:
reader = AhbReader(ahb_xml_file_path)
actual = reader.get_pakete()
assert len(actual) == expected_length
assert all(isinstance(x, Paket) for x in actual)
assert not any(x for x in actual if x.nummer.startswith("["))
assert not any(x for x in actual if x.nummer.endswith("]"))
@pytest.mark.parametrize(
"ahb_xml_file_path, pruefidentifikator, expect_match",
[
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml",
"25001",
True,
),
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml",
"11001",
False,
),
],
)
def test_get_anwendungsfall(ahb_xml_file_path: Path, pruefidentifikator: str, expect_match: bool) -> None:
reader = AhbReader(ahb_xml_file_path)
actual = reader.get_anwendungsfall(pruefidentifikator)
if expect_match:
assert actual is not None
assert isinstance(actual, Anwendungsfall)
assert actual.pruefidentifikator == pruefidentifikator
if "UTILTS" in str(ahb_xml_file_path):
assert actual.format == "UTILTS"
else:
assert actual is None
@pytest.mark.parametrize(
"ahb_xml_file_path, expected",
[
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml",
ahb_utilts_11c,
),
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02.xml",
ahb_utilts_11d,
),
],
)
def test_get_anwendungshandbuch(ahb_xml_file_path: Path, expected: Anwendungshandbuch) -> None:
reader = AhbReader(ahb_xml_file_path)
actual = reader.read()
assert actual is not None
assert isinstance(actual, Anwendungshandbuch)
assert actual == expected
assert len(actual.anwendungsfaelle) == 9
assert {awf.pruefidentifikator for awf in actual.anwendungsfaelle} == {
"25001",
"25002",
"25003",
"25004",
"25005",
"25006",
"25007",
"25008",
"25009",
}