Ejemplo n.º 1
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(self.cfg)

        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo["pulp_href"])

        files = {"file": utils.http_get(FILE_URL)}
        artifact = self.client.post(ARTIFACTS_PATH, files=files)

        # create first content unit.
        content_attrs = gen_file_content_attrs(artifact)
        content_attrs["repository"] = repo["pulp_href"]
        self.client.post(FILE_CONTENT_PATH, content_attrs)

        files = {"file": utils.http_get(FILE_URL2)}
        artifact = self.client.post(ARTIFACTS_PATH, files=files)

        # 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"]

        self.client.post(FILE_CONTENT_PATH, second_content_attrs)

        repo_latest_version = self.client.get(
            self.client.get(repo["pulp_href"])["latest_version_href"])

        self.assertEqual(
            repo_latest_version["content_summary"]["present"]["file.file"]
            ["count"], 1)
Ejemplo n.º 2
0
 def test_01_create_content_unit(self):
     """Create content unit."""
     attrs = gen_file_content_attrs(self.artifact)
     self.content_unit.update(self.client.post(FILE_CONTENT_PATH, attrs))
     for key, val in attrs.items():
         with self.subTest(key=key):
             self.assertEqual(self.content_unit[key], val)
Ejemplo n.º 3
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(self.cfg)
        files = {'file': utils.http_get(FILE_URL)}
        artifact = self.client.post(ARTIFACTS_PATH, files=files)
        attrs = gen_file_content_attrs(artifact)

        # create first content unit.
        self.client.post(FILE_CONTENT_PATH, attrs)

        # using the same attrs used to create the first content unit.
        response = api.Client(self.cfg,
                              api.echo_handler).post(FILE_CONTENT_PATH, attrs)
        with self.assertRaises(HTTPError):
            response.raise_for_status()
        for key in ('already', 'content', 'relative', 'path', 'artifact'):
            self.assertIn(key,
                          response.json()['non_field_errors'][0].lower(),
                          response.json())
Ejemplo n.º 4
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(self.cfg)
        files = {'file': utils.http_get(FILE_URL)}
        artifact = self.client.post(ARTIFACTS_PATH, files=files)

        # create first content unit.
        self.client.post(FILE_CONTENT_PATH, gen_file_content_attrs(artifact))

        # create second content unit.
        self.client.post(FILE_CONTENT_PATH, gen_file_content_attrs(artifact))
Ejemplo n.º 5
0
    def test_03_fully_update(self):
        """Attempt to update a content unit using HTTP PUT.

        This HTTP method is not supported and a HTTP exception is expected.
        """
        attrs = gen_file_content_attrs(self.artifact)
        with self.assertRaises(HTTPError) as exc:
            self.client.put(self.content_unit['_href'], attrs)
        self.assertEqual(exc.exception.response.status_code, 405)
Ejemplo n.º 6
0
 def test_01_create_content_unit(self):
     """Create content unit."""
     attrs = gen_file_content_attrs(self.artifact)
     call_report = self.client.post(FILE_CONTENT_PATH, data=attrs)
     created_resources = next(api.poll_spawned_tasks(self.cfg, call_report))["created_resources"]
     self.content_unit.update(self.client.get(created_resources[0]))
     for key, val in attrs.items():
         with self.subTest(key=key):
             self.assertEqual(self.content_unit[key], val)
Ejemplo n.º 7
0
    def test_03_fully_update(self):
        """Attempt to update a content unit using HTTP PUT.

        This HTTP method is not supported and a HTTP exception is expected.
        """
        attrs = gen_file_content_attrs(self.artifact)
        with self.assertRaises(AttributeError) as exc:
            self.file_content_api.update(self.content_unit["pulp_href"], attrs)
        error_message = "'ContentFilesApi' object has no attribute 'update'"
        self.assertEqual(exc.exception.args[0], error_message)
Ejemplo n.º 8
0
 def test_01_create_content_unit(self):
     """Create content unit."""
     attrs = gen_file_content_attrs(self.artifact)
     response = self.file_content_api.create(**attrs)
     created_resources = monitor_task(response.task).created_resources
     content_unit = self.file_content_api.read(created_resources[0])
     self.content_unit.update(content_unit.to_dict())
     for key, val in attrs.items():
         with self.subTest(key=key):
             self.assertEqual(self.content_unit[key], val)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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")
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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(self.cfg)
        files = {"file": utils.http_get(FILE_URL)}
        artifact = self.client.post(ARTIFACTS_PATH, files=files)
        attrs = gen_file_content_attrs(artifact)

        # create first content unit.
        self.client.post(FILE_CONTENT_PATH, attrs)

        # using the same attrs used to create the first content unit.
        with self.assertRaises(TaskReportError) as exc:
            self.client.post(FILE_CONTENT_PATH, attrs)
        self.assertEqual(exc.exception.task["state"], "failed")
        error = exc.exception.task["error"]
        for key in ("already", "relative", "path", "digest"):
            self.assertIn(key, error["description"].lower(), error)