Skip to content

Commit

Permalink
Fix status code and message
Browse files Browse the repository at this point in the history
  • Loading branch information
susilnem committed Jan 13, 2025
1 parent 50c8566 commit fab0c9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion local_units/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def test_latest_changes(self):
self.assert_200(response)

# Checking the latest changes
response = self.client.post(f"/api/v2/local-units/{local_unit_id}/latest-change-request/")
response = self.client.get(f"/api/v2/local-units/{local_unit_id}/latest-change-request/")
self.assert_200(response)
self.assertEqual(response.data["previous_data_details"]["local_branch_name"], previous_data["local_branch_name"])
self.assertEqual(response.data["previous_data_details"]["english_branch_name"], previous_data["english_branch_name"])
Expand Down
17 changes: 13 additions & 4 deletions local_units/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def get_validate(self, request, pk=None, version=None):
).last()

if not change_request_instance:
return bad_request("No change request found to validate")
return response.Response(
{"message": "No change request found to validate"},
status=status.HTTP_404_NOT_FOUND,
)

# Checking the validator type
validator = Validator.LOCAL
Expand Down Expand Up @@ -191,7 +194,10 @@ def get_revert(self, request, pk=None, version=None):
).last()

if not change_request_instance:
return bad_request("No change request found to revert")
return response.Response(
{"message": "No change request found to revert"},
status=status.HTTP_404_NOT_FOUND,
)

change_request_instance.status = LocalUnitChangeRequest.Status.REVERT
change_request_instance.rejected_reason = reason
Expand Down Expand Up @@ -237,7 +243,7 @@ def get_revert(self, request, pk=None, version=None):
@action(
detail=True,
url_path="latest-change-request",
methods=["post"],
methods=["get"],
serializer_class=LocalUnitChangeRequestSerializer,
permission_classes=[permissions.IsAuthenticated, IsAuthenticatedForLocalUnit, DenyGuestUserPermission],
)
Expand All @@ -249,7 +255,10 @@ def get_latest_changes(self, request, pk=None, version=None):
).last()

if not change_request:
return bad_request("Last change request not found")
return response.Response(
{"message": "Last change request not found"},
status=status.HTTP_404_NOT_FOUND,
)

serializer = LocalUnitChangeRequestSerializer(change_request, context={"request": request})
return response.Response(serializer.data)
Expand Down

0 comments on commit fab0c9b

Please sign in to comment.