def test_tracked_kickstart_elements_tracking(self):
        """Test tracking of elements."""

        appended_elements = [
            self._element1, self._element2, self._element3, self._element4,
            self._element5, self._element6, self._element7
        ]
        elements = TrackedKickstartElements()
        for element in appended_elements:
            elements.append(element)

        processed_elements = elements.get_and_process_elements(
            commands=["network"], sections=["pre"], addons=["pony"])
        unprocessed_elements = elements.unprocessed_elements
        # still keeping order of elements
        assert unprocessed_elements == [
            self._element5, self._element6, self._element7
        ]
        # nothing is missing
        assert set(elements.all_elements) == \
            set.union(set(processed_elements), set(unprocessed_elements))
        # elements once processed remain processed if you just get them
        elements.get_elements(commands=["network"],
                              sections=["pre"],
                              addons=["pony"])
        assert elements.unprocessed_elements == unprocessed_elements
        # processing some more elements - firewall command
        firewall_elements = elements.get_and_process_elements(
            commands=["firewall"])
        assert set(elements.unprocessed_elements) == \
                         set.difference(set(unprocessed_elements), set(firewall_elements))
        assert elements.unprocessed_elements == [
            self._element6, self._element7
        ]
    def test_tracked_kickstart_elements_filter(self):
        """Test filtering of elements."""

        expected_elements = [
            self._element1, self._element2, self._element3, self._element4,
            self._element5, self._element6, self._element7
        ]
        elements = TrackedKickstartElements()
        for element in expected_elements:
            elements.append(element)

        assert elements.all_elements == expected_elements

        # filtering
        network_commands = elements.get_elements(commands=["network"])
        assert network_commands == [self._element2, self._element3]

        pony_addon = elements.get_elements(addons=["pony"])
        assert pony_addon == [self._element4]

        pre_sections = elements.get_elements(sections=["pre"])
        assert pre_sections == [self._element1]
        # addon is not considered a section
        addon_sections = elements.get_elements(sections=["addon"])
        assert addon_sections == []

        mixed_elements = elements.get_elements(commands=["network"],
                                               sections=["pre", "post"],
                                               addons=["pony"])
        assert mixed_elements == \
            [self._element1, self._element2, self._element3, self._element4, self._element7]

        # nothing required - nothing got
        assert elements.get_elements() == []
Beispiel #3
0
    def test_tracked_kickstart_elements_filter(self):
        """Test filtering of elements."""

        expected_elements = [self._element1, self._element2, self._element3,
                             self._element4, self._element5, self._element6,
                             self._element7]
        elements = TrackedKickstartElements()
        for element in expected_elements:
            elements.append(element)

        self.assertEqual(elements.all_elements, expected_elements)

        # filtering
        network_commands = elements.get_elements(commands=["network"])
        self.assertEqual(network_commands, [self._element2, self._element3])

        pony_addon = elements.get_elements(addons=["pony"])
        self.assertEqual(pony_addon, [self._element4])

        pre_sections = elements.get_elements(sections=["pre"])
        self.assertEqual(pre_sections, [self._element1])
        # addon is not considered a section
        addon_sections = elements.get_elements(sections=["addon"])
        self.assertEqual(addon_sections, [])

        mixed_elements = elements.get_elements(commands=["network"],
                                               sections=["pre", "post"],
                                               addons=["pony"])
        self.assertEqual(mixed_elements,
                         [self._element1, self._element2, self._element3, self._element4,
                          self._element7])

        # nothing required - nothing got
        self.assertEqual(elements.get_elements(), [])