Skip to content

Commit df586d9

Browse files
committed
rename synth class to AciResult + breakdown --puv into --api-only and --no-cleanup
1 parent cebba59 commit df586d9

4 files changed

Lines changed: 228 additions & 20 deletions

File tree

tests/test_AciResult.py

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
import pytest
2+
import importlib
3+
import json
4+
5+
script = importlib.import_module("aci-preupgrade-validation-script")
6+
7+
8+
@pytest.mark.parametrize(
9+
"func_name, name, description, result, recommended_action, reason, doc_url, column, row, unformatted_column, unformatted_rows, expected_show, expected_criticality, expected_passed",
10+
[
11+
# Check 1: NA
12+
(
13+
"fake_func_name_NA_test",
14+
"NA",
15+
"",
16+
script.NA,
17+
"",
18+
"",
19+
"",
20+
["col1", "col2"],
21+
[["row1", "row2"], ["row3", "row4"]],
22+
["col1", "col2"],
23+
[["row1", "row2"], ["row3", "row4"]],
24+
False,
25+
"informational",
26+
"passed"
27+
),
28+
# Check 2: PASS
29+
(
30+
"fake_func_name_PASS_test",
31+
"PASS",
32+
"",
33+
script.PASS,
34+
"",
35+
"",
36+
"",
37+
[],
38+
[],
39+
[],
40+
[],
41+
True,
42+
"informational",
43+
"passed"
44+
),
45+
# Check 3: POST
46+
(
47+
"fake_func_name_POST_test",
48+
"POST",
49+
"",
50+
script.POST,
51+
"reboot",
52+
"test reason",
53+
"https://test_doc_url.html",
54+
["col1", "col2"],
55+
[["row1", "row2"], ["row3", "row4"]],
56+
["col1", "col2"],
57+
[["row1", "row2"], ["row3", "row4"]],
58+
False,
59+
"informational",
60+
"failed"
61+
),
62+
# Check 4: MANUAL
63+
(
64+
"fake_func_name_MANUAL_test",
65+
"MANUAL",
66+
"",
67+
script.MANUAL,
68+
"reboot",
69+
"test reason",
70+
"https://test_doc_url.html",
71+
["col1", "col2"],
72+
[["row1", "row2"], ["row3", "row4"]],
73+
["col1", "col2"],
74+
[["row1", "row2"], ["row3", "row4"]],
75+
True,
76+
"warning",
77+
"failed"
78+
),
79+
# Check 5: ERROR
80+
(
81+
"fake_func_name_ERROR_test",
82+
"ERROR",
83+
"",
84+
script.ERROR,
85+
"reboot",
86+
"test reason",
87+
"https://test_doc_url.html",
88+
["col1", "col2"],
89+
[["row1", "row2"], ["row3", "row4"]],
90+
["col1", "col2"],
91+
[["row1", "row2"], ["row3", "row4"]],
92+
True,
93+
"major",
94+
"failed"
95+
),
96+
# Check 6: FAIL_UF
97+
(
98+
"fake_func_name_FAIL_UF_test",
99+
"FAIL_UF",
100+
"",
101+
script.FAIL_UF,
102+
"reboot",
103+
"test reason",
104+
"https://test_doc_url.html",
105+
["col1", "col2"],
106+
[["row1", "row2"], ["row3", "row4"]],
107+
["col1", "col2"],
108+
[["row1", "row2"], ["row3", "row4"]],
109+
True,
110+
"critical",
111+
"failed"
112+
),
113+
# Check 7: FAIL_O
114+
(
115+
"fake_func_name_FAIL_O_test",
116+
"FAIL_O",
117+
"",
118+
script.FAIL_O,
119+
"reboot",
120+
"test reason",
121+
"https://test_doc_url.html",
122+
["col1", "col2", "col3"],
123+
[["row1", "row2", "row3"], ["row4", "row5", "row6"]],
124+
["col4", "col5"],
125+
[["row1", "row2"], ["row3", "row4"]],
126+
True,
127+
"critical",
128+
"failed"
129+
),
130+
# Check 8: FAIL_O Formatted only
131+
(
132+
"fake_func_name_FAIL_O_formatted_only_test",
133+
"FAIL_O Formatted only",
134+
"",
135+
script.FAIL_O,
136+
"reboot",
137+
"test reason",
138+
"https://test_doc_url.html",
139+
["col1", "col2", "col3"],
140+
[["row1", "row2", "row3"], ["row4", "row5", "row6"]],
141+
[],
142+
[],
143+
True,
144+
"critical",
145+
"failed"
146+
),
147+
# Check 9: FAIL_O
148+
(
149+
"fake_func_name_FAIL_O_unformatted_only_test",
150+
"FAIL_O Unformatted only",
151+
"",
152+
script.FAIL_O,
153+
"reboot",
154+
"test reason",
155+
"https://test_doc_url.html",
156+
[],
157+
[],
158+
["col1", "col2", "col3"],
159+
[["row1", "row2", "row3"], ["row4", "row5", "row6"]],
160+
True,
161+
"critical",
162+
"failed"
163+
),
164+
],
165+
)
166+
def test_AciResult(
167+
func_name,
168+
name,
169+
description,
170+
result,
171+
recommended_action,
172+
reason,
173+
doc_url,
174+
column,
175+
row,
176+
unformatted_column,
177+
unformatted_rows,
178+
expected_show,
179+
expected_criticality,
180+
expected_passed,
181+
):
182+
synth = script.AciResult(func_name, name, description)
183+
synth.updateWithResults(result, recommended_action, reason, doc_url, column, row, unformatted_column, unformatted_rows)
184+
file = synth.writeResult()
185+
with open(file, "r") as f:
186+
data = json.load(f)
187+
assert data["ruleId"] == func_name
188+
assert data["showValidation"] == expected_show
189+
assert data["severity"] == expected_criticality
190+
assert data["ruleStatus"] == expected_passed
191+
192+
193+
@pytest.mark.parametrize(
194+
"headers, data",
195+
[
196+
("", []), # invalid headers (columns)
197+
([], {}), # invalid data (rows)
198+
("", {}), # invalid headers and data
199+
]
200+
)
201+
def test_invalid_headers_or_data(headers, data):
202+
with pytest.raises(TypeError):
203+
synth = script.AciResult("func_name", "Check Title", "A Description")
204+
synth.craftData(
205+
column=headers,
206+
rows=data,
207+
)

tests/test_parse_args.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@ def test_no_args():
1414
# To simulate the script being run without any command-line arguments,
1515
# we set `sys.argv[1:]` to an empty list when `args` is `None`.
1616
sys.argv[1:] = []
17-
is_puv, tversion, cversion, debug_function = script.parse_args(args=None)
18-
assert is_puv is False
17+
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args=None)
18+
assert api_only is False
1919
assert tversion is None
2020
assert cversion is None
2121
assert debug_function is None
22+
assert no_cleanup is False
2223

2324

2425
@pytest.mark.parametrize(
2526
"args, expected_result",
2627
[
2728
([], False),
28-
(["--puv"], True),
29+
(["--api-only"], True),
2930
],
3031
)
31-
def test_puv(args, expected_result):
32-
is_puv, tversion, cversion, debug_function = script.parse_args(args)
33-
assert is_puv == expected_result
32+
def test_api_only(args, expected_result):
33+
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args)
34+
assert api_only == expected_result
3435

3536

3637
@pytest.mark.parametrize(
@@ -45,7 +46,7 @@ def test_puv(args, expected_result):
4546
],
4647
)
4748
def test_tversion(args, expected_result):
48-
is_puv, tversion, cversion, debug_function = script.parse_args(args)
49+
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args)
4950
if tversion is not None:
5051
assert isinstance(tversion, str)
5152
assert str(tversion) == str(expected_result)
@@ -63,7 +64,7 @@ def test_tversion(args, expected_result):
6364
],
6465
)
6566
def test_cversion(args, expected_result):
66-
is_puv, tversion, cversion, debug_function = script.parse_args(args)
67+
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args)
6768
if cversion is not None:
6869
assert isinstance(cversion, str)
6970
assert str(cversion) == str(expected_result)
@@ -78,7 +79,7 @@ def test_cversion(args, expected_result):
7879
],
7980
)
8081
def test_debug_func(args, expected_result):
81-
is_puv, tversion, cversion, debug_function = script.parse_args(args)
82+
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args)
8283
if debug_function is not None:
8384
assert isinstance(debug_function, str)
8485
assert str(debug_function) == str(expected_result)

tests/test_prepare.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _mock_get_target_version(arg_tversion):
6262

6363

6464
@pytest.mark.parametrize(
65-
"icurl_outputs, is_puv, arg_tversion, arg_cversion, debug_function, expected_result",
65+
"icurl_outputs, api_only, arg_tversion, arg_cversion, debug_function, expected_result",
6666
[
6767
# Default, no argparse arguments
6868
(
@@ -77,7 +77,7 @@ def _mock_get_target_version(arg_tversion):
7777
None,
7878
{"username": "admin", "password": "mypassword", "cversion": AciVersion("6.1(1a)"), "tversion": AciVersion("6.2(1a)"), "sw_cversion": AciVersion("6.0(9d)"), "vpc_node_ids": ["101", "102"]},
7979
),
80-
# `is_puv` is True (i.e. --puv)
80+
# `api_only` is True (i.e. --puv)
8181
# No `get_credentials()`, no username nor password
8282
(
8383
{
@@ -163,9 +163,9 @@ def _mock_get_target_version(arg_tversion):
163163
),
164164
],
165165
)
166-
def test_prepare(mock_icurl, is_puv, arg_tversion, arg_cversion, debug_function, expected_result):
167-
checks = script.get_checks(is_puv, debug_function)
168-
inputs = script.prepare(is_puv, arg_tversion, arg_cversion, len(checks))
166+
def test_prepare(mock_icurl, api_only, arg_tversion, arg_cversion, debug_function, expected_result):
167+
checks = script.get_checks(api_only, debug_function)
168+
inputs = script.prepare(api_only, arg_tversion, arg_cversion, len(checks))
169169
for key, value in expected_result.items():
170170
if "version" in key:
171171
assert isinstance(inputs[key], AciVersion)
@@ -182,7 +182,7 @@ def test_prepare(mock_icurl, is_puv, arg_tversion, arg_cversion, debug_function,
182182
assert meta["cversion"] == str(expected_result["cversion"])
183183
assert meta["tversion"] == str(expected_result["tversion"])
184184
assert meta["sw_cversion"] == str(expected_result["sw_cversion"])
185-
assert meta["is_puv"] == is_puv
185+
assert meta["api_only"] == api_only
186186
assert meta["total_checks"] == len(checks)
187187
if debug_function:
188188
assert meta["total_checks"] == 1
@@ -201,7 +201,7 @@ def test_cversion_invald():
201201

202202

203203
@pytest.mark.parametrize(
204-
"icurl_outputs, is_puv, arg_tversion, arg_cversion, debug_function, expected_result",
204+
"icurl_outputs, api_only, arg_tversion, arg_cversion, debug_function, expected_result",
205205
[
206206
# `get_cversion()` failure
207207
(
@@ -259,12 +259,12 @@ def test_cversion_invald():
259259
),
260260
],
261261
)
262-
def test_prepare_exception(capsys, caplog, mock_icurl, is_puv, arg_tversion, arg_cversion, debug_function, expected_result):
262+
def test_prepare_exception(capsys, caplog, mock_icurl, api_only, arg_tversion, arg_cversion, debug_function, expected_result):
263263
caplog.set_level(logging.CRITICAL)
264264
with pytest.raises(SystemExit):
265265
with pytest.raises(Exception):
266-
checks = script.get_checks(is_puv, debug_function)
267-
script.prepare(is_puv, arg_tversion, arg_cversion, len(checks))
266+
checks = script.get_checks(api_only, debug_function)
267+
script.prepare(api_only, arg_tversion, arg_cversion, len(checks))
268268
captured = capsys.readouterr()
269269
print(captured.out)
270270
assert captured.out.endswith(expected_result)

tests/test_run_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
script = importlib.import_module("aci-preupgrade-validation-script")
77
AciVersion = script.AciVersion
88
JSON_DIR = script.JSON_DIR
9-
ApicResult = script.syntheticMaintPValidate
9+
ApicResult = script.AciResult
1010
Result = script.Result
1111
check_wrapper = script.check_wrapper
1212

0 commit comments

Comments
 (0)