Passed
Pull Request — rhel7-branch (#74)
by Matěj
01:08
created

test_content_handling.test_init_xccdf_content()   A

Complexity

Conditions 3

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 3
nop 0
1
import os
2
3
import pytest
4
5
from org_fedora_oscap import content_handling as ch
6
7
8
DS_FILEPATH = os.path.join(
9
    os.path.dirname(__file__), os.path.pardir, "testing_files", "testing_ds.xml")
10
11
DS_IDS = "scap_org.open-scap_datastream_tst"
12
CHK_FIRST_ID = "scap_org.open-scap_cref_first-xccdf.xml"
13
CHK_SECOND_ID = "scap_org.open-scap_cref_second-xccdf.xml"
14
15
PROFILE1_ID = "xccdf_com.example_profile_my_profile"
16
PROFILE2_ID = "xccdf_com.example_profile_my_profile2"
17
PROFILE3_ID = "xccdf_com.example_profile_my_profile3"
18
19
20
@pytest.fixture()
21
def ds_handler():
22
    return ch.DataStreamHandler(DS_FILEPATH)
23
24
25
def test_init_invalid_file_path():
26
    with pytest.raises(ch.DataStreamHandlingError) as e:
27
        ch.DataStreamHandler("testing_ds.xml")
28
        assert "Invalid file path" in e.exception.message
29
30
31
def test_init_not_scap_content():
32
    with pytest.raises(ch.DataStreamHandlingError) as e:
33
        ch.DataStreamHandler("../testing_files/testing_ks.cfg")
34
        assert "not a valid SCAP content file" in e.exception.message
35
36
37
def test_init_xccdf_content():
38
    with pytest.raises(ch.DataStreamHandlingError) as e:
39
        ch.DataStreamHandler("../testing_files/xccdf.xml")
40
        assert "not a data stream collection" in e.exception.message
41
42
43
def test_get_data_streams(ds_handler):
44
    assert DS_IDS in ds_handler.get_data_streams()
45
46
47
def test_get_data_streams_checklists(ds_handler):
48
    expected_ids = {DS_IDS: [CHK_FIRST_ID, CHK_SECOND_ID]}
49
50
    ds_ids = ds_handler.get_data_streams_checklists()
51
    assert expected_ids == ds_ids
52
53
54
def test_get_checklists(ds_handler):
55
    expected_checklists = [CHK_FIRST_ID, CHK_SECOND_ID]
56
57
    chk_ids = ds_handler.get_checklists(DS_IDS)
58
    assert expected_checklists == chk_ids
59
60
61
def test_get_checklists_invalid(ds_handler):
62
    with pytest.raises(ch.DataStreamHandlingError) as e:
63
        ds_handler.get_checklists("invalid.id")
64
        assert "Invalid data stream id given" in e.exception.message
65
66
67
def test_get_profiles(ds_handler):
68
    profile_ids = ds_handler.get_profiles(DS_IDS, CHK_FIRST_ID)
69
70
    # When Benchmark doesn't contain Rules selected by default
71
    # the default Profile should not be present
72
    assert 2 == len(profile_ids)
73
    assert PROFILE1_ID == profile_ids[0].id
74
    assert PROFILE2_ID == profile_ids[1].id
75
76
77
def test_get_profiles_with_default(ds_handler):
78
    profile_ids = ds_handler.get_profiles(DS_IDS, CHK_SECOND_ID)
79
80
    # When Benchmark contains Rules selected by default
81
    # the default Profile should be present
82
    assert 2 == len(profile_ids)
83
    assert "default" == profile_ids[0].id
84
    assert PROFILE3_ID == profile_ids[1].id
85