Passed
Pull Request — master (#30)
by Jan
05:22
created

tests.unit_tests.test_scap_result_parser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 6

5 Functions

Rating   Name   Duplication   Size   Complexity  
A get_parser() 0 5 2
A test_validation() 0 8 1
A test_parse_report() 0 12 1
A test_get_profile_info() 0 10 1
A test_get_info_about_rules_in_profile() 0 8 1
1
import pytest
2
3
from oscap_report.scap_results_parser.data_structures import Report
4
from oscap_report.scap_results_parser.scap_results_parser import \
5
    SCAPResultsParser
6
7
from ..constants import PATH_TO_ARF, PATH_TO_EMPTY_XML_FILE, PATH_TO_XCCDF
8
9
10
def get_parser(file_path):
11
    xml_data = None
12
    with open(file_path, "r", encoding="utf-8") as xml_report:
13
        xml_data = xml_report.read().encode()
14
    return SCAPResultsParser(xml_data)
15
16
17
@pytest.mark.parametrize("file_path, result", [
18
    (PATH_TO_ARF, True),
19
    (PATH_TO_XCCDF, False),
20
    (PATH_TO_EMPTY_XML_FILE, False),
21
])
22
def test_validation(file_path, result):
23
    parser = get_parser(file_path)
24
    assert parser.validate(parser.arf_schemas_path) == result
25
26
27
@pytest.mark.parametrize("file_path, number_of_cpe_platforms", [
28
    (PATH_TO_ARF, 13),
29
    (PATH_TO_XCCDF, 13),
30
])
31
def test_get_profile_info(file_path, number_of_cpe_platforms):
32
    parser = get_parser(file_path)
33
    report = parser.get_profile_info()
34
    assert len(report.cpe_platforms) == number_of_cpe_platforms
35
    assert report.profile_name is not None
36
    assert report.rules is None
37
38
39
@pytest.mark.parametrize("file_path, number_of_rules", [
40
    (PATH_TO_ARF, 714),
41
    (PATH_TO_XCCDF, 714),
42
])
43
def test_get_info_about_rules_in_profile(file_path, number_of_rules):
44
    parser = get_parser(file_path)
45
    rules = parser.get_info_about_rules_in_profile()
46
    assert len(rules.keys()) == number_of_rules
47
48
49
@pytest.mark.parametrize("file_path, contains_oval_tree", [
50
    (PATH_TO_ARF, True),
51
    (PATH_TO_XCCDF, False),
52
])
53
def test_parse_report(file_path, contains_oval_tree):
54
    parser = get_parser(file_path)
55
    report = parser.parse_report()
56
    assert isinstance(report, Report)
57
    assert report.profile_name is not None
58
    assert report.rules is not None
59
    rule_id = "xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny"
60
    assert (report.rules[rule_id].oval_tree is not None) == contains_oval_tree
61