Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a traceback #234

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from ..data_structures import ProfileInfo
from ..namespaces import NAMESPACES
from .shared_static_methods_of_parser import SharedStaticMethodsOfParser


class ProfileInfoParser:
Expand Down Expand Up @@ -45,8 +46,8 @@ def get_profile_info(self, profile_id):
description = profile_el.find('.//xccdf:description', NAMESPACES)
profile_info_dict = {
"profile_id": profile_id,
"title": title.text if title is not None else "",
"description": description.text if description is not None else "",
"title": SharedStaticMethodsOfParser.get_text_of_xml_element(title),
"description": SharedStaticMethodsOfParser.get_text_of_xml_element(description),
"extends": profile_el.get("extends", ""),
"cpe_platforms_for_profile": self._get_cpe_platforms_for_profile()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def get_unique_key(key):
def get_key_of_xml_element(element):
return element.tag[element.tag.index('}') + 1:] if '}' in element.tag else element.tag

@staticmethod
def get_text_of_xml_element(element):
if element is not None and element.text is not None:
return "".join(element.itertext())
return ""

@staticmethod
def get_unique_id_in_dict(object_, dict_):
if SharedStaticMethodsOfParser.get_key_of_xml_element(object_) in dict_:
Expand Down
18 changes: 18 additions & 0 deletions tests/unit_tests/test_shared_static_methods_of_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,21 @@ def test_get_unique_id_in_dict(object_, dict_):
def test_get_key_of_xml_element(element, expect_key):
key_element = SharedStaticMethodsOfParser.get_key_of_xml_element(element)
assert key_element == expect_key


@pytest.fixture
def element(request):
e = etree.Element("xml_element")
e.text = request.param
return e


@pytest.mark.unit_test
@pytest.mark.parametrize("element, expected_text", [
(None, ""),
("", ""),
("abcd", "abcd"),
], indirect=["element"])
def test_get_text_of_xml_element(element, expected_text):
text = SharedStaticMethodsOfParser.get_text_of_xml_element(element)
assert text == expected_text
Loading