|
| 1 | +import pytest |
| 2 | + |
| 3 | +from pulpcore.client.pulp_deb import ( |
| 4 | + AptRepositorySyncURL, |
| 5 | +) |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +def setup_autopublish( |
| 10 | + deb_get_fixture_server_url, deb_repository_factory, deb_remote_factory, deb_distribution_factory |
| 11 | +): |
| 12 | + """Create remote, repo, publish settings, and distribution.""" |
| 13 | + url = deb_get_fixture_server_url() |
| 14 | + remote = deb_remote_factory(url=url) |
| 15 | + repo = deb_repository_factory(autopublish=True) |
| 16 | + distribution = deb_distribution_factory(repository=repo) |
| 17 | + |
| 18 | + return repo, remote, distribution |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.parallel |
| 22 | +def test_01_sync(setup_autopublish, apt_repository_api, apt_publication_api, monitor_task): |
| 23 | + """Assert that syncing the repository triggers auto-publish and auto-distribution.""" |
| 24 | + repo, remote, distribution = setup_autopublish |
| 25 | + assert apt_publication_api.list(repository=repo.pulp_href).count == 0 |
| 26 | + assert distribution.publication is None |
| 27 | + |
| 28 | + # Sync the repository. |
| 29 | + repository_sync_data = AptRepositorySyncURL(remote=remote.pulp_href) |
| 30 | + sync_response = apt_repository_api.sync(repo.pulp_href, repository_sync_data) |
| 31 | + task = monitor_task(sync_response.task) |
| 32 | + |
| 33 | + # Check that all the appropriate resources were created |
| 34 | + assert len(task.created_resources) > 1 |
| 35 | + publications = apt_publication_api.list(repository=repo.pulp_href) |
| 36 | + assert publications.count == 1 |
| 37 | + |
| 38 | + # Sync the repository again. Since there should be no new repository version, there |
| 39 | + # should be no new publications or distributions either. |
| 40 | + sync_response = apt_repository_api.sync(repo.pulp_href, repository_sync_data) |
| 41 | + task = monitor_task(sync_response.task) |
| 42 | + |
| 43 | + assert len(task.created_resources) == 0 |
| 44 | + assert apt_publication_api.list(repository=repo.pulp_href).count == 1 |
| 45 | + |
| 46 | + |
| 47 | +@pytest.mark.parallel |
| 48 | +def test_02_modify( |
| 49 | + setup_autopublish, apt_repository_api, apt_package_api, apt_publication_api, monitor_task |
| 50 | +): |
| 51 | + """Assert that modifying the repository triggers auto-publish and auto-distribution.""" |
| 52 | + repo, remote, distribution = setup_autopublish |
| 53 | + assert apt_publication_api.list(repository=repo.pulp_href).count == 0 |
| 54 | + assert distribution.publication is None |
| 55 | + |
| 56 | + # Modify the repository by adding a content unit |
| 57 | + content = apt_package_api.list().results[0].pulp_href |
| 58 | + |
| 59 | + modify_response = apt_repository_api.modify(repo.pulp_href, {"add_content_units": [content]}) |
| 60 | + task = monitor_task(modify_response.task) |
| 61 | + |
| 62 | + # Check that all the appropriate resources were created |
| 63 | + assert len(task.created_resources) > 1 |
| 64 | + publications = apt_publication_api.list(repository=repo.pulp_href) |
| 65 | + assert publications.count == 1 |
0 commit comments