diff --git a/semester/models.py b/semester/models.py index 9accbac..80dd7a2 100644 --- a/semester/models.py +++ b/semester/models.py @@ -1,9 +1,9 @@ from django.db import models + class Semester(models.Model): semester = models.CharField(max_length=8) details = models.CharField(max_length=200) def __str__(self): return f'{self.semester}' - diff --git a/semester/serializers.py b/semester/serializers.py index e90f152..53ae99c 100644 --- a/semester/serializers.py +++ b/semester/serializers.py @@ -1,8 +1,9 @@ from rest_framework import serializers from semester.models import Semester + class SemesterSerializers(serializers.ModelSerializer): - + class Meta: model = Semester - fields = '__all__' \ No newline at end of file + fields = '__all__' diff --git a/semester/tests.py b/semester/tests.py index 7ce503c..e4aa38a 100644 --- a/semester/tests.py +++ b/semester/tests.py @@ -1,3 +1,16 @@ from django.test import TestCase +from django.contrib.auth.models import User +from rest_framework import status +from rest_framework.test import APIRequestFactory, force_authenticate -# Create your tests here. +from semester.models import Semester + + +class SemesterTests(TestCase): + def setUp(self): + self.semester = Semester.objects.create(semester='5', details='Just another semester') + + + def test_get_all_semester(self): + response = self.client.get('/sem/semester/') + self.assertEqual(response.status_code, status.HTTP_200_OK) \ No newline at end of file diff --git a/semester/urls.py b/semester/urls.py index ce8397d..32601d4 100644 --- a/semester/urls.py +++ b/semester/urls.py @@ -6,4 +6,4 @@ router = SimpleRouter() router.register("semester", views.SemesterViewSets, basename='api-semester') -urlpatterns = router.urls \ No newline at end of file +urlpatterns = router.urls diff --git a/semester/views.py b/semester/views.py index c758009..85bc077 100644 --- a/semester/views.py +++ b/semester/views.py @@ -4,7 +4,9 @@ from semester.serializers import SemesterSerializers from rest_framework.decorators import permission_classes from rest_framework.permissions import IsAuthenticated + + class SemesterViewSets(ModelViewSet): permission_classes =[IsAuthenticated] serializer_class = SemesterSerializers - queryset = Semester.objects.all() \ No newline at end of file + queryset = Semester.objects.all()