From 05a29ea3f9bf06b051d5e5375cd6f07cc1f14173 Mon Sep 17 00:00:00 2001 From: Doston Toirov <31990136+Dostonbek1@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:08:28 -0400 Subject: [PATCH] chore: change delete DE & credentials to use 409 response code (#440) --- src/aap_eda/api/views/credential.py | 2 +- src/aap_eda/api/views/decision_environment.py | 4 ++-- tests/integration/api/test_credential.py | 2 +- tests/integration/api/test_decision_environment.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aap_eda/api/views/credential.py b/src/aap_eda/api/views/credential.py index 6ddb86415..fdf3bd95c 100644 --- a/src/aap_eda/api/views/credential.py +++ b/src/aap_eda/api/views/credential.py @@ -142,7 +142,7 @@ def destroy(self, request, *args, **kwargs): ).exists() if is_used and not force: - raise exceptions.Forbidden( + raise exceptions.Conflict( "Credential is being used by Activations " "and cannot be deleted. If you want to force delete, " "please add /?force=true query param." diff --git a/src/aap_eda/api/views/decision_environment.py b/src/aap_eda/api/views/decision_environment.py index cda9cad39..98d3dc7ac 100644 --- a/src/aap_eda/api/views/decision_environment.py +++ b/src/aap_eda/api/views/decision_environment.py @@ -117,7 +117,7 @@ def retrieve(self, request, pk): status.HTTP_204_NO_CONTENT: OpenApiResponse( None, description="Delete successful." ), - status.HTTP_403_FORBIDDEN: OpenApiResponse( + status.HTTP_409_CONFLICT: OpenApiResponse( None, description="Decision Environment in use by Activations." ), }, @@ -139,7 +139,7 @@ def destroy(self, request, *args, **kwargs): ).exists() if activations_exist and force_delete not in ["true", "1", "yes"]: - raise api_exc.Forbidden( + raise api_exc.Conflict( "Decision Environment is being used by Activations " "and cannot be deleted. If you want to force delete, " "please add /?force=True query param." diff --git a/tests/integration/api/test_credential.py b/tests/integration/api/test_credential.py index 4278b9fd4..71ebcd8b9 100644 --- a/tests/integration/api/test_credential.py +++ b/tests/integration/api/test_credential.py @@ -127,7 +127,7 @@ def test_delete_credential_used_by_activation(client: APIClient): create_activation(activation_dependencies) credential_id = activation_dependencies["credential_id"] response = client.delete(f"{api_url_v1}/credentials/{credential_id}/") - assert response.status_code == status.HTTP_403_FORBIDDEN + assert response.status_code == status.HTTP_409_CONFLICT @pytest.mark.django_db diff --git a/tests/integration/api/test_decision_environment.py b/tests/integration/api/test_decision_environment.py index 83cd0c3b1..5f0ea3c36 100644 --- a/tests/integration/api/test_decision_environment.py +++ b/tests/integration/api/test_decision_environment.py @@ -130,10 +130,10 @@ def test_partial_update_decision_environment(client: APIClient, init_db): @pytest.mark.django_db -def test_delete_decision_environment_forbidden(client: APIClient, init_db): +def test_delete_decision_environment_conflict(client: APIClient, init_db): obj_id = int(init_db.decision_environment.id) response = client.delete(f"{api_url_v1}/decision-environments/{obj_id}/") - assert response.status_code == status.HTTP_403_FORBIDDEN + assert response.status_code == status.HTTP_409_CONFLICT @pytest.mark.django_db