Skip to content

Commit

Permalink
Merge pull request #234 from jan-cerny/issue_233
Browse files Browse the repository at this point in the history
Fix a traceback
  • Loading branch information
evgenyz committed Jun 17, 2024
2 parents be59973 + 7b7a886 commit 813a440
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
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

0 comments on commit 813a440

Please sign in to comment.