Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a dedicated content filter test #912

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions pulp_deb/tests/functional/api/test_api_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import pytest

from pulp_deb.tests.functional.constants import (
DEB_FIXTURE_SINGLE_DIST,
DEB_FIXTURE_UPDATE_REPOSITORY_NAME,
)


@pytest.fixture
def deb_content_filters_init(deb_init_and_sync):
def _deb_content_filters_init():
remote_args = {"distributions": DEB_FIXTURE_SINGLE_DIST}
repo, _ = deb_init_and_sync(remote_args=remote_args)
repo_v1_href = repo.latest_version_href
assert repo_v1_href.endswith("/1/")

repo, _ = deb_init_and_sync(
repository=repo, url=DEB_FIXTURE_UPDATE_REPOSITORY_NAME, remote_args=remote_args
)
repo_v2_href = repo.latest_version_href
assert repo_v2_href.endswith("/2/")
return (repo, repo_v1_href, repo_v2_href)

return _deb_content_filters_init


@pytest.fixture
def deb_content_filters_get_hrefs(apt_release_api, apt_release_component_api):
def _deb_content_filters_get_hrefs(repo_version_href, component):
releases = apt_release_api.list(repository_version=repo_version_href)
release_href = releases.results[0].pulp_href
release_components = apt_release_component_api.list(repository_version=repo_version_href)
rc = [x for x in release_components.results if x.component == component]
rc_href = rc[0].pulp_href
return (release_href, rc_href)

return _deb_content_filters_get_hrefs


@pytest.mark.parallel
def test_content_relationship_filters(
deb_content_filters_init,
deb_content_filters_get_hrefs,
apt_package_api,
apt_release_api,
apt_release_component_api,
):
"""Test whether filtering content for different repository versions are working."""
# Create a repository with two different repository versions.
repo, repo_v1_href, repo_v2_href = deb_content_filters_init()
assert repo_v1_href.endswith("/1/")
assert repo_v2_href.endswith("/2/")

# Get the hrefs for the release and release components of the latest repository version
release_href, rc_href = deb_content_filters_get_hrefs(repo_v2_href, "asgard")

# Assert that the filters are working
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
packages = apt_package_api.list(release_component=f"{rc_href},{repo.pulp_href}")
assert packages.count == 5

# Filter for the specific package that got added in the latest repository version
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


@pytest.mark.parametrize(
"q,count",
[
# TODO: this should probably expanded to test multiple cases
pytest.param(*data, id=data[0])
for data in [("package__startswith=fri", 1), ("package__contains=hor", 1)]
],
)
def test_package_name_filters(
deb_init_and_sync,
apt_package_api,
q,
count,
delete_orphans_pre,
):
"""Test whether package name filtering is working."""
repo, _ = deb_init_and_sync()
assert repo.latest_version_href.endswith("/1/")
assert apt_package_api.list(q=q).count == count
2 changes: 1 addition & 1 deletion pulp_deb/tests/functional/api/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from pulp_deb.tests.functional.utils import get_counts_from_content_summary


@pytest.mark.parallel
def test_copy(
deb_init_and_sync,
deb_repository_factory,
apt_package_api,
deb_copy_content,
deb_get_repository_by_href,
deb_get_content_summary,
delete_orphans_pre,
):
"""Test whether the copy operation can successfully copy a single package."""
source_repo, _ = deb_init_and_sync()
Expand Down
34 changes: 0 additions & 34 deletions pulp_deb/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,40 +275,6 @@ def test_sync_optimize_skip_unchanged_package_index(
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


@pytest.mark.parallel
def test_sync_optimize_switch_to_no_mirror(
Expand Down