ScoDoc-PE/tests/unit/test_notes_rattrapage.py

185 lines
7.0 KiB
Python
Raw Normal View History

2021-10-11 12:29:33 +02:00
"""Test calculs rattrapages
"""
2023-08-25 17:58:57 +02:00
import datetime
2021-10-11 12:29:33 +02:00
import app
from app import db
from app.comp import res_sem
from app.comp.res_but import ResultatsSemestreBUT
2023-08-30 09:22:51 +02:00
from app.models import Evaluation, FormSemestre, ModuleImpl
from app.scodoc import (
sco_bulletins,
sco_formsemestre,
sco_saisie_notes,
)
2021-10-11 12:29:33 +02:00
from app.scodoc import sco_utils as scu
from config import TestConfig
from tests.unit import sco_fake_gen
2021-10-11 12:29:33 +02:00
DEPT = TestConfig.DEPT_TEST
def test_notes_rattrapage(test_client):
"""Test quelques opérations élémentaires de ScoDoc
2021-10-30 23:27:27 +02:00
Création 1 étudiant, formation, semestre, inscription etudiant,
creation 1 evaluation, saisie notes.
2021-10-11 12:29:33 +02:00
"""
app.set_sco_dept(DEPT)
G = sco_fake_gen.ScoFake(verbose=False)
etuds = [G.create_etud(code_nip=None)] # un seul
2022-01-15 21:36:06 +01:00
formation_id = G.create_formation(acronyme="")
ue_id = G.create_ue(formation_id=formation_id, acronyme="TST1", titre="ue test")
matiere_id = G.create_matiere(ue_id=ue_id, titre="matière test")
module_id = G.create_module(
matiere_id=matiere_id,
2021-10-11 12:29:33 +02:00
code="TSM1",
coefficient=1.0,
titre="module test",
)
# --- Mise place d'un semestre
2022-01-15 21:36:06 +01:00
formsemestre_id = G.create_formsemestre(
formation_id=formation_id,
2021-10-11 12:29:33 +02:00
semestre_id=1,
date_debut="01/01/2020",
date_fin="30/06/2020",
)
2022-01-15 21:36:06 +01:00
sem = sco_formsemestre.get_formsemestre(formsemestre_id)
moduleimpl_id = G.create_moduleimpl(
module_id=module_id,
formsemestre_id=formsemestre_id,
2021-10-11 12:29:33 +02:00
)
# --- Inscription des étudiants
for etud in etuds:
2022-01-15 21:36:06 +01:00
G.inscrit_etudiant(formsemestre_id, etud)
2021-10-11 12:29:33 +02:00
# --- Creation évaluation
e = G.create_evaluation(
2022-01-15 21:36:06 +01:00
moduleimpl_id=moduleimpl_id,
2023-08-25 17:58:57 +02:00
date_debut=datetime.datetime(2020, 1, 1),
2021-10-11 12:29:33 +02:00
description="evaluation test",
coefficient=1.0,
)
# --- Création d'une évaluation "de rattrapage"
e_rat = G.create_evaluation(
2022-01-15 21:36:06 +01:00
moduleimpl_id=moduleimpl_id,
2023-08-25 17:58:57 +02:00
date_debut=datetime.datetime(2020, 1, 2),
2021-10-11 12:29:33 +02:00
description="evaluation rattrapage",
coefficient=1.0,
evaluation_type=scu.EVALUATION_RATTRAPAGE,
)
etud = etuds[0]
2022-12-06 13:06:50 +01:00
_, _, _ = G.create_note(evaluation_id=e["id"], etudid=etud["etudid"], note=12.0)
_, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["etudid"], note=11.0)
# --- Vérifications internes structures ScoDoc
formsemestre = db.session.get(FormSemestre, formsemestre_id)
res: ResultatsSemestreBUT = res_sem.load_formsemestre_results(formsemestre)
mod_res = res.modimpls_results[moduleimpl_id]
moduleimpl = db.session.get(ModuleImpl, moduleimpl_id)
# retrouve l'éval. de rattrapage:
eval_rat = mod_res.get_evaluation_rattrapage(moduleimpl)
assert eval_rat.id == e_rat["id"]
# Les deux évaluations sont considérées comme complètes:
assert len(mod_res.get_evaluations_completes(moduleimpl)) == 2
# --- Vérification sur bulletin
2021-10-11 12:29:33 +02:00
b = sco_bulletins.formsemestre_bulletinetud_dict(
sem["formsemestre_id"], etud["etudid"]
)
# Vérifie structure du bulletin:
assert b["etudid"] == etud["etudid"]
assert len(b["ues"][0]["modules"][0]["evaluations"]) == 2
assert len(b["ues"][0]["modules"]) == 1
# Note moyenne: ici le ratrapage est inférieur à la note:
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(12.0)
# rattrapage > moyenne:
2022-12-06 13:06:50 +01:00
_, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["etudid"], note=18.0)
2021-10-11 12:29:33 +02:00
b = sco_bulletins.formsemestre_bulletinetud_dict(
sem["formsemestre_id"], etud["etudid"]
)
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(18.0)
# rattrapage vs absences
2022-12-06 13:06:50 +01:00
_, _, _ = G.create_note(
evaluation_id=e["id"], etudid=etud["etudid"], note=None
) # abs
_, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["etudid"], note=17.0)
2021-10-11 12:29:33 +02:00
b = sco_bulletins.formsemestre_bulletinetud_dict(
sem["formsemestre_id"], etud["etudid"]
)
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(17.0)
# et sans note de rattrapage
2022-12-06 13:06:50 +01:00
_, _, _ = G.create_note(evaluation_id=e["id"], etudid=etud["etudid"], note=10.0)
_, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["etudid"], note=None)
2021-10-11 12:29:33 +02:00
b = sco_bulletins.formsemestre_bulletinetud_dict(
sem["formsemestre_id"], etud["etudid"]
)
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(10.0)
# Supprime toutes les notes de l'évaluation de rattrapage:
sco_saisie_notes.evaluation_suppress_alln(e_rat["id"], dialog_confirmed=True)
b = sco_bulletins.formsemestre_bulletinetud_dict(
sem["formsemestre_id"], etud["etudid"]
)
# Vérifie structure du bulletin:
assert b["etudid"] == etud["etudid"]
assert len(b["ues"][0]["modules"][0]["evaluations"]) == 1 # reste une eval normale
assert len(b["ues"][0]["modules"]) == 1
# Note moyenne: reviens à 10/20
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(10.0)
# Supprime l'évaluation de rattrapage:
2023-08-30 09:22:51 +02:00
evaluation = db.session.get(Evaluation, e_rat["id"])
assert evaluation
evaluation.delete()
b = sco_bulletins.formsemestre_bulletinetud_dict(
sem["formsemestre_id"], etud["etudid"]
)
assert len(b["ues"][0]["modules"][0]["evaluations"]) == 1 # reste une eval normale
# Création évaluation session 2:
e_session2 = G.create_evaluation(
moduleimpl_id=moduleimpl_id,
2023-08-25 17:58:57 +02:00
date_debut=datetime.datetime(2020, 1, 2),
description="evaluation session 2",
coefficient=1.0,
evaluation_type=scu.EVALUATION_SESSION2,
)
res: ResultatsSemestreBUT = res_sem.load_formsemestre_results(formsemestre)
mod_res = res.modimpls_results[moduleimpl_id]
# retrouve l'éval. de session 2:
eval_session2 = mod_res.get_evaluation_session2(moduleimpl)
assert eval_session2.id == e_session2["id"]
# Les deux évaluations sont considérées comme complètes:
assert len(mod_res.get_evaluations_completes(moduleimpl)) == 2
# Saisie note session 2:
2022-12-06 13:06:50 +01:00
_, _, _ = G.create_note(
evaluation_id=e_session2["id"], etudid=etud["etudid"], note=5.0
)
b = sco_bulletins.formsemestre_bulletinetud_dict(
sem["formsemestre_id"], etud["etudid"]
)
# Note moyenne: utilise session 2 même si inférieure
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(5.0)
_, _, _ = G.create_note(
2022-12-06 13:06:50 +01:00
evaluation_id=e_session2["id"], etudid=etud["etudid"], note=20.0
)
b = sco_bulletins.formsemestre_bulletinetud_dict(
sem["formsemestre_id"], etud["etudid"]
)
# Note moyenne: utilise session 2 même si inférieure
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(20.0)
_, _, _ = G.create_note(
2022-12-06 13:06:50 +01:00
evaluation_id=e_session2["id"], etudid=etud["etudid"], note=None
)
b = sco_bulletins.formsemestre_bulletinetud_dict(
sem["formsemestre_id"], etud["etudid"]
)
# Note moyenne: revient à note normale
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(10.0)