Skip to content

Commit

Permalink
Add tests for content filters, and make filters return empty list if …
Browse files Browse the repository at this point in the history
…Content not in RepoVersion instead of raising ValidationError.

closes pulp#780
  • Loading branch information
sdherr committed Jun 5, 2023
1 parent a0816d5 commit 3302e30
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES/780.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add tests for content filters, and make filters return empty list if Content not in RepoVersion instead of raising ValidationError.
5 changes: 2 additions & 3 deletions pulp_deb/app/viewsets/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ def filter(self, qs, value):

arg_instance = NamedModelViewSet.get_resource(arg_href, self.ARG_CLASS)
if not repo_version.content.filter(pk=arg_instance.pk).exists():
raise ValidationError(
detail=_("Specified filter argument is not in specified RepositoryVersion")
)
# If the package (or whatever) is not in the repo version then return an empty list.
return qs.none()

return self._filter(qs, arg_instance, repo_version.content)

Expand Down
43 changes: 41 additions & 2 deletions pulp_deb/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def test_sync_optimize_skip_unchanged_package_index(
deb_repository_factory,
deb_get_repository_by_href,
deb_sync_repository,
apt_package_api,
apt_release_api,
apt_release_component_api,
):
"""Test whether package synchronization is skipped when a package has not been changed."""
# Create a repository and a remote and verify latest `repository_version` is 0
Expand All @@ -264,7 +267,8 @@ def test_sync_optimize_skip_unchanged_package_index(
repo = deb_get_repository_by_href(repo.pulp_href)

# Verify latest `repository_version` is 1 and sync was not skipped
assert repo.latest_version_href.endswith("/1/")
repo_v1_href = repo.latest_version_href
assert repo_v1_href.endswith("/1/")
assert not is_sync_skipped(task, DEB_REPORT_CODE_SKIP_RELEASE)
assert not is_sync_skipped(task, DEB_REPORT_CODE_SKIP_PACKAGE)

Expand All @@ -276,10 +280,45 @@ def test_sync_optimize_skip_unchanged_package_index(
repo = deb_get_repository_by_href(repo.pulp_href)

# Verify latest `repository_version` is 2, release was not skipped and package was skipped
assert repo.latest_version_href.endswith("/2/")
repo_v2_href = repo.latest_version_href
assert repo_v2_href.endswith("/2/")
assert not is_sync_skipped(task_diff, DEB_REPORT_CODE_SKIP_RELEASE)
assert is_sync_skipped(task_diff, DEB_REPORT_CODE_SKIP_PACKAGE)

# === Test whether the content filters are working. ===
# This doesn't _technically_ have anything to do with testing syncing, but it's a
# convenient place to do it since we've already created a repo with content and
# multiple versions. Repo version 1 synced from debian/ragnarok and version 2 synced
# from debian-update/ragnarok.
releases = apt_release_api.list(repository_version=repo_v2_href)
assert releases.count == 1
release_href = releases.results[0].pulp_href
release_components = apt_release_component_api.list(repository_version=repo_v2_href)
assert release_components.count == 2
rc = [x for x in release_components.results if x.component == "asgard"]
rc_href = rc[0].pulp_href

# some simple "happy path" tests to ensure the filters are working properly
assert apt_package_api.list(release=f"{release_href},{repo_v1_href}").count == 4
assert apt_package_api.list(release=f"{release_href},{repo_v2_href}").count == 6
assert apt_package_api.list(release=f"{release_href},{repo.pulp_href}").count == 6

assert apt_package_api.list(release_component=f"{rc_href},{repo_v1_href}").count == 3
assert apt_package_api.list(release_component=f"{rc_href},{repo_v2_href}").count == 5
assert apt_package_api.list(release_component=f"{rc_href},{repo.pulp_href}").count == 5

packages = apt_package_api.list(release_component=f"{rc_href},{repo.pulp_href}")
# The package that was added to asgard in debian-update.
package_href = [x for x in packages.results if x.package == "heimdallr"][0].pulp_href

assert apt_release_api.list(package=f"{package_href},{repo_v1_href}").count == 0
assert apt_release_api.list(package=f"{package_href},{repo_v2_href}").count == 1
assert apt_release_api.list(package=f"{package_href},{repo.pulp_href}").count == 1

assert apt_release_component_api.list(package=f"{package_href},{repo_v1_href}").count == 0
assert apt_release_component_api.list(package=f"{package_href},{repo_v2_href}").count == 1
assert apt_release_component_api.list(package=f"{package_href},{repo.pulp_href}").count == 1


def test_sync_orphan_cleanup_fail(
deb_remote_factory,
Expand Down
14 changes: 14 additions & 0 deletions pulp_deb/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
AptRepositorySyncURL,
ContentGenericContentsApi,
ContentPackagesApi,
ContentReleasesApi,
ContentReleaseComponentsApi,
DebAptPublication,
DebVerbatimPublication,
DistributionsAptApi,
Expand Down Expand Up @@ -68,6 +70,18 @@ def apt_package_api(apt_client):
return ContentPackagesApi(apt_client)


@pytest.fixture
def apt_release_api(apt_client):
"""Fixture for APT release API."""
return ContentReleasesApi(apt_client)


@pytest.fixture
def apt_release_component_api(apt_client):
"""Fixture for APT release API."""
return ContentReleaseComponentsApi(apt_client)


@pytest.fixture
def apt_generic_content_api(apt_client):
"""Fixture for APT generic content API."""
Expand Down

0 comments on commit 3302e30

Please sign in to comment.