Пример #1
0
    def _get_environment_data(self, env) -> CompsEnvironmentData:
        """Get the environment data.

        :param env: a DNF representation of the environment
        :return: an instance of CompsEnvironmentData
        """
        data = CompsEnvironmentData()
        data.id = env.id or ""
        data.name = env.ui_name or ""
        data.description = env.ui_description or ""

        optional = {i.name for i in env.option_ids}
        default = {i.name for i in env.option_ids if i.default}

        for grp in self._base.comps.groups:

            if grp.id in optional:
                data.optional_groups.append(grp.id)

            if grp.visible:
                data.visible_groups.append(grp.id)

            if grp.id in default:
                data.default_groups.append(grp.id)

        return data
    def test_get_environment_data(self):
        """Test the get_environment_data method."""
        self._add_environment("e1")

        expected = CompsEnvironmentData()
        expected.id = "e1"
        expected.name = "The 'e1' environment"
        expected.description = "This is the 'e1' environment."

        data = self.dnf_manager.get_environment_data("e1")
        assert isinstance(data, CompsEnvironmentData)
        assert compare_data(data, expected)
    def test_environment_data_available_groups(self):
        """Test the get_available_groups method."""
        data = CompsEnvironmentData()
        assert data.get_available_groups() == []

        data.optional_groups = ["g1", "g2", "g3"]
        data.visible_groups = ["g3", "g4", "g5"]
        data.default_groups = ["g1", "g3"]

        assert data.get_available_groups() == ["g1", "g2", "g3", "g4", "g5"]
Пример #4
0
    def test_get_software_selection_status(self):
        """Test the get_software_selection_status function."""
        selection = PackagesSelectionData()
        selection.environment = "e1"

        environment_data = CompsEnvironmentData()
        environment_data.name = "The e1 environment"

        dnf_manager = Mock(spec=DNFManager)
        dnf_manager.is_environment_valid.return_value = True
        dnf_manager.get_environment_data.return_value = environment_data

        status = get_software_selection_status(dnf_manager, selection)
        assert status == "The e1 environment"

        status = get_software_selection_status(dnf_manager,
                                               selection,
                                               kickstarted=True)
        assert status == "The e1 environment"

        dnf_manager.is_environment_valid.return_value = False

        status = get_software_selection_status(dnf_manager, selection)
        assert status == "Selected environment is not valid"

        status = get_software_selection_status(dnf_manager,
                                               selection,
                                               kickstarted=True)
        assert status == "Invalid environment specified in kickstart"

        selection.environment = ""

        status = get_software_selection_status(dnf_manager, selection)
        assert status == "Please confirm software selection"

        status = get_software_selection_status(dnf_manager,
                                               selection,
                                               kickstarted=True)
        assert status == "Custom software selected"
Пример #5
0
    def environment_data_available_groups_test(self):
        """Test the get_available_groups method."""
        data = CompsEnvironmentData()
        self.assertEqual(data.get_available_groups(), [])

        data.optional_groups = ["g1", "g2", "g3"]
        data.visible_groups = ["g3", "g4", "g5"]
        data.default_groups = ["g1", "g3"]

        self.assertEqual(data.get_available_groups(),
                         ["g1", "g2", "g3", "g4", "g5"])
Пример #6
0
    def setUp(self):
        """Set up the test."""
        self.environment_data = CompsEnvironmentData()
        self.environment_data.id = "e1"
        self.environment_data.optional_groups = ["g1", "g2", "g3", "g4", "g5"]

        self.dnf_manager = Mock(spec=DNFManager)

        self.dnf_manager.resolve_environment.return_value = True
        self.dnf_manager.get_environment_data.return_value = self.environment_data

        self.dnf_manager.get_group_data.side_effect = self._get_group_data
        self.dnf_manager.resolve_group.return_value = True

        self.cache = SoftwareSelectionCache(self.dnf_manager)