Blame tests/test_content_handling.py

Packit 792a06
import os
Packit 792a06
Packit 792a06
import pytest
Packit 792a06
Packit 792a06
from org_fedora_oscap import content_handling as ch
Packit 792a06
Packit 792a06
Packit 792a06
TESTING_FILES_PATH = os.path.join(
Packit 792a06
    os.path.dirname(__file__), os.path.pardir, "testing_files")
Packit 792a06
DS_FILEPATH = os.path.join(
Packit 792a06
    TESTING_FILES_PATH, "testing_ds.xml")
Packit 792a06
Packit 792a06
DS_IDS = "scap_org.open-scap_datastream_tst"
Packit 792a06
CHK_FIRST_ID = "scap_org.open-scap_cref_first-xccdf.xml"
Packit 792a06
CHK_SECOND_ID = "scap_org.open-scap_cref_second-xccdf.xml"
Packit 792a06
Packit 792a06
PROFILE1_ID = "xccdf_com.example_profile_my_profile"
Packit 792a06
PROFILE2_ID = "xccdf_com.example_profile_my_profile2"
Packit 792a06
PROFILE3_ID = "xccdf_com.example_profile_my_profile3"
Packit 792a06
Packit 792a06
Packit 792a06
@pytest.fixture()
Packit 792a06
def ds_handler():
Packit 792a06
    return ch.DataStreamHandler(DS_FILEPATH)
Packit 792a06
Packit 792a06
Packit 792a06
def test_init_invalid_file_path():
Packit 792a06
    with pytest.raises(ch.DataStreamHandlingError) as excinfo:
Packit 792a06
        ch.DataStreamHandler("testing_ds.xmlll")
Packit 792a06
    assert "Invalid file path" in str(excinfo.value)
Packit 792a06
Packit 792a06
Packit 792a06
def test_init_not_scap_content():
Packit 792a06
    with pytest.raises(ch.DataStreamHandlingError) as excinfo:
Packit 792a06
        ch.DataStreamHandler(os.path.join(TESTING_FILES_PATH, "testing_ks.cfg"))
Packit 792a06
    assert "not a valid SCAP content file" in str(excinfo.value)
Packit 792a06
Packit 792a06
Packit 792a06
def test_init_xccdf_content():
Packit 792a06
    with pytest.raises(ch.DataStreamHandlingError) as excinfo:
Packit 792a06
        ch.DataStreamHandler(os.path.join(TESTING_FILES_PATH, "xccdf.xml"))
Packit 792a06
    assert "not a data stream collection" in str(excinfo.value)
Packit 792a06
Packit 792a06
Packit 792a06
def test_get_data_streams(ds_handler):
Packit 792a06
    assert DS_IDS in ds_handler.get_data_streams()
Packit 792a06
Packit 792a06
Packit 792a06
def test_get_data_streams_checklists(ds_handler):
Packit 792a06
    expected_ids = {DS_IDS: [CHK_FIRST_ID, CHK_SECOND_ID]}
Packit 792a06
Packit 792a06
    ds_ids = ds_handler.get_data_streams_checklists()
Packit 792a06
    assert expected_ids == ds_ids
Packit 792a06
Packit 792a06
Packit 792a06
def test_get_checklists(ds_handler):
Packit 792a06
    expected_checklists = [CHK_FIRST_ID, CHK_SECOND_ID]
Packit 792a06
Packit 792a06
    chk_ids = ds_handler.get_checklists(DS_IDS)
Packit 792a06
    assert expected_checklists == chk_ids
Packit 792a06
Packit 792a06
Packit 792a06
def test_get_checklists_invalid(ds_handler):
Packit 792a06
    with pytest.raises(ch.DataStreamHandlingError) as excinfo:
Packit 792a06
        ds_handler.get_checklists("invalid.id")
Packit 792a06
        assert "Invalid data stream id given" in str(excinfo.value)
Packit 792a06
Packit 792a06
Packit 792a06
def test_get_profiles(ds_handler):
Packit 792a06
    profile_ids = ds_handler.get_profiles(DS_IDS, CHK_FIRST_ID)
Packit 792a06
Packit 792a06
    # When Benchmark doesn't contain Rules selected by default
Packit 792a06
    # the default Profile should not be present
Packit 792a06
    assert 2 == len(profile_ids)
Packit 792a06
    assert PROFILE1_ID == profile_ids[0].id
Packit 792a06
    assert PROFILE2_ID == profile_ids[1].id
Packit 792a06
Packit 792a06
Packit 792a06
def test_get_profiles_with_default(ds_handler):
Packit 792a06
    profile_ids = ds_handler.get_profiles(DS_IDS, CHK_SECOND_ID)
Packit 792a06
Packit 792a06
    # When Benchmark contains Rules selected by default
Packit 792a06
    # the default Profile should be present
Packit 792a06
    assert 2 == len(profile_ids)
Packit 792a06
    assert "default" == profile_ids[0].id
Packit 792a06
    assert PROFILE3_ID == profile_ids[1].id