Files
n3wt-school/Back-End/Subscriptions/tests.py
2025-06-05 16:42:50 +02:00

98 lines
5.4 KiB
Python

from django.test import TestCase
from .models import Language, Guardian, Sibling, BilanCompetence, Student, RegistrationFileGroup, RegistrationForm, RegistrationSchoolFileMaster, RegistrationParentFileMaster, RegistrationSchoolFileTemplate, StudentCompetency, RegistrationParentFileTemplate, AbsenceManagement
from django.utils import timezone
from datetime import date
from Establishment.models import Establishment
class LanguageModelTest(TestCase):
def test_create_language(self):
lang = Language.objects.create(label="Français")
self.assertEqual(lang.label, "Français")
self.assertIsNotNone(lang.id)
class GuardianModelTest(TestCase):
def test_create_guardian(self):
guardian = Guardian.objects.create(last_name="Dupont", first_name="Jean")
self.assertEqual(guardian.last_name, "Dupont")
self.assertEqual(guardian.first_name, "Jean")
class SiblingModelTest(TestCase):
def test_create_sibling(self):
sibling = Sibling.objects.create(last_name="Martin", first_name="Julie")
self.assertEqual(sibling.last_name, "Martin")
self.assertEqual(sibling.first_name, "Julie")
class BilanCompetenceModelTest(TestCase):
def test_create_bilan(self):
student = Student.objects.create(last_name="Test", first_name="Eleve")
bilan = BilanCompetence.objects.create(student=student, period="T1-2024_2025")
self.assertEqual(bilan.student, student)
self.assertEqual(bilan.period, "T1-2024_2025")
class StudentModelTest(TestCase):
def test_create_student(self):
student = Student.objects.create(last_name="Durand", first_name="Paul")
self.assertEqual(student.last_name, "Durand")
self.assertEqual(student.first_name, "Paul")
class RegistrationFileGroupModelTest(TestCase):
def test_create_group(self):
group = RegistrationFileGroup.objects.create(name="Groupe A")
self.assertEqual(group.name, "Groupe A")
class RegistrationFormModelTest(TestCase):
def test_create_registration_form(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
student = Student.objects.create(last_name="Test", first_name="Eleve")
group = RegistrationFileGroup.objects.create(name="Groupe B", establishment=est)
form = RegistrationForm.objects.create(student=student, fileGroup=group, establishment=est)
self.assertEqual(form.student, student)
self.assertEqual(form.fileGroup, group)
self.assertEqual(form.establishment, est)
class RegistrationSchoolFileMasterModelTest(TestCase):
def test_create_school_file_master(self):
master = RegistrationSchoolFileMaster.objects.create(id=1, name="Doc école")
self.assertEqual(master.name, "Doc école")
class RegistrationParentFileMasterModelTest(TestCase):
def test_create_parent_file_master(self):
master = RegistrationParentFileMaster.objects.create(name="Doc parent")
self.assertEqual(master.name, "Doc parent")
class RegistrationSchoolFileTemplateModelTest(TestCase):
def test_create_school_file_template(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
master = RegistrationSchoolFileMaster.objects.create(id=2, name="Doc école 2")
student = Student.objects.create(last_name="Test", first_name="Eleve")
group = RegistrationFileGroup.objects.create(name="Groupe C", establishment=est)
form = RegistrationForm.objects.create(student=student, fileGroup=group, establishment=est)
template = RegistrationSchoolFileTemplate.objects.create(id=2, master=master, name="Fichier école", registration_form=form)
self.assertEqual(template.name, "Fichier école")
self.assertEqual(template.master, master)
class StudentCompetencyModelTest(TestCase):
def test_create_student_competency(self):
student = Student.objects.create(last_name="Test", first_name="Eleve")
# Pour le test, on suppose qu'un modèle School.EstablishmentCompetency existe et est importable
# Ici, on ne peut pas créer l'objet sans ce modèle, donc ce test est à adapter selon la base réelle
pass
class RegistrationParentFileTemplateModelTest(TestCase):
def test_create_parent_file_template(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
master = RegistrationParentFileMaster.objects.create(name="Doc parent 2")
student = Student.objects.create(last_name="Test", first_name="Eleve")
group = RegistrationFileGroup.objects.create(name="Groupe D", establishment=est)
form = RegistrationForm.objects.create(student=student, fileGroup=group, establishment=est)
template = RegistrationParentFileTemplate.objects.create(master=master, registration_form=form)
self.assertEqual(template.master, master)
self.assertEqual(template.registration_form, form)
class AbsenceManagementModelTest(TestCase):
def test_create_absence(self):
student = Student.objects.create(last_name="Test", first_name="Eleve")
absence = AbsenceManagement.objects.create(student=student, day=date.today())
self.assertEqual(absence.student, student)
self.assertEqual(absence.day, date.today())