Пример #1
0
    def test_base(self):
        self.response_mock.text = "data"
        obj = repos.TripleoDeloreanRepos("centos8", "master",
                                         "current-tripleo")

        self.assertEquals(obj.name, "tripleo-delorean-current-tripleo")
        self.assertEquals(obj.repo_data, "data")
        self.assertEquals(str(obj), "data")
        self.requests_mock.assert_called_with(
            "https://trunk.rdoproject.org/centos8-master/current-tripleo/delorean.repo"
        )

        obj = repos.TripleoDeloreanRepos("centos8", "master", "deps")
        self.assertEquals(obj.repo_data, "data")
        self.assertEquals(str(obj), "data")
        self.requests_mock.assert_called_with(
            "https://trunk.rdoproject.org/centos8-master/delorean-deps.repo")
Пример #2
0
 def construct_repo(self, repo_type, version, name):
     # RHEL only supports rhsm
     if "rhel" in self.distro_id:
         return repos.RhsmRepo(name)
     if "centos" in repo_type:
         return repos.TripleoCentosRepo(repo_type, name)
     if "ceph" in repo_type:
         return repos.TripleoCephRepo(self.distro_normalized_id, name)
     if "delorean" in repo_type:
         dlrn_dist = f"{self.distro_id}{self.distro_major_version_id}"
         return repos.TripleoDeloreanRepos(dlrn_dist, version, name)
     raise exceptions.RepositoryNotSupported(repo_type)
Пример #3
0
    def test_save(self, isdir_mock, isfile_mock, access_mock):
        self.response_mock.text = "data"
        obj = repos.TripleoDeloreanRepos("centos8", "master",
                                         "current-tripleo")

        isdir_mock.return_value = True
        isfile_mock.retun_value = False
        access_mock.return_value = True
        with mock.patch("builtins.open", mock.mock_open()) as file_mock:
            obj.save()
            calls = [
                mock.call(
                    "/etc/yum.repos.d/tripleo-delorean-current-tripleo.repo",
                    "w",
                    encoding="utf-8",
                ),
                mock.call().__enter__(),
                mock.call().write(str(obj)),
                mock.call().__exit__(None, None, None),
            ]
            self.assertEqual(file_mock.mock_calls, calls)

        isdir_mock.return_value = False
        isfile_mock.retun_value = False
        access_mock.return_value = True
        with mock.patch("builtins.open", mock.mock_open()) as file_mock:
            self.assertRaises(FileNotFoundError, obj.save)

        isdir_mock.return_value = True
        isfile_mock.retun_value = False
        access_mock.return_value = False
        with mock.patch("builtins.open", mock.mock_open()) as file_mock:
            self.assertRaises(PermissionError, obj.save)

        isdir_mock.return_value = True
        isfile_mock.retun_value = True
        access_mock.side_effect = [True, False]
        with mock.patch("builtins.open", mock.mock_open()) as file_mock:
            self.assertRaises(PermissionError, obj.save)