Skip to content

Commit

Permalink
feat: add endpoints: check_type
Browse files Browse the repository at this point in the history
  • Loading branch information
dmartin4820 authored and fyliu committed Aug 26, 2024
1 parent fe84802 commit 2f99c60
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from core.models import Affiliate
from core.models import Affiliation
from core.models import CheckType
from core.models import Event
from core.models import Faq
from core.models import FaqViewed
Expand Down Expand Up @@ -316,3 +317,14 @@ class Meta:
"is_partner",
)
read_only_fields = ("uuid", "created_at", "updated_at")


class CheckTypeSerializer(serializers.ModelSerializer):
"""
Used to retrieve check_type info
"""

class Meta:
model = CheckType
fields = ("uuid", "name", "description")
read_only_fields = ("uuid", "created_at", "updated_at")
2 changes: 2 additions & 0 deletions app/core/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .views import AffiliateViewSet
from .views import AffiliationViewSet
from .views import CheckTypeViewSet
from .views import EventViewSet
from .views import FaqViewedViewSet
from .views import FaqViewSet
Expand Down Expand Up @@ -40,6 +41,7 @@
AffiliationViewSet,
basename="affiliation",
)
router.register(r"check-types", CheckTypeViewSet, basename="check-type")
urlpatterns = [
path("me/", UserProfileAPIView.as_view(), name="my_profile"),
]
Expand Down
16 changes: 16 additions & 0 deletions app/core/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ..models import Affiliate
from ..models import Affiliation
from ..models import CheckType
from ..models import Event
from ..models import Faq
from ..models import FaqViewed
Expand All @@ -27,6 +28,7 @@
from ..models import Technology
from .serializers import AffiliateSerializer
from .serializers import AffiliationSerializer
from .serializers import CheckTypeSerializer
from .serializers import EventSerializer
from .serializers import FaqSerializer
from .serializers import FaqViewedSerializer
Expand Down Expand Up @@ -330,3 +332,17 @@ class AffiliationViewSet(viewsets.ModelViewSet):
permission_classes = [IsAuthenticated]
queryset = Affiliation.objects.all()
serializer_class = AffiliationSerializer


@extend_schema_view(
list=extend_schema(description="Return a list of all the check_type"),
create=extend_schema(description="Create a new check_type"),
retrieve=extend_schema(description="Return the details of an check_type"),
destroy=extend_schema(description="Delete an check_type"),
update=extend_schema(description="Update an check_type"),
partial_update=extend_schema(description="Patch an check_type"),
)
class CheckTypeViewSet(viewsets.ModelViewSet):
permission_classes = [IsAuthenticated]
queryset = CheckType.objects.all()
serializer_class = CheckTypeSerializer
11 changes: 11 additions & 0 deletions app/core/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
STACK_ELEMENT_TYPE_URL = reverse("stack-element-type-list")
SDG_URL = reverse("sdg-list")
AFFILIATION_URL = reverse("affiliation-list")
CHECK_TYPE_URL = reverse("check-type-list")

CREATE_USER_PAYLOAD = {
"username": "TestUserAPI",
Expand Down Expand Up @@ -346,3 +347,13 @@ def test_create_affiliation(auth_client, project, affiliate):
assert res.data["is_partner"] == payload["is_partner"]
assert res.data["affiliate"] == payload["affiliate"]
assert res.data["project"] == payload["project"]


def test_create_check_type(auth_client):
payload = {
"name": "This is a test check_type",
"description": "This is a test description",
}
res = auth_client.post(CHECK_TYPE_URL, payload)
assert res.status_code == status.HTTP_201_CREATED
assert res.data["name"] == payload["name"]

0 comments on commit 2f99c60

Please sign in to comment.