added base for tests

This commit is contained in:
Faraphel 2023-12-01 18:48:51 +01:00
parent 60cbbbd273
commit 5a5e83aff1
4 changed files with 84 additions and 107 deletions

View file

@ -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
def test_creation():
""" """
Test the JWT token creation Test the creation of users
""" """
user = factories.FakeUserFactory()
class UserApiTestCase(test.APITestCase):
def setUp(self):
self.user_admin = factories.FakeUserFactory(is_superuser=True)
self.user_anonymous = factories.FakeUserFactory()
def test_permission_admin(self):
""" 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 DepartmentTestCase(test.TestCase):
pass @staticmethod
def test_creation():
"""
Test the creation of departments
"""
department = factories.FakeDepartmentFactory()
class StudentGroupApiTestCase(test.APITestCase): class StudentGroupTestCase(test.TestCase):
pass @staticmethod
def test_creation():
"""
Test the creation of student groups
"""
student_group = factories.FakeStudentGroupFactory()
class TeachingUnitApiTestCase(test.APITestCase): class TeachingUnitTestCase(test.TestCase):
pass @staticmethod
def test_creation():
"""
Test the creation of teaching units
"""
teaching_unit = factories.FakeTeachingUnitFactory()
class StudentCardApiTestCase(test.APITestCase): class StudentCardTestCase(test.TestCase):
pass @staticmethod
def test_creation():
"""
Test the creation of student cards
"""
student_card = factories.FakeStudentCardFactory()
class TeachingSessionApiTestCase(test.APITestCase): class TeachingSessionTestCase(test.TestCase):
pass @staticmethod
def test_creation():
"""
Test the creation of teaching sessions
"""
teaching_session = factories.FakeTeachingSessionFactory()
class AttendanceApiTestCase(test.APITestCase): class AttendanceTestCase(test.TestCase):
pass @staticmethod
def test_creation():
"""
Test the creation of attendances
"""
attendance = factories.FakeAttendanceFactory()
class AbsenceApiTestCase(test.APITestCase): class AbsenceTestCase(test.TestCase):
pass @staticmethod
def test_creation():
"""
Test the creation of absences
"""
absence = factories.FakeAbsenceFactory()
class AbsenceAttachmentApiTestCase(test.APITestCase): class AbsenceAttachmentTestCase(test.TestCase):
pass @staticmethod
def test_creation():
"""
Test the creation of absence attachments
"""
absence_attachment = factories.FakeAbsenceAttachmentFactory()

View file

@ -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]

View file

@ -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)

View file

@ -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()