Skip to content

Commit

Permalink
Add local test data repositories
Browse files Browse the repository at this point in the history
closes pulp#395
  • Loading branch information
hstct committed Feb 20, 2023
1 parent d37cf89 commit ab1180a
Show file tree
Hide file tree
Showing 202 changed files with 2,503 additions and 45 deletions.
1 change: 1 addition & 0 deletions CHANGES/395.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add precompiled test data for pytest to use in functional tests
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ include pulp_deb/tests/functional/sign_deb_release.sh
include pyproject.toml
include requirements.txt
include unittest_requirements.txt
recursive-include pulp_deb/tests/functional/data *
recursive-include pulp_deb/tests/functional/fixtures *
65 changes: 42 additions & 23 deletions pulp_deb/tests/functional/api/test_crud_remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from pulp_smash import utils

from pulp_deb.tests.functional.constants import DOWNLOAD_POLICIES, DEB_SIGNING_KEY
from pulp_deb.tests.functional.utils import gen_deb_remote
from pulp_deb.tests.functional.utils import gen_local_deb_remote


@pytest.mark.parallel
def test_create_remote_repository(deb_remote_custom_data_factory):
def test_create_remote_repository(deb_remote_custom_data_factory, deb_get_fixture_server_url):
"""Test creation of the remote."""
data = gen_verbose_remote_data()
url = deb_get_fixture_server_url()
data = gen_verbose_remote_data(url)
remote = deb_remote_custom_data_factory(data)

for key, val in data.items():
Expand All @@ -22,9 +23,12 @@ def test_create_remote_repository(deb_remote_custom_data_factory):


@pytest.mark.parallel
def test_create_remote_repository_with_same_name(deb_remote_custom_data_factory):
def test_create_remote_repository_with_same_name(
deb_remote_custom_data_factory, deb_get_fixture_server_url
):
"""Verify whether it is possible to create a remote with the same name."""
data = gen_verbose_remote_data()
url = deb_get_fixture_server_url()
data = gen_verbose_remote_data(url)
deb_remote_custom_data_factory(data)

with pytest.raises(ApiException) as exc:
Expand All @@ -34,9 +38,12 @@ def test_create_remote_repository_with_same_name(deb_remote_custom_data_factory)


@pytest.mark.parallel
def test_create_remote_repository_without_url(deb_remote_custom_data_factory):
def test_create_remote_repository_without_url(
deb_remote_custom_data_factory, deb_get_fixture_server_url
):
"""Verify whether it is possible to create a remote without an URL."""
data = gen_verbose_remote_data()
url = deb_get_fixture_server_url()
data = gen_verbose_remote_data(url)
del data["url"]

with pytest.raises(ApiException) as exc:
Expand All @@ -47,11 +54,13 @@ def test_create_remote_repository_without_url(deb_remote_custom_data_factory):

@pytest.mark.parallel
def test_read_remote_by_href(
deb_remote_custom_data_factory,
deb_get_fixture_server_url,
deb_get_remote_by_href,
deb_remote_custom_data_factory,
):
"""Verify whether it is possible to read a remote repository by its href."""
data = gen_verbose_remote_data()
url = deb_get_fixture_server_url()
data = gen_verbose_remote_data(url)
remote = deb_remote_custom_data_factory(data)
read_remote = deb_get_remote_by_href(remote.pulp_href)

Expand All @@ -61,11 +70,13 @@ def test_read_remote_by_href(

@pytest.mark.parallel
def test_read_remote_by_name(
deb_remote_custom_data_factory,
deb_get_fixture_server_url,
deb_get_remotes_by_name,
deb_remote_custom_data_factory,
):
"""Verify whether it is possible to read a remote repository by its name."""
data = gen_verbose_remote_data()
url = deb_get_fixture_server_url()
data = gen_verbose_remote_data(url)
remote = deb_remote_custom_data_factory(data)
read_remote = deb_get_remotes_by_name(remote.name)

Expand All @@ -77,14 +88,16 @@ def test_read_remote_by_name(

@pytest.mark.parallel
def test_patch_remote(
deb_remote_custom_data_factory,
deb_get_fixture_server_url,
deb_get_remote_by_href,
deb_patch_remote,
deb_remote_custom_data_factory,
):
"""Verify whether it is possible to update a remote with PATCH."""
data = gen_verbose_remote_data()
url = deb_get_fixture_server_url()
data = gen_verbose_remote_data(url)
remote = deb_remote_custom_data_factory(data)
patch_data = gen_verbose_remote_data()
patch_data = gen_verbose_remote_data(url)
deb_patch_remote(remote, patch_data)
patch_remote = deb_get_remote_by_href(remote.pulp_href)

Expand All @@ -97,14 +110,16 @@ def test_patch_remote(

@pytest.mark.parallel
def test_put_remote(
deb_remote_custom_data_factory,
deb_get_fixture_server_url,
deb_get_remote_by_href,
deb_put_remote,
deb_remote_custom_data_factory,
):
"""Verify whether it is possible to update a remote with PUT."""
data = gen_verbose_remote_data()
url = deb_get_fixture_server_url()
data = gen_verbose_remote_data(url)
remote = deb_remote_custom_data_factory(data)
put_data = gen_verbose_remote_data()
put_data = gen_verbose_remote_data(url)
deb_put_remote(remote, put_data)
put_remote = deb_get_remote_by_href(remote.pulp_href)

Expand All @@ -118,11 +133,13 @@ def test_put_remote(
@pytest.mark.parallel
def test_delete_remote(
deb_delete_remote,
deb_remote_custom_data_factory,
deb_get_fixture_server_url,
deb_get_remote_by_href,
deb_remote_custom_data_factory,
):
"""Verify whether it is possible to delete a remote."""
data = gen_verbose_remote_data()
url = deb_get_fixture_server_url()
data = gen_verbose_remote_data(url)
remote = deb_remote_custom_data_factory(data)
deb_delete_remote(remote)

Expand All @@ -134,13 +151,15 @@ def test_delete_remote(

@pytest.mark.parallel
def test_remote_download_policies(
deb_remote_custom_data_factory,
deb_get_remote_by_href,
deb_get_fixture_server_url,
deb_patch_remote,
deb_remote_custom_data_factory,
):
"""Verify download policy behavior for valid and invalid values."""
# Create a remote without a download policy.
data = gen_verbose_remote_data()
url = deb_get_fixture_server_url()
data = gen_verbose_remote_data(url)
del data["policy"]
remote = deb_remote_custom_data_factory(data)

Expand Down Expand Up @@ -169,7 +188,7 @@ def test_remote_download_policies(
assert remote.policy == remote_snapshot.policy


def gen_verbose_remote_data():
def gen_verbose_remote_data(url):
"""Return a semi-random dict for use in defining a remote.
For most tests, it's desirable to create remotes with as few attributes
Expand All @@ -178,7 +197,7 @@ def gen_verbose_remote_data():
sense to provide as many attributes as possible.
Note that 'username' and 'password' are write-only attributes.
"""
data = gen_deb_remote()
data = gen_local_deb_remote(url)
data.update(
{
"password": utils.uuid4(),
Expand Down
8 changes: 5 additions & 3 deletions pulp_deb/tests/functional/api/test_download_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from pulp_smash import config, utils
from pulp_smash.pulp3.utils import download_content_unit
from pulp_deb.tests.functional.constants import DEB_FIXTURE_STANDARD_REPOSITORY_NAME

from pulp_deb.tests.functional.constants import DEB_FIXTURE_URL
from pulp_deb.tests.functional.utils import (
get_deb_content_unit_paths,
get_deb_verbatim_content_unit_paths,
Expand All @@ -24,6 +24,7 @@ def test_download_content(
deb_verbatim_publication_factory,
deb_get_repository_by_href,
deb_sync_repository,
deb_fixture_server,
is_verbatim,
):
"""Verify whether content served by pulp can be downloaded.
Expand All @@ -33,7 +34,7 @@ def test_download_content(
"""
# Create repository, remote and sync them
repo = deb_repository_factory()
remote = deb_remote_factory()
remote = deb_remote_factory(DEB_FIXTURE_STANDARD_REPOSITORY_NAME)
deb_sync_repository(remote, repo)
repo = deb_get_repository_by_href(repo.pulp_href)

Expand All @@ -47,8 +48,9 @@ def test_download_content(

# Select a random content unit from the distribution and store its checksums
unit_paths = get_random_content_unit_path(repo, is_verbatim)
url = deb_fixture_server.make_url(DEB_FIXTURE_STANDARD_REPOSITORY_NAME)
fixtures_hashes = [
hashlib.sha256(utils.http_get(urljoin(DEB_FIXTURE_URL, unit_path[0]))).hexdigest()
hashlib.sha256(utils.http_get(urljoin(url, unit_path[0]))).hexdigest()
for unit_path in unit_paths
]

Expand Down
3 changes: 1 addition & 2 deletions pulp_deb/tests/functional/api/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from pulp_deb.tests.functional.constants import (
DEB_FIXTURE_DISTRIBUTIONS,
DEB_FIXTURE_URL,
DEB_GENERIC_CONTENT_NAME,
DEB_PACKAGE_NAME,
)
Expand Down Expand Up @@ -54,7 +53,7 @@ def test_publish_any_repo_version(
cfg = config.get_config()

# Create a repository with at least two repository versions
remote = deb_remote_factory(url=DEB_FIXTURE_URL, distributions=DEB_FIXTURE_DISTRIBUTIONS)
remote = deb_remote_factory(distributions=DEB_FIXTURE_DISTRIBUTIONS)
repo = deb_repository_factory()
deb_sync_repository(remote, repo)
for deb_generic_content in get_content(repo.to_dict())[DEB_GENERIC_CONTENT_NAME]:
Expand Down
25 changes: 12 additions & 13 deletions pulp_deb/tests/functional/api/test_sync_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
DEB_FIXTURE_COMPONENT,
DEB_FIXTURE_COMPONENT_UPDATE,
DEB_FIXTURE_SINGLE_DIST,
DEB_FIXTURE_URL,
DEB_FIXTURE_DISTRIBUTIONS,
DEB_FIXTURE_URL_UPDATE,
DEB_FIXTURE_UPDATE_REPOSITORY_NAME,
DEB_REPORT_CODE_SKIP_PACKAGE,
DEB_REPORT_CODE_SKIP_RELEASE,
)
Expand All @@ -25,7 +24,7 @@ def test_sync_optimize_skip_unchanged_release_file(
"""Test whether synchronization is skipped when a Release file remains unchanged."""
# Create a repository and a remote and verify latest `repository_version` is 0
repo = deb_repository_factory()
remote = deb_remote_factory(url=DEB_FIXTURE_URL, distributions=DEB_FIXTURE_DISTRIBUTIONS)
remote = deb_remote_factory(distributions=DEB_FIXTURE_DISTRIBUTIONS)
assert repo.latest_version_href.endswith("/0/")

# Sync the repository
Expand All @@ -50,16 +49,16 @@ def test_sync_optimize_skip_unchanged_release_file(
"remote_params, remote_diff_params",
[
(
[DEB_FIXTURE_URL, DEB_FIXTURE_SINGLE_DIST, DEB_FIXTURE_COMPONENT, None],
[DEB_FIXTURE_URL, DEB_FIXTURE_SINGLE_DIST, DEB_FIXTURE_COMPONENT_UPDATE, None],
["/debian/", DEB_FIXTURE_SINGLE_DIST, DEB_FIXTURE_COMPONENT, None],
["/debian/", DEB_FIXTURE_SINGLE_DIST, DEB_FIXTURE_COMPONENT_UPDATE, None],
),
(
[DEB_FIXTURE_URL, DEB_FIXTURE_SINGLE_DIST, None, DEB_FIXTURE_ARCH],
[DEB_FIXTURE_URL, DEB_FIXTURE_SINGLE_DIST, None, DEB_FIXTURE_ARCH_UPDATE],
["/debian/", DEB_FIXTURE_SINGLE_DIST, None, DEB_FIXTURE_ARCH],
["/debian/", DEB_FIXTURE_SINGLE_DIST, None, DEB_FIXTURE_ARCH_UPDATE],
),
(
[DEB_FIXTURE_URL, DEB_FIXTURE_SINGLE_DIST, DEB_FIXTURE_COMPONENT, None],
[DEB_FIXTURE_URL_UPDATE, DEB_FIXTURE_SINGLE_DIST, DEB_FIXTURE_COMPONENT_UPDATE, None],
["/debian/", DEB_FIXTURE_SINGLE_DIST, DEB_FIXTURE_COMPONENT, None],
["/debian-update/", DEB_FIXTURE_SINGLE_DIST, DEB_FIXTURE_COMPONENT_UPDATE, None],
),
],
)
Expand All @@ -82,7 +81,7 @@ def test_sync_optimize_no_skip_release_file(
# Create a repository and a remote and verify latest `repository_version` is 0
repo = deb_repository_factory()
remote = deb_remote_factory(
url=remote_params[0],
remote_params[0],
distributions=remote_params[1],
components=remote_params[2],
architectures=remote_params[3],
Expand All @@ -100,7 +99,7 @@ def test_sync_optimize_no_skip_release_file(

# Create a new remote with different parameters and sync with repository
remote_diff = deb_remote_factory(
url=remote_diff_params[0],
remote_diff_params[0],
distributions=remote_diff_params[1],
components=remote_diff_params[2],
architectures=remote_diff_params[3],
Expand All @@ -124,7 +123,7 @@ def test_sync_optimize_skip_unchanged_package_index(
"""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
repo = deb_repository_factory()
remote = deb_remote_factory(url=DEB_FIXTURE_URL, distributions=DEB_FIXTURE_SINGLE_DIST)
remote = deb_remote_factory(distributions=DEB_FIXTURE_SINGLE_DIST)
assert repo.latest_version_href.endswith("/0/")

# Sync the repository
Expand All @@ -138,7 +137,7 @@ def test_sync_optimize_skip_unchanged_package_index(

# Create new remote with both updated and unchanged packages and sync with repository
remote_diff = deb_remote_factory(
url=DEB_FIXTURE_URL_UPDATE, distributions=DEB_FIXTURE_SINGLE_DIST
DEB_FIXTURE_UPDATE_REPOSITORY_NAME, distributions=DEB_FIXTURE_SINGLE_DIST
)
task_diff = deb_sync_repository(remote_diff, repo)
repo = deb_get_repository_by_href(repo.pulp_href)
Expand Down
33 changes: 29 additions & 4 deletions pulp_deb/tests/functional/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from pulp_smash.pulp3.bindings import monitor_task
from pulp_smash.pulp3.utils import gen_distribution, gen_repo
from pathlib import Path
import pytest
import os
import stat

from pulp_deb.tests.functional.utils import gen_local_deb_remote
from pulp_smash.utils import execute_pulpcore_python, uuid4
from pulp_deb.tests.functional.utils import gen_deb_remote
from pulp_deb.tests.functional.constants import DEB_FIXTURE_STANDARD_REPOSITORY_NAME

from pulpcore.client.pulp_deb import (
ApiClient,
Expand Down Expand Up @@ -99,11 +101,16 @@ def _deb_repository_factory():


@pytest.fixture
def deb_remote_factory(apt_remote_api, gen_object_with_cleanup):
def deb_remote_factory(
apt_remote_api,
deb_fixture_server,
gen_object_with_cleanup,
):
"""Fixture that generates a deb remote with cleanup."""

def _deb_remote_factory(**kwargs):
return gen_object_with_cleanup(apt_remote_api, gen_deb_remote(**kwargs))
def _deb_remote_factory(repo_name=DEB_FIXTURE_STANDARD_REPOSITORY_NAME, **kwargs):
url = deb_fixture_server.make_url(repo_name)
return gen_object_with_cleanup(apt_remote_api, gen_local_deb_remote(url=str(url), **kwargs))

return _deb_remote_factory

Expand Down Expand Up @@ -266,3 +273,21 @@ def deb_signing_service_factory(
f"SigningService.objects.filter(name='{service_name}').delete()"
)
execute_pulpcore_python(cli_client, cmd)


@pytest.fixture
def deb_fixture_server(gen_fixture_server):
"""A fixture that spins up a local web server to serve test data."""
p = Path(__file__).parent.absolute()
fixture_path = p.joinpath("data/")
yield gen_fixture_server(fixture_path, None)


@pytest.fixture
def deb_get_fixture_server_url(deb_fixture_server):
"""A fixture that provides the url of the local web server."""

def _deb_get_fixture_server_url(repo_name=DEB_FIXTURE_STANDARD_REPOSITORY_NAME):
return deb_fixture_server.make_url(repo_name)

return _deb_get_fixture_server_url
2 changes: 2 additions & 0 deletions pulp_deb/tests/functional/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def _clean_dict(d):
DEB_FIXTURE_COMPONENT_UPDATE = "jotunheimr"
DEB_FIXTURE_ARCH = "ppc64"
DEB_FIXTURE_ARCH_UPDATE = "armeb"
DEB_FIXTURE_STANDARD_REPOSITORY_NAME = "/debian/"
DEB_FIXTURE_UPDATE_REPOSITORY_NAME = "/debian-update/"

DEB_FIXTURE_SUMMARY = _clean_dict(
{
Expand Down
Loading

0 comments on commit ab1180a

Please sign in to comment.