|
1
|
|
|
import subprocess |
|
2
|
|
|
import os |
|
3
|
|
|
import json |
|
4
|
|
|
import pytest |
|
5
|
|
|
from readchar import key |
|
6
|
|
|
|
|
7
|
|
|
import tests.any_test_help |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
@pytest.mark.usefixtures("remove_generated_reports_in_root") |
|
11
|
|
|
def test_command_json_to_graph(): |
|
12
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() + '.json' |
|
13
|
|
|
out = subprocess.check_output(['python3', |
|
14
|
|
|
'-m', |
|
15
|
|
|
'oval_graph.command_line', |
|
16
|
|
|
'arf-to-json', |
|
17
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
18
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
19
|
|
|
]) |
|
20
|
|
|
with open(src, "w+") as f: |
|
21
|
|
|
f.writelines(out.decode('utf-8')) |
|
22
|
|
|
out = subprocess.check_output(['python3', |
|
23
|
|
|
'-m', |
|
24
|
|
|
'oval_graph.command_line', |
|
25
|
|
|
'json-to-graph', |
|
26
|
|
|
'--off-web-browser', |
|
27
|
|
|
src, |
|
28
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
29
|
|
|
]) |
|
30
|
|
|
tests.any_test_help.compare_results_html( |
|
31
|
|
|
out.decode('utf-8').split('\n')[-2]) |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
def test_command_json_to_graph_is_tty(): |
|
35
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() + '.json' |
|
36
|
|
|
with open(src, 'w+')as output: |
|
37
|
|
|
subprocess.check_call(['python3', |
|
38
|
|
|
'-m', |
|
39
|
|
|
'oval_graph.command_line', |
|
40
|
|
|
'arf-to-json', |
|
41
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
42
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
43
|
|
|
], |
|
44
|
|
|
stdout=output) |
|
45
|
|
|
out_dir = tests.any_test_help.get_random_dir_in_tmp() |
|
46
|
|
|
out = subprocess.check_output(['python3', |
|
47
|
|
|
'-m', |
|
48
|
|
|
'oval_graph.command_line', |
|
49
|
|
|
'json-to-graph', |
|
50
|
|
|
'--off-web-browser', |
|
51
|
|
|
'--out', |
|
52
|
|
|
out_dir, |
|
53
|
|
|
src, |
|
54
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
55
|
|
|
]) |
|
56
|
|
|
tests.any_test_help.compare_results_html( |
|
57
|
|
|
os.path.join(out_dir, os.listdir(out_dir)[0])) |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
def test_inquirer_choice_rule(): |
|
61
|
|
|
pexpect = pytest.importorskip("pexpect") |
|
62
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() + '.json' |
|
63
|
|
|
sut = pexpect.spawn('python3', |
|
64
|
|
|
['-m', |
|
65
|
|
|
'oval_graph.command_line', |
|
66
|
|
|
'arf-to-json', |
|
67
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
68
|
|
|
r'_package_\w+_removed' |
|
69
|
|
|
]) |
|
70
|
|
|
sut.expect(r'\w+') |
|
71
|
|
|
sut.send(key.DOWN) |
|
72
|
|
|
sut.send(key.SPACE) |
|
73
|
|
|
sut.send(key.UP) |
|
74
|
|
|
sut.send(key.SPACE) |
|
75
|
|
|
sut.send(key.ENTER) |
|
76
|
|
|
sut.wait() |
|
77
|
|
|
out = sut.readlines() |
|
78
|
|
|
|
|
79
|
|
|
with open(src, "w+") as f: |
|
80
|
|
|
f.writelines(row.decode("utf-8") for row in out[21:]) |
|
81
|
|
|
tests.any_test_help.compare_results_json(src) |
|
82
|
|
|
|
|
83
|
|
|
out_dir = tests.any_test_help.get_random_dir_in_tmp() |
|
84
|
|
|
sut = pexpect.spawn('python3', |
|
85
|
|
|
['-m', |
|
86
|
|
|
'oval_graph.command_line', |
|
87
|
|
|
'json-to-graph', |
|
88
|
|
|
'-o', |
|
89
|
|
|
out_dir, |
|
90
|
|
|
'--off-web-browser', |
|
91
|
|
|
src, |
|
92
|
|
|
'.' |
|
93
|
|
|
]) |
|
94
|
|
|
sut.expect(r'\w+') |
|
95
|
|
|
sut.send(key.DOWN) |
|
96
|
|
|
sut.send(key.SPACE) |
|
97
|
|
|
sut.send(key.ENTER) |
|
98
|
|
|
sut.wait() |
|
99
|
|
|
assert len(os.listdir(out_dir)) == 1 |
|
100
|
|
|
assert ("xccdf_org.ssgproject.content_rule_package_abrt_removed" |
|
101
|
|
|
in os.listdir(out_dir)[0]) |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
def test_command_parameter_all(): |
|
105
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() + '.json' |
|
106
|
|
|
with open(src, 'w+')as output: |
|
107
|
|
|
subprocess.check_call(['python3', |
|
108
|
|
|
'-m', |
|
109
|
|
|
'oval_graph.command_line', |
|
110
|
|
|
'arf-to-json', |
|
111
|
|
|
'--all', |
|
112
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
113
|
|
|
'.' |
|
114
|
|
|
], |
|
115
|
|
|
stdout=output) |
|
116
|
|
|
with open(src, "r") as f: |
|
117
|
|
|
rules = json.load(f) |
|
118
|
|
|
assert len(rules.keys()) == 184 |
|
119
|
|
|
out_dir = tests.any_test_help.get_random_dir_in_tmp() |
|
120
|
|
|
subprocess.check_call(['python3', |
|
121
|
|
|
'-m', |
|
122
|
|
|
'oval_graph.command_line', |
|
123
|
|
|
'json-to-graph', |
|
124
|
|
|
src, |
|
125
|
|
|
'.', |
|
126
|
|
|
'--off-web-browser', |
|
127
|
|
|
'--all', |
|
128
|
|
|
'-o', |
|
129
|
|
|
out_dir |
|
130
|
|
|
]) |
|
131
|
|
|
assert len(os.listdir(out_dir)) == 184 |
|
132
|
|
|
|