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.
|
||||
"""
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework import test
|
||||
from django import test
|
||||
|
||||
from Palto.Palto import factories
|
||||
from Palto.Palto import models, factories
|
||||
|
||||
|
||||
class TokenJwtTestCase(test.APITestCase):
|
||||
"""
|
||||
Test the JWT token creation
|
||||
"""
|
||||
class UserTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def test_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()
|
||||
class DepartmentTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def test_creation():
|
||||
"""
|
||||
Test the creation of departments
|
||||
"""
|
||||
|
||||
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)
|
||||
department = factories.FakeDepartmentFactory()
|
||||
|
||||
|
||||
class DepartmentApiTestCase(test.APITestCase):
|
||||
pass
|
||||
class StudentGroupTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def test_creation():
|
||||
"""
|
||||
Test the creation of student groups
|
||||
"""
|
||||
|
||||
student_group = factories.FakeStudentGroupFactory()
|
||||
|
||||
|
||||
class StudentGroupApiTestCase(test.APITestCase):
|
||||
pass
|
||||
class TeachingUnitTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def test_creation():
|
||||
"""
|
||||
Test the creation of teaching units
|
||||
"""
|
||||
|
||||
teaching_unit = factories.FakeTeachingUnitFactory()
|
||||
|
||||
|
||||
class TeachingUnitApiTestCase(test.APITestCase):
|
||||
pass
|
||||
class StudentCardTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def test_creation():
|
||||
"""
|
||||
Test the creation of student cards
|
||||
"""
|
||||
|
||||
student_card = factories.FakeStudentCardFactory()
|
||||
|
||||
|
||||
class StudentCardApiTestCase(test.APITestCase):
|
||||
pass
|
||||
class TeachingSessionTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def test_creation():
|
||||
"""
|
||||
Test the creation of teaching sessions
|
||||
"""
|
||||
|
||||
teaching_session = factories.FakeTeachingSessionFactory()
|
||||
|
||||
|
||||
class TeachingSessionApiTestCase(test.APITestCase):
|
||||
pass
|
||||
class AttendanceTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def test_creation():
|
||||
"""
|
||||
Test the creation of attendances
|
||||
"""
|
||||
|
||||
attendance = factories.FakeAttendanceFactory()
|
||||
|
||||
|
||||
class AttendanceApiTestCase(test.APITestCase):
|
||||
pass
|
||||
class AbsenceTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def test_creation():
|
||||
"""
|
||||
Test the creation of absences
|
||||
"""
|
||||
|
||||
absence = factories.FakeAbsenceFactory()
|
||||
|
||||
|
||||
class AbsenceApiTestCase(test.APITestCase):
|
||||
pass
|
||||
class AbsenceAttachmentTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def test_creation():
|
||||
"""
|
||||
Test the creation of absence attachments
|
||||
"""
|
||||
|
||||
|
||||
class AbsenceAttachmentApiTestCase(test.APITestCase):
|
||||
pass
|
||||
absence_attachment = factories.FakeAbsenceAttachmentFactory()
|
||||
|
|
|
@ -14,53 +14,53 @@ from ... import models
|
|||
|
||||
class UserViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = serializers.UserSerializer
|
||||
queryset = models.User.objects.all().order_by("pk")
|
||||
queryset = models.User.objects.all()
|
||||
permission_classes = [IsAuthenticated, permissions.UserPermission]
|
||||
|
||||
|
||||
class DepartmentViewSet(UserViewSet):
|
||||
serializer_class = serializers.DepartmentSerializer
|
||||
queryset = models.Department.objects.all().order_by("pk")
|
||||
queryset = models.Department.objects.all()
|
||||
permission_classes = [permissions.DepartmentPermission]
|
||||
|
||||
|
||||
class StudentGroupViewSet(UserViewSet):
|
||||
serializer_class = serializers.StudentGroupSerializer
|
||||
queryset = models.StudentGroup.objects.all().order_by("pk")
|
||||
queryset = models.StudentGroup.objects.all()
|
||||
permission_classes = [IsAuthenticated, permissions.StudentGroupPermission]
|
||||
|
||||
|
||||
class TeachingUnitViewSet(UserViewSet):
|
||||
serializer_class = serializers.TeachingUnitSerializer
|
||||
queryset = models.TeachingUnit.objects.all().order_by("pk")
|
||||
queryset = models.TeachingUnit.objects.all()
|
||||
permission_classes = [IsAuthenticated, permissions.TeachingUnitPermission]
|
||||
|
||||
|
||||
class StudentCardViewSet(UserViewSet):
|
||||
serializer_class = serializers.StudentCardSerializer
|
||||
queryset = models.StudentCard.objects.all().order_by("pk")
|
||||
queryset = models.StudentCard.objects.all()
|
||||
permission_classes = [IsAuthenticated, permissions.StudentCardPermission]
|
||||
|
||||
|
||||
class TeachingSessionViewSet(UserViewSet):
|
||||
serializer_class = serializers.TeachingSessionSerializer
|
||||
queryset = models.TeachingSession.objects.all().order_by("pk")
|
||||
queryset = models.TeachingSession.objects.all()
|
||||
permission_classes = [IsAuthenticated, permissions.TeachingSessionPermission]
|
||||
|
||||
|
||||
class AttendanceViewSet(UserViewSet):
|
||||
serializer_class = serializers.AttendanceSerializer
|
||||
queryset = models.Attendance.objects.all().order_by("pk")
|
||||
queryset = models.Attendance.objects.all()
|
||||
permission_classes = [IsAuthenticated, permissions.AttendancePermission]
|
||||
|
||||
|
||||
class AbsenceViewSet(UserViewSet):
|
||||
serializer_class = serializers.AbsenceSerializer
|
||||
queryset = models.Absence.objects.all().order_by("pk")
|
||||
queryset = models.Absence.objects.all()
|
||||
permission_classes = [IsAuthenticated, permissions.AbsencePermission]
|
||||
|
||||
|
||||
class AbsenceAttachmentViewSet(UserViewSet):
|
||||
serializer_class = serializers.AbsenceAttachmentSerializer
|
||||
queryset = models.AbsenceAttachment.objects.all().order_by("pk")
|
||||
queryset = models.AbsenceAttachment.objects.all()
|
||||
permission_classes = [IsAuthenticated, permissions.AbsenceAttachmentPermission]
|
||||
|
|
|
@ -196,6 +196,6 @@ class FakeAbsenceAttachmentFactory(factory.django.DjangoModelFactory):
|
|||
class Meta:
|
||||
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.
|
||||
"""
|
||||
|
||||
from django import test
|
||||
|
||||
from Palto.Palto import factories
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
# 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