Skip to content

Commit

Permalink
Simplify content fetching test fixtures
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
hstct committed Nov 3, 2023
1 parent 5b17ad2 commit 028f355
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 100 deletions.
10 changes: 6 additions & 4 deletions pulp_deb/tests/functional/api/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pulp_deb/tests/functional/api/test_download_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pulp_deb/tests/functional/api/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pulp_deb/tests/functional/api/test_pulpexport_pulpimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions pulp_deb/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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")
Expand Down
95 changes: 14 additions & 81 deletions pulp_deb/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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):
Expand All @@ -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"]
Expand Down

0 comments on commit 028f355

Please sign in to comment.