|
1
|
|
|
import json |
|
2
|
|
|
import re |
|
3
|
|
|
import subprocess |
|
4
|
|
|
from pathlib import Path |
|
5
|
|
|
|
|
6
|
|
|
import pytest |
|
7
|
|
|
|
|
8
|
|
|
from ..test_tools import TestTools |
|
9
|
|
|
from .command_constants import ARF_TO_JSON, COMMAND_START, TEST_ARF_XML_PATH |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
@pytest.mark.usefixtures("remove_generated_reports_in_root") |
|
13
|
|
|
def test_command_json_to_graph(): |
|
14
|
|
|
path = str(TestTools.get_random_path_in_tmp()) + '.json' |
|
15
|
|
|
out = subprocess.check_output(ARF_TO_JSON) |
|
16
|
|
|
|
|
17
|
|
|
with open(path, "w+", encoding="utf-8") as output: |
|
18
|
|
|
output.writelines(out.decode('utf-8')) |
|
19
|
|
|
|
|
20
|
|
|
command = [*COMMAND_START, |
|
21
|
|
|
'json-to-graph', |
|
22
|
|
|
'-o', '.', |
|
23
|
|
|
path, |
|
24
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
25
|
|
|
] |
|
26
|
|
|
subprocess.check_call(command, cwd='./') |
|
27
|
|
|
file_paths = TestTools.find_files( |
|
28
|
|
|
"graph-of-xccdf_org.ssgproject.content_rule_package_abrt_removed", |
|
29
|
|
|
'../') |
|
30
|
|
|
TestTools.compare_results_html(file_paths[0]) |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
@pytest.mark.usefixtures("remove_generated_reports_in_root") |
|
34
|
|
|
def test_command_json_to_graph_with_verbose(): |
|
35
|
|
|
path = str(TestTools.get_random_path_in_tmp()) + '.json' |
|
36
|
|
|
out = subprocess.check_output(ARF_TO_JSON) |
|
37
|
|
|
with open(path, "w+", encoding="utf-8") as output: |
|
38
|
|
|
output.writelines(out.decode('utf-8')) |
|
39
|
|
|
|
|
40
|
|
|
command = [*COMMAND_START, |
|
41
|
|
|
'json-to-graph', |
|
42
|
|
|
'-o', '.', |
|
43
|
|
|
'--verbose', |
|
44
|
|
|
path, |
|
45
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
46
|
|
|
] |
|
47
|
|
|
out = subprocess.check_output(command, |
|
48
|
|
|
cwd='./', |
|
49
|
|
|
stderr=subprocess.STDOUT) |
|
50
|
|
|
path_regex = r"\"(.*?)\"$" |
|
51
|
|
|
path_search = re.search(path_regex, out.decode('utf-8')).group(1) |
|
52
|
|
|
file_path = Path(__file__).parent.parent.parent / path_search |
|
53
|
|
|
TestTools.compare_results_html(file_path) |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
def test_command_parameter_all(): |
|
57
|
|
|
path = str(TestTools.get_random_path_in_tmp()) + '.json' |
|
58
|
|
|
command = [*COMMAND_START, |
|
59
|
|
|
'arf-to-json', |
|
60
|
|
|
'--all', |
|
61
|
|
|
TEST_ARF_XML_PATH, |
|
62
|
|
|
'.' |
|
63
|
|
|
] |
|
64
|
|
|
with open(path, 'w+', encoding="utf-8") as output: |
|
65
|
|
|
subprocess.check_call(command, stdout=output) |
|
66
|
|
|
|
|
67
|
|
|
with open(path, "r", encoding="utf-8") as data: |
|
68
|
|
|
rules = json.load(data) |
|
69
|
|
|
assert len(rules.keys()) == 184 |
|
70
|
|
|
out_path = TestTools.get_random_path_in_tmp() |
|
71
|
|
|
command = [*COMMAND_START, |
|
72
|
|
|
'json-to-graph', |
|
73
|
|
|
path, |
|
74
|
|
|
'.', |
|
75
|
|
|
'--all', |
|
76
|
|
|
'-o', |
|
77
|
|
|
str(out_path) |
|
78
|
|
|
] |
|
79
|
|
|
subprocess.check_call(command) |
|
80
|
|
|
assert len(list(out_path.glob('**/*.html'))) == 184 |
|
81
|
|
|
|