From 5f0866fd15483175591fbfaa4ece06b69480e1f4 Mon Sep 17 00:00:00 2001 From: N3WT DE COMPET Date: Thu, 5 Jun 2025 16:31:07 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Cr=C3=A9ation=20de=20tests=20unitaires?= =?UTF-8?q?=20pour=20le=20back[#63]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Back-End/Auth/tests.py | 12 ++++ Back-End/Common/tests.py | 8 +++ Back-End/Establishment/tests.py | 17 +++++ Back-End/GestionMessagerie/tests.py | 13 ++++ Back-End/GestionNotification/tests.py | 22 ++++++ Back-End/Planning/tests.py | 27 ++++++++ Back-End/School/tests.py | 76 ++++++++++++++++++++- Back-End/Subscriptions/tests.py | 97 +++++++++++++++++++++++++++ Back-End/pytest.ini | 3 + Back-End/requirements.txt | 3 + docker-compose.yml | 14 ++++ 11 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 Back-End/Auth/tests.py create mode 100644 Back-End/Establishment/tests.py create mode 100644 Back-End/GestionMessagerie/tests.py create mode 100644 Back-End/GestionNotification/tests.py create mode 100644 Back-End/Planning/tests.py create mode 100644 Back-End/Subscriptions/tests.py create mode 100644 Back-End/pytest.ini diff --git a/Back-End/Auth/tests.py b/Back-End/Auth/tests.py new file mode 100644 index 0000000..3115544 --- /dev/null +++ b/Back-End/Auth/tests.py @@ -0,0 +1,12 @@ +from django.test import TestCase +from .models import Profile + +class ProfileModelTest(TestCase): + def test_create_profile(self): + user = Profile.objects.create_user( + username="testuser", + email="test@example.com", + password="testpass123" + ) + self.assertEqual(user.email, "test@example.com") + self.assertTrue(user.check_password("testpass123")) diff --git a/Back-End/Common/tests.py b/Back-End/Common/tests.py index 7ce503c..43f9714 100644 --- a/Back-End/Common/tests.py +++ b/Back-End/Common/tests.py @@ -1,3 +1,11 @@ from django.test import TestCase +from .models import Domain # Create your tests here. + +class DomainModelTest(TestCase): + def test_create_domain(self): + domain = Domain.objects.create(name="Mathématiques", cycle=1) + self.assertEqual(domain.name, "Mathématiques") + self.assertEqual(domain.cycle, 1) + self.assertIsNotNone(domain.id) diff --git a/Back-End/Establishment/tests.py b/Back-End/Establishment/tests.py new file mode 100644 index 0000000..54edf9c --- /dev/null +++ b/Back-End/Establishment/tests.py @@ -0,0 +1,17 @@ +from django.test import TestCase +from .models import Establishment, StructureType, EvaluationFrequency + +class EstablishmentModelTest(TestCase): + def test_create_establishment(self): + est = Establishment.objects.create( + name="École Test", + address="1 rue de l'École", + total_capacity=100, + establishment_type=[StructureType.PRIMAIRE], + evaluation_frequency=EvaluationFrequency.TRIMESTER, + licence_code="ABC123" + ) + self.assertEqual(est.name, "École Test") + self.assertEqual(est.establishment_type, [StructureType.PRIMAIRE]) + self.assertTrue(est.is_active) + self.assertIsNotNone(est.created_at) diff --git a/Back-End/GestionMessagerie/tests.py b/Back-End/GestionMessagerie/tests.py new file mode 100644 index 0000000..d5dce27 --- /dev/null +++ b/Back-End/GestionMessagerie/tests.py @@ -0,0 +1,13 @@ +from django.test import TestCase +from .models import Conversation + +class ConversationModelTest(TestCase): + def test_create_conversation(self): + conv = Conversation.objects.create( + name="Groupe Test", + conversation_type="group" + ) + self.assertEqual(conv.name, "Groupe Test") + self.assertEqual(conv.conversation_type, "group") + self.assertTrue(conv.is_active) + self.assertIsNotNone(conv.id) diff --git a/Back-End/GestionNotification/tests.py b/Back-End/GestionNotification/tests.py new file mode 100644 index 0000000..b6910ec --- /dev/null +++ b/Back-End/GestionNotification/tests.py @@ -0,0 +1,22 @@ +from django.test import TestCase +from .models import Notification, TypeNotif +from Auth.models import Profile + +class NotificationModelTest(TestCase): + def setUp(self): + self.user = Profile.objects.create_user( + username="notifuser", + email="notif@example.com", + password="testpass123" + ) + + def test_create_notification(self): + notif = Notification.objects.create( + user=self.user, + message="Un message a été reçu", + typeNotification=TypeNotif.NOTIF_MESSAGE + ) + self.assertEqual(notif.user, self.user) + self.assertEqual(notif.message, "Un message a été reçu") + self.assertFalse(notif.is_read) + self.assertEqual(notif.typeNotification, TypeNotif.NOTIF_MESSAGE) diff --git a/Back-End/Planning/tests.py b/Back-End/Planning/tests.py new file mode 100644 index 0000000..9b056ae --- /dev/null +++ b/Back-End/Planning/tests.py @@ -0,0 +1,27 @@ +from django.test import TestCase +from .models import Planning +from Establishment.models import Establishment +from School.models import SchoolClass + +class PlanningModelTest(TestCase): + def setUp(self): + self.establishment = Establishment.objects.create( + name="École Test", + address="1 rue de l'École", + total_capacity=100, + establishment_type=[1], + evaluation_frequency=1, + licence_code="ABC123" + ) + self.school_class = SchoolClass.objects.create( + atmosphere_name="Classe Test", + establishment=self.establishment + ) + + def test_create_planning(self): + planning = Planning.objects.create( + school_class=self.school_class, + establishment=self.establishment + ) + self.assertEqual(planning.school_class, self.school_class) + self.assertEqual(planning.establishment, self.establishment) diff --git a/Back-End/School/tests.py b/Back-End/School/tests.py index 7ce503c..c1d25da 100644 --- a/Back-End/School/tests.py +++ b/Back-End/School/tests.py @@ -1,3 +1,77 @@ 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 -# Create your tests here. +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) diff --git a/Back-End/Subscriptions/tests.py b/Back-End/Subscriptions/tests.py new file mode 100644 index 0000000..874b49e --- /dev/null +++ b/Back-End/Subscriptions/tests.py @@ -0,0 +1,97 @@ +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()) diff --git a/Back-End/pytest.ini b/Back-End/pytest.ini new file mode 100644 index 0000000..a503623 --- /dev/null +++ b/Back-End/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +DJANGO_SETTINGS_MODULE = N3wtSchool.settings +python_files = tests.py test_*.py *_tests.py diff --git a/Back-End/requirements.txt b/Back-End/requirements.txt index c930b58..9c806c4 100644 --- a/Back-End/requirements.txt +++ b/Back-End/requirements.txt @@ -70,3 +70,6 @@ xhtml2pdf==0.2.16 channels==4.0.0 channels-redis==4.1.0 daphne==4.1.0 +pytest +pytest-django +pytest-json-report diff --git a/docker-compose.yml b/docker-compose.yml index f000e9a..ef7e435 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,6 +36,20 @@ services: - database command: python start.py + backend-test: + build: + context: ./Back-End + volumes: + - ./Back-End:/Back-End + env_file: "./conf/backend.env" + links: + - "database:database" + - "redis:redis" + depends_on: + - redis + - database + command: python manage.py test + volumes: postgres-data: redis-data: