Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix status code on latest change request #2382

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading