added base for tests
This commit is contained in:
parent
60cbbbd273
commit
5a5e83aff1
4 changed files with 84 additions and 107 deletions
|
@ -4,64 +4,96 @@ Tests for the Palto project's API v1.
|
||||||
Everything to test the API v1 is described here.
|
Everything to test the API v1 is described here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from rest_framework import status
|
from django import test
|
||||||
from rest_framework import test
|
|
||||||
|
|
||||||
from Palto.Palto import factories
|
from Palto.Palto import models, factories
|
||||||
|
|
||||||
|
|
||||||
class TokenJwtTestCase(test.APITestCase):
|
class UserTestCase(test.TestCase):
|
||||||
"""
|
@staticmethod
|
||||||
Test the JWT token creation
|
def test_creation():
|
||||||
"""
|
"""
|
||||||
|
Test the creation of users
|
||||||
|
"""
|
||||||
|
|
||||||
|
user = factories.FakeUserFactory()
|
||||||
|
|
||||||
|
|
||||||
class UserApiTestCase(test.APITestCase):
|
class DepartmentTestCase(test.TestCase):
|
||||||
def setUp(self):
|
@staticmethod
|
||||||
self.user_admin = factories.FakeUserFactory(is_superuser=True)
|
def test_creation():
|
||||||
self.user_anonymous = factories.FakeUserFactory()
|
"""
|
||||||
|
Test the creation of departments
|
||||||
|
"""
|
||||||
|
|
||||||
def test_permission_admin(self):
|
department = factories.FakeDepartmentFactory()
|
||||||
""" Test the permissions of the object for an admin """
|
|
||||||
|
|
||||||
self.client.force_login(self.user_admin)
|
|
||||||
|
|
||||||
# check for a get request
|
|
||||||
response = self.client.get("/api/v1/users/")
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
||||||
|
|
||||||
# check for a post request
|
|
||||||
response = self.client.post("/api/v1/users/")
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class DepartmentApiTestCase(test.APITestCase):
|
class StudentGroupTestCase(test.TestCase):
|
||||||
pass
|
@staticmethod
|
||||||
|
def test_creation():
|
||||||
|
"""
|
||||||
|
Test the creation of student groups
|
||||||
|
"""
|
||||||
|
|
||||||
|
student_group = factories.FakeStudentGroupFactory()
|
||||||
|
|
||||||
|
|
||||||
class StudentGroupApiTestCase(test.APITestCase):
|
class TeachingUnitTestCase(test.TestCase):
|
||||||
pass
|
@staticmethod
|
||||||
|
def test_creation():
|
||||||
|
"""
|
||||||
|
Test the creation of teaching units
|
||||||
|
"""
|
||||||
|
|
||||||
|
teaching_unit = factories.FakeTeachingUnitFactory()
|
||||||
|
|
||||||
|
|
||||||
class TeachingUnitApiTestCase(test.APITestCase):
|
class StudentCardTestCase(test.TestCase):
|
||||||
pass
|
@staticmethod
|
||||||
|
def test_creation():
|
||||||
|
"""
|
||||||
|
Test the creation of student cards
|
||||||
|
"""
|
||||||
|
|
||||||
|
student_card = factories.FakeStudentCardFactory()
|
||||||
|
|
||||||
|
|
||||||
class StudentCardApiTestCase(test.APITestCase):
|
class TeachingSessionTestCase(test.TestCase):
|
||||||
pass
|
@staticmethod
|
||||||
|
def test_creation():
|
||||||
|
"""
|
||||||
|
Test the creation of teaching sessions
|
||||||
|
"""
|
||||||
|
|
||||||
|
teaching_session = factories.FakeTeachingSessionFactory()
|
||||||
|
|
||||||
|
|
||||||
class TeachingSessionApiTestCase(test.APITestCase):
|
class AttendanceTestCase(test.TestCase):
|
||||||
pass
|
@staticmethod
|
||||||
|
def test_creation():
|
||||||
|
"""
|
||||||
|
Test the creation of attendances
|
||||||
|
"""
|
||||||
|
|
||||||
|
attendance = factories.FakeAttendanceFactory()
|
||||||
|
|
||||||
|
|
||||||
class AttendanceApiTestCase(test.APITestCase):
|
class AbsenceTestCase(test.TestCase):
|
||||||
pass
|
@staticmethod
|
||||||
|
def test_creation():
|
||||||
|
"""
|
||||||
|
Test the creation of absences
|
||||||
|
"""
|
||||||
|
|
||||||
|
absence = factories.FakeAbsenceFactory()
|
||||||
|
|
||||||
|
|
||||||
class AbsenceApiTestCase(test.APITestCase):
|
class AbsenceAttachmentTestCase(test.TestCase):
|
||||||
pass
|
@staticmethod
|
||||||
|
def test_creation():
|
||||||
|
"""
|
||||||
|
Test the creation of absence attachments
|
||||||
|
"""
|
||||||
|
|
||||||
|
absence_attachment = factories.FakeAbsenceAttachmentFactory()
|
||||||
class AbsenceAttachmentApiTestCase(test.APITestCase):
|
|
||||||
pass
|
|
||||||
|
|
|
@ -14,53 +14,53 @@ from ... import models
|
||||||
|
|
||||||
class UserViewSet(viewsets.ModelViewSet):
|
class UserViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = serializers.UserSerializer
|
serializer_class = serializers.UserSerializer
|
||||||
queryset = models.User.objects.all().order_by("pk")
|
queryset = models.User.objects.all()
|
||||||
permission_classes = [IsAuthenticated, permissions.UserPermission]
|
permission_classes = [IsAuthenticated, permissions.UserPermission]
|
||||||
|
|
||||||
|
|
||||||
class DepartmentViewSet(UserViewSet):
|
class DepartmentViewSet(UserViewSet):
|
||||||
serializer_class = serializers.DepartmentSerializer
|
serializer_class = serializers.DepartmentSerializer
|
||||||
queryset = models.Department.objects.all().order_by("pk")
|
queryset = models.Department.objects.all()
|
||||||
permission_classes = [permissions.DepartmentPermission]
|
permission_classes = [permissions.DepartmentPermission]
|
||||||
|
|
||||||
|
|
||||||
class StudentGroupViewSet(UserViewSet):
|
class StudentGroupViewSet(UserViewSet):
|
||||||
serializer_class = serializers.StudentGroupSerializer
|
serializer_class = serializers.StudentGroupSerializer
|
||||||
queryset = models.StudentGroup.objects.all().order_by("pk")
|
queryset = models.StudentGroup.objects.all()
|
||||||
permission_classes = [IsAuthenticated, permissions.StudentGroupPermission]
|
permission_classes = [IsAuthenticated, permissions.StudentGroupPermission]
|
||||||
|
|
||||||
|
|
||||||
class TeachingUnitViewSet(UserViewSet):
|
class TeachingUnitViewSet(UserViewSet):
|
||||||
serializer_class = serializers.TeachingUnitSerializer
|
serializer_class = serializers.TeachingUnitSerializer
|
||||||
queryset = models.TeachingUnit.objects.all().order_by("pk")
|
queryset = models.TeachingUnit.objects.all()
|
||||||
permission_classes = [IsAuthenticated, permissions.TeachingUnitPermission]
|
permission_classes = [IsAuthenticated, permissions.TeachingUnitPermission]
|
||||||
|
|
||||||
|
|
||||||
class StudentCardViewSet(UserViewSet):
|
class StudentCardViewSet(UserViewSet):
|
||||||
serializer_class = serializers.StudentCardSerializer
|
serializer_class = serializers.StudentCardSerializer
|
||||||
queryset = models.StudentCard.objects.all().order_by("pk")
|
queryset = models.StudentCard.objects.all()
|
||||||
permission_classes = [IsAuthenticated, permissions.StudentCardPermission]
|
permission_classes = [IsAuthenticated, permissions.StudentCardPermission]
|
||||||
|
|
||||||
|
|
||||||
class TeachingSessionViewSet(UserViewSet):
|
class TeachingSessionViewSet(UserViewSet):
|
||||||
serializer_class = serializers.TeachingSessionSerializer
|
serializer_class = serializers.TeachingSessionSerializer
|
||||||
queryset = models.TeachingSession.objects.all().order_by("pk")
|
queryset = models.TeachingSession.objects.all()
|
||||||
permission_classes = [IsAuthenticated, permissions.TeachingSessionPermission]
|
permission_classes = [IsAuthenticated, permissions.TeachingSessionPermission]
|
||||||
|
|
||||||
|
|
||||||
class AttendanceViewSet(UserViewSet):
|
class AttendanceViewSet(UserViewSet):
|
||||||
serializer_class = serializers.AttendanceSerializer
|
serializer_class = serializers.AttendanceSerializer
|
||||||
queryset = models.Attendance.objects.all().order_by("pk")
|
queryset = models.Attendance.objects.all()
|
||||||
permission_classes = [IsAuthenticated, permissions.AttendancePermission]
|
permission_classes = [IsAuthenticated, permissions.AttendancePermission]
|
||||||
|
|
||||||
|
|
||||||
class AbsenceViewSet(UserViewSet):
|
class AbsenceViewSet(UserViewSet):
|
||||||
serializer_class = serializers.AbsenceSerializer
|
serializer_class = serializers.AbsenceSerializer
|
||||||
queryset = models.Absence.objects.all().order_by("pk")
|
queryset = models.Absence.objects.all()
|
||||||
permission_classes = [IsAuthenticated, permissions.AbsencePermission]
|
permission_classes = [IsAuthenticated, permissions.AbsencePermission]
|
||||||
|
|
||||||
|
|
||||||
class AbsenceAttachmentViewSet(UserViewSet):
|
class AbsenceAttachmentViewSet(UserViewSet):
|
||||||
serializer_class = serializers.AbsenceAttachmentSerializer
|
serializer_class = serializers.AbsenceAttachmentSerializer
|
||||||
queryset = models.AbsenceAttachment.objects.all().order_by("pk")
|
queryset = models.AbsenceAttachment.objects.all()
|
||||||
permission_classes = [IsAuthenticated, permissions.AbsenceAttachmentPermission]
|
permission_classes = [IsAuthenticated, permissions.AbsenceAttachmentPermission]
|
||||||
|
|
|
@ -196,6 +196,6 @@ class FakeAbsenceAttachmentFactory(factory.django.DjangoModelFactory):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.AbsenceAttachment
|
model = models.AbsenceAttachment
|
||||||
|
|
||||||
content: str = factory.django.FileField()
|
content = factory.django.FileField()
|
||||||
|
|
||||||
absence: models.Absence = factory.SubFactory(FakeAbsenceFactory)
|
absence = factory.SubFactory(FakeAbsenceFactory)
|
||||||
|
|
|
@ -4,61 +4,6 @@ Tests for the Palto project.
|
||||||
Tests allow to easily check after modifying the logic behind a feature that everything still work as intended.
|
Tests allow to easily check after modifying the logic behind a feature that everything still work as intended.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django import test
|
from django.test import TestCase
|
||||||
|
|
||||||
from Palto.Palto import factories
|
|
||||||
|
|
||||||
|
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
class UserTestCase(test.TestCase):
|
|
||||||
@staticmethod
|
|
||||||
def test_creation():
|
|
||||||
factories.FakeUserFactory()
|
|
||||||
|
|
||||||
|
|
||||||
class DepartmentTestCase(test.TestCase):
|
|
||||||
@staticmethod
|
|
||||||
def test_creation():
|
|
||||||
factories.FakeDepartmentFactory()
|
|
||||||
|
|
||||||
|
|
||||||
class StudentGroupTestCase(test.TestCase):
|
|
||||||
@staticmethod
|
|
||||||
def test_creation():
|
|
||||||
factories.FakeStudentGroupFactory()
|
|
||||||
|
|
||||||
|
|
||||||
class TeachingUnitTestCase(test.TestCase):
|
|
||||||
@staticmethod
|
|
||||||
def test_creation():
|
|
||||||
factories.FakeTeachingUnitFactory()
|
|
||||||
|
|
||||||
|
|
||||||
class StudentCardTestCase(test.TestCase):
|
|
||||||
@staticmethod
|
|
||||||
def test_creation():
|
|
||||||
factories.FakeStudentCardFactory()
|
|
||||||
|
|
||||||
|
|
||||||
class TeachingSessionTestCase(test.TestCase):
|
|
||||||
@staticmethod
|
|
||||||
def test_creation():
|
|
||||||
factories.FakeTeachingSessionFactory()
|
|
||||||
|
|
||||||
|
|
||||||
class AttendanceTestCase(test.TestCase):
|
|
||||||
@staticmethod
|
|
||||||
def test_creation():
|
|
||||||
factories.FakeAttendanceFactory()
|
|
||||||
|
|
||||||
|
|
||||||
class AbsenceTestCase(test.TestCase):
|
|
||||||
@staticmethod
|
|
||||||
def test_creation():
|
|
||||||
factories.FakeAbsenceFactory()
|
|
||||||
|
|
||||||
|
|
||||||
class AbsenceAttachmentTestCase(test.TestCase):
|
|
||||||
@staticmethod
|
|
||||||
def test_creation():
|
|
||||||
factories.FakeAbsenceAttachmentFactory()
|
|
||||||
|
|
Loading…
Reference in a new issue