Skip to content

Commit

Permalink
chore: change delete DE & credentials to use 409 response code (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dostonbek1 authored Oct 18, 2023
1 parent 68473e7 commit 05a29ea
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/aap_eda/api/views/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions src/aap_eda/api/views/decision_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
),
},
Expand All @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/api/test_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/api/test_decision_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 05a29ea

Please sign in to comment.