diff --git a/app/core/api/serializers.py b/app/core/api/serializers.py index 168a9171..480a9679 100644 --- a/app/core/api/serializers.py +++ b/app/core/api/serializers.py @@ -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 @@ -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") diff --git a/app/core/api/urls.py b/app/core/api/urls.py index e67e5521..664d397f 100644 --- a/app/core/api/urls.py +++ b/app/core/api/urls.py @@ -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 @@ -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"), ] diff --git a/app/core/api/views.py b/app/core/api/views.py index ffd83364..f932a051 100644 --- a/app/core/api/views.py +++ b/app/core/api/views.py @@ -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 @@ -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 @@ -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 diff --git a/app/core/tests/test_api.py b/app/core/tests/test_api.py index 6d57e12f..d5f02700 100644 --- a/app/core/tests/test_api.py +++ b/app/core/tests/test_api.py @@ -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", @@ -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"]