def test_all(self): """Test whether a particular repository version can be published. 1. Create a repository with at least 2 repository versions. 2. Create a publication without supplying a repository_version (i.e. take the latest ``repository_version``). 3. Assert that the publication ``repository_version`` attribute points to the latest repository version. 4. Create a publication by supplying the non-latest ``repository_version``. 5. Assert that the publication ``repository_version`` attribute points to the supplied repository version. 6. Assert that an exception is raised when providing two different repository versions to be published at same time. """ cfg = config.get_config() delete_orphans() client = api.Client(cfg, api.json_handler) body = gen_remote(fixture_u1.url, cookbooks={fixture_u1.example1_name: ""}) remote = client.post(COOKBOOK_REMOTE_PATH, body) self.addCleanup(client.delete, remote["pulp_href"]) repo = client.post(COOKBOOK_REPO_PATH, gen_repo()) self.addCleanup(client.delete, repo["pulp_href"]) sync(cfg, remote, repo, mirror=True) repo = client.get(repo["pulp_href"]) repo_content = get_cookbook_content(repo) self.assertTrue(repo_content) # Step 1 repo = client.post(COOKBOOK_REPO_PATH, gen_repo()) self.addCleanup(client.delete, repo["pulp_href"]) for cookbook in repo_content: modify_repo(cfg, repo, add_units=[cookbook]) version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo)) non_latest = choice(version_hrefs[:-1]) # Step 2 publication = create_publication(cfg, repo) # Step 3 self.assertEqual(publication["repository_version"], version_hrefs[-1]) # Step 4 publication = create_publication(cfg, repo, version_href=non_latest) # Step 5 self.assertEqual(publication["repository_version"], non_latest) # Step 6 with self.assertRaises(HTTPError): body = {"repository": repo["pulp_href"], "repository_version": non_latest} client.post(COOKBOOK_PUBLICATION_PATH, body)
def test_publish_invalid_repo_version(self): """Repo version containing two units with the same name and version can't be published.""" cfg = config.get_config() delete_orphans(cfg) client = api.Client(cfg, api.json_handler) # Create repo u1 and sync partially repo_u1 = client.post(REPO_PATH, gen_repo()) self.addCleanup(client.delete, repo_u1["_href"]) body = gen_remote(fixture_u1.url, cookbooks={fixture_u1.example1_name: ""}) remote_u1 = client.post(COOKBOOK_REMOTE_PATH, body) self.addCleanup(client.delete, remote_u1["_href"]) sync(cfg, remote_u1, repo_u1, mirror=True) repo_u1 = client.get(repo_u1["_href"]) # Create repo u1_diff_digest and sync partially repo_u1_diff_digest = client.post(REPO_PATH, gen_repo()) self.addCleanup(client.delete, repo_u1_diff_digest["_href"]) body = gen_remote(fixture_u1_diff_digest.url, cookbooks={fixture_u1.example1_name: ""}) remote_u1_diff_digest = client.post(COOKBOOK_REMOTE_PATH, body) self.addCleanup(client.delete, remote_u1_diff_digest["_href"]) sync(cfg, remote_u1_diff_digest, repo_u1_diff_digest, mirror=True) repo_u1_diff_digest = client.get(repo_u1_diff_digest["_href"]) # Add a content unit from u1_diff_digest to u1 (duplicate name&version) content_u1_diff_digest = get_cookbook_content(repo_u1_diff_digest) self.assertTrue(content_u1_diff_digest) client.post( repo_u1["_versions_href"], {"add_content_units": [content_u1_diff_digest[0]["_href"]]}) with self.assertRaisesRegex(TaskReportError, "would contain multiple versions"): create_publication(cfg, repo_u1)
def create_distribution(self, cfg, client, repo): """Create a publication for the latest repo version and a distribution.""" # Create a publication. publication = create_publication(cfg, repo) self.addCleanup(client.delete, publication["_href"]) # Create a distribution. body = gen_distribution() body["publication"] = publication["_href"] response_dict = client.post(COOKBOOK_DISTRIBUTION_PATH, body) dist_task = client.get(response_dict["task"]) distribution_href = dist_task["created_resources"][0] distribution = client.get(distribution_href) self.addCleanup(client.delete, distribution_href) # Assert that the publication contains a reference to the distribution publication = client.get(publication["_href"]) self.assertEqual(publication["distributions"], [distribution_href]) return distribution