Skip to content

Commit

Permalink
[AAP-18000] chore: change validation errors format (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsong-rh authored Nov 8, 2023
1 parent 4a34c1d commit ef1b5e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/aap_eda/api/serializers/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,6 @@ def parse_validation_errors(errors: dict) -> str:
messages = {key: str(error[0]) for key, error in errors.items() if error}

if "non_field_errors" in messages:
messages["errors"] = messages.pop("non_field_errors")
messages["field_errors"] = messages.pop("non_field_errors")

return str(messages)
10 changes: 5 additions & 5 deletions tests/integration/api/test_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def test_restart_activation_with_invalid_tokens(client: APIClient, action):
)

error_message = (
"{'errors': 'More than one controller token found, "
"{'field_errors': 'More than one controller token found, "
"currently only 1 token is supported'}"
)

Expand All @@ -510,13 +510,13 @@ def test_restart_activation_with_invalid_tokens(client: APIClient, action):
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert (
response.data["errors"]
== "{'errors': 'No controller token specified'}"
== "{'field_errors': 'No controller token specified'}"
)
activation.refresh_from_db()
assert activation.status == ActivationStatus.ERROR
assert (
activation.status_message
== "{'errors': 'No controller token specified'}"
== "{'field_errors': 'No controller token specified'}"
)


Expand Down Expand Up @@ -798,7 +798,7 @@ def test_create_activation_no_token(client: APIClient):
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert (
str(response.data["errors"])
== "{'errors': 'No controller token specified'}"
== "{'field_errors': 'No controller token specified'}"
)


Expand All @@ -817,6 +817,6 @@ def test_create_activation_more_tokens(client: APIClient):
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert (
str(response.data["errors"])
== "{'errors': 'More than one controller token found, "
== "{'field_errors': 'More than one controller token found, "
"currently only 1 token is supported'}"
)

0 comments on commit ef1b5e9

Please sign in to comment.