-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(API): new /stats endpoint for TotalStats (#476)
- Loading branch information
Showing
6 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from rest_framework import serializers | ||
|
||
from open_prices.stats.models import TotalStats | ||
|
||
|
||
class TotalStatsSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = TotalStats | ||
# fields = "__all__" | ||
exclude = ["id", "created"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.urls import reverse | ||
from rest_framework.test import APITestCase | ||
|
||
from open_prices.stats.models import TotalStats | ||
|
||
|
||
class StatsTest(APITestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.url = reverse("api:stats") | ||
|
||
def test_get_total_stats(self): | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(response.json().keys()), len(TotalStats.COUNT_FIELDS) + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from drf_spectacular.utils import extend_schema | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from open_prices.api.stats.serializers import TotalStatsSerializer | ||
from open_prices.stats.models import TotalStats | ||
|
||
|
||
class StatsView(APIView): | ||
authentication_classes = [] | ||
permission_classes = [] | ||
|
||
@extend_schema(responses=TotalStatsSerializer, tags=["stats"]) | ||
def get(self, request: Request) -> Response: | ||
serializer = TotalStatsSerializer(TotalStats.get_solo()) | ||
return Response(serializer.data, status=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters