Beispiel #1
0
    def test_method_update_xml_element_empty_instance(self):
        """
        Tests the update_xml_element method
        """

        xccdf_title = Title()

        self.assertFalse(hasattr(xccdf_title, 'xml_element'),
                         'XML element is defined')

        xccdf_title.update_xml_element()

        self.assertTrue(hasattr(xccdf_title, 'xml_element'),
                        'XML element is not defined')
Beispiel #2
0
    def load_children(self):
        """
        Load the subelements from the xml_element in its correspondent classes.

        :returns: List of child objects.
        :rtype: list
        :raises CardinalityException: If there is more than one Version child.
        :raises CardinalityException: If there is no Group and no Rule child.
        """

        # Containers
        children = list()
        statuses = list()
        version = None
        titles = list()
        descriptions = list()
        platforms = list()
        groups = list()
        rules = list()

        # Element load
        for element in self.xml_element:
            uri, tag = Element.get_namespace_and_tag(element.tag)
            if tag == 'version':
                if version is None:
                    version = Version(element)
                else:
                    error_msg = 'version element found more than once'
                    raise CardinalityException(error_msg)
            elif tag == 'status':
                statuses.append(Status(element))
            elif tag == 'title':
                titles.append(Title(element))
            elif tag == 'description':
                descriptions.append(Description(element))
            elif tag == 'platform':
                platforms.append(Platform(element))
            elif tag == 'Group':
                groups.append(Group(element))
            elif tag == 'Rule':
                rules.append(Rule(element))

        # Element validation
        if len(groups) <= 0 and len(rules) <= 0:
            error_msg = 'a group must contain at least a group or a rule'
            raise CardinalityException(error_msg)

        # List construction
        children.extend(statuses)
        if version is not None:
            children.append(version)
        children.extend(titles)
        children.extend(descriptions)
        children.extend(platforms)
        children.extend(groups)
        children.extend(rules)

        return children
Beispiel #3
0
    def test_init_all_with_empty_instace(self):
        """
        Tests the class constructor with an empty instance
        """

        xccdf_title = Title()

        self.assertEqual(xccdf_title.name, 'title',
                         'Title tag name does not match')
Beispiel #4
0
    def test_print_object_empty_instance(self):
        """
        Tests the string representation of an Title object
        from an empty instance
        """

        xccdf_title = Title()

        string_value = 'title'
        self.assertEqual(str(xccdf_title), string_value,
                         'String representation does not match')
Beispiel #5
0
    def create_title_object(self, object_type='ok'):
        """
        Helper method to create the Title object

        :returns: Title object
        :rtype: xccdf.models.title.Title
        """

        xml_element = self.load_example_element(object_type)

        return Title(xml_element)
Beispiel #6
0
    def test_method_to_xml_string(self):
        """
        Tests the to_xml_string method
        """

        xccdf_title = self.create_title_object('ok')

        xml_content = xccdf_title.to_xml_string()

        new_xccdf_title = Title(etree.fromstring(xml_content.encode('utf-8')))

        self.assertEqual(xccdf_title.text, new_xccdf_title.text,
                         'Title text does not match')
        self.assertEqual(xccdf_title.lang, new_xccdf_title.lang,
                         'Title lang does not match')
        self.assertEqual(xccdf_title.override, new_xccdf_title.override,
                         'Title override does not match')