Completed
Push — rhel7-branch ( 8617a0...0b2570 )
by
unknown
15s queued 10s
created

test_content_handling.test_get_profiles()   A

Complexity

Conditions 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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