Skip to content

Commit

Permalink
[Backend] Remove delete leaderboard data API (#4168)
Browse files Browse the repository at this point in the history
  • Loading branch information
gchhablani authored Sep 19, 2023
1 parent dfb3d74 commit bd6f443
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 70 deletions.
5 changes: 0 additions & 5 deletions apps/challenges/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,6 @@
views.get_leaderboard_data,
name="get_leaderboard_data",
),
url(
r"^challenge/delete_leaderboard_data/(?P<leaderboard_data_pk>[0-9]+)/$",
views.delete_leaderboard_data,
name="delete_leaderboard_data",
),
url(
r"^challenge/update_challenge_approval/$",
views.update_challenge_approval,
Expand Down
31 changes: 0 additions & 31 deletions apps/challenges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4783,37 +4783,6 @@ def get_leaderboard_data(request, challenge_phase_split_pk):
return Response(response_data, status=status.HTTP_200_OK)


@api_view(["DELETE"])
@throttle_classes([UserRateThrottle])
@permission_classes((permissions.IsAuthenticated, HasVerifiedEmail))
@authentication_classes((JWTAuthentication, ExpiringTokenAuthentication))
def delete_leaderboard_data(request, leaderboard_data_pk):
"""
API to delete leaderboard data
Arguments:
leaderboard_data_pk {int} -- Leaderboard data primary key
Returns:
{dict} -- Response object
"""
if not is_user_a_staff(request.user):
response_data = {
"error": "Sorry, you are not authorized to access this resource!"
}
return Response(response_data, status=status.HTTP_401_UNAUTHORIZED)
try:
leaderboard_data = LeaderboardData.objects.get(pk=leaderboard_data_pk)
except LeaderboardData.DoesNotExist:
response_data = {
"error": "Leaderboard data not found!"
}
return Response(response_data, status=status.HTTP_404_NOT_FOUND)
leaderboard_data.delete()
response_data = {
"message": "Leaderboard data deleted successfully!"
}
return Response(response_data, status=status.HTTP_204_NO_CONTENT)


@api_view(["POST"])
@throttle_classes([UserRateThrottle])
@permission_classes((permissions.IsAuthenticated, HasVerifiedEmail))
Expand Down
34 changes: 0 additions & 34 deletions tests/unit/challenges/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6035,40 +6035,6 @@ def test_get_leaderboard_data_when_not_staff(self):
self.assertEqual(response.data, expected)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_delete_leaderboard_data_success(self):
self.url = reverse_lazy(
"challenges:delete_leaderboard_data",
kwargs={"leaderboard_data_pk": self.leaderboard_data.pk},
)
response = self.client.delete(self.url)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

def test_delete_leaderboard_data_when_leaderboard_data_does_not_exist(self):
self.url = reverse_lazy(
"challenges:delete_leaderboard_data",
kwargs={"leaderboard_data_pk": self.leaderboard_data.pk + 1000},
)
expected = {
"error": "Leaderboard data not found!"
}
response = self.client.delete(self.url)
self.assertEqual(response.data, expected)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

def test_delete_leaderboard_data_when_not_staff(self):
self.url = reverse_lazy(
"challenges:delete_leaderboard_data",
kwargs={"leaderboard_data_pk": self.leaderboard_data.pk},
)
self.user.is_staff = False
self.user.save()
expected = {
"error": "Sorry, you are not authorized to access this resource!"
}
response = self.client.delete(self.url)
self.assertEqual(response.data, expected)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)


class TestUpdateChallenge(BaseAPITestClass):
def setUp(self):
Expand Down

0 comments on commit bd6f443

Please sign in to comment.