diff --git a/CHANGES/+python_bindings.removal b/CHANGES/+python_bindings.removal new file mode 100644 index 0000000000..4b6af06565 --- /dev/null +++ b/CHANGES/+python_bindings.removal @@ -0,0 +1,2 @@ +Updated the OpenAPI generator version used to generate python bindings to 7.10.0. +This involves stricter client side validation of api calls when using the bindings. diff --git a/pulp_file/tests/functional/api/test_rbac.py b/pulp_file/tests/functional/api/test_rbac.py index dd8a1e18b7..311e0ad952 100644 --- a/pulp_file/tests/functional/api/test_rbac.py +++ b/pulp_file/tests/functional/api/test_rbac.py @@ -28,14 +28,16 @@ def _try_action(user, client, action, outcome, *args, **kwargs): action_api = getattr(client, f"{action}_with_http_info") try: with user: - response, status, _ = action_api(*args, **kwargs, _return_http_data_only=False) - if isinstance(response, AsyncOperationResponse): - response = monitor_task(response.task) + response = action_api(*args, **kwargs) + if isinstance(response.data, AsyncOperationResponse): + response.data = monitor_task(response.data.task) except ApiException as e: assert e.status == outcome, f"{e}" else: - assert status == outcome, f"User performed {action} when they shouldn't been able to" - return response + assert ( + response.status_code == outcome + ), f"User performed {action} when they shouldn't been able to" + return response.data return _try_action diff --git a/pulpcore/pytest_plugin.py b/pulpcore/pytest_plugin.py index 813d85c913..e49b34858c 100644 --- a/pulpcore/pytest_plugin.py +++ b/pulpcore/pytest_plugin.py @@ -585,7 +585,7 @@ def _random_artifact_factory(size=32, pulp_domain=None): kwargs["pulp_domain"] = pulp_domain temp_file = tmp_path / str(uuid.uuid4()) temp_file.write_bytes(os.urandom(size)) - return pulpcore_bindings.ArtifactsApi.create(temp_file, **kwargs) + return pulpcore_bindings.ArtifactsApi.create(str(temp_file), **kwargs) return _random_artifact_factory diff --git a/pulpcore/tests/functional/api/test_api_docs.py b/pulpcore/tests/functional/api/test_api_docs.py index 8c0aef8ed2..15c1c5819f 100644 --- a/pulpcore/tests/functional/api/test_api_docs.py +++ b/pulpcore/tests/functional/api/test_api_docs.py @@ -1,7 +1,6 @@ """Tests related to the api docs page.""" import pytest -from pulpcore.client.pulpcore import ApiException @pytest.fixture(scope="session") @@ -15,7 +14,7 @@ def test_valid_credentials(pulpcore_bindings, pulp_docs_url): Assert the API documentation is returned. """ - response = pulpcore_bindings.client.request("GET", pulp_docs_url) + response = pulpcore_bindings.client.rest_client.request("GET", pulp_docs_url) assert response.status == 200 @@ -26,7 +25,7 @@ def test_no_credentials(pulpcore_bindings, pulp_docs_url, anonymous_user): Assert the API documentation is returned. """ with anonymous_user: - response = pulpcore_bindings.client.request("GET", pulp_docs_url) + response = pulpcore_bindings.client.rest_client.request("GET", pulp_docs_url) assert response.status == 200 @@ -36,7 +35,6 @@ def test_http_method(pulpcore_bindings, pulp_docs_url): Assert an error is returned. """ - with pytest.raises(ApiException) as e: - pulpcore_bindings.client.request("POST", pulp_docs_url) + response = pulpcore_bindings.client.rest_client.request("POST", pulp_docs_url) - assert e.value.status == 405 + assert response.status == 405 diff --git a/pulpcore/tests/functional/api/test_auth.py b/pulpcore/tests/functional/api/test_auth.py index 68644e5040..3023b14dcf 100644 --- a/pulpcore/tests/functional/api/test_auth.py +++ b/pulpcore/tests/functional/api/test_auth.py @@ -4,11 +4,10 @@ `_. """ -import pytest import json - from base64 import b64encode -from pulpcore.client.pulpcore import ApiException + +import pytest from pulpcore.app import settings @@ -20,9 +19,9 @@ def test_base_auth_success(pulpcore_bindings, pulp_admin_user): Assert that a response indicating success is returned. """ with pulp_admin_user: - response, status, headers = pulpcore_bindings.ArtifactsApi.list_with_http_info() - assert status == 200 - assert headers["Content-Type"] == "application/json" + response = pulpcore_bindings.ArtifactsApi.list_with_http_info() + assert response.status_code == 200 + assert response.headers["Content-Type"] == "application/json" # Maybe test correlation ID as well? @@ -33,7 +32,7 @@ def test_base_auth_failure(pulpcore_bindings, invalid_user): Assert that a response indicating failure is returned. """ with invalid_user: - with pytest.raises(ApiException) as e: + with pytest.raises(pulpcore_bindings.ApiException) as e: pulpcore_bindings.ArtifactsApi.list() assert e.value.status == 401 @@ -50,7 +49,7 @@ def test_base_auth_required(pulpcore_bindings, anonymous_user): Assert that a response indicating failure is returned. """ with anonymous_user: - with pytest.raises(ApiException) as e: + with pytest.raises(pulpcore_bindings.ApiException) as e: pulpcore_bindings.ArtifactsApi.list() assert e.value.status == 401 @@ -79,8 +78,8 @@ def test_jq_header_remote_auth(pulpcore_bindings, anonymous_user): encoded_header = b64encode(bytes(header_content, "ascii")) pulpcore_bindings.ArtifactsApi.api_client.default_headers["x-rh-identity"] = encoded_header - _, status, _ = pulpcore_bindings.ArtifactsApi.list_with_http_info() - assert status == 200 + response = pulpcore_bindings.ArtifactsApi.list_with_http_info() + assert response.status_code == 200 @pytest.mark.parallel @@ -106,7 +105,7 @@ def test_jq_header_remote_auth_denied_by_wrong_header(pulpcore_bindings, anonymo encoded_header ) - with pytest.raises(ApiException) as exception: + with pytest.raises(pulpcore_bindings.ApiException) as exception: pulpcore_bindings.ArtifactsApi.list() assert exception.value.status == 401 @@ -127,7 +126,7 @@ def test_jq_header_remote_auth_denied_by_wrong_content(pulpcore_bindings, anonym pulpcore_bindings.ArtifactsApi.api_client.default_headers["x-rh-identity"] = encoded_header - with pytest.raises(ApiException) as exception: + with pytest.raises(pulpcore_bindings.ApiException) as exception: pulpcore_bindings.ArtifactsApi.list() assert exception.value.status == 401 diff --git a/pulpcore/tests/functional/api/test_correlation_id.py b/pulpcore/tests/functional/api/test_correlation_id.py index ffeca6024f..c88620fd65 100644 --- a/pulpcore/tests/functional/api/test_correlation_id.py +++ b/pulpcore/tests/functional/api/test_correlation_id.py @@ -1,7 +1,6 @@ def test_correlation_id(cid, pulpcore_bindings, monitor_task): """Test that a correlation can be passed as a header and logged.""" - response, status, headers = pulpcore_bindings.OrphansCleanupApi.cleanup_with_http_info({}) - monitor_task(response.task) - task = pulpcore_bindings.TasksApi.read(response.task) - assert headers["Correlation-ID"] == cid + response = pulpcore_bindings.OrphansCleanupApi.cleanup_with_http_info({}) + task = monitor_task(response.data.task) + assert response.headers["Correlation-ID"] == cid assert task.logging_cid == cid diff --git a/pulpcore/tests/functional/api/test_crd_artifacts.py b/pulpcore/tests/functional/api/test_crd_artifacts.py index 6a9f13274d..143907b1c1 100644 --- a/pulpcore/tests/functional/api/test_crd_artifacts.py +++ b/pulpcore/tests/functional/api/test_crd_artifacts.py @@ -7,7 +7,6 @@ import pytest from django.conf import settings -from pulpcore.client.pulpcore import ApiException @pytest.fixture @@ -21,12 +20,12 @@ def pulpcore_random_file(tmp_path): return {"name": name, "size": 1024, "digest": digest} -def _do_upload_valid_attrs(artifact_api, file, data): +def _do_upload_valid_attrs(pulpcore_bindings, file, data): """Upload a file with the given attributes.""" - artifact = artifact_api.create(file, **data) + artifact = pulpcore_bindings.ArtifactsApi.create(str(file), **data) # assumes ALLOWED_CONTENT_CHECKSUMS does NOT contain "md5" assert artifact.md5 is None, "MD5 {}".format(artifact.md5) - read_artifact = artifact_api.read(artifact.pulp_href) + read_artifact = pulpcore_bindings.ArtifactsApi.read(artifact.pulp_href) # assumes ALLOWED_CONTENT_CHECKSUMS does NOT contain "md5" assert read_artifact.md5 is None for key, val in artifact.to_dict().items(): @@ -54,9 +53,7 @@ def test_upload_valid_attrs(pulpcore_bindings, pulpcore_random_file, monitor_tas monitor_task( pulpcore_bindings.OrphansCleanupApi.cleanup({"orphan_protection_time": 0}).task ) - _do_upload_valid_attrs( - pulpcore_bindings.ArtifactsApi, pulpcore_random_file["name"], data - ) + _do_upload_valid_attrs(pulpcore_bindings, pulpcore_random_file["name"], data) def test_upload_empty_file(pulpcore_bindings, tmp_path, monitor_task): @@ -79,7 +76,7 @@ def test_upload_empty_file(pulpcore_bindings, tmp_path, monitor_task): pulpcore_bindings.OrphansCleanupApi.cleanup({"orphan_protection_time": 0}).task ) data = {key: file_attrs[key] for key in keys} - _do_upload_valid_attrs(pulpcore_bindings.ArtifactsApi, file, data) + _do_upload_valid_attrs(pulpcore_bindings, file, data) @pytest.mark.parallel @@ -98,16 +95,16 @@ def test_upload_invalid_attrs(pulpcore_bindings, pulpcore_random_file): for i in range(1, len(file_attrs) + 1): for keys in itertools.combinations(file_attrs, i): data = {key: file_attrs[key] for key in keys} - _do_upload_invalid_attrs(pulpcore_bindings.ArtifactsApi, pulpcore_random_file, data) + _do_upload_invalid_attrs(pulpcore_bindings, pulpcore_random_file, data) -def _do_upload_invalid_attrs(artifact_api, file, data): +def _do_upload_invalid_attrs(pulpcore_bindings, file, data): """Upload a file with the given attributes.""" - with pytest.raises(ApiException) as e: - artifact_api.create(file["name"], **data) + with pytest.raises(pulpcore_bindings.ApiException) as e: + pulpcore_bindings.ArtifactsApi.create(str(file["name"]), **data) assert e.value.status == 400 - artifacts = artifact_api.list() + artifacts = pulpcore_bindings.ArtifactsApi.list() for artifact in artifacts.results: assert artifact.sha256 != file["digest"] @@ -119,8 +116,8 @@ def test_upload_md5(pulpcore_bindings, pulpcore_random_file): Assumes ALLOWED_CONTENT_CHECKSUMS does NOT contain ``md5`` """ file_attrs = {"md5": str(uuid.uuid4()), "size": pulpcore_random_file["size"]} - with pytest.raises(ApiException) as e: - pulpcore_bindings.ArtifactsApi.create(pulpcore_random_file["name"], **file_attrs) + with pytest.raises(pulpcore_bindings.ApiException) as e: + pulpcore_bindings.ArtifactsApi.create(str(pulpcore_random_file["name"]), **file_attrs) assert e.value.status == 400 @@ -141,7 +138,7 @@ def test_upload_mixed_attrs(pulpcore_bindings, pulpcore_random_file): {"sha256": str(uuid.uuid4()), "size": pulpcore_random_file["size"]}, ) for data in invalid_data: - _do_upload_invalid_attrs(pulpcore_bindings.ArtifactsApi, pulpcore_random_file, data) + _do_upload_invalid_attrs(pulpcore_bindings, pulpcore_random_file, data) @pytest.mark.parallel @@ -152,19 +149,19 @@ def test_delete_artifact(pulpcore_bindings, pulpcore_random_file, gen_user): pytest.skip("this test only works for filesystem storage") media_root = settings.MEDIA_ROOT - artifact = pulpcore_bindings.ArtifactsApi.create(pulpcore_random_file["name"]) + artifact = pulpcore_bindings.ArtifactsApi.create(str(pulpcore_random_file["name"])) path_to_file = os.path.join(media_root, artifact.file) file_exists = os.path.exists(path_to_file) assert file_exists # try to delete as a regular (non-admin) user regular_user = gen_user() - with regular_user, pytest.raises(ApiException) as e: + with regular_user, pytest.raises(pulpcore_bindings.ApiException) as e: pulpcore_bindings.ArtifactsApi.delete(artifact.pulp_href) assert e.value.status == 403 # destroy artifact api is not allowed, even for admins - with pytest.raises(ApiException) as e: + with pytest.raises(pulpcore_bindings.ApiException) as e: pulpcore_bindings.ArtifactsApi.delete(artifact.pulp_href) assert e.value.status == 403 @@ -173,8 +170,8 @@ def test_delete_artifact(pulpcore_bindings, pulpcore_random_file, gen_user): def test_upload_artifact_as_a_regular_user(pulpcore_bindings, gen_user, pulpcore_random_file): """Regular users do not have permission to upload artifacts.""" regular_user = gen_user() - with regular_user, pytest.raises(ApiException) as e: - pulpcore_bindings.ArtifactsApi.create(pulpcore_random_file["name"]) + with regular_user, pytest.raises(pulpcore_bindings.ApiException) as e: + pulpcore_bindings.ArtifactsApi.create(str(pulpcore_random_file["name"])) assert e.value.status == 403 @@ -184,14 +181,14 @@ def test_list_and_retrieve_artifact_as_a_regular_user( ): """Regular users are not allowed to list and/or retrieve artifacts.""" regular_user = gen_user() - artifact = pulpcore_bindings.ArtifactsApi.create(pulpcore_random_file["name"]) + artifact = pulpcore_bindings.ArtifactsApi.create(str(pulpcore_random_file["name"])) # check if list is not allowed - with regular_user, pytest.raises(ApiException) as e: + with regular_user, pytest.raises(pulpcore_bindings.ApiException) as e: pulpcore_bindings.ArtifactsApi.list() assert e.value.status == 403 # check if retrieve is also not allowed - with regular_user, pytest.raises(ApiException) as e: + with regular_user, pytest.raises(pulpcore_bindings.ApiException) as e: pulpcore_bindings.ArtifactsApi.read(artifact.pulp_href) assert e.value.status == 403 diff --git a/pulpcore/tests/functional/api/test_filter.py b/pulpcore/tests/functional/api/test_filter.py index 740320367c..bdab02db2a 100644 --- a/pulpcore/tests/functional/api/test_filter.py +++ b/pulpcore/tests/functional/api/test_filter.py @@ -2,8 +2,6 @@ import random import uuid -from pulpcore.client.pulpcore.exceptions import ApiException, ApiTypeError - # Warning: Do not use HEX digits here! NAMES = ( @@ -97,7 +95,7 @@ def test_pulp_id_href_filter( assert redi_results.count == 0 # Test that filter fails when not a valid type - with pytest.raises(ApiException) as exc: + with pytest.raises(pulpcore_bindings.ApiException) as exc: pulpcore_bindings.ContentguardsApi.list(**{filter: ["hello"]}) assert exc.value.status == 400 @@ -135,7 +133,7 @@ def test_pulp_type_filter( assert "core/rbac" in c.pulp_href or "core/content_redirect" in c.pulp_href # Test filtering by invalid pulp_type - with pytest.raises(ApiException) as exc: + with pytest.raises(pulpcore_bindings.ApiException) as exc: pulpcore_bindings.ContentguardsApi.list(pulp_type__in=["i.invalid"]) assert exc.value.status == 400 @@ -145,17 +143,19 @@ def test_pulp_type_filter( ) # Test filter does not exist on child viewsets - with pytest.raises(ApiTypeError) as exc: + with pytest.raises((pulpcore_bindings.ApiTypeError, ValueError)) as exc: pulpcore_bindings.ContentguardsRbacApi.list(pulp_type__in=["core.rbac"]) - assert "Got an unexpected keyword argument 'pulp_type__in'" in str(exc.value) + assert "nexpected keyword argument" in str(exc.value) + assert "pulp_type__in" in str(exc.value) - with pytest.raises(ApiTypeError) as exc: + with pytest.raises((pulpcore_bindings.ApiTypeError, ValueError)) as exc: pulpcore_bindings.ContentguardsContentRedirectApi.list( pulp_type__in=["core.content_redirect"] ) - assert "Got an unexpected keyword argument 'pulp_type__in'" in str(exc.value) + assert "nexpected keyword argument" in str(exc.value) + assert "pulp_type__in" in str(exc.value) @pytest.mark.parallel @pytest.mark.parametrize( @@ -234,7 +234,7 @@ def test_q_filter_invalid( ): """Tests the "q" filter with invalid expressions.""" - with pytest.raises(ApiException) as exc_info: + with pytest.raises(pulpcore_bindings.ApiException) as exc_info: pulpcore_bindings.ContentguardsApi.list(q=q.format(*NAMES)) assert exc_info.value.status == 400 assert exc_info.value.body == exception_message diff --git a/pulpcore/tests/functional/api/test_openpgp.py b/pulpcore/tests/functional/api/test_openpgp.py index 172f86a320..019978889e 100644 --- a/pulpcore/tests/functional/api/test_openpgp.py +++ b/pulpcore/tests/functional/api/test_openpgp.py @@ -133,14 +133,14 @@ def test_key_upload(tmpdir, openpgp_keyring_factory, pulpcore_bindings, monitor_ bob_pub.write_text(BOB_PUB, "UTF-8") result = pulpcore_bindings.ContentOpenpgpPublickeyApi.create( - file=alice_pub, repository=keyring.pulp_href + file=str(alice_pub), repository=keyring.pulp_href ) monitor_task(result.task) result = pulpcore_bindings.ContentOpenpgpPublickeyApi.create( - file=bob_pub, repository=keyring.pulp_href + file=str(bob_pub), repository=keyring.pulp_href ) monitor_task(result.task) result = pulpcore_bindings.ContentOpenpgpPublickeyApi.create( - file=alice_revoked, repository=keyring.pulp_href + file=str(alice_revoked), repository=keyring.pulp_href ) monitor_task(result.task) diff --git a/pulpcore/tests/functional/api/test_status.py b/pulpcore/tests/functional/api/test_status.py index 861b431b95..d3df0ca675 100644 --- a/pulpcore/tests/functional/api/test_status.py +++ b/pulpcore/tests/functional/api/test_status.py @@ -4,7 +4,6 @@ from django.conf import settings from jsonschema import validate -from pulpcore.client.pulpcore import ApiException STATUS = { @@ -96,10 +95,10 @@ def test_post_authenticated( assert post_attr not in attrs # Try anyway to POST to /status/ status_url = f"{pulp_api_v3_url}status/" - with pytest.raises(ApiException) as e: - pulpcore_bindings.client.request("POST", status_url, headers={"User-Agent": test_path}) - - assert e.value.status == 405 + response = pulpcore_bindings.client.rest_client.request( + "POST", status_url, headers={"User-Agent": test_path} + ) + assert response.status == 405 @pytest.mark.parallel diff --git a/pulpcore/tests/functional/api/test_task_purge.py b/pulpcore/tests/functional/api/test_task_purge.py index 5a5855e812..600578cf65 100644 --- a/pulpcore/tests/functional/api/test_task_purge.py +++ b/pulpcore/tests/functional/api/test_task_purge.py @@ -5,8 +5,6 @@ from datetime import datetime, timedelta, timezone import pytest -from pulpcore.client.pulpcore import ApiException, Purge -from pulpcore.client.pulp_file import RepositorySyncURL from pulpcore.constants import TASK_STATES, TASK_FINAL_STATES @@ -94,7 +92,7 @@ def good_and_bad_task( def test_purge_before_time(pulpcore_bindings, good_and_bad_task, monitor_task): """Purge that should find no tasks to delete.""" _, _, pre_total, _, _ = good_and_bad_task - dta = Purge(finished_before="1970-01-01T00:00") + dta = pulpcore_bindings.Purge(finished_before="1970-01-01T00:00") response = pulpcore_bindings.TasksApi.purge(dta) task = monitor_task(response.task) new_total, new_final, new_summary = _task_summary(pulpcore_bindings) @@ -106,7 +104,7 @@ def test_purge_before_time(pulpcore_bindings, good_and_bad_task, monitor_task): def test_purge_defaults(pulpcore_bindings, good_and_bad_task, monitor_task): """Purge using defaults (finished_before=30-days-ago, state=completed)""" - dta = Purge() + dta = pulpcore_bindings.Purge() response = pulpcore_bindings.TasksApi.purge(dta) monitor_task(response.task) @@ -124,18 +122,18 @@ def test_purge_all(pulpcore_bindings, good_and_bad_task, monitor_task, async_tas good_task, bad_task, pre_total, pre_final, pre_summary = good_and_bad_task states = list(TASK_FINAL_STATES) - dta = Purge(finished_before=TOMORROW_STR, states=states) + dta = pulpcore_bindings.Purge(finished_before=TOMORROW_STR, states=states) response = pulpcore_bindings.TasksApi.purge(dta) task = monitor_task(response.task) 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): + with pytest.raises(pulpcore_bindings.ApiException): pulpcore_bindings.TasksApi.read(good_task.pulp_href) # Make sure failed sync-task is gone - with pytest.raises(ApiException): + with pytest.raises(pulpcore_bindings.ApiException): pulpcore_bindings.TasksApi.read(bad_task.pulp_href) # Make sure we reported the deletions @@ -147,12 +145,12 @@ def test_purge_leave_one(pulpcore_bindings, good_and_bad_task, monitor_task, asy # Leave only the failed sync good_task, bad_task, pre_total, pre_final, pre_summary = good_and_bad_task - dta = Purge(finished_before=bad_task.finished_at) + dta = pulpcore_bindings.Purge(finished_before=bad_task.finished_at) response = pulpcore_bindings.TasksApi.purge(dta) task = monitor_task(response.task) # Make sure good task is gone - with pytest.raises(ApiException): + with pytest.raises(pulpcore_bindings.ApiException): pulpcore_bindings.TasksApi.read(good_task.pulp_href) # Make sure the bad task still exists @@ -164,7 +162,7 @@ def test_purge_leave_one(pulpcore_bindings, good_and_bad_task, monitor_task, asy def test_purge_only_failed(pulpcore_bindings, good_and_bad_task, monitor_task): """Purge all failed tasks only.""" - dta = Purge(finished_before=TOMORROW_STR, states=["failed"]) + dta = pulpcore_bindings.Purge(finished_before=TOMORROW_STR, states=["failed"]) response = pulpcore_bindings.TasksApi.purge(dta) monitor_task(response.task) # good task should exist @@ -172,28 +170,28 @@ def test_purge_only_failed(pulpcore_bindings, good_and_bad_task, monitor_task): pulpcore_bindings.TasksApi.read(good_task.pulp_href) # bad task should not exist - with pytest.raises(ApiException): + with pytest.raises(pulpcore_bindings.ApiException): pulpcore_bindings.TasksApi.read(bad_task.pulp_href) def test_bad_date(pulpcore_bindings, good_and_bad_task): """What happens if you use a bad date format?""" - dta = Purge(finished_before="THISISNOTADATE") - with pytest.raises(ApiException): + with pytest.raises((pulpcore_bindings.ApiException, ValueError)): + dta = pulpcore_bindings.Purge(finished_before="THISISNOTADATE") pulpcore_bindings.TasksApi.purge(dta) def test_bad_state(pulpcore_bindings, good_and_bad_task): """What happens if you specify junk for a state?""" - dta = Purge(finished_before=TOMORROW_STR, states=["BAD STATE"]) - with pytest.raises(ApiException): + with pytest.raises((pulpcore_bindings.ApiException, ValueError)): + dta = pulpcore_bindings.Purge(finished_before=TOMORROW_STR, states=["BAD STATE"]) pulpcore_bindings.TasksApi.purge(dta) def test_not_final_state(pulpcore_bindings, good_and_bad_task): """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): + with pytest.raises((pulpcore_bindings.ApiException, ValueError)): + dta = pulpcore_bindings.Purge(finished_before=TOMORROW_STR, states=["running"]) pulpcore_bindings.TasksApi.purge(dta) @@ -208,7 +206,7 @@ def test_purge_with_different_users( ): # create admin related data admin_remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - admin_sync_data = RepositorySyncURL(remote=admin_remote.pulp_href) + admin_sync_data = file_bindings.RepositorySyncURL(remote=admin_remote.pulp_href) admin_repo = file_repository_factory() # create random user related data @@ -221,7 +219,7 @@ def test_purge_with_different_users( ) with user: user_remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - user_sync_data = RepositorySyncURL(remote=user_remote.pulp_href) + user_sync_data = file_bindings.RepositorySyncURL(remote=user_remote.pulp_href) user_repo = file_repository_factory() # Sync as admin @@ -230,7 +228,7 @@ def test_purge_with_different_users( # Purge as user states = list(TASK_FINAL_STATES) - data = Purge(finished_before=TOMORROW_STR, states=states) + data = pulpcore_bindings.Purge(finished_before=TOMORROW_STR, states=states) with user: response = pulpcore_bindings.TasksApi.purge(data) task = monitor_task(response.task) @@ -245,13 +243,13 @@ def test_purge_with_different_users( # Purge as user states = list(TASK_FINAL_STATES) - data = Purge(finished_before=TOMORROW_STR, states=states) + data = pulpcore_bindings.Purge(finished_before=TOMORROW_STR, states=states) with user: response = pulpcore_bindings.TasksApi.purge(data) monitor_task(response.task) # Make sure task DOES NOT exist - with pytest.raises(ApiException): + with pytest.raises(pulpcore_bindings.ApiException): pulpcore_bindings.TasksApi.read(sync_task.pulp_href) # Sync as user @@ -261,10 +259,10 @@ def test_purge_with_different_users( # Purge as ADMIN states = list(TASK_FINAL_STATES) - data = Purge(finished_before=TOMORROW_STR, states=states) + data = pulpcore_bindings.Purge(finished_before=TOMORROW_STR, states=states) response = pulpcore_bindings.TasksApi.purge(data) monitor_task(response.task) # Make sure task DOES NOT exist - with pytest.raises(ApiException): + with pytest.raises(pulpcore_bindings.ApiException): pulpcore_bindings.TasksApi.read(sync_task.pulp_href) diff --git a/pulpcore/tests/functional/api/test_tasking.py b/pulpcore/tests/functional/api/test_tasking.py index 06584d5ec2..5d6e5a5376 100644 --- a/pulpcore/tests/functional/api/test_tasking.py +++ b/pulpcore/tests/functional/api/test_tasking.py @@ -227,15 +227,6 @@ def test_retrieve_task_using_valid_worker(task, pulpcore_bindings): assert response.results and response.count -@pytest.mark.parallel -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: - 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, pulpcore_bindings): """Expects to retrieve a task using a valid date.""" @@ -334,28 +325,6 @@ def test_task_version_prevent_pickup(dispatch_task, pulpcore_bindings): pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) -def test_emmiting_unblocked_task_telemetry(dispatch_task, pulpcore_bindings, pulp_settings): - # Checking online workers ready to get a task - workers_online = pulpcore_bindings.WorkersApi.list(online="true").count - - # We need to generate long running tasks to block the workers from executing other tasks - resident_task_hrefs = [ - dispatch_task("pulpcore.app.tasks.test.sleep", args=(30,)) - for worker in range(workers_online) - ] - - # Then we dispatch a quick unblockable task just to keep it waiting in the queue - task_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,)) - - task = pulpcore_bindings.TasksApi.read(task_href) - assert task.state == "waiting" - - [ - pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) - for task_href in resident_task_hrefs - ] - - @pytest.mark.parallel def test_correct_task_ownership( dispatch_task, pulpcore_bindings, gen_user, file_repository_factory diff --git a/pulpcore/tests/functional/api/test_upload.py b/pulpcore/tests/functional/api/test_upload.py index 0dd8e87b0e..cac05ae10c 100644 --- a/pulpcore/tests/functional/api/test_upload.py +++ b/pulpcore/tests/functional/api/test_upload.py @@ -24,15 +24,15 @@ def _create_chunks(number_chunks=2, chunk_sizes=None): hasher = hashlib.new("sha256") start = 0 for chunk_size in chunk_sizes: - name = tmp_path / str(uuid.uuid4()) - with open(name, "wb") as f: - content = os.urandom(chunk_size) - hasher.update(content) - f.write(content) - f.flush() + chunk_file = tmp_path / str(uuid.uuid4()) + content = os.urandom(chunk_size) + hasher.update(content) + chunk_file.write_bytes(content) content_sha = hashlib.sha256(content).hexdigest() end = start + chunk_size - 1 - chunks["chunks"].append((name, f"bytes {start}-{end}/{chunks['size']}", content_sha)) + chunks["chunks"].append( + (str(chunk_file), f"bytes {start}-{end}/{chunks['size']}", content_sha) + ) start = start + chunk_size chunks["digest"] = hasher.hexdigest() return chunks @@ -138,28 +138,27 @@ def test_upload_response( expected_keys = ["pulp_href", "pulp_created", "size"] for key in expected_keys: - assert getattr(upload, key) + assert hasattr(upload, key) for data in file_chunks_data["chunks"]: kwargs = {"file": data[0], "content_range": data[1], "upload_href": upload.pulp_href} response = pulpcore_bindings.UploadsApi.update(**kwargs) for key in expected_keys: - assert getattr(response, key) + assert hasattr(response, key) upload = pulpcore_bindings.UploadsApi.read(upload.pulp_href) expected_keys.append("chunks") for key in expected_keys: - assert getattr(upload, key) + assert hasattr(upload, key) expected_chunks = [ {"offset": 0, "size": 6291456}, {"offset": 6291456, "size": 4194304}, ] - - sorted_chunks_response = sorted([c.to_dict() for c in upload.chunks], key=lambda i: i["offset"]) + sorted_chunks_response = sorted([c.dict() for c in upload.chunks], key=lambda i: i["offset"]) assert sorted_chunks_response == expected_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 9029374865..ac068fe1d9 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_access.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_access.py @@ -62,7 +62,7 @@ def test_upload_file_on_demand_already( assert content.artifact is None file_content = file_fixtures_root / "basic" / content.relative_path - body = {"relative_path": content.relative_path, "file": file_content} + body = {"relative_path": content.relative_path, "file": str(file_content)} task = monitor_task(file_bindings.ContentFilesApi.create(**body).task) assert len(task.created_resources) == 1 assert task.created_resources[0] == content.pulp_href 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 0cb6355a66..945361cdb8 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_crud_repos.py +++ b/pulpcore/tests/functional/api/using_plugin/test_crud_repos.py @@ -159,16 +159,6 @@ def _do_update_attr(attr, partial=False): assert file_bindings.DistributionsFileApi.read(distribution_w_repo).repository is None assert file_bindings.DistributionsFileApi.read(distribution_w_publication).publication is None - # Attempt to create repository passing extraneous invalid parameter. - # Assert response returns an error 400 including ["Unexpected field"]. - with pytest.raises(ApiException) as e: - file_bindings.RepositoriesFileApi.create({"name": str(uuid4()), "foo": "bar"}) - - assert e.value.status == 400 - error_body = json.loads(e.value.body) - assert "foo" in error_body - assert "Unexpected field" in error_body["foo"] - @pytest.mark.parallel def test_crud_remotes_full_workflow( @@ -262,25 +252,11 @@ def _compare_results(data, received): new_remote = file_bindings.RemotesFileApi.read(remote.pulp_href) _compare_results(data, new_remote) - # Test invalid float < 0 - data = { - "total_timeout": -1.0, - } - with pytest.raises(ApiException): - file_bindings.RemotesFileApi.partial_update(remote.pulp_href, data) - - # Test invalid non-float - data = { - "connect_timeout": "abc", - } - with pytest.raises(ApiException): - file_bindings.RemotesFileApi.partial_update(remote.pulp_href, data) - # Test reset to empty data = { - "total_timeout": False, + "total_timeout": None, "connect_timeout": None, - "sock_connect_timeout": False, + "sock_connect_timeout": None, "sock_read_timeout": None, } response = file_bindings.RemotesFileApi.partial_update(remote.pulp_href, data) @@ -289,12 +265,6 @@ def _compare_results(data, received): _compare_results(data, new_remote) # Test that headers value must be a list of dicts - data = {"headers": {"Connection": "keep-alive"}} - with pytest.raises(ApiException): - file_bindings.RemotesFileApi.partial_update(remote.pulp_href, data) - data = {"headers": [1, 2, 3]} - with pytest.raises(ApiException): - file_bindings.RemotesFileApi.partial_update(remote.pulp_href, data) data = {"headers": [{"Connection": "keep-alive"}]} response = file_bindings.RemotesFileApi.partial_update(remote.pulp_href, data) monitor_task(response.task) diff --git a/pulpcore/tests/functional/api/using_plugin/test_distributions.py b/pulpcore/tests/functional/api/using_plugin/test_distributions.py index d9bbb93387..1cae19689d 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_distributions.py +++ b/pulpcore/tests/functional/api/using_plugin/test_distributions.py @@ -4,11 +4,6 @@ import json from uuid import uuid4 -from pulpcore.client.pulp_file import ( - RepositorySyncURL, - FileFileDistribution, - FileFilePublication, -) from pulpcore.client.pulp_file.exceptions import ApiException @@ -24,7 +19,7 @@ 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) + body = file_bindings.RepositorySyncURL(remote=remote.pulp_href) monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) # Remove content to create two more repository versions @@ -44,7 +39,7 @@ def test_crud_publication_distribution( # Create a publication from version 2 repo_versions = file_bindings.RepositoriesFileVersionsApi.list(file_repo.pulp_href).results - publish_data = FileFilePublication(repository_version=repo_versions[2].pulp_href) + publish_data = file_bindings.FileFilePublication(repository_version=repo_versions[2].pulp_href) publication = gen_object_with_cleanup(file_bindings.PublicationsFileApi, publish_data) distribution_data = { "publication": publication.pulp_href, @@ -90,7 +85,7 @@ def test_crud_publication_distribution( new_name = str(uuid4()) distribution.name = new_name monitor_task( - file_bindings.DistributionsFileApi.update(distribution.pulp_href, distribution).task + file_bindings.DistributionsFileApi.update(distribution.pulp_href, distribution.dict()).task ) distribution = file_bindings.DistributionsFileApi.read(distribution.pulp_href) assert distribution.name == new_name @@ -99,7 +94,7 @@ def test_crud_publication_distribution( new_base_path = str(uuid4()) distribution.base_path = new_base_path monitor_task( - file_bindings.DistributionsFileApi.update(distribution.pulp_href, distribution).task + file_bindings.DistributionsFileApi.update(distribution.pulp_href, distribution.dict()).task ) distribution = file_bindings.DistributionsFileApi.read(distribution.pulp_href) assert distribution.base_path == new_base_path @@ -180,7 +175,7 @@ def generate_repo_with_content(): repo = file_repository_factory() 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) + body = file_bindings.RepositorySyncURL(remote=remote.pulp_href) task_response = file_bindings.RepositoriesFileApi.sync(repo.pulp_href, body).task version_href = monitor_task(task_response).created_resources[0] content = file_bindings.ContentFilesApi.list(repository_version_added=version_href).results[ @@ -190,11 +185,11 @@ def generate_repo_with_content(): repo1, content1 = generate_repo_with_content() - publish_data = FileFilePublication(repository=repo1.pulp_href) + publish_data = file_bindings.FileFilePublication(repository=repo1.pulp_href) publication = gen_object_with_cleanup(file_bindings.PublicationsFileApi, publish_data) # test if a publication attached to a distribution exposes the published content - data = FileFileDistribution( + data = file_bindings.FileFileDistribution( name=str(uuid4()), base_path=str(uuid4()), publication=publication.pulp_href ) distribution_pub1 = gen_object_with_cleanup(file_bindings.DistributionsFileApi, data) @@ -203,9 +198,9 @@ def generate_repo_with_content(): assert [distribution_pub1] == results # test if a publication pointing to repository version no. 0 does not expose any content - publish_data = FileFilePublication(repository_version=repo1.versions_href + "0/") + publish_data = file_bindings.FileFilePublication(repository_version=repo1.versions_href + "0/") publication_version_0 = gen_object_with_cleanup(file_bindings.PublicationsFileApi, publish_data) - data = FileFileDistribution( + data = file_bindings.FileFileDistribution( name=str(uuid4()), base_path=str(uuid4()), publication=publication_version_0.pulp_href ) gen_object_with_cleanup(file_bindings.DistributionsFileApi, data) @@ -215,7 +210,7 @@ def generate_repo_with_content(): # test if a repository assigned to a distribution exposes the content available in the latest # publication for that repository's versions - data = FileFileDistribution( + data = file_bindings.FileFileDistribution( name=str(uuid4()), base_path=str(uuid4()), repository=repo1.pulp_href ) distribution_repopub = gen_object_with_cleanup(file_bindings.DistributionsFileApi, data) @@ -237,20 +232,20 @@ def generate_repo_with_content(): monitor_task(response.task) assert [] == file_bindings.DistributionsFileApi.list(with_content=content2.pulp_href).results - publish_data = FileFilePublication(repository=repo1.pulp_href) + publish_data = file_bindings.FileFilePublication(repository=repo1.pulp_href) new_publication = gen_object_with_cleanup(file_bindings.PublicationsFileApi, publish_data) # test later (20 lines below) if the publication now exposes the recently added content in the # affected distributions (i.e., the distribution with the reference to a repository and the # new one) - data = FileFileDistribution( + data = file_bindings.FileFileDistribution( name="pub3", base_path="pub3", publication=new_publication.pulp_href ) distribution_pub3 = gen_object_with_cleanup(file_bindings.DistributionsFileApi, data) # test if a repository without any attached publication does not expose any kind of content # to a user even though the content is still present in the latest repository version - data = FileFileDistribution( + data = file_bindings.FileFileDistribution( name=str(uuid4()), base_path=str(uuid4()), repository=repo2.pulp_href ) distribution_repo_only = gen_object_with_cleanup(file_bindings.DistributionsFileApi, data) @@ -262,7 +257,7 @@ def generate_repo_with_content(): assert {distribution_pub3.pulp_href, distribution_repopub.pulp_href} == results # create a publication to see whether the content of the second repository is now served or not - publish_data = FileFilePublication(repository=repo2.pulp_href) + publish_data = file_bindings.FileFilePublication(repository=repo2.pulp_href) gen_object_with_cleanup(file_bindings.PublicationsFileApi, publish_data) results = set( diff --git a/pulpcore/tests/functional/api/using_plugin/test_filesystemexport.py b/pulpcore/tests/functional/api/using_plugin/test_filesystemexport.py index 7c54bfbf12..2875e93027 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_filesystemexport.py +++ b/pulpcore/tests/functional/api/using_plugin/test_filesystemexport.py @@ -51,10 +51,6 @@ def test_create_exporter_with_custom_method_field(create_exporter): exporter, _ = create_exporter({"method": "symlink"}) assert "symlink" == exporter.method - with pytest.raises(ApiException) as ae: - create_exporter({"method": "invalid"}) - assert 400 == ae.value.status - @pytest.mark.parallel def test_read_exporter(pulpcore_bindings, create_exporter): diff --git a/pulpcore/tests/functional/api/using_plugin/test_migrate.py b/pulpcore/tests/functional/api/using_plugin/test_migrate.py index 37bf5da395..b5a5da750b 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_migrate.py +++ b/pulpcore/tests/functional/api/using_plugin/test_migrate.py @@ -39,8 +39,9 @@ def test_migrate_default_domain(pulpcore_bindings, pulp_domain_enabled): kwargs = {} if pulp_domain_enabled: kwargs["pulp_domain"] = domain.name + body = {"storage_class": "pulpcore.app.models.storage.FileSystem", "storage_settings": {}} with pytest.raises(pulpcore_bindings.ApiException) as e: - pulpcore_bindings.DomainsApi.migrate({}, **kwargs) + pulpcore_bindings.DomainsApi.migrate(body, **kwargs) assert e.value.status == 400 assert "Default domain can not be migrated" in e.value.body diff --git a/pulpcore/tests/functional/api/using_plugin/test_orphans.py b/pulpcore/tests/functional/api/using_plugin/test_orphans.py index 986087cc80..a25b0d8328 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_orphans.py +++ b/pulpcore/tests/functional/api/using_plugin/test_orphans.py @@ -3,8 +3,6 @@ import os import pytest -from pulpcore.app import settings - def test_content_orphan_filter( file_bindings, @@ -16,11 +14,11 @@ def test_content_orphan_filter( # test orphan_for with different values content_units = file_bindings.ContentFilesApi.list( - orphaned_for="0", pulp_href__in=[content_unit.pulp_href] + orphaned_for=0, pulp_href__in=[content_unit.pulp_href] ) assert content_units.count == 1 content_units = file_bindings.ContentFilesApi.list( - orphaned_for="100", pulp_href__in=[content_unit.pulp_href] + orphaned_for=100, pulp_href__in=[content_unit.pulp_href] ) assert content_units.count == 0 @@ -30,7 +28,7 @@ def test_content_orphan_filter( task = file_bindings.RepositoriesFileApi.modify(repo.pulp_href, body).task monitor_task(task) content_units = file_bindings.ContentFilesApi.list( - orphaned_for="0", pulp_href__in=[content_unit.pulp_href] + orphaned_for=0, pulp_href__in=[content_unit.pulp_href] ) assert content_units.count == 0 @@ -43,11 +41,11 @@ def test_artifact_orphan_filter( ): # test orphan_for with different values artifacts = pulpcore_bindings.ArtifactsApi.list( - orphaned_for="0", pulp_href__in=[random_artifact.pulp_href] + orphaned_for=0, pulp_href__in=[random_artifact.pulp_href] ) assert artifacts.count == 1 artifacts = pulpcore_bindings.ArtifactsApi.list( - orphaned_for="100", pulp_href__in=[random_artifact.pulp_href] + orphaned_for=100, pulp_href__in=[random_artifact.pulp_href] ) assert artifacts.count == 0 @@ -57,7 +55,7 @@ def test_artifact_orphan_filter( ).task monitor_task(task) artifacts = pulpcore_bindings.ArtifactsApi.list( - orphaned_for="0", pulp_href__in=[random_artifact.pulp_href] + orphaned_for=0, pulp_href__in=[random_artifact.pulp_href] ) assert artifacts.count == 0 @@ -68,16 +66,17 @@ def test_orphans_delete( random_artifact, file_random_content_unit, monitor_task, + pulp_settings, ): # Verify that the system contains the orphan content unit and the orphan artifact. content_unit = file_bindings.ContentFilesApi.read(file_random_content_unit.pulp_href) artifact = pulpcore_bindings.ArtifactsApi.read(random_artifact.pulp_href) - if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": + if pulp_settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": # Verify that the artifacts are on disk relative_path = pulpcore_bindings.ArtifactsApi.read(content_unit.artifact).file - artifact_path1 = os.path.join(settings.MEDIA_ROOT, relative_path) - artifact_path2 = os.path.join(settings.MEDIA_ROOT, artifact.file) + artifact_path1 = os.path.join(pulp_settings.MEDIA_ROOT, relative_path) + artifact_path2 = os.path.join(pulp_settings.MEDIA_ROOT, artifact.file) assert os.path.exists(artifact_path1) is True assert os.path.exists(artifact_path2) is True @@ -85,11 +84,11 @@ def test_orphans_delete( monitor_task(pulpcore_bindings.OrphansApi.delete().task) # Assert that the content unit and artifact are gone - if settings.ORPHAN_PROTECTION_TIME == 0: + if pulp_settings.ORPHAN_PROTECTION_TIME == 0: with pytest.raises(file_bindings.ApiException) as exc: file_bindings.ContentFilesApi.read(file_random_content_unit.pulp_href) assert exc.value.status == 404 - if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": + if pulp_settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": assert os.path.exists(artifact_path1) is False assert os.path.exists(artifact_path2) is False @@ -100,6 +99,7 @@ def test_orphans_cleanup( random_artifact, file_random_content_unit, monitor_task, + pulp_settings, ): # Cleanup orphans with a nonzero orphan_protection_time monitor_task(pulpcore_bindings.OrphansCleanupApi.cleanup({"orphan_protection_time": 10}).task) @@ -108,11 +108,11 @@ def test_orphans_cleanup( content_unit = file_bindings.ContentFilesApi.read(file_random_content_unit.pulp_href) artifact = pulpcore_bindings.ArtifactsApi.read(random_artifact.pulp_href) - if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": + if pulp_settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": # Verify that the artifacts are on disk relative_path = pulpcore_bindings.ArtifactsApi.read(content_unit.artifact).file - artifact_path1 = os.path.join(settings.MEDIA_ROOT, relative_path) - artifact_path2 = os.path.join(settings.MEDIA_ROOT, artifact.file) + artifact_path1 = os.path.join(pulp_settings.MEDIA_ROOT, relative_path) + artifact_path2 = os.path.join(pulp_settings.MEDIA_ROOT, artifact.file) assert os.path.exists(artifact_path1) is True assert os.path.exists(artifact_path2) is True @@ -123,7 +123,7 @@ def test_orphans_cleanup( with pytest.raises(file_bindings.ApiException) as exc: file_bindings.ContentFilesApi.read(file_random_content_unit.pulp_href) assert exc.value.status == 404 - if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": + if pulp_settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": assert os.path.exists(artifact_path1) is False assert os.path.exists(artifact_path2) is False diff --git a/pulpcore/tests/functional/api/using_plugin/test_proxy.py b/pulpcore/tests/functional/api/using_plugin/test_proxy.py index 77cd41211c..473b562c8f 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_proxy.py +++ b/pulpcore/tests/functional/api/using_plugin/test_proxy.py @@ -1,14 +1,11 @@ import pytest from pulpcore.tests.functional.utils import PulpTaskError -from pulpcore.client.pulp_file import ( - RepositorySyncURL, -) import sys def _run_basic_sync_and_assert(file_bindings, monitor_task, remote, file_repo): - body = RepositorySyncURL(remote=remote.pulp_href) + body = file_bindings.RepositorySyncURL(remote=remote.pulp_href) monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) # Check content is present, but no artifacts are there @@ -73,7 +70,7 @@ def test_sync_https_through_http_proxy_with_auth( remote_on_demand = file_remote_ssl_factory( manifest_path=basic_manifest_path, policy="on_demand", - tls_validation="true", + tls_validation=True, proxy_url=http_proxy_with_auth.proxy_url, proxy_username=http_proxy_with_auth.username, proxy_password=http_proxy_with_auth.password, @@ -97,7 +94,7 @@ def test_sync_https_through_http_proxy_with_auth_but_auth_not_configured( remote_on_demand = file_remote_ssl_factory( manifest_path=basic_manifest_path, policy="on_demand", - tls_validation="true", + tls_validation=True, proxy_url=http_proxy_with_auth.proxy_url, ) @@ -123,7 +120,7 @@ def test_sync_http_through_https_proxy( manifest_path=basic_manifest_path, policy="on_demand", proxy_url=https_proxy.proxy_url, - tls_validation="false", # We instead should have a `proxy_insecure` option + tls_validation=False, # We instead should have a `proxy_insecure` option ) _run_basic_sync_and_assert(file_bindings, monitor_task, remote_on_demand, file_repo) diff --git a/pulpcore/tests/functional/api/using_plugin/test_repair.py b/pulpcore/tests/functional/api/using_plugin/test_repair.py index 2f690f13a6..7785ef5672 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_repair.py +++ b/pulpcore/tests/functional/api/using_plugin/test_repair.py @@ -3,9 +3,6 @@ from django.core.files.storage import default_storage from random import sample -from pulpcore.client.pulpcore import Repair -from pulpcore.client.pulp_file import RepositorySyncURL - from pulpcore.tests.functional.utils import get_files_in_manifest @@ -20,7 +17,7 @@ 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) + sync_data = file_bindings.RepositorySyncURL(remote=remote.pulp_href) monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, sync_data).task) repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) @@ -51,14 +48,14 @@ def test_repair_global_with_checksums( 6. Assert that the repair task reported no missing, corrupted or repaired units. """ # STEP 3 - response = pulpcore_bindings.RepairApi.post(Repair(verify_checksums=True)) + response = pulpcore_bindings.RepairApi.post(pulpcore_bindings.Repair(verify_checksums=True)) results = monitor_task(response.task) # STEP 4 _verify_repair_results(results, missing=1, corrupted=1, repaired=2) # STEP 5 - response = pulpcore_bindings.RepairApi.post(Repair(verify_checksums=True)) + response = pulpcore_bindings.RepairApi.post(pulpcore_bindings.Repair(verify_checksums=True)) results = monitor_task(response.task) # STEP 6 @@ -66,7 +63,10 @@ def test_repair_global_with_checksums( def test_repair_global_without_checksums( - pulpcore_bindings, repository_with_corrupted_artifacts, monitor_task + pulpcore_bindings, + repository_with_corrupted_artifacts, + monitor_task, + delete_orphans_pre, ): """Test whether missing files can be redownloaded. @@ -80,21 +80,21 @@ def test_repair_global_without_checksums( 8. Assert that the repair task reported one corrupted and one repaired unit. """ # STEP 3 - response = pulpcore_bindings.RepairApi.post(Repair(verify_checksums=False)) + response = pulpcore_bindings.RepairApi.post(pulpcore_bindings.Repair(verify_checksums=False)) results = monitor_task(response.task) # STEP 4 _verify_repair_results(results, missing=1, repaired=1) # STEP 5 - response = pulpcore_bindings.RepairApi.post(Repair(verify_checksums=False)) + response = pulpcore_bindings.RepairApi.post(pulpcore_bindings.Repair(verify_checksums=False)) results = monitor_task(response.task) # STEP 6 _verify_repair_results(results) # STEP 7 - response = pulpcore_bindings.RepairApi.post(Repair(verify_checksums=True)) + response = pulpcore_bindings.RepairApi.post(pulpcore_bindings.Repair(verify_checksums=True)) results = monitor_task(response.task) # STEP 8 @@ -117,7 +117,7 @@ def test_repair_repository_version_with_checksums( # STEP 3 latest_version = repository_with_corrupted_artifacts.latest_version_href response = file_bindings.RepositoriesFileVersionsApi.repair( - latest_version, Repair(verify_checksums=True) + latest_version, file_bindings.Repair(verify_checksums=True) ) results = monitor_task(response.task) @@ -126,7 +126,7 @@ def test_repair_repository_version_with_checksums( # STEP 5 response = file_bindings.RepositoriesFileVersionsApi.repair( - latest_version, Repair(verify_checksums=True) + latest_version, file_bindings.Repair(verify_checksums=True) ) results = monitor_task(response.task) @@ -152,7 +152,7 @@ def test_repair_repository_version_without_checksums( # STEP 3 latest_version = repository_with_corrupted_artifacts.latest_version_href response = file_bindings.RepositoriesFileVersionsApi.repair( - latest_version, Repair(verify_checksums=False) + latest_version, file_bindings.Repair(verify_checksums=False) ) results = monitor_task(response.task) @@ -161,7 +161,7 @@ def test_repair_repository_version_without_checksums( # STEP 5 response = file_bindings.RepositoriesFileVersionsApi.repair( - latest_version, Repair(verify_checksums=False) + latest_version, file_bindings.Repair(verify_checksums=False) ) results = monitor_task(response.task) @@ -170,7 +170,7 @@ def test_repair_repository_version_without_checksums( # STEP 7 response = file_bindings.RepositoriesFileVersionsApi.repair( - latest_version, Repair(verify_checksums=True) + latest_version, file_bindings.Repair(verify_checksums=True) ) results = monitor_task(response.task) 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 115dcba355..1c5757f495 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py +++ b/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py @@ -384,42 +384,10 @@ def test_content_immutable_repo_version( Test that POST/PUT/PATCH operations are not allowed on repository versions. """ - file_repo = file_repository_factory() - remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - task = file_bindings.RepositoriesFileApi.sync( - file_repo.pulp_href, {"remote": remote.pulp_href} - ).task - monitor_task(task) - - repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) - assert repo.latest_version_href[-2] == "1" - repo_ver_attributes = dir(file_bindings.RepositoriesFileVersionsApi) - - # POST assertion - for attr in repo_ver_attributes: - assert "create" not in attr - 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(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 - - # PATCH assertion - for attr in repo_ver_attributes: - assert "partial_update" not in attr - 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 + api = file_bindings.RepositoriesFileVersionsApi + assert hasattr(api, "create") is False + assert hasattr(api, "update") is False + assert hasattr(api, "partial_update") is False @pytest.mark.parallel @@ -441,19 +409,6 @@ def test_filter_repo_version( assert repo.latest_version_href[-2] == "9" repo_versions = file_bindings.RepositoriesFileVersionsApi.list(repo.pulp_href).results - # Filter repository version by invalid date. - criteria = str(uuid4()) - for params in ( - {"pulp_created": criteria}, - {"pulp_created__gt": criteria, "pulp_created__lt": criteria}, - {"pulp_created__gte": criteria, "pulp_created__lte": criteria}, - {"pulp_created__range": [criteria, criteria]}, - ): - with pytest.raises(file_bindings.ApiException) as e: - file_bindings.RepositoriesFileVersionsApi.list(repo.pulp_href, **params) - assert e.value.status == 400 - assert "Enter a valid date/time." in e.value.body - # Filter repository version by a valid date dates = [v.pulp_created for v in reversed(repo_versions)] for params, num_results in ( @@ -476,19 +431,6 @@ def test_filter_repo_version( results = file_bindings.RepositoriesFileVersionsApi.list(repo.pulp_href, **params) assert results.count == 0, params - # Filter repository version by an invalid version number. - criteria = str(uuid4()) - for params in ( - {"number": criteria}, - {"number__gt": criteria, "number__lt": criteria}, - {"number__gte": criteria, "number__lte": criteria}, - {"number__range": [criteria, criteria]}, - ): - with pytest.raises(file_bindings.ApiException) as e: - file_bindings.RepositoriesFileVersionsApi.list(repo.pulp_href, **params) - assert e.value.status == 400 - assert "Enter a number." in e.value.body - # Filter repository version by a valid version number numbers = [v.number for v in reversed(repo_versions)] for params, num_results in ( diff --git a/pulpcore/tests/functional/utils.py b/pulpcore/tests/functional/utils.py index d5651099fc..a3da5b390e 100644 --- a/pulpcore/tests/functional/utils.py +++ b/pulpcore/tests/functional/utils.py @@ -50,9 +50,11 @@ def __init__(self, module, client): 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) + # So we get memoization for free. + if name.endswith("Api"): + api_object = getattr(self.module, name)(self.client) + else: + api_object = getattr(self.module, name) self.__dict__[name] = api_object return api_object