From 028f355d16ea98926056eb3610f3738e1831a8e5 Mon Sep 17 00:00:00 2001 From: Tobias Grigo Date: Fri, 3 Nov 2023 13:47:46 +0100 Subject: [PATCH] Simplify content fetching test fixtures [noissue] --- pulp_deb/tests/functional/api/test_copy.py | 10 +- .../functional/api/test_download_policies.py | 10 +- pulp_deb/tests/functional/api/test_publish.py | 6 +- .../api/test_pulpexport_pulpimport.py | 4 +- pulp_deb/tests/functional/api/test_sync.py | 10 +- pulp_deb/tests/functional/conftest.py | 95 +++---------------- 6 files changed, 35 insertions(+), 100 deletions(-) diff --git a/pulp_deb/tests/functional/api/test_copy.py b/pulp_deb/tests/functional/api/test_copy.py index 55c57b1c7..37b7f1cd8 100644 --- a/pulp_deb/tests/functional/api/test_copy.py +++ b/pulp_deb/tests/functional/api/test_copy.py @@ -13,7 +13,7 @@ def test_copy( apt_package_api, deb_copy_content, deb_get_repository_by_href, - deb_get_added_content_summary, + deb_get_content_summary_added_count, ): """Test whether the copy operation can successfully copy a single package.""" source_repo, _ = deb_init_and_sync() @@ -26,7 +26,7 @@ def test_copy( ) target_repo = deb_get_repository_by_href(target_repo.pulp_href) - assert DEB_ADVANCED_COPY_FIXTURE_SUMMARY == deb_get_added_content_summary(target_repo) + assert DEB_ADVANCED_COPY_FIXTURE_SUMMARY == deb_get_content_summary_added_count(target_repo) @pytest.mark.parallel @@ -35,7 +35,7 @@ def test_copy_all( deb_repository_factory, deb_copy_content, deb_get_repository_by_href, - deb_get_added_content_summary, + deb_get_content_summary_added_count, ): """Test whether the copy operation can successfully copy all packages of a repository.""" source_repo, _ = deb_init_and_sync() @@ -46,7 +46,9 @@ def test_copy_all( ) target_repo = deb_get_repository_by_href(target_repo.pulp_href) - assert DEB_FULL_ADVANCED_COPY_FIXTURE_SUMMARY == deb_get_added_content_summary(target_repo) + assert DEB_FULL_ADVANCED_COPY_FIXTURE_SUMMARY == deb_get_content_summary_added_count( + target_repo + ) @pytest.mark.parallel diff --git a/pulp_deb/tests/functional/api/test_download_policies.py b/pulp_deb/tests/functional/api/test_download_policies.py index aa211448c..a0d696731 100644 --- a/pulp_deb/tests/functional/api/test_download_policies.py +++ b/pulp_deb/tests/functional/api/test_download_policies.py @@ -8,8 +8,8 @@ def test_download_policy( apt_package_api, deb_init_and_sync, - deb_get_present_content_summary, - deb_get_added_content_summary, + deb_get_content_summary_added_count, + deb_get_content_summary_present_count, deb_publication_factory, remote_args, delete_orphans_pre, @@ -19,14 +19,14 @@ def test_download_policy( assert repo.latest_version_href.endswith("/1/") # Verify the correct amount of content units are available - assert DEB_FIXTURE_SUMMARY == deb_get_present_content_summary(repo) - assert DEB_FIXTURE_SUMMARY == deb_get_added_content_summary(repo) + assert DEB_FIXTURE_SUMMARY == deb_get_content_summary_present_count(repo) + assert DEB_FIXTURE_SUMMARY == deb_get_content_summary_added_count(repo) # Sync again and verify the same amount of content units are available latest_version_href = repo.latest_version_href repo, _ = deb_init_and_sync(repository=repo, remote=remote) assert repo.latest_version_href == latest_version_href - assert DEB_FIXTURE_SUMMARY == deb_get_present_content_summary(repo) + assert DEB_FIXTURE_SUMMARY == deb_get_content_summary_present_count(repo) # Create a publication and verify the `repository_version` is not empty publication = deb_publication_factory(repo, simple=True) diff --git a/pulp_deb/tests/functional/api/test_publish.py b/pulp_deb/tests/functional/api/test_publish.py index 59b56855e..961b72383 100644 --- a/pulp_deb/tests/functional/api/test_publish.py +++ b/pulp_deb/tests/functional/api/test_publish.py @@ -290,7 +290,7 @@ def test_publish_repository_version_verbatim( def test_publish_empty_repository( create_publication_and_verify_repo_version, deb_distribution_factory, - deb_get_present_content, + deb_get_content_summary, download_content_unit, ): """Test whether an empty respository with no packages can be published.""" @@ -300,9 +300,9 @@ def test_publish_empty_repository( publication_args=DEB_PUBLICATION_ARGS_SIMPLE_AND_STRUCTURED, ) - release = deb_get_present_content( + release = deb_get_content_summary( repo=publication.to_dict(), version_href=publication.repository_version - ) + ).present package_index_paths = DEB_PUBLISH_EMPTY_REPOSITORY["package_index_paths"] assert DEB_PACKAGE_NAME not in release.keys() diff --git a/pulp_deb/tests/functional/api/test_pulpexport_pulpimport.py b/pulp_deb/tests/functional/api/test_pulpexport_pulpimport.py index 11aa59387..f5d830b11 100644 --- a/pulp_deb/tests/functional/api/test_pulpexport_pulpimport.py +++ b/pulp_deb/tests/functional/api/test_pulpexport_pulpimport.py @@ -250,7 +250,7 @@ def test_import_create_repos( deb_create_export, deb_delete_remote, deb_delete_repository, - deb_get_present_content_summary, + deb_get_content_summary_present_count, deb_importer_factory, deb_init_and_sync, deb_perform_import, @@ -303,7 +303,7 @@ def test_import_create_repos( # Inspect the results assert repo.latest_version_href.endswith("/versions/1/") assert apt_repository_api.list().count == existing_repos + 1 - assert deb_get_present_content_summary(repo) == DEB_FIXTURE_SUMMARY + assert deb_get_content_summary_present_count(repo) == DEB_FIXTURE_SUMMARY def _find_path(created_export): diff --git a/pulp_deb/tests/functional/api/test_sync.py b/pulp_deb/tests/functional/api/test_sync.py index 2a354aef3..580b81bf6 100644 --- a/pulp_deb/tests/functional/api/test_sync.py +++ b/pulp_deb/tests/functional/api/test_sync.py @@ -34,8 +34,8 @@ ) def test_sync( deb_init_and_sync, - deb_get_added_content_summary, - deb_get_present_content_summary, + deb_get_content_summary_added_count, + deb_get_content_summary_present_count, deb_get_repository_by_href, deb_sync_repository, fixture_summary, @@ -49,8 +49,8 @@ def test_sync( assert not is_sync_skipped(task, DEB_REPORT_CODE_SKIP_RELEASE) # Verify that the repo content and added content matches the summary - assert deb_get_present_content_summary(repo) == fixture_summary - assert deb_get_added_content_summary(repo) == fixture_summary + assert deb_get_content_summary_present_count(repo) == fixture_summary + assert deb_get_content_summary_added_count(repo) == fixture_summary # Sync the repository again task_skip = deb_sync_repository(remote, repo) @@ -61,7 +61,7 @@ def test_sync( assert is_sync_skipped(task_skip, DEB_REPORT_CODE_SKIP_RELEASE) # Verify that the repo content still matches the summary - assert deb_get_present_content_summary(repo) == fixture_summary + assert deb_get_content_summary_present_count(repo) == fixture_summary @pytest.mark.skip("Skip - ignore_missing_package_indices sync parameter does currently not work") diff --git a/pulp_deb/tests/functional/conftest.py b/pulp_deb/tests/functional/conftest.py index 51864f706..f02b936ff 100644 --- a/pulp_deb/tests/functional/conftest.py +++ b/pulp_deb/tests/functional/conftest.py @@ -617,73 +617,6 @@ def _deb_init_and_sync( return _deb_init_and_sync -@pytest.fixture -def deb_get_content(apt_repository_versions_api): - """A fixture that fetches the content from a repository.""" - - def _deb_get_content(repo, version_href=None): - """Fetches the content from a given repository. - :param repo: The repository where the content is fetched from. - :param version_href: The repository version from where the content should be fetched. - Default: latest repository version. - :returns: The content summary of the repository. - """ - version_href = version_href or repo.latest_version_href - if version_href is None: - return {} - return apt_repository_versions_api.read(version_href).content_summary - - return _deb_get_content - - -@pytest.fixture -def deb_get_present_content(deb_get_content): - """A fixture that fetches the present content from a repository.""" - - def _deb_get_present_content(repo, version_href=None): - """Fetches the present content from a given repository. - - :param repo: The repository where the content is fetched from. - :param version_href: The repository version from where the content is fetched freom. - :returns: The present content of the repository. - """ - return deb_get_content(repo, version_href).present - - return _deb_get_present_content - - -@pytest.fixture -def deb_get_added_content(deb_get_content): - """A fixture that fetches the added content from a repository.""" - - def _deb_get_added_content(repo, version_href=None): - """Fetches the added content from a given repository. - - :param repo: The repository where the content is fetched from. - :param version_href: The repository version from where the content is fetched freom. - :returns: The added content of the repository. - """ - return deb_get_content(repo, version_href).added - - return _deb_get_added_content - - -@pytest.fixture -def deb_get_removed_content(deb_get_content): - """A fixture that fetches the removed content from a repository.""" - - def _deb_get_removed_content(repo, version_href=None): - """Fetches the removed content from a given repository. - - :param repo: The repository where the content is fetched from. - :param version_href: The repository version from where the content is fetched freom. - :returns: The removed content of the repository. - """ - return deb_get_content(repo, version_href).removed - - return _deb_get_removed_content - - @pytest.fixture def deb_get_content_summary(apt_repository_versions_api): """A fixture that fetches the content summary from a repository.""" @@ -705,10 +638,10 @@ def _deb_get_content_summary(repo, version_href=None): @pytest.fixture -def deb_get_added_content_summary(deb_get_content_summary): - """A fixture that fetches the added content summary from a repository version.""" +def deb_get_content_summary_added_count(deb_get_content_summary): + """A fixture that fetches the count of added content summary from a repository version.""" - def _deb_get_added_content_summary(repo, version_href=None): + def _deb_get_content_summary_added_count(repo, version_href=None): """Fetches the added content summary from a given repository. :param repo: The repository where content is fetched from. @@ -720,14 +653,14 @@ def _deb_get_added_content_summary(repo, version_href=None): content[key] = content[key]["count"] return content - return _deb_get_added_content_summary + return _deb_get_content_summary_added_count @pytest.fixture -def deb_get_present_content_summary(deb_get_content_summary): - """A fixture that fetches the present content summary from a repository version.""" +def deb_get_content_summary_present_count(deb_get_content_summary): + """A fixture that fetches the count of present content summary from a repository version.""" - def _deb_get_present_content_summary(repo, version_href=None): + def _deb_get_content_summary_present_count(repo, version_href=None): """Fetches the present content summary from a given repository. :param repo: The repository where content is fetched from. @@ -739,14 +672,14 @@ def _deb_get_present_content_summary(repo, version_href=None): content[key] = content[key]["count"] return content - return _deb_get_present_content_summary + return _deb_get_content_summary_present_count @pytest.fixture -def deb_get_removed_content_summary(deb_get_content_summary): - """A fixture that fetches the removed content summary from a repository version.""" +def deb_get_content_summary_removed_count(deb_get_content_summary): + """A fixture that fetches the count removed content summary from a repository version.""" - def _deb_get_removed_content_summary(repo, version_href=None): + def _deb_get_content_summary_removed_count(repo, version_href=None): """Fetches the removed content from a given repository. :param repo: The repository where the content is fetched from. @@ -758,11 +691,11 @@ def _deb_get_removed_content_summary(repo, version_href=None): content[key] = content[key]["count"] return content - return _deb_get_removed_content_summary + return _deb_get_content_summary_removed_count @pytest.fixture -def deb_get_content_types(deb_get_present_content, request): +def deb_get_content_types(deb_get_content_summary, request): """A fixture that fetches content by type.""" def _deb_get_content_types(content_api_name, content_type, repo, version_href=None): @@ -775,7 +708,7 @@ def _deb_get_content_types(content_api_name, content_type, repo, version_href=No :returns: List of the fetched content type. """ api = request.getfixturevalue(content_api_name) - content = deb_get_present_content(repo, version_href) + content = deb_get_content_summary(repo, version_href).present if content_type not in content.keys(): return {} content_hrefs = content[content_type]["href"]