diff --git a/CHANGES/790.misc b/CHANGES/790.misc new file mode 100644 index 000000000..94b055021 --- /dev/null +++ b/CHANGES/790.misc @@ -0,0 +1 @@ +Added better scoping for the pytest fixtures. diff --git a/pulp_deb/tests/functional/api/test_download_content.py b/pulp_deb/tests/functional/api/test_download_content.py index 4b4925a10..314158284 100644 --- a/pulp_deb/tests/functional/api/test_download_content.py +++ b/pulp_deb/tests/functional/api/test_download_content.py @@ -18,6 +18,7 @@ @pytest.mark.parametrize("is_verbatim", [False, True]) def test_download_content( deb_distribution_factory, + deb_get_fixture_server_url, deb_publication_factory, deb_remote_factory, deb_repository_factory, @@ -34,7 +35,8 @@ def test_download_content( """ # Create repository, remote and sync them repo = deb_repository_factory() - remote = deb_remote_factory(DEB_FIXTURE_STANDARD_REPOSITORY_NAME) + url = deb_get_fixture_server_url() + remote = deb_remote_factory(url=url) deb_sync_repository(remote, repo) repo = deb_get_repository_by_href(repo.pulp_href) diff --git a/pulp_deb/tests/functional/api/test_download_policies.py b/pulp_deb/tests/functional/api/test_download_policies.py index dc3ba3fd9..56e2e1ac3 100644 --- a/pulp_deb/tests/functional/api/test_download_policies.py +++ b/pulp_deb/tests/functional/api/test_download_policies.py @@ -12,6 +12,7 @@ @pytest.mark.parametrize("policy", ["on_demand", "streamed"]) def test_download_policy( apt_package_api, + deb_get_fixture_server_url, deb_get_repository_by_href, deb_publication_factory, deb_remote_factory, @@ -24,7 +25,8 @@ def test_download_policy( orphans_cleanup_api_client.cleanup({"orphan_protection_time": 0}) # Create repository and remote and verify latest `repository_version` is 0 repo = deb_repository_factory() - remote = deb_remote_factory(policy=policy) + url = deb_get_fixture_server_url() + remote = deb_remote_factory(url=url, policy=policy) assert repo.latest_version_href.endswith("/0/") # Sync and verify latest `repository_version` is 1 @@ -57,6 +59,7 @@ def test_download_policy( @pytest.mark.parametrize("policy", ["on_demand", "streamed"]) def test_lazy_sync_immediate_download_test( artifacts_api_client, + deb_get_fixture_server_url, deb_get_remote_by_href, deb_get_repository_by_href, deb_patch_remote, @@ -72,7 +75,8 @@ def test_lazy_sync_immediate_download_test( # Create repository and remote and sync them repo = deb_repository_factory() - remote = deb_remote_factory(policy=policy) + url = deb_get_fixture_server_url() + remote = deb_remote_factory(url=url, policy=policy) deb_sync_repository(remote, repo) repo = deb_get_repository_by_href(repo.pulp_href) diff --git a/pulp_deb/tests/functional/api/test_publish.py b/pulp_deb/tests/functional/api/test_publish.py index 3a06fef2d..1932602b9 100644 --- a/pulp_deb/tests/functional/api/test_publish.py +++ b/pulp_deb/tests/functional/api/test_publish.py @@ -37,6 +37,7 @@ ], ) def test_publish_any_repo_version( + deb_get_fixture_server_url, deb_remote_factory, deb_repository_factory, deb_sync_repository, @@ -61,7 +62,8 @@ def test_publish_any_repo_version( cfg = config.get_config() # Create a repository with at least two repository versions - remote = deb_remote_factory(distributions=DEB_FIXTURE_DISTRIBUTIONS) + url = deb_get_fixture_server_url() + remote = deb_remote_factory(url=url, 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]: @@ -112,6 +114,7 @@ def test_publish_any_repo_version( ], ) def test_publish_signing_services( + deb_get_fixture_server_url, deb_remote_factory, deb_repository_factory, deb_sync_repository, @@ -135,7 +138,8 @@ def test_publish_signing_services( # Create a repository with at least two dists signing_service = deb_signing_service_factory - remote = deb_remote_factory(distributions=DEB_FIXTURE_DISTRIBUTIONS) + url = deb_get_fixture_server_url() + remote = deb_remote_factory(url=url, distributions=DEB_FIXTURE_DISTRIBUTIONS) distro = DEB_FIXTURE_DISTRIBUTIONS.split()[0] repo_options = {} publish_options = {"simple": True, "structured": True} diff --git a/pulp_deb/tests/functional/api/test_sync.py b/pulp_deb/tests/functional/api/test_sync.py index 3f4bbe563..f41ef1e92 100644 --- a/pulp_deb/tests/functional/api/test_sync.py +++ b/pulp_deb/tests/functional/api/test_sync.py @@ -30,6 +30,7 @@ ], ) def test_sync( + deb_get_fixture_server_url, deb_remote_factory, deb_repository_factory, deb_get_repository_by_href, @@ -40,7 +41,8 @@ def test_sync( """Test whether synchronizations with and without udebs works as expected.""" # Create a repository and a remote and verify latest `repository_version` is 0 repo = deb_repository_factory() - remote = deb_remote_factory(**remote_params) + url = deb_get_fixture_server_url() + remote = deb_remote_factory(url=url, **remote_params) assert repo.latest_version_href.endswith("/0/") # Sync the repository @@ -74,7 +76,6 @@ def test_sync( [ ( { - "repo_name": DEB_FIXTURE_INVALID_REPOSITORY_NAME, "architectures": "ppc64", "ignore_missing_package_indices": False, }, @@ -82,7 +83,6 @@ def test_sync( ), ( { - "repo_name": DEB_FIXTURE_INVALID_REPOSITORY_NAME, "architectures": "armeb", "ignore_missing_package_indices": False, }, @@ -92,6 +92,7 @@ def test_sync( ) def test_sync_missing_package_indices( expected, + deb_get_fixture_server_url, deb_remote_factory, deb_repository_factory, deb_sync_repository, @@ -106,7 +107,8 @@ def test_sync_missing_package_indices( """ # Create repository and remote repo = deb_repository_factory() - remote = deb_remote_factory(**remote_params) + url = deb_get_fixture_server_url(DEB_FIXTURE_INVALID_REPOSITORY_NAME) + remote = deb_remote_factory(url=url, **remote_params) # Verify a PulpTaskError is raised and the error message is as expected with pytest.raises(PulpTaskError) as exc: @@ -117,13 +119,17 @@ def test_sync_missing_package_indices( @pytest.mark.parallel @pytest.mark.parametrize( - "remote_params, expected", + "repo_name, remote_params, expected", [ - ({"url": "http://i-am-an-invalid-url.com/invalid/"}, ["Cannot connect"]), - ({"distributions": "no_dist"}, ["Could not find a Release file at"]), + ("http://i-am-an-invalid-url.com/invalid/", {}, ["Cannot connect"]), + ( + DEB_FIXTURE_STANDARD_REPOSITORY_NAME, + {"distributions": "no_dist"}, + ["Could not find a Release file at"], + ), ( + DEB_FIXTURE_INVALID_REPOSITORY_NAME, { - "repo_name": DEB_FIXTURE_INVALID_REPOSITORY_NAME, "distributions": "nosuite", "gpgkey": DEB_SIGNING_KEY, }, @@ -133,10 +139,12 @@ def test_sync_missing_package_indices( ) def test_sync_invalid_cases( expected, + deb_get_fixture_server_url, deb_remote_factory, deb_repository_factory, deb_sync_repository, remote_params, + repo_name, ): """Test whether various invalid sync cases fail as expected. @@ -148,7 +156,8 @@ def test_sync_invalid_cases( """ # Create repository and remote repo = deb_repository_factory() - remote = deb_remote_factory(**remote_params) + url = repo_name if repo_name.startswith("http://") else deb_get_fixture_server_url(repo_name) + remote = deb_remote_factory(url=url, **remote_params) # Verify a PulpTaskError is raised and the error message is as expected with pytest.raises(PulpTaskError) as exc: @@ -159,45 +168,45 @@ def test_sync_invalid_cases( @pytest.mark.parallel @pytest.mark.parametrize( - "remote_params, remote_diff_params", + "repo_name, remote_params, repo_diff_name, remote_diff_params", [ ( + DEB_FIXTURE_STANDARD_REPOSITORY_NAME, { - "repo_name": DEB_FIXTURE_STANDARD_REPOSITORY_NAME, "distributions": DEB_FIXTURE_SINGLE_DIST, "components": DEB_FIXTURE_COMPONENT, "architectures": None, }, + DEB_FIXTURE_STANDARD_REPOSITORY_NAME, { - "repo_name": DEB_FIXTURE_STANDARD_REPOSITORY_NAME, "distributions": DEB_FIXTURE_SINGLE_DIST, "components": DEB_FIXTURE_COMPONENT_UPDATE, "architectures": None, }, ), ( + DEB_FIXTURE_STANDARD_REPOSITORY_NAME, { - "repo_name": DEB_FIXTURE_STANDARD_REPOSITORY_NAME, "distributions": DEB_FIXTURE_SINGLE_DIST, "components": None, "architectures": DEB_FIXTURE_ARCH, }, + DEB_FIXTURE_STANDARD_REPOSITORY_NAME, { - "repo_name": DEB_FIXTURE_STANDARD_REPOSITORY_NAME, "distributions": DEB_FIXTURE_SINGLE_DIST, "components": None, "architectures": DEB_FIXTURE_ARCH_UPDATE, }, ), ( + DEB_FIXTURE_STANDARD_REPOSITORY_NAME, { - "repo_name": DEB_FIXTURE_STANDARD_REPOSITORY_NAME, "distributions": DEB_FIXTURE_SINGLE_DIST, "components": DEB_FIXTURE_COMPONENT, "architectures": None, }, + DEB_FIXTURE_UPDATE_REPOSITORY_NAME, { - "repo_name": DEB_FIXTURE_UPDATE_REPOSITORY_NAME, "distributions": DEB_FIXTURE_SINGLE_DIST, "components": DEB_FIXTURE_COMPONENT_UPDATE, "architectures": None, @@ -206,11 +215,14 @@ def test_sync_invalid_cases( ], ) def test_sync_optimize_no_skip_release_file( + deb_get_fixture_server_url, deb_remote_factory, deb_repository_factory, deb_get_repository_by_href, remote_params, remote_diff_params, + repo_name, + repo_diff_name, deb_sync_repository, ): """Test whether synchronizations have not been skipped for certain conditions. @@ -223,7 +235,8 @@ 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(**remote_params) + url = deb_get_fixture_server_url(repo_name) + remote = deb_remote_factory(url=url, **remote_params) assert repo.latest_version_href.endswith("/0/") # Sync the repository @@ -236,7 +249,8 @@ def test_sync_optimize_no_skip_release_file( assert not is_sync_skipped(task, DEB_REPORT_CODE_SKIP_PACKAGE) # Create a new remote with different parameters and sync with repository - remote_diff = deb_remote_factory(**remote_diff_params) + url = deb_get_fixture_server_url(repo_diff_name) + remote_diff = deb_remote_factory(url=url, **remote_diff_params) task_diff = deb_sync_repository(remote_diff, repo) repo = deb_get_repository_by_href(repo.pulp_href) @@ -248,6 +262,7 @@ def test_sync_optimize_no_skip_release_file( @pytest.mark.parallel def test_sync_optimize_skip_unchanged_package_index( + deb_get_fixture_server_url, deb_remote_factory, deb_repository_factory, deb_get_repository_by_href, @@ -259,7 +274,8 @@ 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(distributions=DEB_FIXTURE_SINGLE_DIST) + url = deb_get_fixture_server_url() + remote = deb_remote_factory(url=url, distributions=DEB_FIXTURE_SINGLE_DIST) assert repo.latest_version_href.endswith("/0/") # Sync the repository @@ -273,9 +289,8 @@ def test_sync_optimize_skip_unchanged_package_index( assert not is_sync_skipped(task, DEB_REPORT_CODE_SKIP_PACKAGE) # Create new remote with both updated and unchanged packages and sync with repository - remote_diff = deb_remote_factory( - DEB_FIXTURE_UPDATE_REPOSITORY_NAME, distributions=DEB_FIXTURE_SINGLE_DIST - ) + url = deb_get_fixture_server_url(DEB_FIXTURE_UPDATE_REPOSITORY_NAME) + remote_diff = deb_remote_factory(url=url, distributions=DEB_FIXTURE_SINGLE_DIST) task_diff = deb_sync_repository(remote_diff, repo) repo = deb_get_repository_by_href(repo.pulp_href) @@ -321,6 +336,7 @@ def test_sync_optimize_skip_unchanged_package_index( def test_sync_orphan_cleanup_fail( + deb_get_fixture_server_url, deb_remote_factory, deb_repository_factory, deb_get_repository_by_href, @@ -337,15 +353,15 @@ def test_sync_orphan_cleanup_fail( repo = deb_repository_factory(retain_repo_versions=1) # Create a remote and sync with repo. Verify the latest `repository_version` is 1. - remote = deb_remote_factory(distributions=DEB_FIXTURE_SINGLE_DIST) + url = deb_get_fixture_server_url() + remote = deb_remote_factory(url=url, distributions=DEB_FIXTURE_SINGLE_DIST) deb_sync_repository(remote, repo) repo = deb_get_repository_by_href(repo.pulp_href) assert repo.latest_version_href.endswith("/1/") # Create a new remote with updated packages and sync again. Verify `repository_version` is 2. - remote_diff = deb_remote_factory( - DEB_FIXTURE_UPDATE_REPOSITORY_NAME, distributions=DEB_FIXTURE_SINGLE_DIST - ) + url = deb_get_fixture_server_url(DEB_FIXTURE_UPDATE_REPOSITORY_NAME) + remote_diff = deb_remote_factory(url=url, distributions=DEB_FIXTURE_SINGLE_DIST) deb_sync_repository(remote_diff, repo) repo = deb_get_repository_by_href(repo.pulp_href) assert repo.latest_version_href.endswith("/2/") diff --git a/pulp_deb/tests/functional/conftest.py b/pulp_deb/tests/functional/conftest.py index ee0bcb375..fa3146c11 100644 --- a/pulp_deb/tests/functional/conftest.py +++ b/pulp_deb/tests/functional/conftest.py @@ -1,11 +1,10 @@ -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_deb_remote, gen_local_deb_remote +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.constants import DEB_FIXTURE_STANDARD_REPOSITORY_NAME @@ -26,69 +25,70 @@ ) -@pytest.fixture -def apt_client(cid, bindings_cfg): +@pytest.fixture(scope="session") +def apt_client(_api_client_set, bindings_cfg): """Fixture for APT client.""" api_client = ApiClient(bindings_cfg) - api_client.default_headers["Correlation-ID"] = cid - return api_client + _api_client_set.add(api_client) + yield api_client + _api_client_set.remove(api_client) -@pytest.fixture +@pytest.fixture(scope="session") def apt_repository_api(apt_client): """Fixture for APT repositories API.""" return RepositoriesAptApi(apt_client) -@pytest.fixture +@pytest.fixture(scope="session") def apt_remote_api(apt_client): """Fixture for APT remote API.""" return RemotesAptApi(apt_client) -@pytest.fixture +@pytest.fixture(scope="session") def apt_publication_api(apt_client): """Fixture for APT publication API.""" return PublicationsAptApi(apt_client) -@pytest.fixture +@pytest.fixture(scope="session") def apt_verbatim_publication_api(apt_client): """Fixture for Verbatim publication API.""" return PublicationsVerbatimApi(apt_client) -@pytest.fixture +@pytest.fixture(scope="session") def apt_distribution_api(apt_client): """Fixture for APT distribution API.""" return DistributionsAptApi(apt_client) -@pytest.fixture +@pytest.fixture(scope="session") def apt_package_api(apt_client): """Fixture for APT package API.""" return ContentPackagesApi(apt_client) -@pytest.fixture +@pytest.fixture(scope="session") def apt_release_api(apt_client): """Fixture for APT release API.""" return ContentReleasesApi(apt_client) -@pytest.fixture +@pytest.fixture(scope="session") def apt_release_component_api(apt_client): """Fixture for APT release API.""" return ContentReleaseComponentsApi(apt_client) -@pytest.fixture +@pytest.fixture(scope="session") def apt_generic_content_api(apt_client): """Fixture for APT generic content API.""" return ContentGenericContentsApi(apt_client) -@pytest.fixture +@pytest.fixture(scope="class") def deb_distribution_factory(apt_distribution_api, gen_object_with_cleanup): """Fixture that generates a deb distribution with cleanup from a given publication.""" @@ -100,7 +100,7 @@ def _deb_distribution_factory(publication): return _deb_distribution_factory -@pytest.fixture +@pytest.fixture(scope="class") def deb_generic_content_factory(apt_generic_content_api, gen_object_with_cleanup): """Fixture that generates deb generic content with cleanup.""" @@ -110,7 +110,7 @@ def _deb_generic_content_factory(**kwargs): return _deb_generic_content_factory -@pytest.fixture +@pytest.fixture(scope="class") def deb_package_factory(apt_package_api, gen_object_with_cleanup): """Fixture that generates deb package with cleanup.""" @@ -120,7 +120,7 @@ def _deb_package_factory(**kwargs): return _deb_package_factory -@pytest.fixture +@pytest.fixture(scope="class") def deb_publication_factory(apt_publication_api, gen_object_with_cleanup): """Fixture that generates a deb publication with cleanup from a given repository.""" @@ -131,7 +131,7 @@ def _deb_publication_factory(repo, **kwargs): return _deb_publication_factory -@pytest.fixture +@pytest.fixture(scope="class") def deb_repository_factory(apt_repository_api, gen_object_with_cleanup): """Fixture that generates a deb repository with cleanup.""" @@ -141,24 +141,17 @@ def _deb_repository_factory(**kwargs): return _deb_repository_factory -@pytest.fixture -def deb_remote_factory( - apt_remote_api, - deb_fixture_server, - gen_object_with_cleanup, -): +@pytest.fixture(scope="class") +def deb_remote_factory(apt_remote_api, gen_object_with_cleanup): """Fixture that generates a deb remote with cleanup.""" - def _deb_remote_factory(repo_name=DEB_FIXTURE_STANDARD_REPOSITORY_NAME, **kwargs): - if "url" in kwargs: - return gen_object_with_cleanup(apt_remote_api, gen_deb_remote(**kwargs)) - url = deb_fixture_server.make_url(repo_name) + def _deb_remote_factory(url, **kwargs): return gen_object_with_cleanup(apt_remote_api, gen_local_deb_remote(url=str(url), **kwargs)) return _deb_remote_factory -@pytest.fixture +@pytest.fixture(scope="class") def deb_remote_custom_data_factory(apt_remote_api, gen_object_with_cleanup): """Fixture that generates a deb remote with cleanup using custom data.""" @@ -168,7 +161,7 @@ def _deb_remote_custom_data_factory(data): return _deb_remote_custom_data_factory -@pytest.fixture +@pytest.fixture(scope="class") def deb_verbatim_publication_factory(apt_verbatim_publication_api, gen_object_with_cleanup): """Fixture that generates a deb verbatim publication with cleanup from a given repository.""" @@ -210,7 +203,7 @@ def _deb_get_remotes_by_name(name): @pytest.fixture -def deb_delete_remote(apt_remote_api): +def deb_delete_remote(apt_remote_api, monitor_task): """Fixture that will delete a deb remote.""" def _deb_delete_remote(remote): @@ -221,7 +214,7 @@ def _deb_delete_remote(remote): @pytest.fixture -def deb_patch_remote(apt_remote_api): +def deb_patch_remote(apt_remote_api, monitor_task): """Fixture that will partially update a deb remote.""" def _deb_patch_remote(remote, content): @@ -232,7 +225,7 @@ def _deb_patch_remote(remote, content): @pytest.fixture -def deb_put_remote(apt_remote_api): +def deb_put_remote(apt_remote_api, monitor_task): """Fixture that will update a deb remote.""" def _deb_put_remote(remote, content): @@ -243,7 +236,7 @@ def _deb_put_remote(remote, content): @pytest.fixture -def deb_sync_repository(apt_repository_api): +def deb_sync_repository(apt_repository_api, monitor_task): """Fixture that synchronizes a given repository with a given remote and returns the monitored task. """ @@ -277,7 +270,7 @@ def deb_signing_script_path(signing_gpg_homedir_path): return f.name -@pytest.fixture +@pytest.fixture(scope="class") def deb_signing_service_factory( cli_client, deb_signing_script_path,