示例#1
0
    def test_second_unit_raises_error(self):
        """Create a duplicate content unit with different ``artifacts`` and same ``relative_path``.

        Artifacts are unique by ``relative_path`` and ``file``.
        """
        delete_orphans()
        content_api = ContentFilesApi(self.client)
        repo_api = RepositoriesFileApi(self.client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        artifact = gen_artifact()

        # create first content unit.
        content_attrs = gen_file_content_attrs(artifact)
        response = content_api.create(**content_attrs)
        monitor_task(response.task)

        artifact = gen_artifact(file=__file__)

        # create second content unit.
        second_content_attrs = gen_file_content_attrs(artifact)
        second_content_attrs["relative_path"] = content_attrs["relative_path"]
        response = content_api.create(**second_content_attrs)
        monitor_task(response.task)

        data = {
            "add_content_units":
            [c.pulp_href for c in content_api.list().results]
        }
        response = repo_api.modify(repo.pulp_href, data)
        with self.assertRaises(PulpTaskError) as cm:
            monitor_task(response.task)
        task = cm.exception.task.to_dict()

        error_message = ("Cannot create repository version. "
                         "More than one file.file content with "
                         "the duplicate values for relative_path.")
        self.assertEqual(task["error"]["description"], error_message)
示例#2
0
    def test_second_unit_replaces_the_first(self):
        """Create a duplicate content unit with different ``artifacts`` and same ``relative_path``.

        Artifacts are unique by ``relative_path`` and ``file``.
        """
        delete_orphans()
        content_api = ContentFilesApi(self.client)
        repo_api = RepositoriesFileApi(self.client)
        versions_api = RepositoriesFileVersionsApi(self.client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        artifact = gen_artifact()

        # create first content unit.
        content_attrs = gen_file_content_attrs(artifact)
        content_attrs["repository"] = repo.pulp_href
        response = content_api.create(**content_attrs)
        monitor_task(response.task)

        artifact = gen_artifact(file=__file__)

        # create second content unit.
        second_content_attrs = gen_file_content_attrs(artifact)
        second_content_attrs["repository"] = repo.pulp_href
        second_content_attrs["relative_path"] = content_attrs["relative_path"]

        response = content_api.create(**second_content_attrs)
        monitor_task(response.task)

        repo_latest_version = versions_api.read(
            repo_api.read(repo.pulp_href).latest_version_href)

        self.assertEqual(
            repo_latest_version.content_summary.present["file.file"]["count"],
            1)
示例#3
0
    def test_non_error(self):
        """Create a duplicate content unit with different relative_path.

        Artifacts are unique by ``relative_path`` and ``file``.

        In order to avoid an HTTP error, use the same ``artifact`` and
        different ``relative_path``.
        """
        delete_orphans()
        artifact = gen_artifact()

        # create first content unit.
        response = self.file_content_api.create(
            **gen_file_content_attrs(artifact))
        monitor_task(response.task)

        # create second content unit.
        response = self.file_content_api.create(
            **gen_file_content_attrs(artifact))
        monitor_task(response.task)
        task = tasks.read(response.task)
        self.assertEqual(task.state, "completed")
示例#4
0
    def test_raise_error(self):
        """Create a duplicate content unit using same relative_path.

        Artifacts are unique by ``relative_path`` and ``file``.

        In order to raise an HTTP error, the same ``artifact`` and the same
        ``relative_path`` should be used.
        """
        delete_orphans()
        artifact = gen_artifact()
        attrs = gen_file_content_attrs(artifact)

        # create first content unit.
        response = self.file_content_api.create(**attrs)
        monitor_task(response.task)

        # using the same attrs used to create the first content unit.
        response = self.file_content_api.create(**attrs)
        with self.assertRaises(PulpTaskError) as cm:
            monitor_task(response.task)
        error = cm.exception.task.to_dict()["error"]
        for key in ("already", "relative", "path", "digest"):
            self.assertIn(key, error["description"].lower(), error)
示例#5
0
 def setUpClass(cls):
     """Create class-wide variable."""
     delete_orphans()
     cls.content_unit = {}
     cls.file_content_api = ContentFilesApi(gen_file_client())
     cls.artifact = gen_artifact()