Skip to content

Commit

Permalink
Remove not applicable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Honny1 committed Nov 20, 2023
1 parent 3dd92a2 commit 3871c04
Showing 1 changed file with 0 additions and 200 deletions.
200 changes: 0 additions & 200 deletions tests/unit/ssg-module/test_build_renumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,206 +164,6 @@ def oval_def_pear():
return odef


def test_get_nonexisting_check_definition_extends(oval_def_pear):
index = dict()
ext_ref = ssg.build_renumber.get_nonexisting_check_definition_extends(
oval_def_pear, index)
assert ext_ref == "apple"


def test_get_nonexisting_check_definition_extends_existing(
oval_def_apple, oval_def_pear):
index = {"apple": oval_def_apple}
ext_ref = ssg.build_renumber.get_nonexisting_check_definition_extends(
oval_def_pear, index)
assert ext_ref is None


def test_get_nonexisting_check_definition_extends_no_extends(
oval_def_apple, oval_def_pear):
index = {"apple": oval_def_apple}
ext_ref = ssg.build_renumber.get_nonexisting_check_definition_extends(
oval_def_pear, index)
assert ext_ref is None


@pytest.fixture
def oval_with_broken_extend_definition():
name = "oval_with_broken_extend_definition.xml"
file_path = os.path.join(DATADIR, name)
return ET.parse(file_path).getroot()


def test_get_oval_checks_extending_non_existing_checks(
oval_with_broken_extend_definition):
index = ssg.xml.map_elements_to_their_ids(
oval_with_broken_extend_definition,
".//{%s}definition" % oval_namespace)
miss = ssg.build_renumber.get_oval_checks_extending_non_existing_checks(
oval_with_broken_extend_definition, index)
assert len(miss) == 2
defs = set.union(*miss.values())
assert "oval:ssg-package_httpd_removed:def:1" in defs
assert "oval:ssg-service_postfix_enabled:def:1" in defs


@pytest.fixture
def oval_with_correct_extend_definition():
name = "oval_with_correct_extend_definition.xml"
file_path = os.path.join(DATADIR, name)
return ET.parse(file_path).getroot()


def test_get_oval_checks_extending_non_existing_checks_correct(
oval_with_correct_extend_definition):
index = ssg.xml.map_elements_to_their_ids(
oval_with_correct_extend_definition,
".//{%s}definition" % oval_namespace)
miss = ssg.build_renumber.get_oval_checks_extending_non_existing_checks(
oval_with_correct_extend_definition, index)
assert len(miss) == 0


def test_transpose_dict_with_sets():
d1 = {
"animals": {"dog", "cat", "mouse"},
"fruit": {"banana", "plum"}
}
t1 = ssg.build_renumber.transpose_dict_with_sets(d1)
assert len(t1) == 5
assert len(t1["dog"]) == 1
assert "animals" in t1["dog"]
assert len(t1["cat"]) == 1
assert "animals" in t1["cat"]
assert len(t1["mouse"]) == 1
assert "animals" in t1["mouse"]
assert len(t1["banana"]) == 1
assert "fruit" in t1["banana"]
assert len(t1["plum"]) == 1
assert "fruit" in t1["plum"]

d2 = {
"food": {"apple", "pizza"},
"fruit": {"apple", "pear"}
}
t2 = ssg.build_renumber.transpose_dict_with_sets(d2)
assert len(t2) == 3
assert len(t2["apple"]) == 2
assert "food" in t2["apple"]
assert "fruit" in t2["apple"]
assert len(t2["pizza"]) == 1
assert "food" in t2["pizza"]
assert len(t2["pear"]) == 1
assert "fruit" in t2["pear"]

d3 = dict()
t3 = ssg.build_renumber.transpose_dict_with_sets(d3)
assert len(t3) == 0


@pytest.fixture
def xccdf_with_value():
bench = ET.Element("{%s}Benchmark" % XCCDF12_NS)
val = ET.SubElement(bench, "{%s}Value" % XCCDF12_NS)
val.set("id", "var_password_age")
val.set("type", "string")
return bench


@pytest.fixture
def xccdf_with_incomplete_value():
bench = ET.Element("{%s}Benchmark" % XCCDF12_NS)
val = ET.SubElement(bench, "{%s}Value" % XCCDF12_NS)
val.set("id", "var_password_age")
return bench


@pytest.fixture
def oval_with_external_variable_without_id_or_datatype():
oval = ET.Element("{%s}oval_definitions" % oval_namespace)
vars = ET.SubElement(oval, "{%s}variables" % oval_namespace)
e_var = ET.SubElement(vars, "{%s}external_variable" % oval_namespace)
return oval


@pytest.fixture
def oval_with_external_variable_without_id():
oval = ET.Element("{%s}oval_definitions" % oval_namespace)
vars = ET.SubElement(oval, "{%s}variables" % oval_namespace)
e_var = ET.SubElement(vars, "{%s}external_variable" % oval_namespace)
e_var.set("datatype", "string")
return oval


@pytest.fixture
def oval_with_external_variable_without_datatype():
oval = ET.Element("{%s}oval_definitions" % oval_namespace)
vars = ET.SubElement(oval, "{%s}variables" % oval_namespace)
e_var = ET.SubElement(vars, "{%s}external_variable" % oval_namespace)
e_var.set("id", "var_password_age")
return oval


@pytest.fixture
def oval_with_external_variable():
oval = ET.Element("{%s}oval_definitions" % oval_namespace)
vars = ET.SubElement(oval, "{%s}variables" % oval_namespace)
e_var = ET.SubElement(vars, "{%s}external_variable" % oval_namespace)
e_var.set("id", "var_password_age")
e_var.set("datatype", "string")
e_var.set("comment", "this is your long age")
e_var.set("version", "1")
return oval


def test_check_and_correct_xccdf_to_oval_data_export_matching_constraints_1(
xccdf_with_value, oval_with_external_variable_without_id_or_datatype):
with pytest.raises(SSGError) as e:
ssg.build_renumber.check_and_correct_xccdf_to_oval_data_export_matching_constraints(
xccdf_with_value,
oval_with_external_variable_without_id_or_datatype)
assert (
"Invalid OVAL <external_variable> found - either without "
"'id' or 'datatype'") in str(e)


def test_check_and_correct_xccdf_to_oval_data_export_matching_constraints_2(
xccdf_with_value, oval_with_external_variable_without_id):
with pytest.raises(SSGError) as e:
ssg.build_renumber.check_and_correct_xccdf_to_oval_data_export_matching_constraints(
xccdf_with_value, oval_with_external_variable_without_id)
assert (
"Invalid OVAL <external_variable> found - either without "
"'id' or 'datatype'") in str(e)


def test_check_and_correct_xccdf_to_oval_data_export_matching_constraints_3(
xccdf_with_value, oval_with_external_variable_without_datatype):
with pytest.raises(SSGError) as e:
ssg.build_renumber.check_and_correct_xccdf_to_oval_data_export_matching_constraints(
xccdf_with_value, oval_with_external_variable_without_datatype)
assert (
"Invalid OVAL <external_variable> found - either without "
"'id' or 'datatype'") in str(e)


def test_check_and_correct_xccdf_to_oval_data_export_matching_constraints_4(
xccdf_with_incomplete_value, oval_with_external_variable):
with pytest.raises(SSGError) as e:
ssg.build_renumber.check_and_correct_xccdf_to_oval_data_export_matching_constraints(
xccdf_with_incomplete_value, oval_with_external_variable)
assert (
"Invalid XCCDF variable 'var_password_age': Missing the"
" 'type' attribute") in str(e)


def test_check_and_correct_xccdf_to_oval_data_export_matching_constraints_5(
xccdf_with_value, oval_with_external_variable):
ssg.build_renumber.check_and_correct_xccdf_to_oval_data_export_matching_constraints(
xccdf_with_value, oval_with_external_variable)
assert xccdf_with_value is not None


@pytest.fixture
def xccdf_with_invalid_cce():
bench = ET.Element("{%s}Benchmark" % XCCDF12_NS)
Expand Down

0 comments on commit 3871c04

Please sign in to comment.