コード例 #1
0
    def _mock_pkg_profile(packages, repo_file, enabled_modules):
        """
        Turn a list of package objects into an RPMProfile object.
        """

        dict_list = []
        for pkg in packages:
            dict_list.append(pkg.to_dict())

        mock_file = Mock()
        mock_file.read = Mock(return_value=json.dumps(dict_list))

        mock_rpm_profile = RPMProfile(from_file=mock_file)

        mock_enabled_repos_profile = EnabledReposProfile(repo_file=repo_file)

        mock_module_profile = ModulesProfile()
        mock_module_profile.collect = Mock(return_value=enabled_modules)

        mock_profile = {
            "rpm": mock_rpm_profile,
            "enabled_repos": mock_enabled_repos_profile,
            "modulemd": mock_module_profile
        }
        return mock_profile
コード例 #2
0
    def test_module_md_uniquify(self):
        modules_input = [{
            "name": "duck",
            "stream": 0,
            "version": "20180730233102",
            "context": "deadbeef",
            "arch": "noarch",
            "profiles": ["default"],
            "installed_profiles": [],
            "status": "enabled"
        }, {
            "name": "duck",
            "stream": 0,
            "version": "20180707144203",
            "context": "c0ffee42",
            "arch": "noarch",
            "profiles": ["default", "server"],
            "installed_profiles": ["server"],
            "status": "unknown"
        }]

        self.assertEqual(modules_input,
                         ModulesProfile._uniquify(modules_input))
        # now test dup modules
        self.assertEqual(
            modules_input,
            ModulesProfile._uniquify(modules_input + [modules_input[0]]))
コード例 #3
0
    def _mock_pkg_profile(packages, repo_file, enabled_modules):
        """
        Turn a list of package objects into an RPMProfile object.
        """

        dict_list = []
        for pkg in packages:
            dict_list.append(pkg.to_dict())

        mock_file = Mock()
        mock_file.read = Mock(return_value=json.dumps(dict_list))

        mock_rpm_profile = RPMProfile(from_file=mock_file)

        mock_enabled_repos_profile = EnabledReposProfile(repo_file=repo_file)

        mock_module_profile = ModulesProfile()
        mock_module_profile.collect = Mock(return_value=enabled_modules)

        mock_profile = {
            "rpm": mock_rpm_profile,
            "enabled_repos": mock_enabled_repos_profile,
            "modulemd": mock_module_profile
        }
        return mock_profile
コード例 #4
0
    def test_module_md_uniquify(self):
        modules_input = [
            {
                "name": "duck",
                "stream": 0,
                "version": "20180730233102",
                "context": "deadbeef",
                "arch": "noarch",
                "profiles": ["default"],
                "installed_profiles": [],
                "status": "enabled"
            },
            {
                "name": "duck",
                "stream": 0,
                "version": "20180707144203",
                "context": "c0ffee42",
                "arch": "noarch",
                "profiles": ["default", "server"],
                "installed_profiles": ["server"],
                "status": "unknown"
            }

        ]

        self.assertEqual(modules_input, ModulesProfile._uniquify(modules_input))
        # now test dup modules
        self.assertEqual(modules_input, ModulesProfile._uniquify(modules_input + [modules_input[0]]))
コード例 #5
0
    def test_disabled_status(self) -> None:
        """
        Test the case, when module is disabled.
        """
        base_mock = mock.Mock()
        base_mock._moduleContainer = mock.Mock()
        base_mock._moduleContainer.isEnabled = mock.Mock(return_value=False)
        base_mock._moduleContainer.isDisabled = mock.Mock(return_value=True)
        base_mock._moduleContainer.isModuleActive = mock.Mock(
            return_value=False)
        module_pkg_mock = mock.Mock()
        profile_mock = mock.Mock()
        profile_mock.getName = mock.Mock(return_value="mock_profile")
        module_pkg_mock.getProfiles = mock.Mock(return_value=[profile_mock])
        module_pkg_mock.getName = mock.Mock(return_value="mock_module")
        module_pkg_mock.getStream = mock.Mock(return_value="1.23")
        module_pkg_mock.getVersion = mock.Mock(return_value="123456789")
        module_pkg_mock.getContext = mock.Mock(return_value="abcdefgh")
        module_pkg_mock.getArch = mock.Mock(return_value="x86_64")
        self.all_module_list = [module_pkg_mock]
        base_mock._moduleContainer.getModulePackages = mock.Mock(
            return_value=self.all_module_list)
        self.dnf_mock.Base = mock.Mock(return_value=base_mock)

        modules_profile = ModulesProfile()

        self.assertEqual(len(modules_profile.content), 1)
        self.assertEqual(modules_profile.content[0]["status"], "disabled")
        self.assertEqual(modules_profile.content[0]["active"], False)
コード例 #6
0
    def test_default_status_active(self) -> None:
        """
        Test the case, when module is not enabled nor disabled. The status of module
        should be default. Test the case, when the module can be active despite it
        is in default state.
        """
        base_mock = mock.Mock()
        base_mock._moduleContainer = mock.Mock()
        base_mock._moduleContainer.isEnabled = mock.Mock(return_value=False)
        base_mock._moduleContainer.isDisabled = mock.Mock(return_value=False)
        base_mock._moduleContainer.isModuleActive = mock.Mock(
            return_value=True)
        module_pkg_mock = mock.Mock()
        profile_mock = mock.Mock()
        profile_mock.getName = mock.Mock(return_value="mock_profile")
        module_pkg_mock.getProfiles = mock.Mock(return_value=[profile_mock])
        module_pkg_mock.getName = mock.Mock(return_value="mock_module")
        module_pkg_mock.getStream = mock.Mock(return_value="1.23")
        module_pkg_mock.getVersion = mock.Mock(return_value="123456789")
        module_pkg_mock.getContext = mock.Mock(return_value="abcdefgh")
        module_pkg_mock.getArch = mock.Mock(return_value="x86_64")
        self.all_module_list = [module_pkg_mock]
        base_mock._moduleContainer.getModulePackages = mock.Mock(
            return_value=self.all_module_list)
        self.dnf_mock.Base = mock.Mock(return_value=base_mock)

        modules_profile = ModulesProfile()

        self.assertEqual(len(modules_profile.content), 1)
        self.assertEqual(modules_profile.content[0]["status"], "default")
        self.assertEqual(modules_profile.content[0]["active"], True)