Skip to content

Commit

Permalink
PB-1109 Return 400 instead of 404 when FK nonexistent
Browse files Browse the repository at this point in the history
  • Loading branch information
asteiner-swisstopo committed Nov 13, 2024
1 parent 1524253 commit ed63b04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/access/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def update_user(
Return HTTP status code
- 200 (OK) if the user has been updated successfully
- 404 (Not Found) if there is no user with the given username or if there is
no provider with the given ID
- 400 (Bad Request) if there is no provider with the given ID
- 404 (Not Found) if there is no user with the given username
- 500 (Internal Server Error) if there is an inconsistency with Cognito
- 503 (Service Unavailable) if Cognito cannot be reached
"""
Expand All @@ -125,7 +125,7 @@ def update_user(
raise Http404()

if not Provider.objects.filter(id=user_in.provider_id).exists():
raise HttpError(HTTPStatus.NOT_FOUND, "Provider does not exist")
raise HttpError(HTTPStatus.BAD_REQUEST, "Provider does not exist")

for attr, value in user_in.dict(exclude_unset=True).items():
setattr(user_object, attr, value)
Expand Down
6 changes: 3 additions & 3 deletions app/access/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_update_user_returns_404_and_leaves_user_as_is_if_user_nonexistent(self)
user_after = User.objects.filter(username="dude").first()
assert user_after == user_before

def test_update_user_returns_404_and_leaves_user_as_is_if_provider_nonexistent(self):
def test_update_user_returns_400_and_leaves_user_as_is_if_provider_nonexistent(self):

user_before = User.objects.filter(username="dude").first()
nonexistent_id = Provider.objects.last().id + 1234
Expand All @@ -360,8 +360,8 @@ def test_update_user_returns_404_and_leaves_user_as_is_if_provider_nonexistent(s

response = self.client.put("users/dude", json=payload)

assert response.status_code == 404
assert response.data == {"code": 404, "description": "Provider does not exist"}
assert response.status_code == 400
assert response.data == {"code": 400, "description": "Provider does not exist"}
user_after = User.objects.filter(username="dude").first()
assert user_after == user_before

Expand Down

0 comments on commit ed63b04

Please sign in to comment.