fix: tests
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
|
from datetime import date
|
||||||
from app import create_app
|
from app import create_app
|
||||||
from models import db
|
from models import db, Student, StudentEnrollment
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -30,6 +31,30 @@ def client(app):
|
|||||||
return app.test_client()
|
return app.test_client()
|
||||||
|
|
||||||
|
|
||||||
|
def create_student_with_enrollment(first_name, last_name, class_group_id, email=None, enrollment_date=None):
|
||||||
|
"""
|
||||||
|
Helper pour créer un étudiant avec inscription temporelle.
|
||||||
|
Utilise le nouveau système temporel au lieu de l'ancien class_group_id.
|
||||||
|
"""
|
||||||
|
if enrollment_date is None:
|
||||||
|
enrollment_date = date(2023, 9, 1) # Date par défaut de rentrée
|
||||||
|
|
||||||
|
# Créer l'étudiant sans class_group_id
|
||||||
|
student = Student(first_name=first_name, last_name=last_name, email=email)
|
||||||
|
db.session.add(student)
|
||||||
|
db.session.flush() # Pour obtenir l'ID
|
||||||
|
|
||||||
|
# Créer l'inscription temporelle
|
||||||
|
enrollment = StudentEnrollment(
|
||||||
|
student_id=student.id,
|
||||||
|
class_group_id=class_group_id,
|
||||||
|
enrollment_date=enrollment_date
|
||||||
|
)
|
||||||
|
db.session.add(enrollment)
|
||||||
|
|
||||||
|
return student
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def runner(app):
|
def runner(app):
|
||||||
return app.test_cli_runner()
|
return app.test_cli_runner()
|
||||||
@@ -3,6 +3,7 @@ from datetime import date
|
|||||||
from werkzeug.exceptions import NotFound
|
from werkzeug.exceptions import NotFound
|
||||||
from models import db, ClassGroup, Student, Assessment
|
from models import db, ClassGroup, Student, Assessment
|
||||||
from repositories.class_repository import ClassRepository
|
from repositories.class_repository import ClassRepository
|
||||||
|
from .conftest import create_student_with_enrollment
|
||||||
|
|
||||||
|
|
||||||
class TestClassRepository:
|
class TestClassRepository:
|
||||||
@@ -292,7 +293,8 @@ class TestClassRepository:
|
|||||||
db.session.add(class_group)
|
db.session.add(class_group)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
student = Student(first_name="Jean", last_name="Dupont", class_group_id=class_group.id)
|
# Utiliser le helper pour créer un étudiant avec inscription temporelle
|
||||||
|
student = create_student_with_enrollment("Jean", "Dupont", class_group.id)
|
||||||
assessment = Assessment(title="Test", trimester=1, class_group_id=class_group.id, date=date(2023, 10, 15))
|
assessment = Assessment(title="Test", trimester=1, class_group_id=class_group.id, date=date(2023, 10, 15))
|
||||||
db.session.add_all([student, assessment])
|
db.session.add_all([student, assessment])
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@@ -313,12 +315,12 @@ class TestClassRepository:
|
|||||||
db.session.add(class_group)
|
db.session.add(class_group)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
# Utiliser le helper pour créer des étudiants avec inscriptions temporelles
|
||||||
students = [
|
students = [
|
||||||
Student(first_name="Marie", last_name="Zidane", class_group_id=class_group.id),
|
create_student_with_enrollment("Marie", "Zidane", class_group.id),
|
||||||
Student(first_name="Jean", last_name="Dupont", class_group_id=class_group.id),
|
create_student_with_enrollment("Jean", "Dupont", class_group.id),
|
||||||
Student(first_name="Paul", last_name="Martin", class_group_id=class_group.id),
|
create_student_with_enrollment("Paul", "Martin", class_group.id),
|
||||||
]
|
]
|
||||||
db.session.add_all(students)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
@@ -423,7 +425,7 @@ class TestClassRepository:
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Ajouter étudiants et évaluations
|
# Ajouter étudiants et évaluations
|
||||||
student = Student(first_name="Jean", last_name="Dupont", class_group_id=class_group.id)
|
student = create_student_with_enrollment("Jean", "Dupont", class_group.id)
|
||||||
assessment = Assessment(title="Test", trimester=1, class_group_id=class_group.id, date=date(2023, 10, 15))
|
assessment = Assessment(title="Test", trimester=1, class_group_id=class_group.id, date=date(2023, 10, 15))
|
||||||
db.session.add_all([student, assessment])
|
db.session.add_all([student, assessment])
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@@ -464,9 +466,9 @@ class TestClassRepository:
|
|||||||
|
|
||||||
# Ajouter des étudiants
|
# Ajouter des étudiants
|
||||||
students = [
|
students = [
|
||||||
Student(first_name="Jean", last_name="Dupont", class_group_id=class_group.id),
|
create_student_with_enrollment("Jean", "Dupont", class_group.id),
|
||||||
Student(first_name="Marie", last_name="Martin", class_group_id=class_group.id),
|
create_student_with_enrollment("Marie", "Martin", class_group.id),
|
||||||
Student(first_name="Paul", last_name="Durand", class_group_id=class_group.id),
|
create_student_with_enrollment("Paul", "Durand", class_group.id),
|
||||||
]
|
]
|
||||||
db.session.add_all(students)
|
db.session.add_all(students)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from models import db, ClassGroup, Student, Assessment, Exercise, GradingElement, Grade
|
from models import db, ClassGroup, Student, Assessment, Exercise, GradingElement, Grade
|
||||||
|
from .conftest import create_student_with_enrollment
|
||||||
|
|
||||||
|
|
||||||
class TestClassGroup:
|
class TestClassGroup:
|
||||||
@@ -40,64 +41,54 @@ class TestStudent:
|
|||||||
db.session.add(class_group)
|
db.session.add(class_group)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
student = Student(
|
# Utiliser le helper pour créer un étudiant avec inscription temporelle
|
||||||
first_name="Jean",
|
student = create_student_with_enrollment(
|
||||||
last_name="Dupont",
|
"Jean",
|
||||||
email="jean.dupont@example.com",
|
"Dupont",
|
||||||
class_group_id=class_group.id
|
class_group.id,
|
||||||
|
email="jean.dupont@example.com"
|
||||||
)
|
)
|
||||||
db.session.add(student)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
assert student.id is not None
|
assert student.id is not None
|
||||||
assert student.first_name == "Jean"
|
assert student.first_name == "Jean"
|
||||||
assert student.last_name == "Dupont"
|
assert student.last_name == "Dupont"
|
||||||
assert student.email == "jean.dupont@example.com"
|
assert student.email == "jean.dupont@example.com"
|
||||||
assert student.class_group_id == class_group.id
|
|
||||||
|
# Vérifier l'inscription temporelle au lieu de class_group_id
|
||||||
|
assert len(student.enrollments) == 1
|
||||||
|
assert student.enrollments[0].class_group_id == class_group.id
|
||||||
|
|
||||||
def test_student_full_name_property(self, app):
|
def test_student_full_name_property(self, app):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
class_group = ClassGroup(name="6A", year="2023-2024")
|
# Pas besoin de class_group pour tester full_name
|
||||||
db.session.add(class_group)
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
student = Student(
|
student = Student(
|
||||||
first_name="Jean",
|
first_name="Jean",
|
||||||
last_name="Dupont",
|
last_name="Dupont"
|
||||||
class_group_id=class_group.id
|
|
||||||
)
|
)
|
||||||
assert student.full_name == "Jean Dupont"
|
assert student.full_name == "Jean Dupont"
|
||||||
|
|
||||||
def test_student_repr(self, app):
|
def test_student_repr(self, app):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
class_group = ClassGroup(name="6A", year="2023-2024")
|
# Pas besoin de class_group pour tester __repr__
|
||||||
db.session.add(class_group)
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
student = Student(
|
student = Student(
|
||||||
first_name="Jean",
|
first_name="Jean",
|
||||||
last_name="Dupont",
|
last_name="Dupont"
|
||||||
class_group_id=class_group.id
|
|
||||||
)
|
)
|
||||||
assert repr(student) == "<Student Jean Dupont>"
|
assert repr(student) == "<Student Jean Dupont>"
|
||||||
|
|
||||||
def test_student_unique_email(self, app):
|
def test_student_unique_email(self, app):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
class_group = ClassGroup(name="6A", year="2023-2024")
|
# Pas besoin de class_group pour tester contrainte unique email
|
||||||
db.session.add(class_group)
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
student1 = Student(
|
student1 = Student(
|
||||||
first_name="Jean",
|
first_name="Jean",
|
||||||
last_name="Dupont",
|
last_name="Dupont",
|
||||||
email="jean.dupont@example.com",
|
email="jean.dupont@example.com"
|
||||||
class_group_id=class_group.id
|
|
||||||
)
|
)
|
||||||
student2 = Student(
|
student2 = Student(
|
||||||
first_name="Marie",
|
first_name="Marie",
|
||||||
last_name="Martin",
|
last_name="Martin",
|
||||||
email="jean.dupont@example.com",
|
email="jean.dupont@example.com"
|
||||||
class_group_id=class_group.id
|
|
||||||
)
|
)
|
||||||
|
|
||||||
db.session.add(student1)
|
db.session.add(student1)
|
||||||
@@ -287,12 +278,8 @@ class TestGrade:
|
|||||||
db.session.add(class_group)
|
db.session.add(class_group)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
student = Student(
|
# Utiliser le helper pour créer un étudiant avec inscription temporelle
|
||||||
first_name="Jean",
|
student = create_student_with_enrollment("Jean", "Dupont", class_group.id)
|
||||||
last_name="Dupont",
|
|
||||||
class_group_id=class_group.id
|
|
||||||
)
|
|
||||||
db.session.add(student)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
assessment = Assessment(title="Contrôle", trimester=1, class_group_id=class_group.id)
|
assessment = Assessment(title="Contrôle", trimester=1, class_group_id=class_group.id)
|
||||||
@@ -330,12 +317,8 @@ class TestGrade:
|
|||||||
db.session.add(class_group)
|
db.session.add(class_group)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
student = Student(
|
# Utiliser le helper pour créer un étudiant avec inscription temporelle
|
||||||
first_name="Jean",
|
student = create_student_with_enrollment("Jean", "Dupont", class_group.id)
|
||||||
last_name="Dupont",
|
|
||||||
class_group_id=class_group.id
|
|
||||||
)
|
|
||||||
db.session.add(student)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
grade = Grade(
|
grade = Grade(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import pytest
|
|||||||
from models import GradingCalculator, db, Assessment, ClassGroup, Student, Exercise, GradingElement, Grade
|
from models import GradingCalculator, db, Assessment, ClassGroup, Student, Exercise, GradingElement, Grade
|
||||||
from app_config import config_manager
|
from app_config import config_manager
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from .conftest import create_student_with_enrollment
|
||||||
|
|
||||||
|
|
||||||
class TestUnifiedGrading:
|
class TestUnifiedGrading:
|
||||||
@@ -143,10 +144,9 @@ class TestIntegration:
|
|||||||
db.session.add(class_group)
|
db.session.add(class_group)
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
|
|
||||||
# Créer étudiants
|
# Créer étudiants avec inscriptions temporelles
|
||||||
student1 = Student(first_name='Alice', last_name='Martin', class_group_id=class_group.id)
|
student1 = create_student_with_enrollment('Alice', 'Martin', class_group.id)
|
||||||
student2 = Student(first_name='Bob', last_name='Durand', class_group_id=class_group.id)
|
student2 = create_student_with_enrollment('Bob', 'Durand', class_group.id)
|
||||||
db.session.add_all([student1, student2])
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
|
|
||||||
# Créer évaluation
|
# Créer évaluation
|
||||||
@@ -261,16 +261,15 @@ class TestPerformance:
|
|||||||
db.session.add(class_group)
|
db.session.add(class_group)
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
|
|
||||||
# 30 étudiants
|
# 30 étudiants avec inscriptions temporelles
|
||||||
students = []
|
students = []
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
student = Student(
|
student = create_student_with_enrollment(
|
||||||
first_name=f'Étudiant{i}',
|
f'Étudiant{i}',
|
||||||
last_name=f'Test{i}',
|
f'Test{i}',
|
||||||
class_group_id=class_group.id
|
class_group.id
|
||||||
)
|
)
|
||||||
students.append(student)
|
students.append(student)
|
||||||
db.session.add_all(students)
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
|
|
||||||
# Évaluation avec 20 éléments
|
# Évaluation avec 20 éléments
|
||||||
|
|||||||
Reference in New Issue
Block a user