aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2022-11-02 18:57:22 +0000
committerGravatar wookie184 <[email protected]>2022-11-02 18:57:22 +0000
commit798c499c3c7673612a6815c0ab77d95be066d7ce (patch)
treecff7a1df6b2d29fb4fb64a013340bd758e35a97b /pydis_site/apps/api
parentAdd tests for metricity activity endpoint (diff)
Change the endpoint to be a POST not a GET
Diffstat (limited to 'pydis_site/apps/api')
-rw-r--r--pydis_site/apps/api/models/bot/metricity.py2
-rw-r--r--pydis_site/apps/api/tests/test_users.py34
-rw-r--r--pydis_site/apps/api/viewsets/bot/user.py6
3 files changed, 13 insertions, 29 deletions
diff --git a/pydis_site/apps/api/models/bot/metricity.py b/pydis_site/apps/api/models/bot/metricity.py
index 73bc1f0c..f53dd33c 100644
--- a/pydis_site/apps/api/models/bot/metricity.py
+++ b/pydis_site/apps/api/models/bot/metricity.py
@@ -135,7 +135,7 @@ class Metricity:
self,
user_ids: list[str],
days: int
- ) -> list[tuple[int, int]]:
+ ) -> list[tuple[str, int]]:
"""
Query activity by a list of users in the past `days` days.
diff --git a/pydis_site/apps/api/tests/test_users.py b/pydis_site/apps/api/tests/test_users.py
index 60be8598..9c0fa6ba 100644
--- a/pydis_site/apps/api/tests/test_users.py
+++ b/pydis_site/apps/api/tests/test_users.py
@@ -1,4 +1,3 @@
-import json
import random
from unittest.mock import Mock, patch
@@ -510,13 +509,10 @@ class UserMetricityTests(AuthenticatedAPITestCase):
# When
url = reverse("api:bot:user-metricity-activity-data")
- # Can't send data in body with normal GET request so use generic request.
- response = self.client.generic(
- "GET",
+ response = self.client.post(
url,
- data=json.dumps([0, 1]),
+ data=[0, 1],
QUERY_STRING="days=10",
- content_type="application/json"
)
# Then
@@ -530,13 +526,10 @@ class UserMetricityTests(AuthenticatedAPITestCase):
# When
url = reverse("api:bot:user-metricity-activity-data")
- # Can't send data in body with normal GET request so use generic request.
- response = self.client.generic(
- "GET",
+ response = self.client.post(
url,
- data=json.dumps([0, 1]),
+ data=[0, 1],
QUERY_STRING="days=fifty",
- content_type="application/json"
)
# Then
@@ -550,12 +543,9 @@ class UserMetricityTests(AuthenticatedAPITestCase):
# When
url = reverse('api:bot:user-metricity-activity-data')
- # Can't send data in body with normal GET request so use generic request.
- response = self.client.generic(
- "GET",
+ response = self.client.post(
url,
- data=json.dumps([0, 1]),
- content_type="application/json"
+ data=[0, 1],
)
# Then
@@ -569,12 +559,9 @@ class UserMetricityTests(AuthenticatedAPITestCase):
# When
url = reverse('api:bot:user-metricity-activity-data')
- # Can't send data in body with normal GET request so use generic request.
- response = self.client.generic(
- "GET",
+ response = self.client.post(
url,
QUERY_STRING="days=10",
- content_type="application/json"
)
# Then
@@ -588,13 +575,10 @@ class UserMetricityTests(AuthenticatedAPITestCase):
# When
url = reverse('api:bot:user-metricity-activity-data')
- # Can't send data in body with normal GET request so use generic request.
- response = self.client.generic(
- "GET",
+ response = self.client.post(
url,
- data=json.dumps([123, 'username']),
+ data=[123, 'username'],
QUERY_STRING="days=10",
- content_type="application/json"
)
# Then
diff --git a/pydis_site/apps/api/viewsets/bot/user.py b/pydis_site/apps/api/viewsets/bot/user.py
index f1aebee0..f803b3f6 100644
--- a/pydis_site/apps/api/viewsets/bot/user.py
+++ b/pydis_site/apps/api/viewsets/bot/user.py
@@ -139,7 +139,7 @@ class UserViewSet(ModelViewSet):
- 200: returned on success
- 404: if a user with the given `snowflake` could not be found
- ### GET /bot/users/metricity_activity_data
+ ### POST /bot/users/metricity_activity_data
Gets the number of messages sent on the server in a given period.
Users with no messages in the specified period or who do not
@@ -324,7 +324,7 @@ class UserViewSet(ModelViewSet):
return Response(dict(detail="User not found in metricity"),
status=status.HTTP_404_NOT_FOUND)
- @action(detail=False)
+ @action(detail=False, methods=["POST"])
def metricity_activity_data(self, request: Request) -> Response:
"""Request handler for metricity_activity_data endpoint."""
if "days" in request.query_params:
@@ -352,7 +352,7 @@ class UserViewSet(ModelViewSet):
data = metricity.total_messages_in_past_n_days(user_ids, days)
response_data = [
- {"id": d[0], "message_count": d[1]}
+ {"id": int(d[0]), "message_count": d[1]}
for d in data
]
return Response(response_data, status=status.HTTP_200_OK)