def test_collection_upload(self): """Upload a collection. This test targets the following issue: * `Pulp #5262 <https://pulp.plan.io/issues/5262>`_ """ UPLOAD_PATH = urljoin(self.cfg.get_base_url(), "ansible/collections/") response = self.client.post(UPLOAD_PATH, files=self.collection) for key, value in response.items(): with self.subTest(key=key): if key in COLLECTION_METADATA.keys(): self.assertEqual(COLLECTION_METADATA[key], value, response) self.assertEqual(response["sha256"], self.collection_sha256, response) with self.assertRaises(TaskReportError) as exc: self.client.post(UPLOAD_PATH, files=self.collection) self.assertEqual(exc.exception.task["state"], "failed") error = exc.exception.task["error"] for key in ("artifact", "already", "exists"): self.assertIn(key, error["description"].lower(), error) delete_orphans(self.cfg)
def test_collection_upload_repeat(pulp_client, known_collection, pulp_dist): """Upload a duplicate collection. Should fail, because of the conflict of collection name and version. """ cfg = config.get_config() url = urljoin(cfg.get_base_url(), f"api/{pulp_dist['base_path']}/v3/artifacts/collections/") with pytest.raises(HTTPError) as ctx: response = pulp_client.post(url, files=known_collection) assert ctx.exception.response.json()["errors"][0] == { "status": "400", "code": "invalid", "title": "Invalid input.", "detail": "Artifact already exists.", } for key, value in collection_upload.items(): if key in COLLECTION_METADATA.keys(): assert COLLECTION_METADATA[key] == value, response collection_sha256 = hashlib.sha256( known_collection["files"][1]).hexdigest() assert response["sha256"] == collection_sha256, response
def test_collection_upload(self): """Upload a collection. This test targets the following issue: * `Pulp #5262 <https://pulp.plan.io/issues/5262>`_ """ UPLOAD_PATH = urljoin(self.cfg.get_base_url(), "ansible/collections/") response = self.client.post(UPLOAD_PATH, files=self.collection) for key, value in response.items(): with self.subTest(key=key): if key in COLLECTION_METADATA.keys(): self.assertEqual(COLLECTION_METADATA[key], value, response) self.assertEqual(response["sha256"], self.collection_sha256, response) with self.assertRaises(HTTPError) as ctx: self.client.using_handler(api.code_handler).post( UPLOAD_PATH, files=self.collection) for key in ("artifact", "already", "exists"): self.assertIn(key, ctx.exception.response.json()[0].lower(), ctx.exception.response) delete_orphans(self.cfg)
def test_collection_upload(collection_upload): """Upload a new collection. Uploads a newly generated collection and validates the resulting collection version details. """ # Validate the upload response assert collection_upload["error"] is None assert re.match( r"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}", collection_upload["id"] ) assert collection_upload["state"] == "completed" assert "updated_at" in collection_upload assert "started_at" in collection_upload assert "created_at" in collection_upload assert "finished_at" in collection_upload assert "messages" in collection_upload for key, value in collection_upload.items(): if key in COLLECTION_METADATA.keys(): assert COLLECTION_METADATA[key] == value, collection_upload