1
|
|
|
import subprocess |
2
|
|
|
|
3
|
|
|
import pytest |
4
|
|
|
|
5
|
|
|
COMMAND_START = ['python3', |
6
|
|
|
'-m', |
7
|
|
|
'oval_graph.command_line' |
8
|
|
|
] |
9
|
|
|
|
10
|
|
|
JSON_TO_GRAPH_COMMAND = [*COMMAND_START, |
11
|
|
|
'json-to-graph', |
12
|
|
|
'tests_oval_graph/global_test_data/ssg-fedora-ds-arf.xml', |
13
|
|
|
'.' |
14
|
|
|
] |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
@pytest.mark.parametrize("command_name, optional_args", [ |
18
|
|
|
('arf-to-graph', []), |
19
|
|
|
('arf-to-json', []), |
20
|
|
|
('arf-to-graph', ['-v']), |
21
|
|
|
('arf-to-json', ['-v']), |
22
|
|
|
]) |
23
|
|
|
def test_command_with_bad_arf_file(command_name, optional_args): |
24
|
|
|
command = [ |
25
|
|
|
*COMMAND_START, |
26
|
|
|
command_name, |
27
|
|
|
'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml', |
28
|
|
|
'.' |
29
|
|
|
] |
30
|
|
|
command.extend(optional_args) |
31
|
|
|
|
32
|
|
|
out = subprocess.check_output( |
33
|
|
|
command, |
34
|
|
|
stderr=subprocess.STDOUT) |
35
|
|
|
out_string = out.decode('utf-8') |
36
|
|
|
if '-v' in optional_args: |
37
|
|
|
assert out_string.find("Traceback") > -1 |
38
|
|
|
else: |
39
|
|
|
assert out_string.find("Traceback") == -1 |
40
|
|
|
assert out_string.find("Warning:") > -1 |
41
|
|
|
assert out_string.find("Error:") > -1 |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
def test_bad_command_json_to_graph_with_verbose(): |
45
|
|
|
command = [*JSON_TO_GRAPH_COMMAND, '-v'] |
46
|
|
|
out = subprocess.check_output(command, |
47
|
|
|
stderr=subprocess.STDOUT) |
48
|
|
|
out_string = out.decode('utf-8') |
49
|
|
|
assert out_string.find("Traceback") > -1 |
50
|
|
|
assert out_string.find("Error:") > -1 |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
def test_bad_command_json_to_graph(): |
54
|
|
|
out = subprocess.check_output(JSON_TO_GRAPH_COMMAND, |
55
|
|
|
stderr=subprocess.STDOUT) |
56
|
|
|
out_string = out.decode('utf-8') |
57
|
|
|
assert out_string.find("Traceback") == -1 |
58
|
|
|
assert out_string.find("Error:") > -1 |
59
|
|
|
|