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

78 lines
4.6 KiB
Python

from django.test import TestCase
from .models import Speciality, Teacher, SchoolClass, Planning, Discount, Fee, PaymentPlan, PaymentMode, Competency, EstablishmentCompetency
from Establishment.models import Establishment
from Common.models import Category, PaymentPlanType, PaymentModeType
from datetime import date
class SpecialityModelTest(TestCase):
def test_create_speciality(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
speciality = Speciality.objects.create(name="Maths", establishment=est)
self.assertEqual(speciality.name, "Maths")
self.assertEqual(speciality.establishment, est)
class TeacherModelTest(TestCase):
def test_create_teacher(self):
teacher = Teacher.objects.create(last_name="Martin", first_name="Paul")
self.assertEqual(teacher.last_name, "Martin")
self.assertEqual(teacher.first_name, "Paul")
class SchoolClassModelTest(TestCase):
def test_create_school_class(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
school_class = SchoolClass.objects.create(atmosphere_name="Classe A", establishment=est)
self.assertEqual(school_class.atmosphere_name, "Classe A")
self.assertEqual(school_class.establishment, est)
class PlanningModelTest(TestCase):
def test_create_planning(self):
school_class = SchoolClass.objects.create(atmosphere_name="Classe B", establishment=Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A"))
planning = Planning.objects.create(school_class=school_class)
self.assertEqual(planning.school_class, school_class)
class DiscountModelTest(TestCase):
def test_create_discount(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
discount = Discount.objects.create(name="Réduction", establishment=est)
self.assertEqual(discount.name, "Réduction")
self.assertEqual(discount.establishment, est)
class FeeModelTest(TestCase):
def test_create_fee(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
fee = Fee.objects.create(name="Frais", establishment=est)
self.assertEqual(fee.name, "Frais")
self.assertEqual(fee.establishment, est)
class PaymentPlanModelTest(TestCase):
def test_create_payment_plan(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
plan_type = PaymentPlanType.objects.create(code="A", label="Plan A")
payment_plan = PaymentPlan.objects.create(plan_type=plan_type, establishment=est)
self.assertEqual(payment_plan.plan_type, plan_type)
self.assertEqual(payment_plan.establishment, est)
class PaymentModeModelTest(TestCase):
def test_create_payment_mode(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
mode_type = PaymentModeType.objects.create(label="Espèces")
payment_mode = PaymentMode.objects.create(mode=mode_type, establishment=est)
self.assertEqual(payment_mode.mode, mode_type)
self.assertEqual(payment_mode.establishment, est)
class CompetencyModelTest(TestCase):
def test_create_competency(self):
cat = Category.objects.create(name="Maths", domain_id=1)
comp = Competency.objects.create(name="Compétence 1", category=cat)
self.assertEqual(comp.name, "Compétence 1")
self.assertEqual(comp.category, cat)
class EstablishmentCompetencyModelTest(TestCase):
def test_create_establishment_competency(self):
est = Establishment.objects.create(name="École Test", address="1 rue", total_capacity=10, establishment_type=[1], evaluation_frequency=1, licence_code="A")
cat = Category.objects.create(name="Maths", domain_id=1)
comp = Competency.objects.create(name="Compétence 2", category=cat)
est_comp = EstablishmentCompetency.objects.create(establishment=est, competency=comp)
self.assertEqual(est_comp.establishment, est)
self.assertEqual(est_comp.competency, comp)