1
|
|
|
import subprocess |
2
|
|
|
import os |
3
|
|
|
import pytest |
4
|
|
|
from readchar import key |
5
|
|
|
|
6
|
|
|
import tests.any_test_help |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
@pytest.mark.usefixtures("remove_generated_reports_in_root") |
10
|
|
|
def test_command_arf_to_graph(): |
11
|
|
|
out = subprocess.check_output(['python3', |
12
|
|
|
'-m', |
13
|
|
|
'oval_graph.command_line', |
14
|
|
|
'arf-to-graph', |
15
|
|
|
'--off-web-browser', |
16
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
17
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
18
|
|
|
]) |
19
|
|
|
tests.any_test_help.compare_results_html( |
20
|
|
|
out.decode('utf-8').split('\n')[-2]) |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
def test_command_arf_to_graph_with_out_parameter(): |
24
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() |
25
|
|
|
subprocess.check_call(['python3', |
26
|
|
|
'-m', |
27
|
|
|
'oval_graph.command_line', |
28
|
|
|
'arf-to-graph', |
29
|
|
|
'--off-web-browser', |
30
|
|
|
'-o', |
31
|
|
|
src, |
32
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
33
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
34
|
|
|
]) |
35
|
|
|
tests.any_test_help.compare_results_html( |
36
|
|
|
os.path.join(src, os.listdir(src)[0])) |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
def test_inquirer_choice_rule(): |
40
|
|
|
pexpect = pytest.importorskip("pexpect") |
41
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() |
42
|
|
|
sut = pexpect.spawn('python3', |
43
|
|
|
['-m', |
44
|
|
|
'oval_graph.command_line', |
45
|
|
|
'arf-to-graph', |
46
|
|
|
'-o', |
47
|
|
|
src, |
48
|
|
|
'--off-web-browser', |
49
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
50
|
|
|
r'_package_\w+_removed' |
51
|
|
|
]) |
52
|
|
|
sut.expect(r'\w+') |
53
|
|
|
sut.send(key.DOWN) |
54
|
|
|
sut.send(key.SPACE) |
55
|
|
|
sut.send(key.ENTER) |
56
|
|
|
sut.wait() |
57
|
|
|
assert len(os.listdir(src)) == 1 |
58
|
|
|
assert ("xccdf_org.ssgproject.content_rule_package_sendmail_removed" |
59
|
|
|
in os.listdir(src)[0]) |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
def test_command_parameter_all(): |
63
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() |
64
|
|
|
subprocess.check_call(['python3', |
65
|
|
|
'-m', |
66
|
|
|
'oval_graph.command_line', |
67
|
|
|
'arf-to-graph', |
68
|
|
|
'--off-web-browser', |
69
|
|
|
'--all', |
70
|
|
|
'-o', |
71
|
|
|
src, |
72
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
73
|
|
|
'.' |
74
|
|
|
]) |
75
|
|
|
assert len(os.listdir(src)) == 184 |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
def test_command_parameter_all_and_show_failed_rules(): |
79
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() |
80
|
|
|
subprocess.check_call(['python3', |
81
|
|
|
'-m', |
82
|
|
|
'oval_graph.command_line', |
83
|
|
|
'arf-to-graph', |
84
|
|
|
'--off-web-browser', |
85
|
|
|
'--all', |
86
|
|
|
'--show-failed-rules', |
87
|
|
|
'-o', |
88
|
|
|
src, |
89
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
90
|
|
|
r'_package_\w+_removed' |
91
|
|
|
]) |
92
|
|
|
# Right value is 1. Value 2 is caused by problem with parameter |
93
|
|
|
# --show-failed-rules (issue #116) |
94
|
|
|
assert len(os.listdir(src)) == 2 |
95
|
|
|
|