diff --git a/CHANGES/4751.misc b/CHANGES/4751.misc new file mode 100644 index 00000000000..4984745dee4 --- /dev/null +++ b/CHANGES/4751.misc @@ -0,0 +1 @@ +Changed bindings fixtures in the pytest plugin to load lazily. diff --git a/pulp_file/pytest_plugin.py b/pulp_file/pytest_plugin.py index 9c13205cbda..96d82ca0790 100644 --- a/pulp_file/pytest_plugin.py +++ b/pulp_file/pytest_plugin.py @@ -1,69 +1,77 @@ import os import uuid import subprocess +import warnings from collections import defaultdict from pathlib import Path import aiofiles import pytest from aiohttp import web -from pulpcore.client.pulp_file import ( - AcsFileApi, - ApiClient, - ContentFilesApi, - DistributionsFileApi, - PublicationsFileApi, - RemotesFileApi, - RepositoriesFileApi, - RepositoriesFileVersionsApi, -) - -from pulpcore.tests.functional.utils import generate_iso, generate_manifest + +from pulpcore.tests.functional.utils import BindingsNamespace, generate_iso, generate_manifest # Api Bindings fixtures @pytest.fixture(scope="session") -def file_client(_api_client_set, bindings_cfg): - api_client = ApiClient(bindings_cfg) - _api_client_set.add(api_client) - yield api_client - _api_client_set.remove(api_client) +def file_bindings(_api_client_set, bindings_cfg): + """ + A namespace providing preconfigured pulp_file api clients. + + e.g. `file_bindings.RepositoriesFileApi.list()`. + """ + from pulpcore.client import pulp_file as file_bindings_module + + file_client = file_bindings_module.ApiClient(bindings_cfg) + _api_client_set.add(file_client) + yield BindingsNamespace(file_bindings_module, file_client) + _api_client_set.remove(file_client) + + +# TODO Deprecate all the api_client fixtures below. @pytest.fixture(scope="session") -def file_acs_api_client(file_client): - return AcsFileApi(file_client) +def file_acs_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.AcsFileApi @pytest.fixture(scope="session") -def file_content_api_client(file_client): - return ContentFilesApi(file_client) +def file_content_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.ContentFilesApi @pytest.fixture(scope="session") -def file_distribution_api_client(file_client): - return DistributionsFileApi(file_client) +def file_distribution_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.DistributionsFileApi @pytest.fixture(scope="session") -def file_publication_api_client(file_client): - return PublicationsFileApi(file_client) +def file_publication_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.PublicationsFileApi @pytest.fixture(scope="session") -def file_repository_api_client(file_client): - return RepositoriesFileApi(file_client) +def file_repository_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.RepositoriesFileApi @pytest.fixture(scope="session") -def file_repository_version_api_client(file_client): - return RepositoriesFileVersionsApi(file_client) +def file_repository_version_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.RepositoriesFileVersionsApi @pytest.fixture(scope="session") -def file_remote_api_client(file_client): - return RemotesFileApi(file_client) +def file_remote_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.RemotesFileApi # Factory fixtures @@ -75,11 +83,13 @@ def file_random_content_unit(file_content_unit_with_name_factory): @pytest.fixture -def file_content_unit_with_name_factory(file_content_api_client, random_artifact, monitor_task): +def file_content_unit_with_name_factory(file_bindings, random_artifact, monitor_task): def _file_content_unit_with_name_factory(name): artifact_attrs = {"artifact": random_artifact.pulp_href, "relative_path": name} - return file_content_api_client.read( - monitor_task(file_content_api_client.create(**artifact_attrs).task).created_resources[0] + return file_bindings.ContentFilesApi.read( + monitor_task( + file_bindings.ContentFilesApi.create(**artifact_attrs).task + ).created_resources[0] ) return _file_content_unit_with_name_factory diff --git a/pulpcore/tests/functional/__init__.py b/pulpcore/tests/functional/__init__.py index 214f1e7fc55..7695709b668 100644 --- a/pulpcore/tests/functional/__init__.py +++ b/pulpcore/tests/functional/__init__.py @@ -10,8 +10,6 @@ import uuid import warnings -import trustme -import proxy import pytest from aiohttp import web @@ -20,60 +18,16 @@ from packaging.version import parse as parse_version from time import sleep from yarl import URL -from opentelemetry.proto.trace.v1.trace_pb2 import TracesData from pulpcore.tests.functional.utils import ( SLEEP_TIME, TASK_TIMEOUT, + BindingsNamespace, PulpTaskError, PulpTaskGroupError, add_recording_route, ) -from pulpcore.client.pulpcore import ( - Configuration, - AccessPoliciesApi, - ApiClient, - ApiException, - ArtifactsApi, - ContentApi, - ContentguardsApi, - ContentguardsRbacApi, - ContentguardsCompositeApi, - ContentguardsContentRedirectApi, - ContentguardsHeaderApi, - DomainsApi, - DistributionsApi, - ExportersPulpApi, - ExportersPulpExportsApi, - ExportersFilesystemApi, - ExportersFilesystemExportsApi, - GroupsApi, - GroupsRolesApi, - GroupsUsersApi, - ImportersPulpApi, - ImportersPulpImportsApi, - ImportersPulpImportCheckApi, - OrphansCleanupApi, - PublicationsApi, - RemotesApi, - RepairApi, - RepositoriesApi, - RepositoryVersionsApi, - RepositoriesReclaimSpaceApi, - RolesApi, - SigningServicesApi, - StatusApi, - TaskGroupsApi, - TasksApi, - TaskSchedulesApi, - UploadsApi, - UpstreamPulpsApi, - UsersApi, - UsersRolesApi, - WorkersApi, -) - from .gpg_ascii_armor_signing_service import ( _ascii_armored_detached_signing_service_name, ascii_armored_detached_signing_service, @@ -95,19 +49,6 @@ def __init__(self, awaitable): self.awaitable = awaitable -def get_bindings_config(): - api_protocol = os.environ.get("API_PROTOCOL", "https") - api_host = os.environ.get("API_HOST", "pulp") - api_port = os.environ.get("API_PORT", "443") - configuration = Configuration( - host=f"{api_protocol}://{api_host}:{api_port}", - username=os.environ.get("ADMIN_USERNAME", "admin"), - password=os.environ.get("ADMIN_PASSWORD", "password"), - ) - configuration.safe_chars_for_path_param = "/" - return configuration - - def pytest_configure(config): config.addinivalue_line( "markers", @@ -139,12 +80,23 @@ class FixturesConfig: return FixturesConfig() -# API Clients +# API Bindings fixtures @pytest.fixture(scope="session") def bindings_cfg(): - return get_bindings_config() + from pulpcore.client.pulpcore import Configuration + + api_protocol = os.environ.get("API_PROTOCOL", "https") + api_host = os.environ.get("API_HOST", "pulp") + api_port = os.environ.get("API_PORT", "443") + configuration = Configuration( + host=f"{api_protocol}://{api_host}:{api_port}", + username=os.environ.get("ADMIN_USERNAME", "admin"), + password=os.environ.get("ADMIN_PASSWORD", "password"), + ) + configuration.safe_chars_for_path_param = "/" + return configuration @pytest.fixture(scope="session") @@ -169,202 +121,334 @@ def _patch_cid_user_agent(_api_client_set, cid, monkeypatch): @pytest.fixture(scope="session") -def pulpcore_client(_api_client_set, bindings_cfg): - api_client = ApiClient(bindings_cfg) - _api_client_set.add(api_client) - yield api_client - _api_client_set.remove(api_client) +def pulpcore_bindings(_api_client_set, bindings_cfg): + """ + A namespace providing preconfigured pulpcore api clients. + + e.g. `pulpcore_bindings.WorkersApi.list()`. + """ + from pulpcore.client import pulpcore as pulpcore_bindings_module + + pulpcore_client = pulpcore_bindings_module.ApiClient(bindings_cfg) + _api_client_set.add(pulpcore_client) + yield BindingsNamespace(pulpcore_bindings_module, pulpcore_client) + _api_client_set.remove(pulpcore_client) + + +# TODO Deprecate all the api_client fixtures below. + + +@pytest.fixture(scope="session") +def pulpcore_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings.client` instead.", DeprecationWarning + ) + return pulpcore_bindings.client @pytest.fixture(scope="session") -def access_policies_api_client(pulpcore_client): - return AccessPoliciesApi(pulpcore_client) +def access_policies_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.AccessPoliciesApi @pytest.fixture(scope="session") -def tasks_api_client(pulpcore_client): - return TasksApi(pulpcore_client) +def tasks_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.TasksApi @pytest.fixture(scope="session") -def task_groups_api_client(pulpcore_client): - return TaskGroupsApi(pulpcore_client) +def task_groups_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.TaskGroupsApi @pytest.fixture(scope="session") -def workers_api_client(pulpcore_client): - return WorkersApi(pulpcore_client) +def workers_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.WorkersApi @pytest.fixture(scope="session") -def artifacts_api_client(pulpcore_client): - return ArtifactsApi(pulpcore_client) +def artifacts_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ArtifactsApi @pytest.fixture(scope="session") -def uploads_api_client(pulpcore_client): - return UploadsApi(pulpcore_client) +def uploads_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.UploadsApi @pytest.fixture(scope="session") -def task_schedules_api_client(pulpcore_client): - return TaskSchedulesApi(pulpcore_client) +def task_schedules_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.TaskSchedulesApi @pytest.fixture(scope="session") -def status_api_client(pulpcore_client): - return StatusApi(pulpcore_client) +def status_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.StatusApi @pytest.fixture(scope="session") -def groups_api_client(pulpcore_client): - return GroupsApi(pulpcore_client) +def groups_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.GroupsApi @pytest.fixture(scope="session") -def groups_users_api_client(pulpcore_client): - return GroupsUsersApi(pulpcore_client) +def groups_users_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.GroupsUsersApi @pytest.fixture(scope="session") -def groups_roles_api_client(pulpcore_client): - return GroupsRolesApi(pulpcore_client) +def groups_roles_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.GroupsRolesApi @pytest.fixture(scope="session") -def users_api_client(pulpcore_client): - return UsersApi(pulpcore_client) +def users_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.UsersApi @pytest.fixture(scope="session") -def users_roles_api_client(pulpcore_client): - return UsersRolesApi(pulpcore_client) +def users_roles_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.UsersRolesApi @pytest.fixture(scope="session") -def roles_api_client(pulpcore_client): +def roles_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) "Provies the pulp core Roles API client object." - return RolesApi(pulpcore_client) + return pulpcore_bindings.RolesApi @pytest.fixture(scope="session") -def content_api_client(pulpcore_client): - return ContentApi(pulpcore_client) +def content_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentApi @pytest.fixture(scope="session") -def domains_api_client(pulpcore_client): - return DomainsApi(pulpcore_client) +def domains_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.DomainsApi @pytest.fixture(scope="session") -def distributions_api_client(pulpcore_client): - return DistributionsApi(pulpcore_client) +def distributions_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.DistributionsApi @pytest.fixture(scope="session") -def remotes_api_client(pulpcore_client): - return RemotesApi(pulpcore_client) +def remotes_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RemotesApi @pytest.fixture(scope="session") -def repositories_api_client(pulpcore_client): - return RepositoriesApi(pulpcore_client) +def repositories_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RepositoriesApi @pytest.fixture(scope="session") -def repository_versions_api_client(pulpcore_client): - return RepositoryVersionsApi(pulpcore_client) +def repository_versions_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RepositoryVersionsApi @pytest.fixture(scope="session") -def publications_api_client(pulpcore_client): - return PublicationsApi(pulpcore_client) +def publications_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.PublicationsApi @pytest.fixture(scope="session") -def exporters_pulp_api_client(pulpcore_client): - return ExportersPulpApi(pulpcore_client) +def exporters_pulp_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ExportersPulpApi @pytest.fixture(scope="session") -def exporters_pulp_exports_api_client(pulpcore_client): - return ExportersPulpExportsApi(pulpcore_client) +def exporters_pulp_exports_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ExportersPulpExportsApi @pytest.fixture(scope="session") -def exporters_filesystem_api_client(pulpcore_client): - return ExportersFilesystemApi(pulpcore_client) +def exporters_filesystem_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ExportersFilesystemApi @pytest.fixture(scope="session") -def exporters_filesystem_exports_api_client(pulpcore_client): - return ExportersFilesystemExportsApi(pulpcore_client) +def exporters_filesystem_exports_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ExportersFilesystemExportsApi @pytest.fixture(scope="session") -def importers_pulp_api_client(pulpcore_client): - return ImportersPulpApi(pulpcore_client) +def importers_pulp_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ImportersPulpApi @pytest.fixture(scope="session") -def importers_pulp_imports_api_client(pulpcore_client): - return ImportersPulpImportsApi(pulpcore_client) +def importers_pulp_imports_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ImportersPulpImportsApi @pytest.fixture(scope="session") -def importers_pulp_imports_check_api_client(pulpcore_client): - return ImportersPulpImportCheckApi(pulpcore_client) +def importers_pulp_imports_check_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ImportersPulpImportCheckApi @pytest.fixture(scope="session") -def signing_service_api_client(pulpcore_client): - return SigningServicesApi(pulpcore_client) +def signing_service_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.SigningServicesApi @pytest.fixture(scope="session") -def content_guards_api_client(pulpcore_client): - return ContentguardsApi(pulpcore_client) +def content_guards_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsApi @pytest.fixture(scope="session") -def rbac_contentguard_api_client(pulpcore_client): - return ContentguardsRbacApi(pulpcore_client) +def rbac_contentguard_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsRbacApi @pytest.fixture(scope="session") -def redirect_contentguard_api_client(pulpcore_client): - return ContentguardsContentRedirectApi(pulpcore_client) +def redirect_contentguard_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsContentRedirectApi @pytest.fixture(scope="session") -def header_contentguard_api_client(pulpcore_client): - return ContentguardsHeaderApi(pulpcore_client) +def header_contentguard_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsHeaderApi @pytest.fixture(scope="session") -def composite_contentguard_api_client(pulpcore_client): - return ContentguardsCompositeApi(pulpcore_client) +def composite_contentguard_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsCompositeApi @pytest.fixture(scope="session") -def orphans_cleanup_api_client(pulpcore_client): - return OrphansCleanupApi(pulpcore_client) +def orphans_cleanup_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.OrphansCleanupApi @pytest.fixture(scope="session") -def repositories_reclaim_space_api_client(pulpcore_client): - return RepositoriesReclaimSpaceApi(pulpcore_client) +def repositories_reclaim_space_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RepositoriesReclaimSpaceApi @pytest.fixture(scope="session") -def repair_api_client(pulpcore_client): - return RepairApi(pulpcore_client) +def repair_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RepairApi @pytest.fixture(scope="session") -def upstream_pulp_api_client(pulpcore_client): - return UpstreamPulpsApi(pulpcore_client) +def upstream_pulp_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.UpstreamPulpsApi # Threaded local fixture servers @@ -514,8 +598,15 @@ def _gen_fixture_server(fixtures_root, ssl_ctx): # Proxy Fixtures +@pytest.fixture(scope="session") +def _proxy_module(): + import proxy + + return proxy + + @pytest.fixture -def http_proxy(fixtures_cfg, unused_port): +def http_proxy(_proxy_module, fixtures_cfg, unused_port): host = fixtures_cfg.aiohttp_fixtures_origin port = unused_port() proxypy_args = [ @@ -529,12 +620,12 @@ def http_proxy(fixtures_cfg, unused_port): proxy_data = ProxyData(host=host, port=port) - with proxy.Proxy(input_args=proxypy_args): + with _proxy_module.Proxy(input_args=proxypy_args): yield proxy_data @pytest.fixture -def http_proxy_with_auth(fixtures_cfg, unused_port): +def http_proxy_with_auth(_proxy_module, fixtures_cfg, unused_port): host = fixtures_cfg.aiohttp_fixtures_origin port = unused_port() @@ -554,12 +645,12 @@ def http_proxy_with_auth(fixtures_cfg, unused_port): proxy_data = ProxyData(host=host, port=port, username=username, password=password) - with proxy.Proxy(input_args=proxypy_args): + with _proxy_module.Proxy(input_args=proxypy_args): yield proxy_data @pytest.fixture -def https_proxy(fixtures_cfg, unused_port, proxy_tls_certificate_pem_path): +def https_proxy(_proxy_module, fixtures_cfg, unused_port, proxy_tls_certificate_pem_path): host = fixtures_cfg.aiohttp_fixtures_origin port = unused_port() @@ -578,7 +669,7 @@ def https_proxy(fixtures_cfg, unused_port, proxy_tls_certificate_pem_path): proxy_data = ProxyData(host=host, port=port, ssl=True) # TODO update me - with proxy.Proxy(input_args=proxypy_args): + with _proxy_module.Proxy(input_args=proxypy_args): yield proxy_data @@ -610,8 +701,14 @@ def __init__(self, *, host, port, username=None, password=None, ssl=False): @pytest.fixture(scope="session") -def tls_certificate_authority(): - return trustme.CA() +def _trustme_module(): + import trustme + + return trustme + +@pytest.fixture(scope="session") +def tls_certificate_authority(_trustme_module): + return _trustme_module.CA() @pytest.fixture @@ -630,8 +727,8 @@ def tls_certificate(fixtures_cfg, tls_certificate_authority): @pytest.fixture(scope="session") -def proxy_tls_certificate_authority(): - return trustme.CA() +def proxy_tls_certificate_authority(_trustme_module): + return _trustme_module.CA() @pytest.fixture @@ -651,8 +748,8 @@ def proxy_tls_certificate_pem_path(proxy_tls_certificate): @pytest.fixture(scope="session") -def client_tls_certificate_authority(): - return trustme.CA() +def client_tls_certificate_authority(_trustme_module): + return _trustme_module.CA() @pytest.fixture @@ -839,7 +936,7 @@ def delete_orphans_pre(request, orphans_cleanup_api_client, monitor_task): @pytest.fixture(scope="session") -def monitor_task(tasks_api_client, pulp_domain_enabled): +def monitor_task(pulpcore_bindings, pulp_domain_enabled): """ Wait for a task to reach a final state. @@ -847,12 +944,13 @@ def monitor_task(tasks_api_client, pulp_domain_enabled): in seconds (defaulting to 30*60) exceeded or a `PulpTaskError` in case it reached any other final state. """ + from pulpcore.client.pulpcore import ApiException def _monitor_task(task_href, timeout=TASK_TIMEOUT): task_timeout = int(timeout / SLEEP_TIME) for dummy in range(task_timeout): try: - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) except ApiException as e: if pulp_domain_enabled and e.status == 404: # Task's domain has been deleted, nothing to show anymore @@ -874,7 +972,7 @@ def _monitor_task(task_href, timeout=TASK_TIMEOUT): @pytest.fixture(scope="session") -def monitor_task_group(task_groups_api_client): +def monitor_task_group(pulpcore_bindings): """ Wait for a task group to reach a final state. @@ -886,7 +984,7 @@ def monitor_task_group(task_groups_api_client): def _monitor_task_group(task_group_href, timeout=TASK_TIMEOUT): task_timeout = int(timeout / SLEEP_TIME) for dummy in range(task_timeout): - task_group = task_groups_api_client.read(task_group_href) + task_group = pulpcore_bindings.TaskGroupsApi.read(task_group_href) if (task_group.waiting + task_group.running + task_group.canceling) == 0: break diff --git a/pulpcore/tests/functional/api/pulp_file/test_acs.py b/pulpcore/tests/functional/api/pulp_file/test_acs.py index d57054388cc..e843126b23e 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_acs.py +++ b/pulpcore/tests/functional/api/pulp_file/test_acs.py @@ -91,7 +91,7 @@ def test_acs_validation_and_update( @pytest.mark.parallel def test_acs_sync( file_repo, - file_repository_api_client, + file_bindings, file_acs_api_client, basic_manifest_path, gen_object_with_cleanup, @@ -122,7 +122,9 @@ def test_acs_sync( # Sync the repository repository_sync_data = RepositorySyncURL(remote=main_remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, repository_sync_data).task) + monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, repository_sync_data).task + ) # Assert that only the PULP_MANIFEST was downloaded from the main remote assert len(main_server.requests_record) == 1 @@ -143,7 +145,7 @@ def test_acs_sync( @pytest.mark.parallel def test_acs_sync_with_paths( file_repo, - file_repository_api_client, + file_bindings, file_acs_api_client, basic_manifest_path, large_manifest_path, @@ -180,7 +182,9 @@ def test_acs_sync_with_paths( # Sync the repository repository_sync_data = RepositorySyncURL(remote=main_remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, repository_sync_data).task) + monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, repository_sync_data).task + ) # Assert that only the PULP_MANIFEST was downloaded from the main remote assert len(main_server.requests_record) == 1 @@ -202,7 +206,7 @@ def test_acs_sync_with_paths( @pytest.mark.parallel def test_serving_acs_content( file_repo, - file_repository_api_client, + file_bindings, file_acs_api_client, file_distribution_factory, basic_manifest_path, @@ -235,14 +239,16 @@ def test_serving_acs_content( # Turn on auto-publish on the repository monitor_task( - file_repository_api_client.partial_update( + file_bindings.RepositoriesFileApi.partial_update( file_repo.pulp_href, {"autopublish": True, "remote": main_remote.pulp_href} ).task ) # Sync the repository repository_sync_data = RepositorySyncURL(remote=main_remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, repository_sync_data).task) + monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, repository_sync_data).task + ) # Assert that only the PULP_MANIFEST was downloaded from the main remote assert len(main_server.requests_record) == 1 diff --git a/pulpcore/tests/functional/api/pulp_file/test_auto_publish.py b/pulpcore/tests/functional/api/pulp_file/test_auto_publish.py index 684d0ac659b..fa8fe01a009 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_auto_publish.py +++ b/pulpcore/tests/functional/api/pulp_file/test_auto_publish.py @@ -17,7 +17,7 @@ def file_repo_with_auto_publish(file_repository_factory): def test_auto_publish_and_distribution( file_repo_with_auto_publish, file_remote_ssl_factory, - file_repository_api_client, + file_bindings, file_publication_api_client, basic_manifest_path, gen_object_with_cleanup, @@ -28,7 +28,7 @@ def test_auto_publish_and_distribution( ): """Tests auto-publish and auto-distribution""" remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - repo = file_repository_api_client.read(file_repo_with_auto_publish.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(file_repo_with_auto_publish.pulp_href) distribution = gen_object_with_cleanup( file_distribution_api_client, {"name": "foo", "base_path": "bar/foo", "repository": repo.pulp_href}, @@ -46,8 +46,8 @@ def test_auto_publish_and_distribution( # Sync from the remote body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(repo.pulp_href, body).task) - repo = file_repository_api_client.read(repo.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.sync(repo.pulp_href, body).task) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) # Assert that a new repository version was created and a publication was created assert repo.latest_version_href.endswith("/versions/1/") @@ -69,11 +69,11 @@ def test_auto_publish_and_distribution( # Add a new content unit to the repository and assert that a publication gets created and the # new content unit is in it monitor_task( - file_repository_api_client.modify( + file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"add_content_units": [file_random_content_unit.pulp_href]} ).task ) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) files_in_second_publication = get_files_in_manifest( "{}{}".format(distribution.base_url, publication.manifest) ) diff --git a/pulpcore/tests/functional/api/pulp_file/test_bad_sync.py b/pulpcore/tests/functional/api/pulp_file/test_bad_sync.py index e1880bc85f9..eef38a7cc38 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_bad_sync.py +++ b/pulpcore/tests/functional/api/pulp_file/test_bad_sync.py @@ -9,7 +9,7 @@ @pytest.fixture def perform_sync( file_repo, - file_repository_api_client, + file_bindings, file_remote_api_client, gen_object_with_cleanup, monitor_task, @@ -23,7 +23,7 @@ def _perform_sync(url, policy="immediate"): remote = gen_object_with_cleanup(file_remote_api_client, remote_data) body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) return file_repo yield _perform_sync diff --git a/pulpcore/tests/functional/api/pulp_file/test_crud_content_unit.py b/pulpcore/tests/functional/api/pulp_file/test_crud_content_unit.py index 1bf34559e63..5becd885984 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_crud_content_unit.py +++ b/pulpcore/tests/functional/api/pulp_file/test_crud_content_unit.py @@ -57,7 +57,7 @@ def test_same_sha256_same_relative_path_no_repo( def test_same_sha256_same_relative_path_repo_specified( random_artifact, file_content_api_client, - file_repository_api_client, + file_bindings, file_repository_version_api_client, gen_user, file_repository_factory, @@ -81,7 +81,7 @@ def test_same_sha256_same_relative_path_repo_specified( content1 = file_content_api_client.read(monitor_task(response1.task).created_resources[1]) content2 = file_content_api_client.read(monitor_task(response2.task).created_resources[0]) assert content1.pulp_href == content2.pulp_href - repo1 = file_repository_api_client.read(repo1.pulp_href) + repo1 = file_bindings.RepositoriesFileApi.read(repo1.pulp_href) assert repo1.latest_version_href.endswith("/versions/1/") version = file_repository_version_api_client.read(repo1.latest_version_href) @@ -94,7 +94,7 @@ def test_same_sha256_same_relative_path_repo_specified( content3 = file_content_api_client.read(monitor_task(ctask3).created_resources[1]) assert content3.pulp_href == content1.pulp_href - repo2 = file_repository_api_client.read(repo2.pulp_href) + repo2 = file_bindings.RepositoriesFileApi.read(repo2.pulp_href) assert repo2.latest_version_href.endswith("/versions/1/") version = file_repository_version_api_client.read(repo2.latest_version_href) @@ -124,7 +124,7 @@ def test_second_content_unit_with_same_rel_path_replaces_the_first( file_content_api_client, gen_object_with_cleanup, file_repository_version_api_client, - file_repository_api_client, + file_bindings, ): latest_repo_version = file_repository_version_api_client.read(file_repo.latest_version_href) assert latest_repo_version.number == 0 @@ -136,7 +136,7 @@ def test_second_content_unit_with_same_rel_path_replaces_the_first( } gen_object_with_cleanup(file_content_api_client, **artifact_attrs) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) latest_repo_version = file_repository_version_api_client.read(file_repo.latest_version_href) assert latest_repo_version.content_summary.present["file.file"]["count"] == 1 assert latest_repo_version.number == 1 @@ -144,7 +144,7 @@ def test_second_content_unit_with_same_rel_path_replaces_the_first( artifact_attrs["artifact"] = random_artifact_factory().pulp_href gen_object_with_cleanup(file_content_api_client, **artifact_attrs) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) latest_repo_version = file_repository_version_api_client.read(file_repo.latest_version_href) assert latest_repo_version.content_summary.present["file.file"]["count"] == 1 assert latest_repo_version.number == 2 @@ -157,7 +157,7 @@ def test_cannot_create_repo_version_with_two_relative_paths_the_same( file_content_api_client, gen_object_with_cleanup, file_repository_version_api_client, - file_repository_api_client, + file_bindings, monitor_task, ): latest_repo_version = file_repository_version_api_client.read(file_repo.latest_version_href) @@ -178,22 +178,22 @@ def test_cannot_create_repo_version_with_two_relative_paths_the_same( data = {"add_content_units": [first_content_unit.pulp_href, second_content_unit.pulp_href]} with pytest.raises(PulpTaskError): - response = file_repository_api_client.modify(file_repo.pulp_href, data) + response = file_bindings.RepositoriesFileApi.modify(file_repo.pulp_href, data) monitor_task(response.task) @pytest.mark.parallel -def test_bad_inputs_to_modify_endpoint(file_repo, file_repository_api_client, needs_pulp_plugin): +def test_bad_inputs_to_modify_endpoint(file_repo, file_bindings, needs_pulp_plugin): needs_pulp_plugin("core", min="3.23.0.dev") with pytest.raises(ApiException): - file_repository_api_client.modify(file_repo.pulp_href, [{}]) + file_bindings.RepositoriesFileApi.modify(file_repo.pulp_href, [{}]) with pytest.raises(ApiException): - file_repository_api_client.modify(file_repo.pulp_href, {"a": "b"}) + file_bindings.RepositoriesFileApi.modify(file_repo.pulp_href, {"a": "b"}) with pytest.raises(ApiException): - file_repository_api_client.modify(file_repo.pulp_href, ["/content/"]) + file_bindings.RepositoriesFileApi.modify(file_repo.pulp_href, ["/content/"]) @pytest.mark.parallel diff --git a/pulpcore/tests/functional/api/pulp_file/test_domains.py b/pulpcore/tests/functional/api/pulp_file/test_domains.py index 78d3585cec1..a7b147f44d0 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_domains.py +++ b/pulpcore/tests/functional/api/pulp_file/test_domains.py @@ -16,7 +16,7 @@ def test_object_creation( domains_api_client, gen_object_with_cleanup, - file_repository_api_client, + file_bindings, file_remote_factory, basic_manifest_path, ): @@ -30,22 +30,24 @@ def test_object_creation( domain_name = domain.name repo_body = {"name": str(uuid.uuid4())} - repo = gen_object_with_cleanup(file_repository_api_client, repo_body, pulp_domain=domain_name) + repo = gen_object_with_cleanup( + file_bindings.RepositoriesFileApi, repo_body, pulp_domain=domain_name + ) assert f"{domain_name}/api/v3/" in repo.pulp_href - repos = file_repository_api_client.list(pulp_domain=domain_name) + repos = file_bindings.RepositoriesFileApi.list(pulp_domain=domain_name) assert repos.count == 1 assert repo.pulp_href == repos.results[0].pulp_href # Will list repos on default domain - default_repos = file_repository_api_client.list(name=repo.name) + default_repos = file_bindings.RepositoriesFileApi.list(name=repo.name) assert default_repos.count == 0 # Try to create an object w/ cross domain relations default_remote = file_remote_factory(manifest_path=basic_manifest_path, policy="immediate") with pytest.raises(ApiException) as e: repo_body = {"name": str(uuid.uuid4()), "remote": default_remote.pulp_href} - file_repository_api_client.create(repo_body, pulp_domain=domain.name) + file_bindings.RepositoriesFileApi.create(repo_body, pulp_domain=domain.name) assert e.value.status == 400 # What key should this error be under? non-field-errors seems wrong assert json.loads(e.value.body) == { @@ -54,7 +56,7 @@ def test_object_creation( with pytest.raises(ApiException) as e: sync_body = {"remote": default_remote.pulp_href} - file_repository_api_client.sync(repo.pulp_href, sync_body) + file_bindings.RepositoriesFileApi.sync(repo.pulp_href, sync_body) assert e.value.status == 400 assert json.loads(e.value.body) == { "non_field_errors": [f"Objects must all be apart of the {domain_name} domain."] @@ -180,7 +182,7 @@ def test_content_upload( @pytest.mark.parallel def test_content_promotion( domains_api_client, - file_repository_api_client, + file_bindings, file_repository_version_api_client, basic_manifest_path, file_remote_factory, @@ -203,13 +205,13 @@ def test_content_promotion( manifest_path=basic_manifest_path, policy="immediate", pulp_domain=domain.name ) repo_body = {"name": str(uuid.uuid4()), "remote": remote.pulp_href} - repo = file_repository_api_client.create(repo_body, pulp_domain=domain.name) + repo = file_bindings.RepositoriesFileApi.create(repo_body, pulp_domain=domain.name) - task = file_repository_api_client.sync(repo.pulp_href, {}).task + task = file_bindings.RepositoriesFileApi.sync(repo.pulp_href, {}).task response = monitor_task(task) assert len(response.created_resources) == 1 - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert repo.latest_version_href[-2] == "1" # Publish task @@ -244,7 +246,7 @@ def test_content_promotion( assert results.error is None # Cleanup to delete the domain - task = file_repository_api_client.delete(repo.pulp_href).task + task = file_bindings.RepositoriesFileApi.delete(repo.pulp_href).task monitor_task(task) body = {"orphan_protection_time": 0} task = orphans_cleanup_api_client.cleanup(body, pulp_domain=domain.name).task @@ -252,9 +254,7 @@ def test_content_promotion( @pytest.mark.parallel -def test_domain_rbac( - domains_api_client, gen_user, gen_object_with_cleanup, file_repository_api_client -): +def test_domain_rbac(domains_api_client, gen_user, gen_object_with_cleanup, file_bindings): """Test domain level-roles.""" body = { "name": str(uuid.uuid4()), @@ -269,30 +269,32 @@ def test_domain_rbac( user_b = gen_user(username="b", domain_roles=[(file_creator, domain.pulp_href)]) # Create two repos in different domains w/ admin user - gen_object_with_cleanup(file_repository_api_client, {"name": str(uuid.uuid4())}) + gen_object_with_cleanup(file_bindings.RepositoriesFileApi, {"name": str(uuid.uuid4())}) gen_object_with_cleanup( - file_repository_api_client, {"name": str(uuid.uuid4())}, pulp_domain=domain.name + file_bindings.RepositoriesFileApi, {"name": str(uuid.uuid4())}, pulp_domain=domain.name ) with user_b: repo = gen_object_with_cleanup( - file_repository_api_client, {"name": str(uuid.uuid4())}, pulp_domain=domain.name + file_bindings.RepositoriesFileApi, {"name": str(uuid.uuid4())}, pulp_domain=domain.name ) - repos = file_repository_api_client.list(pulp_domain=domain.name) + repos = file_bindings.RepositoriesFileApi.list(pulp_domain=domain.name) assert repos.count == 1 assert repos.results[0].pulp_href == repo.pulp_href # Try to create a repository in default domain with pytest.raises(ApiException) as e: - file_repository_api_client.create({"name": str(uuid.uuid4())}) + file_bindings.RepositoriesFileApi.create({"name": str(uuid.uuid4())}) assert e.value.status == 403 with user_a: - repos = file_repository_api_client.list(pulp_domain=domain.name) + repos = file_bindings.RepositoriesFileApi.list(pulp_domain=domain.name) assert repos.count == 2 # Try to read repos in the default domain - repos = file_repository_api_client.list() + repos = file_bindings.RepositoriesFileApi.list() assert repos.count == 0 # Try to create a repo with pytest.raises(ApiException) as e: - file_repository_api_client.create({"name": str(uuid.uuid4())}, pulp_domain=domain.name) + file_bindings.RepositoriesFileApi.create( + {"name": str(uuid.uuid4())}, pulp_domain=domain.name + ) assert e.value.status == 403 diff --git a/pulpcore/tests/functional/api/pulp_file/test_download_policies.py b/pulpcore/tests/functional/api/pulp_file/test_download_policies.py index 96b8660fd6a..94da114acc6 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_download_policies.py +++ b/pulpcore/tests/functional/api/pulp_file/test_download_policies.py @@ -45,7 +45,7 @@ def test_download_policy( file_repo, file_remote_ssl_factory, file_remote_api_client, - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_publication_api_client, file_distribution_api_client, @@ -64,7 +64,7 @@ def test_download_policy( remote = file_remote_ssl_factory( manifest_path=range_header_manifest_path, policy=download_policy ) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.latest_version_href.endswith("/versions/0/") # Check what content and artifacts are in the fixture repository @@ -72,8 +72,8 @@ def test_download_policy( # Sync from the remote and assert that a new repository version is created body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.latest_version_href.endswith("/versions/1/") version = file_repository_version_api_client.read(file_repo.latest_version_href) @@ -82,8 +82,8 @@ def test_download_policy( # Sync again and assert that nothing changes latest_version_href = file_repo.latest_version_href - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert latest_version_href == file_repo.latest_version_href version = file_repository_version_api_client.read(file_repo.latest_version_href) @@ -234,6 +234,6 @@ def test_download_policy( assert remote.policy == "immediate" # Sync from the remote and assert that artifacts are downloaded - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) for f in expected_files: assert len(artifacts_api_client.list(sha256=f[1]).results) == 1 diff --git a/pulpcore/tests/functional/api/pulp_file/test_labels.py b/pulpcore/tests/functional/api/pulp_file/test_labels.py index a604caffec6..3c664ae7ad9 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_labels.py +++ b/pulpcore/tests/functional/api/pulp_file/test_labels.py @@ -15,7 +15,7 @@ def test_create_repo_with_labels(file_repository_factory): @pytest.mark.parallel -def test_set_unset_all_labels(file_repo, file_repository_api_client, monitor_task): +def test_set_unset_all_labels(file_repo, file_bindings, monitor_task): """Set and unset labels from a repository.""" assert file_repo.pulp_labels == {} @@ -23,23 +23,25 @@ def test_set_unset_all_labels(file_repo, file_repository_api_client, monitor_tas # Set some labels labels = {"key_a": "label_a"} monitor_task( - file_repository_api_client.partial_update(file_repo.pulp_href, {"pulp_labels": labels}).task + file_bindings.RepositoriesFileApi.partial_update( + file_repo.pulp_href, {"pulp_labels": labels} + ).task ) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.pulp_labels == labels # Unset all labels monitor_task( - file_repository_api_client.partial_update(file_repo.pulp_href, {"pulp_labels": {}}).task + file_bindings.RepositoriesFileApi.partial_update( + file_repo.pulp_href, {"pulp_labels": {}} + ).task ) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.pulp_labels == {} @pytest.mark.parallel -def test_add_remove_label_keys( - file_repo, file_repository_api_client, file_repository_factory, monitor_task -): +def test_add_remove_label_keys(file_repo, file_bindings, file_repository_factory, monitor_task): """Add and Remove labels by key.""" # Set some initial labels @@ -49,26 +51,28 @@ def test_add_remove_label_keys( # Add a new key labels["key_b"] = "label_b" monitor_task( - file_repository_api_client.partial_update(file_repo.pulp_href, {"pulp_labels": labels}).task + file_bindings.RepositoriesFileApi.partial_update( + file_repo.pulp_href, {"pulp_labels": labels} + ).task ) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.pulp_labels == labels # Remove the original key del labels["key_a"] monitor_task( - file_repository_api_client.partial_update(file_repo.pulp_href, {"pulp_labels": labels}).task + file_bindings.RepositoriesFileApi.partial_update( + file_repo.pulp_href, {"pulp_labels": labels} + ).task ) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.pulp_labels == labels @pytest.mark.parallel -def test_update_existing_label_value( - file_repository_api_client, file_repository_factory, monitor_task -): +def test_update_existing_label_value(file_bindings, file_repository_factory, monitor_task): """Update an existing label.""" # Set some initial labels @@ -78,15 +82,17 @@ def test_update_existing_label_value( # Modify the value of an existing key labels["key_a"] = "label_b" monitor_task( - file_repository_api_client.partial_update(file_repo.pulp_href, {"pulp_labels": labels}).task + file_bindings.RepositoriesFileApi.partial_update( + file_repo.pulp_href, {"pulp_labels": labels} + ).task ) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.pulp_labels == labels @pytest.mark.parallel -def test_model_partial_update(file_repository_factory, file_repository_api_client, monitor_task): +def test_model_partial_update(file_repository_factory, file_bindings, monitor_task): """Test that labels aren't unset accidentally with PATCH calls of other fields.""" # Set some initial labels @@ -95,10 +101,12 @@ def test_model_partial_update(file_repository_factory, file_repository_api_clien # Update the name only monitor_task( - file_repository_api_client.partial_update(file_repo.pulp_href, {"name": str(uuid4())}).task + file_bindings.RepositoriesFileApi.partial_update( + file_repo.pulp_href, {"name": str(uuid4())} + ).task ) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.pulp_labels == labels @@ -128,7 +136,7 @@ def test_invalid_labels(file_repository_factory): @pytest.mark.parallel -def test_label_select(file_repository_factory, file_repository_api_client): +def test_label_select(file_repository_factory, file_bindings): """Test lots of select types.""" key1 = str(uuid4()).replace("-", "") # We can only have alphanumerics key2 = str(uuid4()).replace("-", "") # We can only have alphanumerics @@ -141,59 +149,63 @@ def test_label_select(file_repository_factory, file_repository_api_client): file_repository_factory(name=str(uuid4()), pulp_labels={}) - results = file_repository_api_client.list(pulp_label_select=f"{key1}=production").results + results = file_bindings.RepositoriesFileApi.list(pulp_label_select=f"{key1}=production").results assert len(results) == 1 - results = file_repository_api_client.list(pulp_label_select=f"{key1}!=production").results + results = file_bindings.RepositoriesFileApi.list( + pulp_label_select=f"{key1}!=production" + ).results assert len(results) == 1 - results = file_repository_api_client.list(pulp_label_select=key1).results + results = file_bindings.RepositoriesFileApi.list(pulp_label_select=key1).results assert len(results) == 2 - results = file_repository_api_client.list(pulp_label_select=f"{key1}~prod").results + results = file_bindings.RepositoriesFileApi.list(pulp_label_select=f"{key1}~prod").results assert len(results) == 1 - results = file_repository_api_client.list( + results = file_bindings.RepositoriesFileApi.list( pulp_label_select=f"{key1}=production,{key2}=true" ).results assert len(results) == 1 - results = file_repository_api_client.list( + results = file_bindings.RepositoriesFileApi.list( pulp_label_select=f"{key1}=production,{key2}!=false" ).results assert len(results) == 1 - results = file_repository_api_client.list(pulp_label_select=f"!{key1},{key2}=false").results + results = file_bindings.RepositoriesFileApi.list( + pulp_label_select=f"!{key1},{key2}=false" + ).results assert len(results) == 0 @pytest.mark.parallel -def test_empty_blank_filter(file_repository_factory, file_repository_api_client): +def test_empty_blank_filter(file_repository_factory, file_bindings): """Test filtering values with a blank string.""" key = str(uuid4()).replace("-", "") # We can only have alphanumerics labels = {key: ""} file_repository_factory(name=str(uuid4()), pulp_labels=labels) - results = file_repository_api_client.list(pulp_label_select=f"{key}=").results + results = file_bindings.RepositoriesFileApi.list(pulp_label_select=f"{key}=").results assert len(results) == 1 - results = file_repository_api_client.list(pulp_label_select=f"{key}~").results + results = file_bindings.RepositoriesFileApi.list(pulp_label_select=f"{key}~").results assert len(results) == 1 @pytest.mark.parallel -def test_invalid_label_select(file_repository_api_client): +def test_invalid_label_select(file_bindings): """Test removing all labels.""" with pytest.raises(ApiException) as e_info: - file_repository_api_client.list(pulp_label_select="").results + file_bindings.RepositoriesFileApi.list(pulp_label_select="").results assert e_info.value.status == 400 with pytest.raises(ApiException) as e_info: - file_repository_api_client.list(pulp_label_select="!environment=production").results + file_bindings.RepositoriesFileApi.list(pulp_label_select="!environment=production").results assert e_info.value.status == 400 with pytest.raises(ApiException) as e_info: - file_repository_api_client.list(pulp_label_select="=bad filter").results + file_bindings.RepositoriesFileApi.list(pulp_label_select="=bad filter").results assert e_info.value.status == 400 diff --git a/pulpcore/tests/functional/api/pulp_file/test_mime_types.py b/pulpcore/tests/functional/api/pulp_file/test_mime_types.py index b1bcb509bf1..db41ef9835b 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_mime_types.py +++ b/pulpcore/tests/functional/api/pulp_file/test_mime_types.py @@ -11,7 +11,7 @@ @pytest.mark.parallel def test_content_types( file_distribution_api_client, - file_repository_api_client, + file_bindings, file_repo_with_auto_publish, file_content_unit_with_name_factory, gen_object_with_cleanup, @@ -38,7 +38,7 @@ def test_content_types( units_to_add = list(map(lambda f: f.pulp_href, files.values())) data = RepositoryAddRemoveContent(add_content_units=units_to_add) monitor_task( - file_repository_api_client.modify(file_repo_with_auto_publish.pulp_href, data).task + file_bindings.RepositoriesFileApi.modify(file_repo_with_auto_publish.pulp_href, data).task ) data = FileFileDistribution( diff --git a/pulpcore/tests/functional/api/pulp_file/test_publish.py b/pulpcore/tests/functional/api/pulp_file/test_publish.py index 188cab67a7e..f437d16759c 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_publish.py +++ b/pulpcore/tests/functional/api/pulp_file/test_publish.py @@ -16,7 +16,7 @@ def test_crd_publications( file_repo, file_remote_ssl_factory, - file_repository_api_client, + file_bindings, file_publication_api_client, basic_manifest_path, gen_object_with_cleanup, @@ -29,19 +29,19 @@ def test_crd_publications( # Sync from the remote initial_repo_version = file_repo.latest_version_href body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) - first_repo_version_href = file_repository_api_client.read( + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) + first_repo_version_href = file_bindings.RepositoriesFileApi.read( file_repo.pulp_href ).latest_version_href assert first_repo_version_href.endswith("/versions/1/") # Add a new content unit to the repository and assert that a new repository version is created monitor_task( - file_repository_api_client.modify( + file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, {"add_content_units": [file_random_content_unit.pulp_href]} ).task ) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.latest_version_href.endswith("/versions/2/") # Create a Publication using a repository and assert that its repository_version is the latest @@ -72,7 +72,7 @@ def test_crd_publications( publication = file_publication_api_client.read(publication.pulp_href) # Read a publication by its href providing specific field list. - config = file_repository_api_client.api_client.configuration + config = file_bindings.RepositoriesFileApi.api_client.configuration auth = BasicAuth(login=config.username, password=config.password) full_href = urljoin(config.host, publication.pulp_href) for fields in [ diff --git a/pulpcore/tests/functional/api/pulp_file/test_pulp_export.py b/pulpcore/tests/functional/api/pulp_file/test_pulp_export.py index 22868f5a464..2f169cd5c65 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_pulp_export.py +++ b/pulpcore/tests/functional/api/pulp_file/test_pulp_export.py @@ -76,7 +76,7 @@ def _pulp_export_factory(exporter, body=None): @pytest.fixture def three_synced_repositories( - file_repository_api_client, + file_bindings, file_repository_factory, file_remote_factory, write_3_iso_file_fixture_data_factory, @@ -90,12 +90,12 @@ def three_synced_repositories( ] repositories = [file_repository_factory(remote=remote.pulp_href) for remote in remotes] sync_tasks = [ - file_repository_api_client.sync(repository.pulp_href, {}).task + file_bindings.RepositoriesFileApi.sync(repository.pulp_href, {}).task for repository in repositories ] [monitor_task(task) for task in sync_tasks] repositories = [ - file_repository_api_client.read(repository.pulp_href) for repository in repositories + file_bindings.RepositoriesFileApi.read(repository.pulp_href) for repository in repositories ] return repositories diff --git a/pulpcore/tests/functional/api/pulp_file/test_rbac.py b/pulpcore/tests/functional/api/pulp_file/test_rbac.py index 10c4c2a9fa9..0f028302d87 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_rbac.py +++ b/pulpcore/tests/functional/api/pulp_file/test_rbac.py @@ -40,78 +40,99 @@ def _try_action(user, client, action, outcome, *args, **kwargs): return _try_action -def test_basic_actions(gen_users, file_repository_api_client, try_action, file_repo): +def test_basic_actions(gen_users, file_bindings, try_action, file_repo): """Test list, read, create, update and delete apis.""" alice, bob, charlie = gen_users("filerepository") - a_list = try_action(alice, file_repository_api_client, "list", 200) + a_list = try_action(alice, file_bindings.RepositoriesFileApi, "list", 200) assert a_list.count >= 1 - b_list = try_action(bob, file_repository_api_client, "list", 200) - c_list = try_action(charlie, file_repository_api_client, "list", 200) + b_list = try_action(bob, file_bindings.RepositoriesFileApi, "list", 200) + c_list = try_action(charlie, file_bindings.RepositoriesFileApi, "list", 200) assert (b_list.count, c_list.count) == (0, 0) # Create testing - try_action(alice, file_repository_api_client, "create", 403, {"name": str(uuid.uuid4())}) - repo = try_action(bob, file_repository_api_client, "create", 201, {"name": str(uuid.uuid4())}) - try_action(charlie, file_repository_api_client, "create", 403, {"name": str(uuid.uuid4())}) + try_action(alice, file_bindings.RepositoriesFileApi, "create", 403, {"name": str(uuid.uuid4())}) + repo = try_action( + bob, file_bindings.RepositoriesFileApi, "create", 201, {"name": str(uuid.uuid4())} + ) + try_action( + charlie, file_bindings.RepositoriesFileApi, "create", 403, {"name": str(uuid.uuid4())} + ) # View testing - try_action(alice, file_repository_api_client, "read", 200, repo.pulp_href) - try_action(bob, file_repository_api_client, "read", 200, repo.pulp_href) - try_action(charlie, file_repository_api_client, "read", 404, repo.pulp_href) + try_action(alice, file_bindings.RepositoriesFileApi, "read", 200, repo.pulp_href) + try_action(bob, file_bindings.RepositoriesFileApi, "read", 200, repo.pulp_href) + try_action(charlie, file_bindings.RepositoriesFileApi, "read", 404, repo.pulp_href) # Update testing update_args = [repo.pulp_href, {"name": str(uuid.uuid4())}] - try_action(alice, file_repository_api_client, "partial_update", 403, *update_args) - try_action(bob, file_repository_api_client, "partial_update", 202, *update_args) - try_action(charlie, file_repository_api_client, "partial_update", 404, *update_args) + try_action(alice, file_bindings.RepositoriesFileApi, "partial_update", 403, *update_args) + try_action(bob, file_bindings.RepositoriesFileApi, "partial_update", 202, *update_args) + try_action(charlie, file_bindings.RepositoriesFileApi, "partial_update", 404, *update_args) # Delete testing - try_action(alice, file_repository_api_client, "delete", 403, repo.pulp_href) - try_action(charlie, file_repository_api_client, "delete", 404, repo.pulp_href) - try_action(bob, file_repository_api_client, "delete", 202, repo.pulp_href) + try_action(alice, file_bindings.RepositoriesFileApi, "delete", 403, repo.pulp_href) + try_action(charlie, file_bindings.RepositoriesFileApi, "delete", 404, repo.pulp_href) + try_action(bob, file_bindings.RepositoriesFileApi, "delete", 202, repo.pulp_href) @pytest.mark.parallel -def test_role_management( - gen_users, file_repository_api_client, file_repository_factory, try_action -): +def test_role_management(gen_users, file_bindings, file_repository_factory, try_action): """Check that role management apis.""" alice, bob, charlie = gen_users("filerepository") with bob: href = file_repository_factory().pulp_href # Permission check testing - aperm_response = try_action(alice, file_repository_api_client, "my_permissions", 200, href) + aperm_response = try_action( + alice, file_bindings.RepositoriesFileApi, "my_permissions", 200, href + ) assert aperm_response.permissions == [] - bperm_response = try_action(bob, file_repository_api_client, "my_permissions", 200, href) + bperm_response = try_action(bob, file_bindings.RepositoriesFileApi, "my_permissions", 200, href) assert len(bperm_response.permissions) > 0 - try_action(charlie, file_repository_api_client, "my_permissions", 404, href) + try_action(charlie, file_bindings.RepositoriesFileApi, "my_permissions", 404, href) # Add "viewer" role testing nested_role = {"users": [charlie.username], "role": "file.filerepository_viewer"} - try_action(alice, file_repository_api_client, "add_role", 403, href, nested_role=nested_role) - try_action(charlie, file_repository_api_client, "add_role", 404, href, nested_role=nested_role) - try_action(bob, file_repository_api_client, "add_role", 201, href, nested_role=nested_role) + try_action( + alice, file_bindings.RepositoriesFileApi, "add_role", 403, href, nested_role=nested_role + ) + try_action( + charlie, file_bindings.RepositoriesFileApi, "add_role", 404, href, nested_role=nested_role + ) + try_action( + bob, file_bindings.RepositoriesFileApi, "add_role", 201, href, nested_role=nested_role + ) # Permission check testing again - cperm_response = try_action(charlie, file_repository_api_client, "my_permissions", 200, href) + cperm_response = try_action( + charlie, file_bindings.RepositoriesFileApi, "my_permissions", 200, href + ) assert len(cperm_response.permissions) == 1 # Remove "viewer" role testing - try_action(alice, file_repository_api_client, "remove_role", 403, href, nested_role=nested_role) try_action( - charlie, file_repository_api_client, "remove_role", 403, href, nested_role=nested_role + alice, file_bindings.RepositoriesFileApi, "remove_role", 403, href, nested_role=nested_role + ) + try_action( + charlie, + file_bindings.RepositoriesFileApi, + "remove_role", + 403, + href, + nested_role=nested_role, + ) + try_action( + bob, file_bindings.RepositoriesFileApi, "remove_role", 201, href, nested_role=nested_role ) - try_action(bob, file_repository_api_client, "remove_role", 201, href, nested_role=nested_role) # Permission check testing one more time - try_action(charlie, file_repository_api_client, "my_permissions", 404, href) + try_action(charlie, file_bindings.RepositoriesFileApi, "my_permissions", 404, href) def test_content_apis( gen_users, file_content_api_client, - file_repository_api_client, + file_bindings, file_repository_factory, file_remote_factory, file_fixture_server, @@ -131,7 +152,9 @@ def test_content_apis( alice, bob, charlie = gen_users(["filerepository"]) repo = file_repository_factory() remote = file_remote_factory(manifest_path=basic_manifest_path, policy="on_demand") - monitor_task(file_repository_api_client.sync(repo.pulp_href, {"remote": remote.pulp_href}).task) + monitor_task( + file_bindings.RepositoriesFileApi.sync(repo.pulp_href, {"remote": remote.pulp_href}).task + ) aresponse = try_action(alice, file_content_api_client, "list", 200) bresponse = try_action(bob, file_content_api_client, "list", 200) @@ -141,7 +164,7 @@ def test_content_apis( assert bresponse.count == cresponse.count == 0 nested_role = {"users": [charlie.username], "role": "file.filerepository_viewer"} - file_repository_api_client.add_role(repo.pulp_href, nested_role) + file_bindings.RepositoriesFileApi.add_role(repo.pulp_href, nested_role) cresponse = try_action(charlie, file_content_api_client, "list", 200) assert cresponse.count > bresponse.count @@ -154,14 +177,14 @@ def test_content_apis( try_action(charlie, file_content_api_client, "create", 403, "1.iso", **body) nested_role = {"users": [charlie.username], "role": "file.filerepository_owner"} - file_repository_api_client.add_role(repo.pulp_href, nested_role) + file_bindings.RepositoriesFileApi.add_role(repo.pulp_href, nested_role) try_action(charlie, file_content_api_client, "create", 202, "1.iso", **body) @pytest.mark.parallel def test_repository_apis( gen_users, - file_repository_api_client, + file_bindings, file_repository_factory, file_remote_factory, file_remote_api_client, @@ -175,13 +198,13 @@ def test_repository_apis( repo = file_repository_factory() bob_remote = file_remote_factory(manifest_path=basic_manifest_path, policy="on_demand") body = {"remote": bob_remote.pulp_href} - try_action(alice, file_repository_api_client, "sync", 403, repo.pulp_href, body) - try_action(bob, file_repository_api_client, "sync", 202, repo.pulp_href, body) - try_action(charlie, file_repository_api_client, "sync", 404, repo.pulp_href, body) + try_action(alice, file_bindings.RepositoriesFileApi, "sync", 403, repo.pulp_href, body) + try_action(bob, file_bindings.RepositoriesFileApi, "sync", 202, repo.pulp_href, body) + try_action(charlie, file_bindings.RepositoriesFileApi, "sync", 404, repo.pulp_href, body) # Modify tests - try_action(alice, file_repository_api_client, "modify", 403, repo.pulp_href, {}) - try_action(bob, file_repository_api_client, "modify", 202, repo.pulp_href, {}) - try_action(charlie, file_repository_api_client, "modify", 404, repo.pulp_href, {}) + try_action(alice, file_bindings.RepositoriesFileApi, "modify", 403, repo.pulp_href, {}) + try_action(bob, file_bindings.RepositoriesFileApi, "modify", 202, repo.pulp_href, {}) + try_action(charlie, file_bindings.RepositoriesFileApi, "modify", 404, repo.pulp_href, {}) @pytest.mark.parallel diff --git a/pulpcore/tests/functional/api/pulp_file/test_remote_settings.py b/pulpcore/tests/functional/api/pulp_file/test_remote_settings.py index 23162de3e62..29eb4d3a84a 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_remote_settings.py +++ b/pulpcore/tests/functional/api/pulp_file/test_remote_settings.py @@ -8,10 +8,10 @@ def _run_basic_sync_and_assert( - remote, file_repo, file_repository_api_client, file_content_api_client, monitor_task + remote, file_repo, file_bindings, file_content_api_client, monitor_task ): body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) # Check content is present, but no artifacts are there content_response = file_content_api_client.list( @@ -29,7 +29,7 @@ def _run_basic_sync_and_assert( def test_http_sync_no_ssl( file_remote_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, basic_manifest_path, monitor_task, @@ -42,7 +42,7 @@ def test_http_sync_no_ssl( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -52,7 +52,7 @@ def test_http_sync_no_ssl( def test_http_sync_ssl_tls_validation_off( file_remote_ssl_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, basic_manifest_path, monitor_task, @@ -67,7 +67,7 @@ def test_http_sync_ssl_tls_validation_off( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -77,7 +77,7 @@ def test_http_sync_ssl_tls_validation_off( def test_http_sync_ssl_tls_validation_on( file_remote_ssl_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, basic_manifest_path, monitor_task, @@ -92,7 +92,7 @@ def test_http_sync_ssl_tls_validation_on( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -102,7 +102,7 @@ def test_http_sync_ssl_tls_validation_on( def test_http_sync_ssl_tls_validation_defaults_to_on( file_remote_ssl_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, basic_manifest_path, monitor_task, @@ -118,7 +118,7 @@ def test_http_sync_ssl_tls_validation_defaults_to_on( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -128,7 +128,7 @@ def test_http_sync_ssl_tls_validation_defaults_to_on( def test_http_sync_ssl_with_client_cert_req( file_remote_client_cert_req_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, basic_manifest_path, monitor_task, @@ -143,7 +143,7 @@ def test_http_sync_ssl_with_client_cert_req( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -153,7 +153,7 @@ def test_http_sync_ssl_with_client_cert_req( def test_ondemand_to_immediate_sync( file_remote_ssl_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, basic_manifest_path, monitor_task, @@ -168,7 +168,7 @@ def test_ondemand_to_immediate_sync( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -180,7 +180,7 @@ def test_ondemand_to_immediate_sync( _run_basic_sync_and_assert( remote_immediate, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -192,7 +192,7 @@ def test_header_for_sync( tls_certificate_authority_cert, file_remote_api_client, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, gen_object_with_cleanup, basic_manifest_path, @@ -220,7 +220,7 @@ def test_header_for_sync( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) diff --git a/pulpcore/tests/functional/api/pulp_file/test_sync.py b/pulpcore/tests/functional/api/pulp_file/test_sync.py index d578f0e0593..6721d150ac5 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_sync.py +++ b/pulpcore/tests/functional/api/pulp_file/test_sync.py @@ -14,7 +14,7 @@ def test_sync_file_protocol_handler( file_repo, - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_remote_api_client, gen_object_with_cleanup, @@ -33,12 +33,12 @@ def test_sync_file_protocol_handler( files = set(os.listdir("/tmp/file/")) body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) # test that all the files are still present assert set(os.listdir("/tmp/file/")) == files - file_repo = file_repository_api_client.read(file_repo.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert file_repo.latest_version_href.endswith("/versions/1/") version = file_repository_version_api_client.read(file_repo.latest_version_href) @@ -50,7 +50,7 @@ def test_sync_file_protocol_handler( def test_mirrored_sync( file_repo, file_remote_ssl_factory, - file_repository_api_client, + file_bindings, basic_manifest_path, monitor_task, ): @@ -58,7 +58,9 @@ def test_mirrored_sync( remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href, mirror=True) - sync_response = file_repository_api_client.sync(file_repo.pulp_href, repository_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync( + file_repo.pulp_href, repository_sync_data + ) task = monitor_task(sync_response.task) # Check that all the appropriate resources were created @@ -72,7 +74,7 @@ def test_invalid_url( file_repo, gen_object_with_cleanup, file_remote_api_client, - file_repository_api_client, + file_bindings, monitor_task, ): """Sync a repository using a remote url that does not exist.""" @@ -85,18 +87,18 @@ def test_invalid_url( body = RepositorySyncURL(remote=remote.pulp_href) with pytest.raises(PulpTaskError): - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) @pytest.mark.parallel def test_invalid_file( - file_repo, file_repository_api_client, invalid_manifest_path, file_remote_factory, monitor_task + file_repo, file_bindings, invalid_manifest_path, file_remote_factory, monitor_task ): """Sync a repository using an invalid file repository.""" remote = file_remote_factory(manifest_path=invalid_manifest_path, policy="immediate") body = RepositorySyncURL(remote=remote.pulp_href) with pytest.raises(PulpTaskError): - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) @pytest.mark.parallel @@ -104,7 +106,7 @@ def test_duplicate_file_sync( file_repo, file_remote_factory, duplicate_filename_paths, - file_repository_api_client, + file_bindings, file_repository_version_api_client, monitor_task, ): @@ -112,8 +114,8 @@ def test_duplicate_file_sync( remote2 = file_remote_factory(manifest_path=duplicate_filename_paths[1], policy="on_demand") body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) version = file_repository_version_api_client.read(file_repo.latest_version_href) assert version.content_summary.present["file.file"]["count"] == 3 @@ -121,8 +123,8 @@ def test_duplicate_file_sync( assert file_repo.latest_version_href.endswith("/1/") body = RepositorySyncURL(remote=remote2.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) version = file_repository_version_api_client.read(file_repo.latest_version_href) assert version.content_summary.present["file.file"]["count"] == 3 @@ -135,7 +137,7 @@ def test_filepath_includes_commas( file_repo, file_remote_factory, manifest_path_with_commas, - file_repository_api_client, + file_bindings, file_repository_version_api_client, monitor_task, ): @@ -143,8 +145,8 @@ def test_filepath_includes_commas( remote = file_remote_factory(manifest_path=manifest_path_with_commas, policy="on_demand") body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) version = file_repository_version_api_client.read(file_repo.latest_version_href) assert version.content_summary.present["file.file"]["count"] == 3 diff --git a/pulpcore/tests/functional/api/pulp_file/test_telemetry_collection.py b/pulpcore/tests/functional/api/pulp_file/test_telemetry_collection.py index 6a9b3977a82..2e6345a8c38 100644 --- a/pulpcore/tests/functional/api/pulp_file/test_telemetry_collection.py +++ b/pulpcore/tests/functional/api/pulp_file/test_telemetry_collection.py @@ -9,7 +9,7 @@ def test_get_requests( file_distribution_api_client, - file_repository_api_client, + file_bindings, file_repo_with_auto_publish, file_content_unit_with_name_factory, gen_object_with_cleanup, @@ -26,7 +26,7 @@ def test_get_requests( units_to_add = list(map(lambda f: f.pulp_href, content_units)) data = RepositoryAddRemoveContent(add_content_units=units_to_add) monitor_task( - file_repository_api_client.modify(file_repo_with_auto_publish.pulp_href, data).task + file_bindings.RepositoriesFileApi.modify(file_repo_with_auto_publish.pulp_href, data).task ) data = FileFileDistribution( diff --git a/pulpcore/tests/functional/api/test_access_policy.py b/pulpcore/tests/functional/api/test_access_policy.py index 5b0f0dd11bc..3f38649d3af 100644 --- a/pulpcore/tests/functional/api/test_access_policy.py +++ b/pulpcore/tests/functional/api/test_access_policy.py @@ -4,87 +4,87 @@ @pytest.mark.parallel -def test_access_policy_cannot_be_created(access_policies_api_client): +def test_access_policy_cannot_be_created(pulpcore_bindings): """Test that only plugin writers can ship a new AccessPolicy.""" - assert not hasattr(access_policies_api_client, "create") + assert not hasattr(pulpcore_bindings.AccessPoliciesApi, "create") @pytest.mark.parallel -def test_access_policy_default_policies(access_policies_api_client): +def test_access_policy_default_policies(pulpcore_bindings): """Test that the default policies from pulpcore are installed.""" - groups_response = access_policies_api_client.list(viewset_name="groups") + groups_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="groups") assert groups_response.count == 1 - groups_users_response = access_policies_api_client.list(viewset_name="groups/users") + groups_users_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="groups/users") assert groups_users_response.count == 1 - tasks_response = access_policies_api_client.list(viewset_name="tasks") + tasks_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="tasks") assert tasks_response.count == 1 -def test_statements_attr_can_be_modified(access_policies_api_client): +def test_statements_attr_can_be_modified(pulpcore_bindings): """Test that `AccessPolicy.statements` can be modified""" - tasks_response = access_policies_api_client.list(viewset_name="tasks") + tasks_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="tasks") tasks_href = tasks_response.results[0].pulp_href - task_access_policy = access_policies_api_client.read(tasks_href) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) original_statements = task_access_policy.statements assert not task_access_policy.customized assert original_statements != [] - access_policies_api_client.partial_update(tasks_href, {"statements": []}) - task_access_policy = access_policies_api_client.read(tasks_href) + pulpcore_bindings.AccessPoliciesApi.partial_update(tasks_href, {"statements": []}) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) assert task_access_policy.customized assert task_access_policy.statements == [] - access_policies_api_client.reset(tasks_href) - task_access_policy = access_policies_api_client.read(tasks_href) + pulpcore_bindings.AccessPoliciesApi.reset(tasks_href) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) assert not task_access_policy.customized assert task_access_policy.statements == original_statements -def test_creation_hooks_attr_can_be_modified(access_policies_api_client): +def test_creation_hooks_attr_can_be_modified(pulpcore_bindings): """Test that `AccessPolicy.creation_hooks` can be modified""" - groups_response = access_policies_api_client.list(viewset_name="groups") + groups_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="groups") groups_href = groups_response.results[0].pulp_href - groups_access_policy = access_policies_api_client.read(groups_href) + groups_access_policy = pulpcore_bindings.AccessPoliciesApi.read(groups_href) original_creation_hooks = groups_access_policy.creation_hooks assert not groups_access_policy.customized assert original_creation_hooks != [] - access_policies_api_client.partial_update(groups_href, {"creation_hooks": []}) - groups_access_policy = access_policies_api_client.read(groups_href) + pulpcore_bindings.AccessPoliciesApi.partial_update(groups_href, {"creation_hooks": []}) + groups_access_policy = pulpcore_bindings.AccessPoliciesApi.read(groups_href) assert groups_access_policy.customized assert groups_access_policy.creation_hooks == [] - access_policies_api_client.reset(groups_href) - groups_access_policy = access_policies_api_client.read(groups_href) + pulpcore_bindings.AccessPoliciesApi.reset(groups_href) + groups_access_policy = pulpcore_bindings.AccessPoliciesApi.read(groups_href) assert not groups_access_policy.customized assert groups_access_policy.creation_hooks == original_creation_hooks @pytest.mark.parallel -def test_customized_is_read_only(access_policies_api_client): +def test_customized_is_read_only(pulpcore_bindings): """Test that the `AccessPolicy.customized` attribute is read only""" - tasks_response = access_policies_api_client.list(viewset_name="tasks") + tasks_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="tasks") tasks_href = tasks_response.results[0].pulp_href - task_access_policy = access_policies_api_client.read(tasks_href) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) - response = access_policies_api_client.partial_update( + response = pulpcore_bindings.AccessPoliciesApi.partial_update( tasks_href, {"customized": not task_access_policy.customized} ) assert response.customized == task_access_policy.customized @pytest.mark.parallel -def test_viewset_name_is_read_only(access_policies_api_client): +def test_viewset_name_is_read_only(pulpcore_bindings): """Test that the `AccessPolicy.viewset_name` attribute is read only""" - tasks_response = access_policies_api_client.list(viewset_name="tasks") + tasks_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="tasks") tasks_href = tasks_response.results[0].pulp_href - task_access_policy = access_policies_api_client.read(tasks_href) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) - response = access_policies_api_client.partial_update( + response = pulpcore_bindings.AccessPoliciesApi.partial_update( tasks_href, {"viewset_name": "not-a-real-name"} ) assert response.viewset_name == task_access_policy.viewset_name diff --git a/pulpcore/tests/functional/api/test_api_docs.py b/pulpcore/tests/functional/api/test_api_docs.py index a824e3dd8a6..45416b0bbdb 100644 --- a/pulpcore/tests/functional/api/test_api_docs.py +++ b/pulpcore/tests/functional/api/test_api_docs.py @@ -9,33 +9,33 @@ def pulp_docs_url(pulp_api_v3_url): @pytest.mark.parallel -def test_valid_credentials(pulpcore_client, pulp_docs_url): +def test_valid_credentials(pulpcore_bindings, pulp_docs_url): """Get API documentation with valid credentials. Assert the API documentation is returned. """ - response = pulpcore_client.request("GET", pulp_docs_url) + response = pulpcore_bindings.client.request("GET", pulp_docs_url) assert response.status == 200 @pytest.mark.parallel -def test_no_credentials(pulpcore_client, pulp_docs_url, anonymous_user): +def test_no_credentials(pulpcore_bindings, pulp_docs_url, anonymous_user): """Get API documentation with no credentials. Assert the API documentation is returned. """ with anonymous_user: - response = pulpcore_client.request("GET", pulp_docs_url) + response = pulpcore_bindings.client.request("GET", pulp_docs_url) assert response.status == 200 @pytest.mark.parallel -def test_http_method(pulpcore_client, pulp_docs_url): +def test_http_method(pulpcore_bindings, pulp_docs_url): """Get API documentation with an HTTP method other than GET. Assert an error is returned. """ with pytest.raises(ApiException) as e: - pulpcore_client.request("POST", pulp_docs_url) + pulpcore_bindings.client.request("POST", pulp_docs_url) assert e.value.status == 405 diff --git a/pulpcore/tests/functional/api/test_correlation_id.py b/pulpcore/tests/functional/api/test_correlation_id.py index 3ebb1fe3fab..ffeca6024f9 100644 --- a/pulpcore/tests/functional/api/test_correlation_id.py +++ b/pulpcore/tests/functional/api/test_correlation_id.py @@ -1,7 +1,7 @@ -def test_correlation_id(cid, tasks_api_client, orphans_cleanup_api_client, monitor_task): +def test_correlation_id(cid, pulpcore_bindings, monitor_task): """Test that a correlation can be passed as a header and logged.""" - response, status, headers = orphans_cleanup_api_client.cleanup_with_http_info({}) + response, status, headers = pulpcore_bindings.OrphansCleanupApi.cleanup_with_http_info({}) monitor_task(response.task) - task = tasks_api_client.read(response.task) + task = pulpcore_bindings.TasksApi.read(response.task) assert headers["Correlation-ID"] == cid assert task.logging_cid == cid diff --git a/pulpcore/tests/functional/api/test_crud_domains.py b/pulpcore/tests/functional/api/test_crud_domains.py index 781fea2d90c..3ff2c8cc585 100644 --- a/pulpcore/tests/functional/api/test_crud_domains.py +++ b/pulpcore/tests/functional/api/test_crud_domains.py @@ -128,7 +128,7 @@ def test_active_domain_deletion(domains_api_client, rbac_contentguard_api_client @pytest.mark.parallel def test_orphan_domain_deletion( domains_api_client, - file_repository_api_client, + file_bindings, file_content_api_client, gen_object_with_cleanup, monitor_task, @@ -145,7 +145,7 @@ def test_orphan_domain_deletion( domain = gen_object_with_cleanup(domains_api_client, body) repository = gen_object_with_cleanup( - file_repository_api_client, {"name": str(uuid.uuid4())}, pulp_domain=domain.name + file_bindings.RepositoriesFileApi, {"name": str(uuid.uuid4())}, pulp_domain=domain.name ) new_file = tmp_path / "new_file" new_file.write_text("Test file") @@ -166,7 +166,7 @@ def test_orphan_domain_deletion( assert e.value.task.state == "failed" # Delete the repository - file_repository_api_client.delete(repository.pulp_href) + file_bindings.RepositoriesFileApi.delete(repository.pulp_href) # Now succeed in deleting the domain response = domains_api_client.delete(domain.pulp_href) diff --git a/pulpcore/tests/functional/api/test_replication.py b/pulpcore/tests/functional/api/test_replication.py index f31f42922a6..44eca90d56d 100644 --- a/pulpcore/tests/functional/api/test_replication.py +++ b/pulpcore/tests/functional/api/test_replication.py @@ -11,7 +11,7 @@ def test_replication( domain_factory, bindings_cfg, - upstream_pulp_api_client, + pulpcore_bindings, monitor_task_group, pulp_settings, gen_object_with_cleanup, @@ -35,10 +35,10 @@ def test_replication( "password": bindings_cfg.password, } upstream_pulp = gen_object_with_cleanup( - upstream_pulp_api_client, upstream_pulp_body, pulp_domain=non_default_domain.name + pulpcore_bindings.UpstreamPulpsApi, upstream_pulp_body, pulp_domain=non_default_domain.name ) # Run the replicate task and assert that all tasks successfully complete. - response = upstream_pulp_api_client.replicate(upstream_pulp.pulp_href) + response = pulpcore_bindings.UpstreamPulpsApi.replicate(upstream_pulp.pulp_href) task_group = monitor_task_group(response.task_group) for task in task_group.tasks: assert task.state == "completed" @@ -48,11 +48,10 @@ def test_replication( def test_replication_with_wrong_ca_cert( domain_factory, bindings_cfg, - upstream_pulp_api_client, + pulpcore_bindings, monitor_task_group, pulp_settings, gen_object_with_cleanup, - tasks_api_client, ): # This test assures that setting ca_cert on an Upstream Pulp causes that CA bundle to be used # to verify the certificate presented by the Upstream Pulp's REST API. The replication tasks @@ -103,21 +102,23 @@ def test_replication_with_wrong_ca_cert( """, } upstream_pulp = gen_object_with_cleanup( - upstream_pulp_api_client, upstream_pulp_body, pulp_domain=non_default_domain.name + pulpcore_bindings.UpstreamPulpsApi, upstream_pulp_body, pulp_domain=non_default_domain.name ) # Run the replicate task and assert that it fails with SSLError with pytest.raises(PulpTaskGroupError) as e: - response = upstream_pulp_api_client.replicate(upstream_pulp.pulp_href) + response = pulpcore_bindings.UpstreamPulpsApi.replicate(upstream_pulp.pulp_href) monitor_task_group(response.task_group) - task = tasks_api_client.read(e.value.task_group.tasks[0].pulp_href) + task = pulpcore_bindings.TasksApi.read(e.value.task_group.tasks[0].pulp_href) assert "SSLError" in task.error["description"] # Update Upstream Pulp with tls_validation=False - upstream_pulp_api_client.partial_update(upstream_pulp.pulp_href, {"tls_validation": False}) + pulpcore_bindings.UpstreamPulpsApi.partial_update( + upstream_pulp.pulp_href, {"tls_validation": False} + ) # Run the replicate task again and assert that all tasks successfully complete. - response = upstream_pulp_api_client.replicate(upstream_pulp.pulp_href) + response = pulpcore_bindings.UpstreamPulpsApi.replicate(upstream_pulp.pulp_href) task_group = monitor_task_group(response.task_group) for task in task_group.tasks: assert task.state == "completed" @@ -166,7 +167,7 @@ def test_replicate_rbac( try_action, domain_factory, bindings_cfg, - upstream_pulp_api_client, + pulpcore_bindings, pulp_settings, gen_object_with_cleanup, ): @@ -185,23 +186,29 @@ def test_replicate_rbac( "pulp_label_select": str(uuid.uuid4()), } upstream_pulp = gen_object_with_cleanup( - upstream_pulp_api_client, upstream_pulp_body, pulp_domain=non_default_domain.name + pulpcore_bindings.UpstreamPulpsApi, + upstream_pulp_body, + pulp_domain=non_default_domain.name, ) # Assert that Alice (upstream pulp viewer) gets a 403 - try_action(alice, upstream_pulp_api_client, "replicate", 403, upstream_pulp.pulp_href) + try_action(alice, pulpcore_bindings.UpstreamPulpsApi, "replicate", 403, upstream_pulp.pulp_href) # Assert that B (upstream pulp owner) gets a 202 - try_action(bob, upstream_pulp_api_client, "replicate", 202, upstream_pulp.pulp_href) + try_action(bob, pulpcore_bindings.UpstreamPulpsApi, "replicate", 202, upstream_pulp.pulp_href) # Assert that Charlie (no role) get a 404 - try_action(charlie, upstream_pulp_api_client, "replicate", 404, upstream_pulp.pulp_href) + try_action( + charlie, pulpcore_bindings.UpstreamPulpsApi, "replicate", 404, upstream_pulp.pulp_href + ) # Assert that Dean can run replication - try_action(dean, upstream_pulp_api_client, "replicate", 202, upstream_pulp.pulp_href) + try_action(dean, pulpcore_bindings.UpstreamPulpsApi, "replicate", 202, upstream_pulp.pulp_href) # Assert that Dean can view the upstream pulp - try_action(dean, upstream_pulp_api_client, "read", 200, upstream_pulp.pulp_href) + try_action(dean, pulpcore_bindings.UpstreamPulpsApi, "read", 200, upstream_pulp.pulp_href) # Assert that Dean can't update the upstream pulp - try_action(dean, upstream_pulp_api_client, "partial_update", 403, upstream_pulp.pulp_href, {}) + try_action( + dean, pulpcore_bindings.UpstreamPulpsApi, "partial_update", 403, upstream_pulp.pulp_href, {} + ) diff --git a/pulpcore/tests/functional/api/test_repos.py b/pulpcore/tests/functional/api/test_repos.py index b6b958005e7..6059fd9e9f9 100644 --- a/pulpcore/tests/functional/api/test_repos.py +++ b/pulpcore/tests/functional/api/test_repos.py @@ -11,7 +11,7 @@ @pytest.mark.parallel def test_repository_content_filters( file_content_api_client, - file_repository_api_client, + file_bindings, file_repository_factory, file_remote_factory, gen_object_with_cleanup, @@ -24,57 +24,57 @@ def test_repository_content_filters( repo_manifest_path = write_3_iso_file_fixture_data_factory(str(uuid4())) remote = file_remote_factory(manifest_path=repo_manifest_path, policy="on_demand") body = RepositorySyncURL(remote=remote.pulp_href) - task_response = file_repository_api_client.sync(repo.pulp_href, body).task + task_response = file_bindings.RepositoriesFileApi.sync(repo.pulp_href, body).task version_href = monitor_task(task_response).created_resources[0] content = file_content_api_client.list(repository_version_added=version_href).results[0] - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) # filter repo by the content - results = file_repository_api_client.list(with_content=content.pulp_href).results + results = file_bindings.RepositoriesFileApi.list(with_content=content.pulp_href).results assert results == [repo] - results = file_repository_api_client.list(latest_with_content=content.pulp_href).results + results = file_bindings.RepositoriesFileApi.list(latest_with_content=content.pulp_href).results assert results == [repo] # remove the content - response = file_repository_api_client.modify( + response = file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"remove_content_units": [content.pulp_href]}, ) monitor_task(response.task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) # the repo still has the content unit - results = file_repository_api_client.list(with_content=content.pulp_href).results + results = file_bindings.RepositoriesFileApi.list(with_content=content.pulp_href).results assert results == [repo] # but not in its latest version anymore - results = file_repository_api_client.list(latest_with_content=content.pulp_href).results + results = file_bindings.RepositoriesFileApi.list(latest_with_content=content.pulp_href).results assert results == [] @pytest.mark.parallel -def test_repository_name_regex_filters(file_repository_factory, file_repository_api_client): +def test_repository_name_regex_filters(file_repository_factory, file_bindings): """Test repository's name regex filters.""" uuid = uuid4() repo = file_repository_factory(name=f"{uuid}-regex-test-repo") pattern = f"^{uuid}-regex-test.*$" - results = file_repository_api_client.list(name__regex=pattern).results + results = file_bindings.RepositoriesFileApi.list(name__regex=pattern).results assert results == [repo] # upper case pattern - results = file_repository_api_client.list(name__regex=pattern.upper()).results + results = file_bindings.RepositoriesFileApi.list(name__regex=pattern.upper()).results assert repo not in results # upper case pattern with iregex - results = file_repository_api_client.list(name__iregex=pattern.upper()).results + results = file_bindings.RepositoriesFileApi.list(name__iregex=pattern.upper()).results assert results == [repo] @pytest.mark.parallel def test_repo_size( file_repo, - file_repository_api_client, + file_bindings, file_remote_factory, basic_manifest_path, random_artifact_factory, @@ -84,8 +84,8 @@ def test_repo_size( # Sync repository with on_demand remote = file_remote_factory(manifest_path=basic_manifest_path, policy="on_demand") body = {"remote": remote.pulp_href} - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) - file_repo = file_repository_api_client.read(file_repo.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) cmd = ( "pulpcore-manager", @@ -114,7 +114,7 @@ def test_repo_size( # Resync with immediate remote = file_remote_factory(manifest_path=basic_manifest_path, policy="immediate") body = {"remote": remote.pulp_href} - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) run = subprocess.run(cmd, capture_output=True, check=True) out = json.loads(run.stdout) diff --git a/pulpcore/tests/functional/api/test_status.py b/pulpcore/tests/functional/api/test_status.py index 8a671491a50..bde2ad806e7 100644 --- a/pulpcore/tests/functional/api/test_status.py +++ b/pulpcore/tests/functional/api/test_status.py @@ -99,7 +99,7 @@ def test_post_authenticated( test_path, pulp_api_v3_path, status_api_client, - pulpcore_client, + pulpcore_bindings, pulp_api_v3_url, received_otel_span, ): @@ -114,7 +114,7 @@ def test_post_authenticated( # Try anyway to POST to /status/ status_url = f"{pulp_api_v3_url}status/" with pytest.raises(ApiException) as e: - pulpcore_client.request("POST", status_url, headers={"User-Agent": test_path}) + pulpcore_bindings.client.request("POST", status_url, headers={"User-Agent": test_path}) assert e.value.status == 405 assert received_otel_span( @@ -130,7 +130,7 @@ def test_post_authenticated( @pytest.mark.parallel def test_storage_per_domain( status_api_client, - pulpcore_client, + pulpcore_bindings, pulp_api_v3_url, domain_factory, random_artifact_factory, @@ -139,13 +139,13 @@ def test_storage_per_domain( domain = domain_factory() # Status endpoint is not exposed at domain url in API spec to prevent duplicates, call manually status_url = f"{pulp_api_v3_url}status/".replace("default", domain.name) - status_response = pulpcore_client.request("GET", status_url) - domain_status = pulpcore_client.deserialize(status_response, "StatusResponse") + status_response = pulpcore_bindings.client.request("GET", status_url) + domain_status = pulpcore_bindings.client.deserialize(status_response, "StatusResponse") assert domain_status.storage.used == 0 random_artifact_factory(size=1, pulp_domain=domain.name) - status_response = pulpcore_client.request("GET", status_url) - domain_status = pulpcore_client.deserialize(status_response, "StatusResponse") + status_response = pulpcore_bindings.client.request("GET", status_url) + domain_status = pulpcore_bindings.client.deserialize(status_response, "StatusResponse") assert domain_status.storage.used == 1 diff --git a/pulpcore/tests/functional/api/test_tasking.py b/pulpcore/tests/functional/api/test_tasking.py index df89d73055c..f7bc1d1ce83 100644 --- a/pulpcore/tests/functional/api/test_tasking.py +++ b/pulpcore/tests/functional/api/test_tasking.py @@ -13,10 +13,10 @@ @pytest.fixture(scope="session") -def dispatch_task(pulpcore_client): +def dispatch_task(pulpcore_bindings): def _dispatch_task(*args, **kwargs): - cid = pulpcore_client.default_headers.get("Correlation-ID") or str(uuid4()) - username = pulpcore_client.configuration.username + cid = pulpcore_bindings.client.default_headers.get("Correlation-ID") or str(uuid4()) + username = pulpcore_bindings.client.configuration.username commands = ( "from django_guid import set_guid; " "from pulpcore.tasking.tasks import dispatch; " @@ -81,7 +81,7 @@ def test_multi_resource_locking(dispatch_task, monitor_task): @pytest.mark.parallel -def test_delete_cancel_waiting_task(dispatch_task, tasks_api_client): +def test_delete_cancel_waiting_task(dispatch_task, pulpcore_bindings): # Queue one task after a long running one resource = str(uuid4()) blocking_task_href = dispatch_task( @@ -91,18 +91,18 @@ def test_delete_cancel_waiting_task(dispatch_task, tasks_api_client): "pulpcore.app.tasks.test.sleep", args=(0,), exclusive_resources=[resource] ) - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "waiting" # Try to delete first with pytest.raises(ApiException) as ctx: - tasks_api_client.delete(task_href) + pulpcore_bindings.TasksApi.delete(task_href) assert ctx.value.status == 409 # Now cancel the task - task = tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + task = pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) # cancel the blocking task - tasks_api_client.tasks_cancel(blocking_task_href, {"state": "canceled"}) + pulpcore_bindings.TasksApi.tasks_cancel(blocking_task_href, {"state": "canceled"}) if task.state == "canceling": assert task.started_at is None @@ -112,7 +112,7 @@ def test_delete_cancel_waiting_task(dispatch_task, tasks_api_client): if task.state != "canceling": break time.sleep(1) - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "canceled" assert task.started_at is None @@ -120,11 +120,11 @@ def test_delete_cancel_waiting_task(dispatch_task, tasks_api_client): @pytest.mark.parallel -def test_delete_cancel_running_task(dispatch_task, tasks_api_client): +def test_delete_cancel_running_task(dispatch_task, pulpcore_bindings): task_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(600,)) for i in range(10): - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) if task.state == "running": break time.sleep(1) @@ -133,11 +133,11 @@ def test_delete_cancel_running_task(dispatch_task, tasks_api_client): # Try to delete first with pytest.raises(ApiException) as ctx: - tasks_api_client.delete(task_href) + pulpcore_bindings.TasksApi.delete(task_href) assert ctx.value.status == 409 # Now cancel the task - task = tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + task = pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) if task.state == "canceling": assert task.started_at is not None @@ -147,7 +147,7 @@ def test_delete_cancel_running_task(dispatch_task, tasks_api_client): if task.state != "canceling": break time.sleep(1) - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "canceled" assert task.started_at is not None @@ -155,24 +155,24 @@ def test_delete_cancel_running_task(dispatch_task, tasks_api_client): @pytest.mark.parallel -def test_cancel_delete_finished_task(tasks_api_client, dispatch_task, monitor_task): +def test_cancel_delete_finished_task(pulpcore_bindings, dispatch_task, monitor_task): task_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,)) monitor_task(task_href) # Try to cancel first with pytest.raises(ApiException) as ctx: - tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) assert ctx.value.status == 409 # Now delete the task - tasks_api_client.delete(task_href) + pulpcore_bindings.TasksApi.delete(task_href) @pytest.mark.parallel -def test_cancel_nonexistent_task(pulp_api_v3_path, tasks_api_client): +def test_cancel_nonexistent_task(pulp_api_v3_path, pulpcore_bindings): task_href = f"{pulp_api_v3_path}tasks/{uuid4()}/" with pytest.raises(ApiException) as ctx: - tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) assert ctx.value.status == 404 @@ -225,71 +225,71 @@ def test_retrieve_task_with_minimal_fields(task, bindings_cfg): @pytest.mark.parallel -def test_retrieve_task_using_invalid_worker(tasks_api_client): +def test_retrieve_task_using_invalid_worker(pulpcore_bindings): """Expects to raise an exception when using invalid worker value as filter.""" with pytest.raises(ApiException) as ctx: - tasks_api_client.list(worker=str(uuid4())) + pulpcore_bindings.TasksApi.list(worker=str(uuid4())) assert ctx.value.status == 400 @pytest.mark.parallel -def test_retrieve_task_using_valid_worker(task, tasks_api_client): +def test_retrieve_task_using_valid_worker(task, pulpcore_bindings): """Expects to retrieve a task using a valid worker URI as filter.""" - response = tasks_api_client.list(worker=task.worker) + response = pulpcore_bindings.TasksApi.list(worker=task.worker) assert response.results and response.count @pytest.mark.parallel -def test_retrieve_task_using_invalid_date(tasks_api_client): +def test_retrieve_task_using_invalid_date(pulpcore_bindings): """Expects to raise an exception when using invalid dates as filters""" with pytest.raises(ApiException) as ctx: - tasks_api_client.list(finished_at=str(uuid4()), started_at=str(uuid4())) + pulpcore_bindings.TasksApi.list(finished_at=str(uuid4()), started_at=str(uuid4())) assert ctx.value.status == 400 @pytest.mark.parallel -def test_retrieve_task_using_valid_date(task, tasks_api_client): +def test_retrieve_task_using_valid_date(task, pulpcore_bindings): """Expects to retrieve a task using a valid date.""" - response = tasks_api_client.list(started_at=task.started_at) + response = pulpcore_bindings.TasksApi.list(started_at=task.started_at) assert response.results and response.count @pytest.mark.parallel -def test_search_task_by_name(task, tasks_api_client): +def test_search_task_by_name(task, pulpcore_bindings): task_name = task.name - search_results = tasks_api_client.list(name=task.name).results + search_results = pulpcore_bindings.TasksApi.list(name=task.name).results assert search_results assert all([task.name == task_name for task in search_results]) @pytest.mark.parallel -def test_search_task_using_an_invalid_name(tasks_api_client): +def test_search_task_using_an_invalid_name(pulpcore_bindings): """Expect to return an empty results array when searching using an invalid task name. """ - search_results = tasks_api_client.list(name=str(uuid4())) + search_results = pulpcore_bindings.TasksApi.list(name=str(uuid4())) assert not search_results.results and not search_results.count @pytest.mark.parallel -def test_filter_tasks_using_worker__in_filter(tasks_api_client, dispatch_task, monitor_task): +def test_filter_tasks_using_worker__in_filter(pulpcore_bindings, dispatch_task, monitor_task): task1_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,)) task2_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,)) task1 = monitor_task(task1_href) task2 = monitor_task(task2_href) - search_results = tasks_api_client.list(worker__in=(task1.worker, task2.worker)) + search_results = pulpcore_bindings.TasksApi.list(worker__in=(task1.worker, task2.worker)) tasks_hrefs = [task.pulp_href for task in search_results.results] @@ -297,22 +297,22 @@ def test_filter_tasks_using_worker__in_filter(tasks_api_client, dispatch_task, m assert task2_href in tasks_hrefs -def test_cancel_gooey_task(tasks_api_client, dispatch_task, monitor_task): +def test_cancel_gooey_task(pulpcore_bindings, dispatch_task, monitor_task): task_href = dispatch_task("pulpcore.app.tasks.test.gooey_task", args=(60,)) for i in range(10): - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) if task.state == "running": break time.sleep(1) - task = tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + task = pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) if task.state == "canceling": for i in range(30): if task.state != "canceling": break time.sleep(1) - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "canceled" @@ -339,12 +339,12 @@ def test_task_created_by(dispatch_task, monitor_task, gen_user, anonymous_user): @pytest.mark.parallel -def test_task_version_prevent_pickup(dispatch_task, tasks_api_client): +def test_task_version_prevent_pickup(dispatch_task, pulpcore_bindings): task1 = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,), versions={"core": "4.0.0"}) task2 = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,), versions={"catdog": "0.0.0"}) time.sleep(5) for task_href in [task1, task2]: - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "waiting" - tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) diff --git a/pulpcore/tests/functional/api/test_upload.py b/pulpcore/tests/functional/api/test_upload.py index 3cfb1047852..129e61670cb 100644 --- a/pulpcore/tests/functional/api/test_upload.py +++ b/pulpcore/tests/functional/api/test_upload.py @@ -44,7 +44,6 @@ def pulpcore_upload_chunks( uploads_api_client, artifacts_api_client, gen_object_with_cleanup, - tasks_api_client, monitor_task, ): """Upload file in chunks.""" diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_access.py b/pulpcore/tests/functional/api/using_plugin/test_content_access.py index b10656f3a2e..d7c63bfdcce 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_access.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_access.py @@ -18,7 +18,7 @@ def test_file_remote_on_demand( file_fixtures_root, file_repo_with_auto_publish, file_remote_api_client, - file_repository_api_client, + file_bindings, gen_object_with_cleanup, monitor_task, ): @@ -32,8 +32,10 @@ def test_file_remote_on_demand( remote = gen_object_with_cleanup(file_remote_api_client, kwargs) # Sync from the remote body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo_with_auto_publish.pulp_href, body).task) - repo = file_repository_api_client.read(file_repo_with_auto_publish.pulp_href) + monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo_with_auto_publish.pulp_href, body).task + ) + repo = file_bindings.RepositoriesFileApi.read(file_repo_with_auto_publish.pulp_href) # Create a distribution from the publication distribution = file_distribution_factory(repository=repo.pulp_href) # attempt to download_file() a file diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_cache.py b/pulpcore/tests/functional/api/using_plugin/test_content_cache.py index b8942a78fd2..ba0e7f18ade 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_cache.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_cache.py @@ -17,7 +17,7 @@ def test_full_workflow( file_repo_with_auto_publish, basic_manifest_path, file_remote_factory, - file_repository_api_client, + file_bindings, file_publication_api_client, file_distribution_api_client, file_content_api_client, @@ -40,8 +40,10 @@ def _check_cache(url): # Sync from the remote and assert that a new repository version is created remote = file_remote_factory(manifest_path=basic_manifest_path, policy="immediate") body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo_with_auto_publish.pulp_href, body).task) - repo = file_repository_api_client.read(file_repo_with_auto_publish.pulp_href) + monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo_with_auto_publish.pulp_href, body).task + ) + repo = file_bindings.RepositoriesFileApi.read(file_repo_with_auto_publish.pulp_href) assert repo.latest_version_href.endswith("/versions/1/") body = FileFilePublication(repository=repo.pulp_href) @@ -85,7 +87,7 @@ def _check_cache(url): relative_path="1.iso", repository_version=repo.latest_version_href ).results[0] body = RepositoryAddRemoveContent(remove_content_units=[cfile.pulp_href]) - response = monitor_task(file_repository_api_client.modify(repo.pulp_href, body).task) + response = monitor_task(file_bindings.RepositoriesFileApi.modify(repo.pulp_href, body).task) pub3 = file_publication_api_client.read(response.created_resources[1]) files = ["", "", "PULP_MANIFEST", "PULP_MANIFEST", "2.iso", "2.iso"] for i, file in enumerate(files): @@ -119,7 +121,7 @@ def _check_cache(url): assert (200, "HIT" if i % 2 == 1 else "MISS") == _check_cache(url), file # Tests that deleting a repository invalidates the cache""" - monitor_task(file_repository_api_client.delete(repo.pulp_href).task) + monitor_task(file_bindings.RepositoriesFileApi.delete(repo.pulp_href).task) files = ["", "PULP_MANIFEST", "2.iso"] for file in files: url = urljoin(distro.base_url, file) diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_delivery.py b/pulpcore/tests/functional/api/using_plugin/test_content_delivery.py index 75c7f11d244..e7cf60dabaa 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_delivery.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_delivery.py @@ -16,7 +16,7 @@ def test_delete_remote_on_demand( file_repo_with_auto_publish, file_remote_ssl_factory, file_remote_api_client, - file_repository_api_client, + file_bindings, basic_manifest_path, monitor_task, file_distribution_factory, @@ -26,8 +26,10 @@ def test_delete_remote_on_demand( # Sync from the remote body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo_with_auto_publish.pulp_href, body).task) - repo = file_repository_api_client.read(file_repo_with_auto_publish.pulp_href) + monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo_with_auto_publish.pulp_href, body).task + ) + repo = file_bindings.RepositoriesFileApi.read(file_repo_with_auto_publish.pulp_href) # Create a distribution pointing to the repository distribution = file_distribution_factory(repository=repo.pulp_href) @@ -45,7 +47,7 @@ def test_delete_remote_on_demand( # Recreate the remote and sync into the repository using it remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(repo.pulp_href, body).task) # Assert that files can now be downloaded from the distribution content_unit_url = urljoin(distribution.base_url, expected_file_list[0][0]) @@ -59,7 +61,7 @@ def test_delete_remote_on_demand( def test_remote_artifact_url_update( file_repo_with_auto_publish, file_remote_ssl_factory, - file_repository_api_client, + file_bindings, basic_manifest_path, basic_manifest_only_path, monitor_task, @@ -70,8 +72,10 @@ def test_remote_artifact_url_update( # Sync from the remote body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo_with_auto_publish.pulp_href, body).task) - repo = file_repository_api_client.read(file_repo_with_auto_publish.pulp_href) + monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo_with_auto_publish.pulp_href, body).task + ) + repo = file_bindings.RepositoriesFileApi.read(file_repo_with_auto_publish.pulp_href) # Create a distribution from the publication distribution = file_distribution_factory(repository=repo.pulp_href) @@ -90,7 +94,9 @@ def test_remote_artifact_url_update( # Sync from the remote and assert that content can now be downloaded body = RepositorySyncURL(remote=remote2.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo_with_auto_publish.pulp_href, body).task) + monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo_with_auto_publish.pulp_href, body).task + ) content_unit_url = urljoin(distribution.base_url, expected_file_list[0][0]) downloaded_file = download_file(content_unit_url) actual_checksum = hashlib.sha256(downloaded_file.body).hexdigest() diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py b/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py index cb025d4f37a..2b09320c4ee 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py @@ -12,7 +12,7 @@ def test_content_promotion( file_repo_with_auto_publish, file_remote_ssl_factory, - file_repository_api_client, + file_bindings, file_publication_api_client, file_distribution_factory, basic_manifest_path, @@ -20,7 +20,7 @@ def test_content_promotion( ): # Create a repository, publication, and 2 distributions remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - file_repo = file_repository_api_client.read(file_repo_with_auto_publish.pulp_href) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo_with_auto_publish.pulp_href) # Check what content and artifacts are in the fixture repository expected_files = get_files_in_manifest(remote.url) @@ -28,7 +28,7 @@ def test_content_promotion( # Sync from the remote and assert that a new repository version is created body = RepositorySyncURL(remote=remote.pulp_href) created = monitor_task( - file_repository_api_client.sync(file_repo.pulp_href, body).task + file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task ).created_resources pub = file_publication_api_client.read(created[1]) diff --git a/pulpcore/tests/functional/api/using_plugin/test_contentguard.py b/pulpcore/tests/functional/api/using_plugin/test_contentguard.py index e8a401d8ee2..c2dc9476c48 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_contentguard.py +++ b/pulpcore/tests/functional/api/using_plugin/test_contentguard.py @@ -12,7 +12,7 @@ @pytest.mark.parallel def test_rbac_content_guard_full_workflow( - rbac_contentguard_api_client, + pulpcore_bindings, groups_api_client, groups_users_api_client, file_distribution_api_client, @@ -55,7 +55,9 @@ def _assert_access(authorized_users): # Check that RBAC ContentGuard can be created and assigned to a distribution with creator_user: - guard = gen_object_with_cleanup(rbac_contentguard_api_client, {"name": distro.name}) + guard = gen_object_with_cleanup( + pulpcore_bindings.ContentguardsRbacApi, {"name": distro.name} + ) body = PatchedfileFileDistribution(content_guard=guard.pulp_href) monitor_task(file_distribution_api_client.partial_update(distro.pulp_href, body).task) distro = file_distribution_api_client.read(distro.pulp_href) @@ -70,29 +72,29 @@ def _assert_access(authorized_users): "role": "core.rbaccontentguard_downloader", } with creator_user: - rbac_contentguard_api_client.add_role(distro.content_guard, body) + pulpcore_bindings.ContentguardsRbacApi.add_role(distro.content_guard, body) _assert_access([creator_user, user_b, user_a, pulp_admin_user]) # Use the /remove/ endpoint to remove users permission to access distribution with creator_user: - rbac_contentguard_api_client.remove_role(distro.content_guard, body) + pulpcore_bindings.ContentguardsRbacApi.remove_role(distro.content_guard, body) _assert_access([creator_user, pulp_admin_user]) # Use the /add/ endpoint to add group body = {"groups": [group.name], "role": "core.rbaccontentguard_downloader"} with creator_user: - rbac_contentguard_api_client.add_role(distro.content_guard, body) + pulpcore_bindings.ContentguardsRbacApi.add_role(distro.content_guard, body) _assert_access([creator_user, user_b, user_a, pulp_admin_user]) # Use the /remove/ endpoint to remove group with creator_user: - rbac_contentguard_api_client.remove_role(distro.content_guard, body) + pulpcore_bindings.ContentguardsRbacApi.remove_role(distro.content_guard, body) _assert_access([creator_user, pulp_admin_user]) @pytest.mark.parallel def test_header_contentguard_workflow( - header_contentguard_api_client, + pulpcore_bindings, gen_user, file_distribution_factory, gen_object_with_cleanup, @@ -109,7 +111,7 @@ def test_header_contentguard_workflow( with creator_user: guard = gen_object_with_cleanup( - header_contentguard_api_client, + pulpcore_bindings.ContentguardsHeaderApi, {"name": distro.name, "header_name": "x-header", "header_value": "123456"}, ) body = PatchedfileFileDistribution(content_guard=guard.pulp_href) @@ -139,7 +141,7 @@ def test_header_contentguard_workflow( with creator_user: guard = gen_object_with_cleanup( - header_contentguard_api_client, + pulpcore_bindings.ContentguardsHeaderApi, { "name": distro.name, "header_name": header_name, @@ -165,9 +167,7 @@ def test_header_contentguard_workflow( def test_composite_contentguard_crud( - composite_contentguard_api_client, - redirect_contentguard_api_client, - header_contentguard_api_client, + pulpcore_bindings, gen_user, gen_object_with_cleanup, ): @@ -183,44 +183,44 @@ def test_composite_contentguard_crud( with creator_user: # Create RedirectContentGuard, HeaderContentGuard hcg = gen_object_with_cleanup( - header_contentguard_api_client, + pulpcore_bindings.ContentguardsHeaderApi, {"name": str(uuid.uuid4()), "header_name": "x-header", "header_value": "123456"}, ) rcg = gen_object_with_cleanup( - redirect_contentguard_api_client, + pulpcore_bindings.ContentguardsContentRedirectApi, {"name": str(uuid.uuid4()), "description": "test_composite_contentguard_crud"}, ) # Create CCG1, no guards; evaluate ccg1 = gen_object_with_cleanup( - composite_contentguard_api_client, + pulpcore_bindings.ContentguardsCompositeApi, {"name": str(uuid.uuid4()), "description": "test_composite_contentguard_crud"}, ) assert not ccg1.guards - ccg1 = composite_contentguard_api_client.read(ccg1.pulp_href) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.read(ccg1.pulp_href) assert not ccg1.guards # Update CCG1, RCG, evaluate, expect 1 body = PatchedCompositeContentGuard(guards=[rcg.pulp_href]) - ccg1 = composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) assert ccg1.guards assert len(ccg1.guards) == 1 # Update CCG1, HCG, evaluate, expect 1 body = PatchedCompositeContentGuard(guards=[hcg.pulp_href]) - ccg1 = composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) assert ccg1.guards assert len(ccg1.guards) == 1 # Update CCG1, [RCG, HCG], evaluate, expect 2 body = PatchedCompositeContentGuard(guards=[rcg.pulp_href, hcg.pulp_href]) - ccg1 = composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) assert ccg1.guards assert len(ccg1.guards) == 2 # Create CCG2, [RCG, HCG], evaluate ccg2 = gen_object_with_cleanup( - composite_contentguard_api_client, + pulpcore_bindings.ContentguardsCompositeApi, { "name": str(uuid.uuid4()), "description": "test_composite_contentguard_crud", @@ -231,20 +231,18 @@ def test_composite_contentguard_crud( assert len(ccg2.guards) == 2 # List CCGs, expect 2 - list_response = composite_contentguard_api_client.list() + list_response = pulpcore_bindings.ContentguardsCompositeApi.list() assert list_response.count == 2 # Delete CCG1 - composite_contentguard_api_client.delete(ccg1.pulp_href) + pulpcore_bindings.ContentguardsCompositeApi.delete(ccg1.pulp_href) # List CCG, expect 1 - list_response = composite_contentguard_api_client.list() + list_response = pulpcore_bindings.ContentguardsCompositeApi.list() assert list_response.count == 1 def test_composite_contentguard_permissions( - composite_contentguard_api_client, - redirect_contentguard_api_client, - header_contentguard_api_client, + pulpcore_bindings, gen_user, gen_object_with_cleanup, monitor_task, @@ -265,17 +263,17 @@ def test_composite_contentguard_permissions( with creator_user: # Create RedirectContentGuard, HeaderContentGuard hcg = gen_object_with_cleanup( - header_contentguard_api_client, + pulpcore_bindings.ContentguardsHeaderApi, {"name": str(uuid.uuid4()), "header_name": "x-header", "header_value": "123456"}, ) rcg = gen_object_with_cleanup( - redirect_contentguard_api_client, + pulpcore_bindings.ContentguardsContentRedirectApi, {"name": str(uuid.uuid4()), "description": "test_composite_contentguard_permissions"}, ) # Create CCG1, no guards ccg1 = gen_object_with_cleanup( - composite_contentguard_api_client, + pulpcore_bindings.ContentguardsCompositeApi, {"name": str(uuid.uuid4()), "description": "test_composite_contentguard_permissions"}, ) @@ -297,7 +295,7 @@ def test_composite_contentguard_permissions( # update CCG with RCG body = PatchedCompositeContentGuard(guards=[rcg.pulp_href]) - ccg1 = composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) # attempt dist-access, expect 403 (1 guard, forbids) response = get_from_url(distro.base_url) @@ -305,7 +303,7 @@ def test_composite_contentguard_permissions( # Create HeaderContentGuard, update CCG with [RCG, HCG] body = PatchedCompositeContentGuard(guards=[rcg.pulp_href, hcg.pulp_href]) - composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) # attempt dist-access, expect 403 (2 guards, both forbid) response = get_from_url(distro.base_url) diff --git a/pulpcore/tests/functional/api/using_plugin/test_crud_repos.py b/pulpcore/tests/functional/api/using_plugin/test_crud_repos.py index acae0a94f70..0de8d2e2281 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_crud_repos.py +++ b/pulpcore/tests/functional/api/using_plugin/test_crud_repos.py @@ -14,7 +14,7 @@ @pytest.mark.parallel def test_crud_repo_full_workflow( - file_repository_api_client, + file_bindings, file_repository_factory, file_remote_factory, basic_manifest_path, @@ -25,7 +25,7 @@ def test_crud_repo_full_workflow( # Try to create another with the same name with pytest.raises(ApiException) as e: - file_repository_api_client.create({"name": repo.name}) + file_bindings.RepositoriesFileApi.create({"name": repo.name}) assert e.value.status == 400 error_body = json.loads(e.value.body) @@ -33,13 +33,13 @@ def test_crud_repo_full_workflow( assert "This field must be unique." in error_body["name"] # Test reading the repository - read_repo = file_repository_api_client.read(repo.pulp_href).to_dict() + read_repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href).to_dict() for key, val in repo.to_dict().items(): assert key in read_repo assert getattr(repo, key) == read_repo[key] # Read a repository by its href providing specific field list. - config = file_repository_api_client.api_client.configuration + config = file_bindings.RepositoriesFileApi.api_client.configuration auth = BasicAuth(login=config.username, password=config.password) full_href = urljoin(config.host, repo.pulp_href) for fields in [ @@ -57,25 +57,27 @@ def test_crud_repo_full_workflow( assert "name" not in response_fields # Read the repository by its name. - page = file_repository_api_client.list(name=repo.name) + page = file_bindings.RepositoriesFileApi.list(name=repo.name) assert len(page.results) == 1 for key, val in repo.to_dict().items(): assert getattr(page.results[0], key) == val # Ensure name is displayed when listing repositories. - for read_repo in file_repository_api_client.list().results: + for read_repo in file_bindings.RepositoriesFileApi.list().results: assert read_repo.name is not None def _do_update_attr(attr, partial=False): """Update a repository attribute.""" body = {} if partial else repo.to_dict() - function = getattr(file_repository_api_client, "partial_update" if partial else "update") + function = getattr( + file_bindings.RepositoriesFileApi, "partial_update" if partial else "update" + ) string = str(uuid4()) body[attr] = string response = function(repo.pulp_href, body) monitor_task(response.task) # verify the update - read_repo = file_repository_api_client.read(repo.pulp_href) + read_repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert string == getattr(read_repo, attr) # Update a repository's name using HTTP PUT. @@ -95,33 +97,33 @@ def _do_update_attr(attr, partial=False): # verify that syncing with no remote raises an error with pytest.raises(ApiException): - file_repository_api_client.sync(repo.pulp_href, {}) + file_bindings.RepositoriesFileApi.sync(repo.pulp_href, {}) # test setting the remote on the repo - response = file_repository_api_client.partial_update( + response = file_bindings.RepositoriesFileApi.partial_update( repo.pulp_href, {"remote": remote.pulp_href} ) monitor_task(response.task) # test syncing without a remote - response = file_repository_api_client.sync(repo.pulp_href, {}) + response = file_bindings.RepositoriesFileApi.sync(repo.pulp_href, {}) monitor_task(response.task) - read_repo = file_repository_api_client.read(repo.pulp_href) + read_repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert read_repo.latest_version_href == f"{repo.pulp_href}versions/1/" # Delete a repository. - response = file_repository_api_client.delete(repo.pulp_href) + response = file_bindings.RepositoriesFileApi.delete(repo.pulp_href) monitor_task(response.task) # verify the delete with pytest.raises(ApiException): - file_repository_api_client.read(repo.pulp_href) + file_bindings.RepositoriesFileApi.read(repo.pulp_href) # Attempt to create repository passing extraneous invalid parameter. # Assert response returns an error 400 including ["Unexpected field"]. with pytest.raises(ApiException) as e: - file_repository_api_client.create({"name": str(uuid4()), "foo": "bar"}) + file_bindings.RepositoriesFileApi.create({"name": str(uuid4()), "foo": "bar"}) assert e.value.status == 400 error_body = json.loads(e.value.body) @@ -327,7 +329,7 @@ def raise_for_invalid_request(remote_attrs): @pytest.mark.parallel def test_repository_remote_filter( - file_repository_api_client, + file_bindings, file_repository_factory, gen_object_with_cleanup, file_remote_factory, @@ -346,30 +348,30 @@ def test_repository_remote_filter( name_in = [repo1.name, repo2.name, repo3.name, repo4.name] # Check that name__in filter is working - response = file_repository_api_client.list(name__in=name_in) + response = file_bindings.RepositoriesFileApi.list(name__in=name_in) assert response.count == 4 # Test that supplying a specific remote only returns repositories with that remote - response = file_repository_api_client.list(remote=remote1.pulp_href) + response = file_bindings.RepositoriesFileApi.list(remote=remote1.pulp_href) assert response.count == 1 assert response.results[0].pulp_href == repo2.pulp_href - response = file_repository_api_client.list(remote=remote2.pulp_href) + response = file_bindings.RepositoriesFileApi.list(remote=remote2.pulp_href) assert response.count == 2 assert {r.pulp_href for r in response.results} == {repo3.pulp_href, repo4.pulp_href} - response = file_repository_api_client.list(remote=remote3.pulp_href) + response = file_bindings.RepositoriesFileApi.list(remote=remote3.pulp_href) assert response.count == 0 # Test that supplying 'null' will only show repositories without a remote - response = file_repository_api_client.list(remote="null", name__in=name_in) + response = file_bindings.RepositoriesFileApi.list(remote="null", name__in=name_in) assert response.count == 1 assert response.results[0].pulp_href == repo1.pulp_href # Test that supplying a base URI of a remote will show all repositories with similar remotes # Using a constant here would be nice, but our URIs are dependent on the machine's settings BASE_URI = remote1.pulp_href[:-37] - response = file_repository_api_client.list(remote=BASE_URI, name__in=name_in) + response = file_bindings.RepositoriesFileApi.list(remote=BASE_URI, name__in=name_in) assert response.count == 3 assert {r.pulp_href for r in response.results} == { repo2.pulp_href, diff --git a/pulpcore/tests/functional/api/using_plugin/test_distributions.py b/pulpcore/tests/functional/api/using_plugin/test_distributions.py index 9b56608a094..74033c20f7b 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_distributions.py +++ b/pulpcore/tests/functional/api/using_plugin/test_distributions.py @@ -16,7 +16,7 @@ def test_crud_publication_distribution( file_content_api_client, file_repo, file_remote_ssl_factory, - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_publication_api_client, basic_manifest_path, @@ -28,17 +28,17 @@ def test_crud_publication_distribution( # Create a remote and sync from it to create the first repository version remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) # Remove content to create two more repository versions - first_repo_version_href = file_repository_api_client.read( + first_repo_version_href = file_bindings.RepositoriesFileApi.read( file_repo.pulp_href ).latest_version_href v1_content = file_content_api_client.list(repository_version=first_repo_version_href).results for i in range(2): monitor_task( - file_repository_api_client.modify( + file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, {"remove_content_units": [v1_content[i].pulp_href]} ).task ) @@ -165,7 +165,7 @@ def test_distribution_filtering( file_distribution_api_client, file_remote_factory, file_random_content_unit, - file_repository_api_client, + file_bindings, file_repository_factory, file_publication_api_client, gen_object_with_cleanup, @@ -179,7 +179,7 @@ def generate_repo_with_content(): repo_manifest_path = write_3_iso_file_fixture_data_factory(str(uuid4())) remote = file_remote_factory(manifest_path=repo_manifest_path, policy="on_demand") body = RepositorySyncURL(remote=remote.pulp_href) - task_response = file_repository_api_client.sync(repo.pulp_href, body).task + task_response = file_bindings.RepositoriesFileApi.sync(repo.pulp_href, body).task version_href = monitor_task(task_response).created_resources[0] content = file_content_api_client.list(repository_version_added=version_href).results[0] return repo, content @@ -226,7 +226,7 @@ def generate_repo_with_content(): # add new content to the first repository to see whether the distribution filtering correctly # traverses to the latest publication concerning the repository under the question that should # contain the content - response = file_repository_api_client.modify( + response = file_bindings.RepositoriesFileApi.modify( repo1.pulp_href, {"remove_content_units": [], "add_content_units": [content2.pulp_href]}, ) diff --git a/pulpcore/tests/functional/api/using_plugin/test_filesystemexport.py b/pulpcore/tests/functional/api/using_plugin/test_filesystemexport.py index eb1f7f9cf58..9d4b93638b0 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_filesystemexport.py +++ b/pulpcore/tests/functional/api/using_plugin/test_filesystemexport.py @@ -101,7 +101,7 @@ def test_delete_exporter(exporters_filesystem_api_client, monitor_task): @pytest.fixture def publications( - file_repository_api_client, + file_bindings, file_repository_factory, file_remote_factory, file_publication_api_client, @@ -115,7 +115,7 @@ def publications( remote = file_remote_factory(manifest_path=basic_manifest_path, policy="immediate") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) - sync_response = file_repository_api_client.sync(repo.pulp_href, repository_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) publication = file_publication_api_client.list(repository=repo.pulp_href).results[0] diff --git a/pulpcore/tests/functional/api/using_plugin/test_labels.py b/pulpcore/tests/functional/api/using_plugin/test_labels.py index 598628b7d81..9eb97726743 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_labels.py +++ b/pulpcore/tests/functional/api/using_plugin/test_labels.py @@ -2,8 +2,8 @@ @pytest.fixture -def label_access_policy(access_policies_api_client): - orig_access_policy = access_policies_api_client.list( +def label_access_policy(pulpcore_bindings): + orig_access_policy = pulpcore_bindings.AccessPoliciesApi.list( viewset_name="repositories/file/file" ).results[0] new_statements = orig_access_policy.statements.copy() @@ -18,32 +18,32 @@ def label_access_policy(access_policies_api_client): "principal": "authenticated", } ) - access_policies_api_client.partial_update( + pulpcore_bindings.AccessPoliciesApi.partial_update( orig_access_policy.pulp_href, {"statements": new_statements} ) yield if orig_access_policy.customized: - access_policies_api_client.partial_update( + pulpcore_bindings.AccessPoliciesApi.partial_update( orig_access_policy.pulp_href, {"statements": orig_access_policy.statements} ) else: - access_policies_api_client.reset(orig_access_policy.pulp_href) + pulpcore_bindings.AccessPoliciesApi.reset(orig_access_policy.pulp_href) @pytest.mark.parallel -def test_set_label(label_access_policy, file_repository_api_client, file_repository_factory): +def test_set_label(label_access_policy, file_bindings, file_repository_factory): repository = file_repository_factory() assert repository.pulp_labels == {} - file_repository_api_client.set_label(repository.pulp_href, {"key": "a", "value": None}) - file_repository_api_client.set_label(repository.pulp_href, {"key": "b", "value": ""}) - file_repository_api_client.set_label(repository.pulp_href, {"key": "c", "value": "val1"}) - file_repository_api_client.set_label(repository.pulp_href, {"key": "d", "value": "val2"}) - file_repository_api_client.set_label(repository.pulp_href, {"key": "e", "value": "val3"}) - file_repository_api_client.set_label(repository.pulp_href, {"key": "c", "value": "val4"}) - file_repository_api_client.set_label(repository.pulp_href, {"key": "d", "value": None}) + file_bindings.RepositoriesFileApi.set_label(repository.pulp_href, {"key": "a", "value": None}) + file_bindings.RepositoriesFileApi.set_label(repository.pulp_href, {"key": "b", "value": ""}) + file_bindings.RepositoriesFileApi.set_label(repository.pulp_href, {"key": "c", "value": "val1"}) + file_bindings.RepositoriesFileApi.set_label(repository.pulp_href, {"key": "d", "value": "val2"}) + file_bindings.RepositoriesFileApi.set_label(repository.pulp_href, {"key": "e", "value": "val3"}) + file_bindings.RepositoriesFileApi.set_label(repository.pulp_href, {"key": "c", "value": "val4"}) + file_bindings.RepositoriesFileApi.set_label(repository.pulp_href, {"key": "d", "value": None}) - repository = file_repository_api_client.read(repository.pulp_href) + repository = file_bindings.RepositoriesFileApi.read(repository.pulp_href) assert repository.pulp_labels == { "a": None, "b": "", @@ -52,9 +52,9 @@ def test_set_label(label_access_policy, file_repository_api_client, file_reposit "e": "val3", } - file_repository_api_client.unset_label(repository.pulp_href, {"key": "e"}) + file_bindings.RepositoriesFileApi.unset_label(repository.pulp_href, {"key": "e"}) - repository = file_repository_api_client.read(repository.pulp_href) + repository = file_bindings.RepositoriesFileApi.read(repository.pulp_href) assert repository.pulp_labels == { "a": None, "b": "", diff --git a/pulpcore/tests/functional/api/using_plugin/test_orphans.py b/pulpcore/tests/functional/api/using_plugin/test_orphans.py index 7e8051dcacc..8681f94c330 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_orphans.py +++ b/pulpcore/tests/functional/api/using_plugin/test_orphans.py @@ -4,23 +4,14 @@ from pulpcore.app import settings -from pulpcore.client.pulpcore import OrphansApi -from pulpcore.client.pulpcore.exceptions import ApiException as CoreApiException -from pulpcore.client.pulp_file.exceptions import ApiException - - -@pytest.fixture -def orphans_api_client(pulpcore_client): - # This API is deprecated. Use it only to test its own functionality. - return OrphansApi(pulpcore_client) - def test_orphans_delete( random_artifact, file_random_content_unit, artifacts_api_client, file_content_api_client, - orphans_api_client, + pulpcore_bindings, + file_bindings, monitor_task, ): # Verify that the system contains the orphan content unit and the orphan artifact. @@ -36,11 +27,11 @@ def test_orphans_delete( assert os.path.exists(artifact_path2) is True # Delete orphans using deprecated API - monitor_task(orphans_api_client.delete().task) + monitor_task(pulpcore_bindings.OrphansApi.delete().task) # Assert that the content unit and artifact are gone if settings.ORPHAN_PROTECTION_TIME == 0: - with pytest.raises(ApiException) as exc: + with pytest.raises(file_bindings.ApiException) as exc: file_content_api_client.read(file_random_content_unit.pulp_href) assert exc.value.status == 404 if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": @@ -53,11 +44,12 @@ def test_orphans_cleanup( file_random_content_unit, artifacts_api_client, file_content_api_client, - orphans_cleanup_api_client, + pulpcore_bindings, + file_bindings, monitor_task, ): # Cleanup orphans with a nonzero orphan_protection_time - monitor_task(orphans_cleanup_api_client.cleanup({"orphan_protection_time": 10}).task) + monitor_task(pulpcore_bindings.OrphansCleanupApi.cleanup({"orphan_protection_time": 10}).task) # Verify that the system contains the orphan content unit and the orphan artifact. content_unit = file_content_api_client.read(file_random_content_unit.pulp_href) @@ -72,10 +64,10 @@ def test_orphans_cleanup( assert os.path.exists(artifact_path2) is True # Cleanup orphans with a zero orphan_protection_time - monitor_task(orphans_cleanup_api_client.cleanup({"orphan_protection_time": 0}).task) + monitor_task(pulpcore_bindings.OrphansCleanupApi.cleanup({"orphan_protection_time": 0}).task) # Assert that the content unit and the artifact are gone - with pytest.raises(ApiException) as exc: + with pytest.raises(file_bindings.ApiException) as exc: file_content_api_client.read(file_random_content_unit.pulp_href) assert exc.value.status == 404 if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": @@ -86,28 +78,29 @@ def test_orphans_cleanup( def test_cleanup_specific_orphans( file_content_unit_with_name_factory, file_content_api_client, - orphans_cleanup_api_client, + pulpcore_bindings, + file_bindings, monitor_task, ): content_unit_1 = file_content_unit_with_name_factory("1.iso") content_unit_2 = file_content_unit_with_name_factory("2.iso") cleanup_dict = {"content_hrefs": [content_unit_1.pulp_href], "orphan_protection_time": 0} - monitor_task(orphans_cleanup_api_client.cleanup(cleanup_dict).task) + monitor_task(pulpcore_bindings.OrphansCleanupApi.cleanup(cleanup_dict).task) # Assert that content_unit_2 is gone and content_unit_1 is present - with pytest.raises(ApiException) as exc: + with pytest.raises(file_bindings.ApiException) as exc: file_content_api_client.read(content_unit_1.pulp_href) assert exc.value.status == 404 assert file_content_api_client.read(content_unit_2.pulp_href).pulp_href # Test whether the `content_hrefs` param raises a ValidationError with [] as the value content_hrefs_dict = {"content_hrefs": []} - with pytest.raises(CoreApiException) as exc: - orphans_cleanup_api_client.cleanup(content_hrefs_dict) + with pytest.raises(pulpcore_bindings.ApiException) as exc: + pulpcore_bindings.OrphansCleanupApi.cleanup(content_hrefs_dict) assert exc.value.status == 400 # Test whether the `content_hrefs` param raises a ValidationError with and invalid href""" content_hrefs_dict = {"content_hrefs": ["/not/a/valid/content/href"]} - with pytest.raises(CoreApiException) as exc: - orphans_cleanup_api_client.cleanup(content_hrefs_dict) + with pytest.raises(pulpcore_bindings.ApiException) as exc: + pulpcore_bindings.OrphansCleanupApi.cleanup(content_hrefs_dict) assert exc.value.status == 400 diff --git a/pulpcore/tests/functional/api/using_plugin/test_pagination.py b/pulpcore/tests/functional/api/using_plugin/test_pagination.py index a46f1109b35..7a357ca1200 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_pagination.py +++ b/pulpcore/tests/functional/api/using_plugin/test_pagination.py @@ -5,7 +5,7 @@ @pytest.mark.parallel def test_repo_version_pagination( file_content_unit_with_name_factory, - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_repo, monitor_task, @@ -14,7 +14,7 @@ def test_repo_version_pagination( for i in range(20): content_unit = file_content_unit_with_name_factory(f"{i}.iso") monitor_task( - file_repository_api_client.modify( + file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, {"add_content_units": [content_unit.pulp_href]} ).task ) diff --git a/pulpcore/tests/functional/api/using_plugin/test_proxy.py b/pulpcore/tests/functional/api/using_plugin/test_proxy.py index 6d674644bbc..a469e0a138d 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_proxy.py +++ b/pulpcore/tests/functional/api/using_plugin/test_proxy.py @@ -7,10 +7,10 @@ def _run_basic_sync_and_assert( - remote, file_repo, file_repository_api_client, file_content_api_client, monitor_task + remote, file_repo, file_bindings, file_content_api_client, monitor_task ): body = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) # Check content is present, but no artifacts are there content_response = file_content_api_client.list( @@ -25,7 +25,7 @@ def _run_basic_sync_and_assert( def test_sync_http_through_http_proxy( file_remote_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, http_proxy, basic_manifest_path, @@ -41,7 +41,7 @@ def test_sync_http_through_http_proxy( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -51,7 +51,7 @@ def test_sync_http_through_http_proxy( def test_sync_https_through_http_proxy( file_remote_ssl_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, http_proxy, basic_manifest_path, @@ -67,7 +67,7 @@ def test_sync_https_through_http_proxy( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -77,7 +77,7 @@ def test_sync_https_through_http_proxy( def test_sync_https_through_http_proxy_with_auth( file_remote_ssl_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, http_proxy_with_auth, basic_manifest_path, @@ -98,7 +98,7 @@ def test_sync_https_through_http_proxy_with_auth( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -108,7 +108,7 @@ def test_sync_https_through_http_proxy_with_auth( def test_sync_https_through_http_proxy_with_auth_but_auth_not_configured( file_remote_ssl_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, http_proxy_with_auth, basic_manifest_path, @@ -128,7 +128,7 @@ def test_sync_https_through_http_proxy_with_auth_but_auth_not_configured( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) @@ -140,7 +140,7 @@ def test_sync_https_through_http_proxy_with_auth_but_auth_not_configured( def test_sync_http_through_https_proxy( file_remote_factory, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, https_proxy, basic_manifest_path, @@ -159,7 +159,7 @@ def test_sync_http_through_https_proxy( _run_basic_sync_and_assert( remote_on_demand, file_repo, - file_repository_api_client, + file_bindings, file_content_api_client, monitor_task, ) diff --git a/pulpcore/tests/functional/api/using_plugin/test_pulpimport.py b/pulpcore/tests/functional/api/using_plugin/test_pulpimport.py index f71831b920a..f4d955c596a 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_pulpimport.py +++ b/pulpcore/tests/functional/api/using_plugin/test_pulpimport.py @@ -33,7 +33,7 @@ @pytest.fixture def import_export_repositories( - file_repository_api_client, + file_bindings, file_repository_factory, file_remote_ssl_factory, basic_manifest_path, @@ -47,10 +47,12 @@ def import_export_repositories( remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="immediate") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) - sync_response = file_repository_api_client.sync(export_repo.pulp_href, repository_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync( + export_repo.pulp_href, repository_sync_data + ) monitor_task(sync_response.task) - export_repo = file_repository_api_client.read(export_repo.pulp_href) + export_repo = file_bindings.RepositoriesFileApi.read(export_repo.pulp_href) export_repos.append(export_repo) import_repos.append(import_repo) @@ -211,9 +213,7 @@ def test_importer_delete(pulp_importer_factory, importers_pulp_api_client): @pytest.mark.parallel -def test_import( - pulp_importer_factory, file_repository_api_client, import_export_repositories, perform_import -): +def test_import(pulp_importer_factory, file_bindings, import_export_repositories, perform_import): """Test an import.""" import_repos, exported_repos = import_export_repositories importer = pulp_importer_factory() @@ -225,7 +225,7 @@ def test_import( assert report.done == len(import_repos) for repo in import_repos: - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert f"{repo.pulp_href}versions/1/" == repo.latest_version_href @@ -248,7 +248,7 @@ def test_import_auto_repo_creation( file_content_api_client, file_repository_factory, file_remote_ssl_factory, - file_repository_api_client, + file_bindings, gen_object_with_cleanup, generate_export, importers_pulp_api_client, @@ -262,10 +262,12 @@ def test_import_auto_repo_creation( remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="immediate") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) - sync_response = file_repository_api_client.sync(export_repo.pulp_href, repository_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync( + export_repo.pulp_href, repository_sync_data + ) monitor_task(sync_response.task) - export_repo = file_repository_api_client.read(export_repo.pulp_href) + export_repo = file_bindings.RepositoriesFileApi.read(export_repo.pulp_href) added_content_in_export_repo = file_content_api_client.list( repository_version_added=export_repo.latest_version_href ).results @@ -280,15 +282,15 @@ def test_import_auto_repo_creation( export = generate_export(exporter) # 3. delete the exported repository - monitor_task(file_repository_api_client.delete(export_repo.pulp_href).task) - assert len(file_repository_api_client.list(name=export_repo.name).results) == 0 + monitor_task(file_bindings.RepositoriesFileApi.delete(export_repo.pulp_href).task) + assert len(file_bindings.RepositoriesFileApi.list(name=export_repo.name).results) == 0 # 4. import the exported repository without creating an import repository beforehand importer = gen_object_with_cleanup(importers_pulp_api_client, {"name": str(uuid.uuid4())}) perform_import(importer, an_export=export, body={"create_repositories": True}) # 5. run assertions on the automatically created import repository - repositories = file_repository_api_client.list(name=export_repo.name).results + repositories = file_bindings.RepositoriesFileApi.list(name=export_repo.name).results assert len(repositories) == 1 imported_repo = repositories[0] @@ -299,7 +301,7 @@ def test_import_auto_repo_creation( ).results assert len(added_content_in_export_repo) == len(added_content_in_imported_repo) - monitor_task(file_repository_api_client.delete(imported_repo.pulp_href).task) + monitor_task(file_bindings.RepositoriesFileApi.delete(imported_repo.pulp_href).task) @pytest.mark.parallel @@ -307,7 +309,7 @@ def test_double_import( pulp_importer_factory, importers_pulp_imports_api_client, import_export_repositories, - file_repository_api_client, + file_bindings, perform_import, ): """Test two imports of our export.""" @@ -321,14 +323,14 @@ def test_double_import( assert len(imports) == 2 for repo in import_repos: - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) # still only one version as pulp won't create a new version if nothing changed assert f"{repo.pulp_href}versions/1/" == repo.latest_version_href @pytest.mark.parallel def test_chunked_import( - pulp_importer_factory, import_export_repositories, file_repository_api_client, perform_import + pulp_importer_factory, import_export_repositories, file_bindings, perform_import ): """Test an import.""" import_repos, exported_repos = import_export_repositories @@ -337,7 +339,7 @@ def test_chunked_import( assert (len(import_repos) + 1) == task_group.completed for repo in import_repos: - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert f"{repo.pulp_href}versions/1/" == repo.latest_version_href # We should be able to import a second time, even though the chunks have now been reassembled. @@ -494,7 +496,7 @@ def exported_version( generate_export, perform_import, file_repo, - file_repository_api_client, + file_bindings, file_repository_version_api_client, content_api_client, monitor_task, @@ -508,7 +510,7 @@ def exported_version( results = file_list.results for a_file in results: href = a_file.pulp_href - modify_response = file_repository_api_client.modify( + modify_response = file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, {"add_content_units": [href]} ) monitor_task(modify_response.task) @@ -537,12 +539,12 @@ def exported_version( @pytest.mark.parallel -def test_import_not_latest_version(exported_version, file_repository_api_client): +def test_import_not_latest_version(exported_version, file_bindings): """Test an import.""" import_repos, task_group = exported_version for report in task_group.group_progress_reports: if report.code == "import.repo.versions": assert report.done == 1 - imported_repo = file_repository_api_client.read(import_repos[0].pulp_href) + imported_repo = file_bindings.RepositoriesFileApi.read(import_repos[0].pulp_href) assert f"{imported_repo.pulp_href}versions/0/" != imported_repo.latest_version_href diff --git a/pulpcore/tests/functional/api/using_plugin/test_purge.py b/pulpcore/tests/functional/api/using_plugin/test_purge.py index e7e0be911fd..3d947a7e8f8 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_purge.py +++ b/pulpcore/tests/functional/api/using_plugin/test_purge.py @@ -14,7 +14,7 @@ TOMORROW_STR = (datetime.now(timezone.utc) + timedelta(days=1)).strftime("%Y-%m-%dT%H:%M") -def _task_summary(tasks_api_client): +def _task_summary(pulpcore_bindings): """ Summary of number of tasks in all known task-states. :return: tuple of (total-tasks, number of final tasks, summary) @@ -23,7 +23,7 @@ def _task_summary(tasks_api_client): total = 0 final_total = 0 for state in TASK_STATES.__dict__.values(): - response = tasks_api_client.list(state=state) + response = pulpcore_bindings.TasksApi.list(state=state) summary[state] = response.count total += summary[state] final_total += summary[state] if state in TASK_FINAL_STATES else 0 @@ -49,8 +49,8 @@ def _check_delete_report(task, expected): @pytest.fixture def sync_results( - file_repository_api_client, - tasks_api_client, + file_bindings, + pulpcore_bindings, file_remote_factory, file_remote_ssl_factory, file_repository_factory, @@ -67,138 +67,138 @@ def sync_results( bad_repo = file_repository_factory() bad_sync_data = RepositorySyncURL(remote=bad_remote.pulp_href) - pre_total, pre_final, pre_summary = _task_summary(tasks_api_client) + pre_total, pre_final, pre_summary = _task_summary(pulpcore_bindings) # good sync - sync_response = file_repository_api_client.sync(good_repo.pulp_href, good_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync(good_repo.pulp_href, good_sync_data) task = monitor_task(sync_response.task) assert "completed" == task.state completed_sync_task = task # bad sync - sync_response = file_repository_api_client.sync(bad_repo.pulp_href, bad_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync(bad_repo.pulp_href, bad_sync_data) with pytest.raises(PulpTaskError): monitor_task(sync_response.task) - task = tasks_api_client.read(sync_response.task) + task = pulpcore_bindings.TasksApi.read(sync_response.task) assert "failed" == task.state failed_sync_task = task - post_total, post_final, post_summary = _task_summary(tasks_api_client) + post_total, post_final, post_summary = _task_summary(pulpcore_bindings) assert post_total == (pre_total + 2) assert post_final == (pre_final + 2) return completed_sync_task, failed_sync_task, pre_total, pre_final, pre_summary -def test_purge_before_time(tasks_api_client, sync_results, monitor_task): +def test_purge_before_time(pulpcore_bindings, sync_results, monitor_task): """Purge that should find no tasks to delete.""" _, _, pre_total, _, _ = sync_results dta = Purge(finished_before="1970-01-01T00:00") - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) task = monitor_task(response.task) - new_total, new_final, new_summary = _task_summary(tasks_api_client) + new_total, new_final, new_summary = _task_summary(pulpcore_bindings) # Should have all tasks remaining (2 completed, 1 failed) assert (pre_total + 3) == new_total # Should show we report having purged no tasks assert _purge_report_total(task) == 0 -def test_purge_defaults(tasks_api_client, sync_results, monitor_task): +def test_purge_defaults(pulpcore_bindings, sync_results, monitor_task): """Purge using defaults (finished_before=30-days-ago, state=completed)""" dta = Purge() - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) monitor_task(response.task) completed_sync_task, failed_sync_task, _, _, _ = sync_results # default is "completed before 30 days ago" - so both sync tasks should still exist # Make sure good sync-task still exists - tasks_api_client.read(completed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(completed_sync_task.pulp_href) # Make sure the failed sync still exists - tasks_api_client.read(failed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(failed_sync_task.pulp_href) -def test_purge_all(tasks_api_client, sync_results, monitor_task): +def test_purge_all(pulpcore_bindings, sync_results, monitor_task): """Purge all tasks in any 'final' state.""" completed_sync_task, failed_sync_task, pre_total, pre_final, pre_summary = sync_results states = list(TASK_FINAL_STATES) dta = Purge(finished_before=TOMORROW_STR, states=states) - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) task = monitor_task(response.task) - new_total, new_final, new_summary = _task_summary(tasks_api_client) + new_total, new_final, new_summary = _task_summary(pulpcore_bindings) assert 1 == new_final, "The purge-task should be the only final-task left" # Make sure good sync-task is gone with pytest.raises(ApiException): - tasks_api_client.read(completed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(completed_sync_task.pulp_href) # Make sure failed sync-task is gone with pytest.raises(ApiException): - tasks_api_client.read(failed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(failed_sync_task.pulp_href) # Make sure we reported the deletions _check_delete_report(task, pre_final + 2) -def test_purge_leave_one(tasks_api_client, sync_results, monitor_task): +def test_purge_leave_one(pulpcore_bindings, sync_results, monitor_task): """Arrange to leave one task unscathed.""" # Leave only the failed sync completed_sync_task, failed_sync_task, pre_total, pre_final, pre_summary = sync_results dta = Purge(finished_before=failed_sync_task.finished_at) - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) task = monitor_task(response.task) # Make sure good sync-task is gone with pytest.raises(ApiException): - tasks_api_client.read(completed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(completed_sync_task.pulp_href) # Make sure the failed sync still exists - tasks_api_client.read(failed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(failed_sync_task.pulp_href) # Make sure we reported the task-deletion _check_delete_report(task, pre_final + 1) -def test_purge_only_failed(tasks_api_client, sync_results, monitor_task): +def test_purge_only_failed(pulpcore_bindings, sync_results, monitor_task): """Purge all failed tasks only.""" dta = Purge(finished_before=TOMORROW_STR, states=["failed"]) - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) monitor_task(response.task) # completed sync-task should exist completed_sync_task, failed_sync_task, pre_total, pre_final, pre_summary = sync_results - tasks_api_client.read(completed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(completed_sync_task.pulp_href) # failed should not exist with pytest.raises(ApiException): - tasks_api_client.read(failed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(failed_sync_task.pulp_href) -def test_bad_date(tasks_api_client, sync_results): +def test_bad_date(pulpcore_bindings, sync_results): """What happens if you use a bad date format?""" dta = Purge(finished_before="THISISNOTADATE") with pytest.raises(ApiException): - tasks_api_client.purge(dta) + pulpcore_bindings.TasksApi.purge(dta) -def test_bad_state(tasks_api_client, sync_results): +def test_bad_state(pulpcore_bindings, sync_results): """What happens if you specify junk for a state?""" dta = Purge(finished_before=TOMORROW_STR, states=["BAD STATE"]) with pytest.raises(ApiException): - tasks_api_client.purge(dta) + pulpcore_bindings.TasksApi.purge(dta) -def test_not_final_state(tasks_api_client, sync_results): +def test_not_final_state(pulpcore_bindings, sync_results): """What happens if you use a valid state that isn't a 'final' one?""" dta = Purge(finished_before=TOMORROW_STR, states=["running"]) with pytest.raises(ApiException): - tasks_api_client.purge(dta) + pulpcore_bindings.TasksApi.purge(dta) def test_purge_with_different_users( - tasks_api_client, - file_repository_api_client, + pulpcore_bindings, + file_bindings, file_remote_ssl_factory, file_repository_factory, basic_manifest_path, @@ -224,46 +224,46 @@ def test_purge_with_different_users( user_repo = file_repository_factory() # Sync as admin - sync_response = file_repository_api_client.sync(admin_repo.pulp_href, admin_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync(admin_repo.pulp_href, admin_sync_data) monitor_task(sync_response.task) # Purge as user states = list(TASK_FINAL_STATES) data = Purge(finished_before=TOMORROW_STR, states=states) with user: - response = tasks_api_client.purge(data) + response = pulpcore_bindings.TasksApi.purge(data) task = monitor_task(response.task) # Make sure sync-task (executed by admin) still exists - tasks_api_client.read(task.pulp_href) + pulpcore_bindings.TasksApi.read(task.pulp_href) # Sync as user with user: - sync_response = file_repository_api_client.sync(user_repo.pulp_href, user_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync(user_repo.pulp_href, user_sync_data) sync_task = monitor_task(sync_response.task) # Purge as user states = list(TASK_FINAL_STATES) data = Purge(finished_before=TOMORROW_STR, states=states) with user: - response = tasks_api_client.purge(data) + response = pulpcore_bindings.TasksApi.purge(data) monitor_task(response.task) # Make sure task DOES NOT exist with pytest.raises(ApiException): - tasks_api_client.read(sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(sync_task.pulp_href) # Sync as user with user: - sync_response = file_repository_api_client.sync(user_repo.pulp_href, user_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync(user_repo.pulp_href, user_sync_data) monitor_task(sync_response.task) # Purge as ADMIN states = list(TASK_FINAL_STATES) data = Purge(finished_before=TOMORROW_STR, states=states) - response = tasks_api_client.purge(data) + response = pulpcore_bindings.TasksApi.purge(data) monitor_task(response.task) # Make sure task DOES NOT exist with pytest.raises(ApiException): - tasks_api_client.read(sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(sync_task.pulp_href) diff --git a/pulpcore/tests/functional/api/using_plugin/test_reclaim_disk_space.py b/pulpcore/tests/functional/api/using_plugin/test_reclaim_disk_space.py index bc832a99d7e..0dbea7c3820 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_reclaim_disk_space.py +++ b/pulpcore/tests/functional/api/using_plugin/test_reclaim_disk_space.py @@ -10,7 +10,7 @@ @pytest.mark.parallel def test_reclaim_immediate_content( - file_repository_api_client, + file_bindings, file_repo, repositories_reclaim_space_api_client, artifacts_api_client, @@ -26,7 +26,9 @@ def test_reclaim_immediate_content( # sync the repository with immediate policy repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) - sync_response = file_repository_api_client.sync(file_repo.pulp_href, repository_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync( + file_repo.pulp_href, repository_sync_data + ) monitor_task(sync_response.task) # reclaim disk space @@ -43,7 +45,9 @@ def test_reclaim_immediate_content( # sync repo again repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) - sync_response = file_repository_api_client.sync(file_repo.pulp_href, repository_sync_data) + sync_response = file_bindings.RepositoriesFileApi.sync( + file_repo.pulp_href, repository_sync_data + ) monitor_task(sync_response.task) # assert re-sync populated missing artifacts @@ -54,7 +58,7 @@ def test_reclaim_immediate_content( @pytest.fixture def sync_repository_distribution( - file_repository_api_client, + file_bindings, file_distribution_factory, file_remote_ssl_factory, file_repo_with_auto_publish, @@ -65,7 +69,7 @@ def _sync_repository_distribution(policy="immediate"): remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy=policy) repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) - sync_response = file_repository_api_client.sync( + sync_response = file_bindings.RepositoriesFileApi.sync( file_repo_with_auto_publish.pulp_href, repository_sync_data ) monitor_task(sync_response.task) diff --git a/pulpcore/tests/functional/api/using_plugin/test_repair.py b/pulpcore/tests/functional/api/using_plugin/test_repair.py index c100507a953..e6a14740c47 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_repair.py +++ b/pulpcore/tests/functional/api/using_plugin/test_repair.py @@ -11,7 +11,7 @@ @pytest.fixture def repository_with_corrupted_artifacts( - file_repository_api_client, + file_bindings, file_repo, artifacts_api_client, file_remote_ssl_factory, @@ -21,8 +21,8 @@ def repository_with_corrupted_artifacts( # STEP 1: sync content from a remote source remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="immediate") sync_data = RepositorySyncURL(remote=remote.pulp_href) - monitor_task(file_repository_api_client.sync(file_repo.pulp_href, sync_data).task) - repo = file_repository_api_client.read(file_repo.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, sync_data).task) + repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) # STEP 2: sample artifacts that will be modified on the filesystem later on content1, content2 = sample(get_files_in_manifest(remote.url), 2) diff --git a/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py b/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py index 9233e17381b..e9f8eadd416 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py +++ b/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py @@ -4,9 +4,6 @@ from tempfile import NamedTemporaryFile from uuid import uuid4 -from pulpcore.client.pulpcore import ApiException as CoreApiException -from pulpcore.client.pulp_file.exceptions import ApiException - from pulpcore.tests.functional.utils import PulpTaskError, get_files_in_manifest @@ -38,7 +35,7 @@ def file_9_contents( def file_repository_content( file_remote_ssl_factory, file_repository_factory, - file_repository_api_client, + file_bindings, file_content_api_client, basic_manifest_path, monitor_task, @@ -46,9 +43,11 @@ def file_repository_content( """Create some content that was synced into a repo on-demand.""" remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") base_repo = file_repository_factory() - task = file_repository_api_client.sync(base_repo.pulp_href, {"remote": remote.pulp_href}).task + task = file_bindings.RepositoriesFileApi.sync( + base_repo.pulp_href, {"remote": remote.pulp_href} + ).task monitor_task(task) - base_repo = file_repository_api_client.read(base_repo.pulp_href) + base_repo = file_bindings.RepositoriesFileApi.read(base_repo.pulp_href) assert base_repo.latest_version_href[-2] == "1" contents = file_content_api_client.list(repository_version=base_repo.latest_version_href) assert contents.count == 3 @@ -58,7 +57,7 @@ def file_repository_content( @pytest.mark.parallel def test_add_remove_content( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_content_api_client, file_repository_factory, @@ -83,9 +82,11 @@ def test_add_remove_content( # Sync content into the repository CONTENT_BASE_HREF = "/api/v3/content/file/files/" remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="immediate") - task = file_repository_api_client.sync(file_repo.pulp_href, {"remote": remote.pulp_href}).task + task = file_bindings.RepositoriesFileApi.sync( + file_repo.pulp_href, {"remote": remote.pulp_href} + ).task task_report = monitor_task(task) - repo = file_repository_api_client.read(file_repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert task_report.created_resources[0] == repo.latest_version_href @@ -120,9 +121,9 @@ def test_add_remove_content( content = choice(contents.results) body = {"remove_content_units": [content.pulp_href]} - task = file_repository_api_client.modify(repo.pulp_href, body).task + task = file_bindings.RepositoriesFileApi.modify(repo.pulp_href, body).task monitor_task(task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) repo_versions = file_repository_version_api_client.list(repo.pulp_href) assert repo_versions.count == 3 @@ -144,9 +145,9 @@ def test_add_remove_content( # Add content to the repository body = {"add_content_units": [content.pulp_href]} - task = file_repository_api_client.modify(repo.pulp_href, body).task + task = file_bindings.RepositoriesFileApi.modify(repo.pulp_href, body).task monitor_task(task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) repo_versions = file_repository_version_api_client.list(repo.pulp_href) assert repo_versions.count == 4 @@ -161,7 +162,7 @@ def test_add_remove_content( @pytest.mark.parallel def test_add_remove_repo_version( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_content_api_client, file_repository_factory, @@ -181,11 +182,11 @@ def test_add_remove_repo_version( # Add versions to repository for content in contents: - task = file_repository_api_client.modify( + task = file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, {"add_content_units": [content.pulp_href]} ).task monitor_task(task) - repo = file_repository_api_client.read(file_repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert repo.latest_version_href[-2] == "9" # Test trying to delete version 0 with a populated repository @@ -193,18 +194,18 @@ def test_add_remove_repo_version( monitor_task(file_repository_version_api_client.delete(ver_zero).task) versions = file_repository_version_api_client.list(repo.pulp_href) assert versions.count == 9 - with pytest.raises(ApiException) as e: + with pytest.raises(file_bindings.ApiException) as e: file_repository_version_api_client.read(ver_zero) assert e.value.status == 404 # Test deleting the last repository version last_ver = repo.latest_version_href monitor_task(file_repository_version_api_client.delete(last_ver).task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert repo.latest_version_href[-2] == "8" versions = file_repository_version_api_client.list(repo.pulp_href) assert versions.count == 8 - with pytest.raises(ApiException) as e: + with pytest.raises(file_bindings.ApiException) as e: file_repository_version_api_client.read(last_ver) assert e.value.status == 404 @@ -217,7 +218,7 @@ def test_add_remove_repo_version( monitor_task(file_repository_version_api_client.delete(middle_ver).task) versions = file_repository_version_api_client.list(repo.pulp_href) assert versions.count == 7 - with pytest.raises(ApiException) as e: + with pytest.raises(file_bindings.ApiException) as e: file_repository_version_api_client.read(middle_ver) assert e.value.status == 404 @@ -245,7 +246,7 @@ def test_add_remove_repo_version( @pytest.mark.parallel def test_squash_repo_version( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_content_api_client, file_repository_factory, @@ -269,7 +270,7 @@ def test_squash_repo_version( """ content_units = file_9_contents file_repo = file_repository_factory() - response1 = file_repository_api_client.modify( + response1 = file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, { "add_content_units": [ @@ -280,7 +281,7 @@ def test_squash_repo_version( }, ) - response2 = file_repository_api_client.modify( + response2 = file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, { "remove_content_units": [ @@ -296,7 +297,7 @@ def test_squash_repo_version( }, ) - response3 = file_repository_api_client.modify( + response3 = file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, { "remove_content_units": [ @@ -308,7 +309,7 @@ def test_squash_repo_version( }, ) - response4 = file_repository_api_client.modify( + response4 = file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, { "remove_content_units": [ @@ -375,9 +376,7 @@ def test_squash_repo_version( @pytest.mark.parallel def test_content_immutable_repo_version( - file_repository_api_client, - file_repository_version_api_client, - file_client, + file_bindings, file_repository_factory, file_remote_ssl_factory, basic_manifest_path, @@ -389,26 +388,28 @@ def test_content_immutable_repo_version( """ file_repo = file_repository_factory() remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - task = file_repository_api_client.sync(file_repo.pulp_href, {"remote": remote.pulp_href}).task + task = file_bindings.RepositoriesFileApi.sync( + file_repo.pulp_href, {"remote": remote.pulp_href} + ).task monitor_task(task) - repo = file_repository_api_client.read(file_repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert repo.latest_version_href[-2] == "1" - repo_ver_attributes = dir(file_repository_version_api_client) + repo_ver_attributes = dir(file_bindings.RepositoriesFileVersionsApi) # POST assertion for attr in repo_ver_attributes: assert "create" not in attr - with pytest.raises(ApiException) as e: - file_client.call_api(repo.latest_version_href, "POST", auth_settings=["basicAuth"]) + with pytest.raises(file_bindings.ApiException) as e: + file_bindings.client.call_api(repo.latest_version_href, "POST", auth_settings=["basicAuth"]) assert e.value.status == 405 body = {"base_version": f"{repo.versions_href}0/"} # PUT assertion for attr in repo_ver_attributes: assert "update" not in attr - with pytest.raises(ApiException) as e: - file_client.call_api( + with pytest.raises(file_bindings.ApiException) as e: + file_bindings.client.call_api( repo.latest_version_href, "PUT", body=body, auth_settings=["basicAuth"] ) assert e.value.status == 405 @@ -416,8 +417,8 @@ def test_content_immutable_repo_version( # PATCH assertion for attr in repo_ver_attributes: assert "partial_update" not in attr - with pytest.raises(ApiException) as e: - file_client.call_api( + with pytest.raises(file_bindings.ApiException) as e: + file_bindings.client.call_api( repo.latest_version_href, "PATCH", body=body, auth_settings=["basicAuth"] ) assert e.value.status == 405 @@ -425,7 +426,7 @@ def test_content_immutable_repo_version( @pytest.mark.parallel def test_filter_repo_version( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_repository_factory, monitor_task, @@ -435,11 +436,11 @@ def test_filter_repo_version( file_repo = file_repository_factory() # Setup 8 content units in Pulp to populate test repository with for content in file_9_contents.values(): - task = file_repository_api_client.modify( + task = file_bindings.RepositoriesFileApi.modify( file_repo.pulp_href, {"add_content_units": [content.pulp_href]} ).task monitor_task(task) - repo = file_repository_api_client.read(file_repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert repo.latest_version_href[-2] == "9" repo_versions = file_repository_version_api_client.list(repo.pulp_href).results @@ -451,7 +452,7 @@ def test_filter_repo_version( {"pulp_created__gte": criteria, "pulp_created__lte": criteria}, {"pulp_created__range": [criteria, criteria]}, ): - with pytest.raises(ApiException) as e: + with pytest.raises(file_bindings.ApiException) as e: file_repository_version_api_client.list(repo.pulp_href, **params) assert e.value.status == 400 assert "Enter a valid date/time." in e.value.body @@ -486,7 +487,7 @@ def test_filter_repo_version( {"number__gte": criteria, "number__lte": criteria}, {"number__range": [criteria, criteria]}, ): - with pytest.raises(ApiException) as e: + with pytest.raises(file_bindings.ApiException) as e: file_repository_version_api_client.list(repo.pulp_href, **params) assert e.value.status == 400 assert "Enter a number." in e.value.body @@ -510,7 +511,7 @@ def test_filter_repo_version( @pytest.mark.parallel def test_create_repo_base_version( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_content_api_client, file_repository_factory, @@ -523,29 +524,31 @@ def test_create_repo_base_version( # Test ``base_version`` for the same repository remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") repo = file_repository_factory() - monitor_task(file_repository_api_client.sync(repo.pulp_href, {"remote": remote.pulp_href}).task) - repo = file_repository_api_client.read(repo.pulp_href) + monitor_task( + file_bindings.RepositoriesFileApi.sync(repo.pulp_href, {"remote": remote.pulp_href}).task + ) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) base_content = file_content_api_client.list(repository_version=repo.latest_version_href) base_version = file_repository_version_api_client.read(repo.latest_version_href) assert base_version.base_version is None # create repo version 2 monitor_task( - file_repository_api_client.modify( + file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"add_content_units": [file_random_content_unit.pulp_href]} ).task ) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) middle_content = file_content_api_client.list(repository_version=repo.latest_version_href) assert middle_content.count == base_content.count + 1 # create repo version 3 from version 1 monitor_task( - file_repository_api_client.modify( + file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"base_version": base_version.pulp_href} ).task ) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) # assert that base_version of the version 3 points to version 1 latest_version = file_repository_version_api_client.read(repo.latest_version_href) assert latest_version.base_version == base_version.pulp_href @@ -558,11 +561,11 @@ def test_create_repo_base_version( repo2 = file_repository_factory() # create a version for repo B using repo A version 1 as base_version monitor_task( - file_repository_api_client.modify( + file_bindings.RepositoriesFileApi.modify( repo2.pulp_href, {"base_version": base_version.pulp_href} ).task ) - repo2 = file_repository_api_client.read(repo2.pulp_href) + repo2 = file_bindings.RepositoriesFileApi.read(repo2.pulp_href) latest_version2 = file_repository_version_api_client.read(repo2.latest_version_href) # assert that base_version of repo B points to version 1 of repo A @@ -583,8 +586,8 @@ def test_create_repo_base_version( "add_content_units": [added_content.pulp_href], "remove_content_units": [removed_content.pulp_href], } - monitor_task(file_repository_api_client.modify(repo3.pulp_href, body).task) - repo3 = file_repository_api_client.read(repo3.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.modify(repo3.pulp_href, body).task) + repo3 = file_bindings.RepositoriesFileApi.read(repo3.pulp_href) latest_version3 = file_repository_version_api_client.read(repo3.latest_version_href) latest_content3 = file_content_api_client.list(repository_version=repo3.latest_version_href) @@ -600,15 +603,18 @@ def test_create_repo_base_version( # Exception is raised when non-existent ``base_version`` is used nonexistant_version = f"{repo.versions_href}5/" - with pytest.raises(ApiException) as e: - file_repository_api_client.modify(repo.pulp_href, {"base_version": nonexistant_version}) + with pytest.raises(file_bindings.ApiException) as e: + file_bindings.RepositoriesFileApi.modify( + repo.pulp_href, {"base_version": nonexistant_version} + ) assert e.value.status == 400 assert "Object does not exist." in e.value.body @pytest.mark.parallel def test_filter_artifacts( - file_repository_api_client, + pulpcore_bindings, + file_bindings, artifacts_api_client, random_artifact_factory, file_repository_factory, @@ -625,11 +631,11 @@ def test_filter_artifacts( for path in duplicate_filename_paths: remote = file_remote_ssl_factory(manifest_path=path, policy="immediate") - task = file_repository_api_client.sync( + task = file_bindings.RepositoriesFileApi.sync( file_repo.pulp_href, {"remote": remote.pulp_href} ).task monitor_task(task) - repo = file_repository_api_client.read(file_repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) # Assert only three artifacts show up when filtering # Even on second sync only three will show up since the 3 added content units have the same # relative paths of current present content and thus ends up replacing them leaving the @@ -640,7 +646,7 @@ def test_filter_artifacts( # Filter by invalid repository version. bad_version = f"{file_repo.versions_href}5/" - with pytest.raises(CoreApiException) as e: + with pytest.raises(pulpcore_bindings.ApiException) as e: artifacts_api_client.list(repository_version=bad_version) assert e.value.status == 400 for key in ("uri", "repositoryversion", "not", "found"): @@ -649,7 +655,7 @@ def test_filter_artifacts( @pytest.mark.parallel def test_delete_repo_version_publication( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_repository_factory, file_remote_ssl_factory, @@ -661,9 +667,11 @@ def test_delete_repo_version_publication( """Test that removing a repo version will delete its publication.""" file_repo = file_repository_factory() remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - task = file_repository_api_client.sync(file_repo.pulp_href, {"remote": remote.pulp_href}).task + task = file_bindings.RepositoriesFileApi.sync( + file_repo.pulp_href, {"remote": remote.pulp_href} + ).task monitor_task(task) - repo = file_repository_api_client.read(file_repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert repo.latest_version_href[-2] == "1" pub_body = {"repository": repo.pulp_href} @@ -673,7 +681,7 @@ def test_delete_repo_version_publication( # delete repo version used to create publication file_repository_version_api_client.delete(repo.latest_version_href) - with pytest.raises(ApiException) as e: + with pytest.raises(file_bindings.ApiException) as e: file_publication_api_client.read(publication.pulp_href) assert e.value.status == 404 @@ -681,7 +689,7 @@ def test_delete_repo_version_publication( @pytest.mark.parallel def test_delete_protected_repo_version( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_repository_factory, file_remote_ssl_factory, @@ -695,9 +703,11 @@ def test_delete_protected_repo_version( """Test that removing a repo version fails if its publication is distributed.""" file_repo = file_repository_factory() remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - task = file_repository_api_client.sync(file_repo.pulp_href, {"remote": remote.pulp_href}).task + task = file_bindings.RepositoriesFileApi.sync( + file_repo.pulp_href, {"remote": remote.pulp_href} + ).task monitor_task(task) - repo = file_repository_api_client.read(file_repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert repo.latest_version_href[-2] == "1" pub_body = {"repository": repo.pulp_href} @@ -708,7 +718,7 @@ def test_delete_protected_repo_version( assert distribution.publication == publication.pulp_href # deleting a protected repo version fails - with pytest.raises(ApiException) as e: + with pytest.raises(file_bindings.ApiException) as e: file_repository_version_api_client.delete(repo.latest_version_href) assert e.value.status == 400 assert "The repository version cannot be deleted" in e.value.body @@ -722,14 +732,14 @@ def test_delete_protected_repo_version( # and then delete the repo version task = file_repository_version_api_client.delete(repo.latest_version_href).task monitor_task(task) - with pytest.raises(ApiException) as e: + with pytest.raises(file_bindings.ApiException) as e: file_repository_version_api_client.read(repo.latest_version_href) assert e.value.status == 404 @pytest.mark.parallel def test_clear_all_units_repo_version( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_content_api_client, file_repository_factory, @@ -742,13 +752,13 @@ def test_clear_all_units_repo_version( # Test addition and removal of all units for a given repository version. repo = file_repository_factory() remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - file_repository_api_client.sync(repo.pulp_href, {"remote": remote.pulp_href}) + file_bindings.RepositoriesFileApi.sync(repo.pulp_href, {"remote": remote.pulp_href}) content = choice(list(file_9_contents.values())) body = {"add_content_units": [content.pulp_href], "remove_content_units": ["*"]} - task = file_repository_api_client.modify(repo.pulp_href, body).task + task = file_bindings.RepositoriesFileApi.modify(repo.pulp_href, body).task monitor_task(task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert repo.latest_version_href[-2] == "2" latest_version = file_repository_version_api_client.read(repo.latest_version_href) @@ -762,16 +772,16 @@ def test_clear_all_units_repo_version( # Test clear all units using base version. repo = file_repository_factory() for content in file_9_contents.values(): - task = file_repository_api_client.modify( + task = file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"add_content_units": [content.pulp_href]} ).task monitor_task(task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) base_version_four = f"{repo.versions_href}4/" body = {"base_version": base_version_four, "remove_content_units": ["*"]} - monitor_task(file_repository_api_client.modify(repo.pulp_href, body).task) - repo = file_repository_api_client.read(repo.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.modify(repo.pulp_href, body).task) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert repo.latest_version_href[-3:-1] == "10" latest_version = file_repository_version_api_client.read(repo.latest_version_href) @@ -780,8 +790,8 @@ def test_clear_all_units_repo_version( assert latest_version.content_summary.removed["file.file"]["count"] == 9 # Test http error is raised when invalid remove - with pytest.raises(ApiException) as e: - file_repository_api_client.modify( + with pytest.raises(file_bindings.ApiException) as e: + file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"remove_content_units": ["*", content.pulp_href]} ) assert e.value.status == 400 @@ -791,7 +801,7 @@ def test_clear_all_units_repo_version( @pytest.mark.parallel def test_repo_version_retention( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_repository_content, file_content_api_client, @@ -809,11 +819,11 @@ def test_repo_version_retention( # Test repo version retention. repo = file_repository_factory(retain_repo_versions=1) for content in contents.results: - task = file_repository_api_client.modify( + task = file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"add_content_units": [content.pulp_href]} ).task monitor_task(task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert repo.latest_version_href[-2] == "3" versions = file_repository_version_api_client.list(repo.pulp_href) @@ -828,17 +838,17 @@ def test_repo_version_retention( # Test repo version retention when retain_repo_versions is set. repo = file_repository_factory() for content in contents.results: - task = file_repository_api_client.modify( + task = file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"add_content_units": [content.pulp_href]} ).task monitor_task(task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) versions = file_repository_version_api_client.list(repo.pulp_href) assert versions.count == 4 # update retain_repo_versions to 2 - task = file_repository_api_client.partial_update( + task = file_bindings.RepositoriesFileApi.partial_update( repo.pulp_href, {"retain_repo_versions": 2} ).task monitor_task(task) @@ -856,18 +866,18 @@ def test_repo_version_retention( repo = file_repository_factory(**body) publications = [] for content in contents.results: - task = file_repository_api_client.modify( + task = file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"add_content_units": [content.pulp_href]} ).task monitor_task(task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) publications.append( file_publication_api_client.list(repository_version=repo.latest_version_href).results[0] ) # all but the last publication should be gone for publication in publications[:-1]: - with pytest.raises(ApiException) as ae: + with pytest.raises(file_bindings.ApiException) as ae: file_publication_api_client.read(publication.pulp_href) assert ae.value.status == 404 @@ -879,7 +889,7 @@ def test_repo_version_retention( @pytest.mark.parallel def test_repo_versions_protected_from_cleanup( - file_repository_api_client, + file_bindings, file_repository_version_api_client, file_repository_content, file_publication_api_client, @@ -891,12 +901,12 @@ def test_repo_versions_protected_from_cleanup( """Test that distributed repo versions are protected from retain_repo_versions.""" def _modify_and_validate(repo, content, expected_version, expected_total): - task = file_repository_api_client.modify( + task = file_bindings.RepositoriesFileApi.modify( repo.pulp_href, {"add_content_units": [content.pulp_href]} ).task monitor_task(task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert repo.latest_version_href[-2] == expected_version versions = file_repository_version_api_client.list(repo.pulp_href) @@ -933,7 +943,8 @@ def _modify_and_validate(repo, content, expected_version, expected_total): @pytest.mark.parallel def test_content_in_repository_version_view( - file_repository_api_client, + pulpcore_bindings, + file_bindings, repository_versions_api_client, file_repository_factory, file_random_content_unit, @@ -945,7 +956,7 @@ def test_content_in_repository_version_view( "/pulp/api/v3/content/file/files/c4ed74cf-a806-490d-a25f-94c3c3dd2dd7/" ) - with pytest.raises(CoreApiException) as e: + with pytest.raises(pulpcore_bindings.ApiException) as e: repository_versions_api_client.list(content=non_existant_content_href) assert e.value.status == 400 @@ -955,9 +966,9 @@ def test_content_in_repository_version_view( # Add content to first repo and assert repo-ver list w/ content is correct body = {"add_content_units": [file_random_content_unit.pulp_href]} - task = file_repository_api_client.modify(repo.pulp_href, body).task + task = file_bindings.RepositoriesFileApi.modify(repo.pulp_href, body).task monitor_task(task) - repo = file_repository_api_client.read(repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(repo.pulp_href) assert repo.latest_version_href[-2] == "1" repo_vers = repository_versions_api_client.list(content=file_random_content_unit.pulp_href) @@ -965,9 +976,9 @@ def test_content_in_repository_version_view( assert repo_vers.results[0].pulp_href == repo.latest_version_href # Add content to second repo and assert repo-ver list w/ content is larger - task = file_repository_api_client.modify(repo2.pulp_href, body).task + task = file_bindings.RepositoriesFileApi.modify(repo2.pulp_href, body).task monitor_task(task) - repo2 = file_repository_api_client.read(repo2.pulp_href) + repo2 = file_bindings.RepositoriesFileApi.read(repo2.pulp_href) assert repo2.latest_version_href[-2] == "1" repo_vers = repository_versions_api_client.list(content=file_random_content_unit.pulp_href) diff --git a/pulpcore/tests/functional/api/using_plugin/test_tasks.py b/pulpcore/tests/functional/api/using_plugin/test_tasks.py index d0bc86f3d6d..f179bcbb297 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_tasks.py +++ b/pulpcore/tests/functional/api/using_plugin/test_tasks.py @@ -12,9 +12,9 @@ @pytest.fixture -def distribution(file_repo, file_distribution_api_client, gen_object_with_cleanup): +def distribution(file_bindings, file_repo, gen_object_with_cleanup): distribution = gen_object_with_cleanup( - file_distribution_api_client, + file_bindings.DistributionsFileApi, {"name": str(uuid4()), "base_path": str(uuid4()), "repository": file_repo.pulp_href}, ) @@ -42,8 +42,8 @@ def test_retrieve_task_with_fields_created_resources_only( @pytest.fixture def setup_filter_fixture( + file_bindings, file_repo, - file_repository_api_client, file_remote_ssl_factory, basic_manifest_path, tasks_api_client, @@ -52,9 +52,11 @@ def setup_filter_fixture( remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") body = RepositorySyncURL(remote=remote.pulp_href) - repo_sync_task = monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + repo_sync_task = monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task + ) - repo_update_action = file_repository_api_client.partial_update( + repo_update_action = file_bindings.RepositoriesFileApi.partial_update( file_repo.pulp_href, {"description": str(uuid4())} ) repo_update_task = tasks_api_client.read(repo_update_action.task) diff --git a/pulpcore/tests/functional/api/using_plugin/test_unlinking_repo.py b/pulpcore/tests/functional/api/using_plugin/test_unlinking_repo.py index 6c299308059..801324e10d4 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_unlinking_repo.py +++ b/pulpcore/tests/functional/api/using_plugin/test_unlinking_repo.py @@ -4,7 +4,7 @@ @pytest.mark.parallel def test_shared_remote_usage( - file_repository_api_client, + file_bindings, file_repository_factory, file_content_api_client, file_remote_ssl_factory, @@ -17,13 +17,13 @@ def test_shared_remote_usage( # Create and sync repos. repos = [file_repository_factory() for dummy in range(4)] sync_tasks = [ - file_repository_api_client.sync(repo.pulp_href, {"remote": remote.pulp_href}).task + file_bindings.RepositoriesFileApi.sync(repo.pulp_href, {"remote": remote.pulp_href}).task for repo in repos ] for task in sync_tasks: monitor_task(task) - repos = [(file_repository_api_client.read(repo.pulp_href)) for repo in repos] + repos = [(file_bindings.RepositoriesFileApi.read(repo.pulp_href)) for repo in repos] # Compare contents of repositories. contents = set() diff --git a/pulpcore/tests/functional/gpg_ascii_armor_signing_service.py b/pulpcore/tests/functional/gpg_ascii_armor_signing_service.py index ee64396f217..c34247ade5c 100644 --- a/pulpcore/tests/functional/gpg_ascii_armor_signing_service.py +++ b/pulpcore/tests/functional/gpg_ascii_armor_signing_service.py @@ -1,16 +1,13 @@ -import asyncio import json -import os -import stat import subprocess import uuid -import aiohttp +import requests import gnupg import pytest -signing_script_string = r"""#!/usr/bin/env bash +SIGNING_SCRIPT_STRING = r"""#!/usr/bin/env bash FILE_PATH=$1 SIGNATURE_PATH="$1.asc" @@ -33,26 +30,24 @@ @pytest.fixture(scope="session") def signing_script_path(signing_script_temp_dir, signing_gpg_homedir_path): - signing_script_filename = signing_script_temp_dir / "sign-metadata.sh" - with open(signing_script_filename, "w", 0o770) as sign_metadata_file: - sign_metadata_file.write( - signing_script_string.replace("HOMEDIRHERE", str(signing_gpg_homedir_path)) - ) + signing_script_file = signing_script_temp_dir / "sign-metadata.sh" + signing_script_file.write_text( + SIGNING_SCRIPT_STRING.replace("HOMEDIRHERE", str(signing_gpg_homedir_path)) + ) - st = os.stat(signing_script_filename) - os.chmod(signing_script_filename, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) + signing_script_file.chmod(0o755) - return signing_script_filename + return signing_script_file @pytest.fixture(scope="session") -def signing_script_temp_dir(tmpdir_factory): - yield tmpdir_factory.mktemp(str(uuid.uuid4())) +def signing_script_temp_dir(tmp_path_factory): + return tmp_path_factory.mktemp("sigining_script_dir") @pytest.fixture(scope="session") -def signing_gpg_homedir_path(tmpdir_factory): - return tmpdir_factory.mktemp(str(uuid.uuid4())) +def signing_gpg_homedir_path(tmp_path_factory): + return tmp_path_factory.mktemp("gpghome") @pytest.fixture @@ -87,18 +82,13 @@ def _sign_with_ascii_armored_detached_signing_service(filename): @pytest.fixture(scope="session") def signing_gpg_metadata(signing_gpg_homedir_path): """A fixture that returns a GPG instance and related metadata (i.e., fingerprint, keyid).""" - private_key_url = "https://raw.githubusercontent.com/pulp/pulp-fixtures/master/common/GPG-PRIVATE-KEY-fixture-signing" # noqa: E501 + PRIVATE_KEY_URL = "https://raw.githubusercontent.com/pulp/pulp-fixtures/master/common/GPG-PRIVATE-KEY-fixture-signing" # noqa: E501 - async def download_key(): - async with aiohttp.ClientSession() as session: - async with session.get(private_key_url) as response: - return await response.text() - - private_key_data = asyncio.run(download_key()) + response = requests.get(PRIVATE_KEY_URL) + response.raise_for_status() gpg = gnupg.GPG(gnupghome=signing_gpg_homedir_path) - - gpg.import_keys(private_key_data) + gpg.import_keys(response.content) fingerprint = gpg.list_keys()[0]["fingerprint"] keyid = gpg.list_keys()[0]["keyid"] diff --git a/pulpcore/tests/functional/utils.py b/pulpcore/tests/functional/utils.py index 1cb60c25f00..865a974ae5a 100644 --- a/pulpcore/tests/functional/utils.py +++ b/pulpcore/tests/functional/utils.py @@ -40,6 +40,21 @@ def __init__(self, task_group): self.task_group = task_group +class BindingsNamespace: + def __init__(self, module, client): + self.module = module + self.client = client + self.ApiException = self.module.exceptions.ApiException + + def __getattr__(self, name): + # __getattr__ is only consulted if nothing is found in __dict__. + assert name.endswith("Api") + + api_object = getattr(self.module, name)(self.client) + self.__dict__[name] = api_object + return api_object + + @dataclass class MockDownload: """Class for representing a downloaded file."""