|
1
|
|
|
import os |
|
2
|
|
|
import sys |
|
3
|
|
|
import tempfile |
|
4
|
|
|
import uuid |
|
5
|
|
|
|
|
6
|
|
|
import mock |
|
7
|
|
|
import pytest |
|
8
|
|
|
|
|
9
|
|
|
import tests.any_test_help |
|
10
|
|
|
from oval_graph.command_line_client.json_to_html import JsonToHtml |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
def get_client_json_to_html(src, rule): |
|
14
|
|
|
return JsonToHtml(["--display", tests.any_test_help.get_src(src), rule]) |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
def get_client_json_to_html_with_define_dest(src, rule): |
|
18
|
|
|
return JsonToHtml( |
|
19
|
|
|
["--output", tests.any_test_help.get_src( |
|
20
|
|
|
os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))), |
|
21
|
|
|
tests.any_test_help.get_src(src), |
|
22
|
|
|
rule, |
|
23
|
|
|
]) |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
def try_expection_for_prepare_graph(src, rule, err): |
|
27
|
|
|
rules = {'rules': [rule]} |
|
28
|
|
|
with pytest.raises(Exception, match=err): |
|
29
|
|
|
client = get_client_json_to_html(src, rule) |
|
30
|
|
|
assert client.prepare_data(rules) |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
def test_prepare_graph_with_not_valid_file(): |
|
34
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
|
35
|
|
|
rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
36
|
|
|
try_expection_for_prepare_graph(src, rule, 'is not valid json') |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
def test_prepare_graph_with_not_exist_rule(): |
|
40
|
|
|
src = 'test_data/referenc_html_report.html' |
|
41
|
|
|
rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
42
|
|
|
try_expection_for_prepare_graph(src, rule, 'No such file or directory:') |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
def test_prepare_graph_with_bat_data(): |
|
46
|
|
|
src = 'test_data/bad_result_data_json.json' |
|
47
|
|
|
rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
48
|
|
|
try_expection_for_prepare_graph(src, rule, 'valid for OVAL tree') |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
def test_search_non_existent_rule(): |
|
52
|
|
|
src = 'test_data/referenc_result_data_json.json' |
|
53
|
|
|
rule = 'non-existent_rule' |
|
54
|
|
|
err = '404' |
|
55
|
|
|
client = get_client_json_to_html(src, rule) |
|
56
|
|
|
with pytest.raises(Exception, match=err): |
|
57
|
|
|
assert client.search_rules_id() |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
@pytest.mark.usefixtures("remove_generated_reports_in_root") |
|
61
|
|
|
def test_prepare_tree(): |
|
62
|
|
|
src = 'test_data/referenc_result_data_json.json' |
|
63
|
|
|
rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
64
|
|
|
client = get_client_json_to_html(src, rule) |
|
65
|
|
|
results_src = client.prepare_data({'rules': client.search_rules_id()}) |
|
66
|
|
|
tests.any_test_help.compare_results_html(results_src[0]) |
|
67
|
|
|
client.kill_web_browsers() |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
def test_prepare_tree_and_save_in_defined_destination(): |
|
71
|
|
|
src = 'test_data/referenc_result_data_json.json' |
|
72
|
|
|
rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
73
|
|
|
client = get_client_json_to_html_with_define_dest(src, rule) |
|
74
|
|
|
results_src = client.prepare_data({'rules': client.search_rules_id()}) |
|
75
|
|
|
tests.any_test_help.compare_results_html(results_src[0]) |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
def test_search_rules_id(): |
|
79
|
|
|
src = 'test_data/referenc_result_data_json.json' |
|
80
|
|
|
part_of_id_rule = 'xccdf_org.ssgproject.' |
|
81
|
|
|
client = get_client_json_to_html(src, part_of_id_rule) |
|
82
|
|
|
assert len(client.search_rules_id()) == 184 |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
def test_get_questions(): |
|
86
|
|
|
src = 'test_data/referenc_result_data_json.json' |
|
87
|
|
|
regex = r'_package_\w+_removed' |
|
88
|
|
|
client = get_client_json_to_html(src, regex) |
|
89
|
|
|
out = client.get_questions()[0].choices |
|
90
|
|
|
rule1 = 'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
91
|
|
|
rule2 = 'xccdf_org.ssgproject.content_rule_package_sendmail_removed' |
|
92
|
|
|
assert out[0] == rule1 |
|
93
|
|
|
assert out[1] == rule2 |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
def test_get_wanted_rules_from_array_of_ids(): |
|
97
|
|
|
src = 'test_data/referenc_result_data_json.json' |
|
98
|
|
|
regex = r'_package_\w+_removed' |
|
99
|
|
|
client = get_client_json_to_html(src, regex) |
|
100
|
|
|
|
|
101
|
|
|
out = [ |
|
102
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed', |
|
103
|
|
|
'xccdf_org.ssgproject.content_rule_package_sendmail_removed', |
|
104
|
|
|
] |
|
105
|
|
|
|
|
106
|
|
|
assert out == client._get_wanted_rules( |
|
107
|
|
|
client.json_data_file.keys()) |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
def test_json_to_html_if_not_installed_inquirer(capsys): |
|
111
|
|
|
with mock.patch.dict(sys.modules, {'inquirer': None}): |
|
112
|
|
|
src = 'test_data/referenc_result_data_json.json' |
|
113
|
|
|
regex = r'_package_\w+_removed' |
|
114
|
|
|
client = get_client_json_to_html(src, regex) |
|
115
|
|
|
client.isatty = True |
|
116
|
|
|
tests.any_test_help.any_client_if_not_installed_inquirer( |
|
117
|
|
|
client, capsys, regex) |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
def test_get_only_fail_rules_not_implemented_error(): |
|
121
|
|
|
src = 'test_data/referenc_result_data_json.json' |
|
122
|
|
|
part_of_id_rule = 'xccdf_org.ssgproject.' |
|
123
|
|
|
client = get_client_json_to_html(src, part_of_id_rule) |
|
124
|
|
|
with pytest.raises(NotImplementedError): |
|
125
|
|
|
assert client.get_only_fail_rule(['rule-id']) |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
def test_get_rows_of_unselected_rules_not_implemented_error(): |
|
129
|
|
|
src = 'test_data/referenc_result_data_json.json' |
|
130
|
|
|
part_of_id_rule = 'xccdf_org.ssgproject.' |
|
131
|
|
|
client = get_client_json_to_html(src, part_of_id_rule) |
|
132
|
|
|
with pytest.raises(NotImplementedError): |
|
133
|
|
|
assert client._get_rows_of_unselected_rules() |
|
134
|
|
|
|