forked from ScoDoc/ScoDoc
tests unitaires calculs moyennes modules et UE
This commit is contained in:
parent
9f9cb6cca2
commit
01a84f3b12
@ -1,4 +1,6 @@
|
||||
"""Test calculs moyennes de modules
|
||||
Vérif moyennes de modules des bulletins
|
||||
et aussi moyennes modules et UE internes (via nt)
|
||||
"""
|
||||
|
||||
from config import TestConfig
|
||||
@ -15,24 +17,51 @@ from app.scodoc import sco_utils as scu
|
||||
DEPT = TestConfig.DEPT_TEST
|
||||
|
||||
|
||||
def check_nt(
|
||||
etudid,
|
||||
formsemestre_id,
|
||||
ue_id,
|
||||
moduleimpl_id,
|
||||
expected_moy_ue=False,
|
||||
expected_mod_moy=False,
|
||||
expected_sum_coefs_ue=False,
|
||||
):
|
||||
"""Vérification bas niveau: vérif resultat avec l'API internet "nt"
|
||||
(peut changer dans le futur, ne pas utiliser hors ScoDoc !)
|
||||
ne vérifie que les valeurs expected non False
|
||||
"""
|
||||
nt = sco_cache.NotesTableCache.get(formsemestre_id)
|
||||
mod_moy = nt.get_etud_mod_moy(moduleimpl_id, etudid)
|
||||
if expected_moy_ue is not False:
|
||||
ue_status = nt.get_etud_ue_status(etudid, ue_id)
|
||||
assert expected_moy_ue == ue_status["moy"]
|
||||
if expected_mod_moy is not False:
|
||||
assert expected_mod_moy == mod_moy
|
||||
if expected_sum_coefs_ue is not False:
|
||||
ue_status = nt.get_etud_ue_status(etudid, ue_id)
|
||||
assert expected_sum_coefs_ue == ue_status["sum_coefs"]
|
||||
|
||||
|
||||
def test_notes_modules(test_client):
|
||||
"""Test quelques opérations élémentaires de ScoDoc
|
||||
Création 1 étudiant, formation, semestre, inscription etudiant,
|
||||
création 1 evaluation, saisie de notes.
|
||||
"""Test calcul des moyennes de modules et d'UE
|
||||
Création étudiant, formation, semestre, inscription etudiant,
|
||||
création evaluation, saisie de notes.
|
||||
Vérifie calcul moyenne avec absences (ABS), excuse (EXC), attente (ATT)
|
||||
"""
|
||||
app.set_sco_dept(DEPT)
|
||||
|
||||
G = sco_fake_gen.ScoFake(verbose=False)
|
||||
etuds = [G.create_etud(code_nip=None)] # un seul
|
||||
etuds = [G.create_etud(code_nip=None) for i in range(2)] # 2 étudiants
|
||||
|
||||
f = G.create_formation(acronyme="")
|
||||
ue = G.create_ue(formation_id=f["formation_id"], acronyme="TST1", titre="ue test")
|
||||
mat = G.create_matiere(ue_id=ue["ue_id"], titre="matière test")
|
||||
ue_id = ue["ue_id"]
|
||||
mat = G.create_matiere(ue_id=ue_id, titre="matière test")
|
||||
coef_mod_1 = 1.5
|
||||
mod = G.create_module(
|
||||
matiere_id=mat["matiere_id"],
|
||||
code="TSM1",
|
||||
coefficient=1.0,
|
||||
coefficient=coef_mod_1,
|
||||
titre="module test",
|
||||
ue_id=ue["ue_id"],
|
||||
formation_id=f["formation_id"],
|
||||
@ -45,27 +74,28 @@ def test_notes_modules(test_client):
|
||||
date_debut="01/01/2020",
|
||||
date_fin="30/06/2020",
|
||||
)
|
||||
|
||||
formsemestre_id = sem["formsemestre_id"]
|
||||
mi = G.create_moduleimpl(
|
||||
module_id=mod["module_id"],
|
||||
formsemestre_id=sem["formsemestre_id"],
|
||||
formsemestre_id=formsemestre_id,
|
||||
)
|
||||
|
||||
moduleimpl_id = mi["moduleimpl_id"]
|
||||
# --- Inscription des étudiants
|
||||
for etud in etuds:
|
||||
G.inscrit_etudiant(sem, etud)
|
||||
etud = etuds[0]
|
||||
etudid = etud["etudid"]
|
||||
# --- Creation évaluations: e1, e2
|
||||
coef_1 = 1.0
|
||||
coef_2 = 2.0
|
||||
e1 = G.create_evaluation(
|
||||
moduleimpl_id=mi["moduleimpl_id"],
|
||||
moduleimpl_id=moduleimpl_id,
|
||||
jour="01/01/2020",
|
||||
description="evaluation 1",
|
||||
coefficient=coef_1,
|
||||
)
|
||||
e2 = G.create_evaluation(
|
||||
moduleimpl_id=mi["moduleimpl_id"],
|
||||
moduleimpl_id=moduleimpl_id,
|
||||
jour="01/01/2020",
|
||||
description="evaluation 2",
|
||||
coefficient=coef_2,
|
||||
@ -73,8 +103,10 @@ def test_notes_modules(test_client):
|
||||
# --- Notes ordinaires
|
||||
note_1 = 12.0
|
||||
note_2 = 13.0
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etud, note=note_1)
|
||||
_, _, _ = G.create_note(evaluation=e2, etud=etud, note=note_2)
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etuds[0], note=note_1)
|
||||
_, _, _ = G.create_note(evaluation=e2, etud=etuds[0], note=note_2)
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etuds[1], note=note_1 / 2)
|
||||
_, _, _ = G.create_note(evaluation=e2, etud=etuds[1], note=note_2 / 3)
|
||||
b = sco_bulletins.formsemestre_bulletinetud_dict(
|
||||
sem["formsemestre_id"], etud["etudid"]
|
||||
)
|
||||
@ -85,6 +117,15 @@ def test_notes_modules(test_client):
|
||||
# Note moyenne:
|
||||
note_th = (coef_1 * note_1 + coef_2 * note_2) / (coef_1 + coef_2)
|
||||
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(note_th)
|
||||
check_nt(
|
||||
etudid,
|
||||
formsemestre_id,
|
||||
ue_id,
|
||||
moduleimpl_id,
|
||||
expected_mod_moy=note_th,
|
||||
expected_moy_ue=note_th,
|
||||
expected_sum_coefs_ue=coef_mod_1,
|
||||
)
|
||||
|
||||
# Absence à une évaluation
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etud, note=None) # abs
|
||||
@ -101,6 +142,16 @@ def test_notes_modules(test_client):
|
||||
sem["formsemestre_id"], etud["etudid"]
|
||||
)
|
||||
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(0.0)
|
||||
check_nt(
|
||||
etudid,
|
||||
formsemestre_id,
|
||||
ue_id,
|
||||
moduleimpl_id,
|
||||
expected_mod_moy=0.0,
|
||||
expected_moy_ue=0.0,
|
||||
expected_sum_coefs_ue=0.0,
|
||||
)
|
||||
|
||||
# Note excusée EXC <-> scu.NOTES_NEUTRALISE
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etud, note=note_1)
|
||||
_, _, _ = G.create_note(evaluation=e2, etud=etud, note=scu.NOTES_NEUTRALISE) # EXC
|
||||
@ -108,6 +159,15 @@ def test_notes_modules(test_client):
|
||||
sem["formsemestre_id"], etud["etudid"]
|
||||
)
|
||||
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(note_1)
|
||||
check_nt(
|
||||
etudid,
|
||||
formsemestre_id,
|
||||
ue_id,
|
||||
moduleimpl_id,
|
||||
expected_mod_moy=note_1,
|
||||
expected_moy_ue=note_1,
|
||||
expected_sum_coefs_ue=coef_mod_1,
|
||||
)
|
||||
# Note en attente ATT <-> scu.NOTES_ATTENTE
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etud, note=note_1)
|
||||
_, _, _ = G.create_note(evaluation=e2, etud=etud, note=scu.NOTES_ATTENTE) # ATT
|
||||
@ -115,6 +175,15 @@ def test_notes_modules(test_client):
|
||||
sem["formsemestre_id"], etud["etudid"]
|
||||
)
|
||||
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(note_1)
|
||||
check_nt(
|
||||
etudid,
|
||||
formsemestre_id,
|
||||
ue_id,
|
||||
moduleimpl_id,
|
||||
expected_mod_moy=note_1,
|
||||
expected_moy_ue=note_1,
|
||||
expected_sum_coefs_ue=coef_mod_1,
|
||||
)
|
||||
# Neutralisation (EXC) des 2 évals
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etud, note=scu.NOTES_NEUTRALISE) # EXC
|
||||
_, _, _ = G.create_note(evaluation=e2, etud=etud, note=scu.NOTES_NEUTRALISE) # EXC
|
||||
@ -122,10 +191,31 @@ def test_notes_modules(test_client):
|
||||
sem["formsemestre_id"], etud["etudid"]
|
||||
)
|
||||
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == "-"
|
||||
# Vérification bas niveau: (peut changer dans le futur !)
|
||||
nt = sco_cache.NotesTableCache.get(sem["formsemestre_id"])
|
||||
mod_moy = nt.get_etud_mod_moy(mi["moduleimpl_id"], etud["etudid"])
|
||||
assert mod_moy == "NA0" # peut changer dans le futur !
|
||||
check_nt(
|
||||
etudid,
|
||||
sem["formsemestre_id"],
|
||||
ue["ue_id"],
|
||||
mi["moduleimpl_id"],
|
||||
expected_mod_moy="NA0",
|
||||
expected_moy_ue=0.0,
|
||||
expected_sum_coefs_ue=0.0,
|
||||
)
|
||||
# Attente (ATT) sur les 2 evals
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etud, note=scu.NOTES_ATTENTE) # ATT
|
||||
_, _, _ = G.create_note(evaluation=e2, etud=etud, note=scu.NOTES_ATTENTE) # ATT
|
||||
b = sco_bulletins.formsemestre_bulletinetud_dict(
|
||||
sem["formsemestre_id"], etud["etudid"]
|
||||
)
|
||||
assert b["ues"][0]["modules"][0]["mod_moy_txt"] == "-"
|
||||
check_nt(
|
||||
etudid,
|
||||
sem["formsemestre_id"],
|
||||
ue["ue_id"],
|
||||
mi["moduleimpl_id"],
|
||||
expected_mod_moy="NA0",
|
||||
expected_moy_ue=0.0,
|
||||
expected_sum_coefs_ue=0.0,
|
||||
)
|
||||
# Non inscrit
|
||||
# - désinscrit notre étudiant:
|
||||
inscr = sco_moduleimpl.do_moduleimpl_inscription_list(
|
||||
@ -141,7 +231,77 @@ def test_notes_modules(test_client):
|
||||
sem["formsemestre_id"], etud["etudid"]
|
||||
)
|
||||
assert b["ues"] == [] # inscrit à aucune UE !
|
||||
# Vérification bas niveau: (peut changer dans le futur !)
|
||||
nt = sco_cache.NotesTableCache.get(sem["formsemestre_id"])
|
||||
mod_moy = nt.get_etud_mod_moy(mi["moduleimpl_id"], etud["etudid"])
|
||||
assert mod_moy == "NI" # peut changer dans le futur !
|
||||
check_nt(
|
||||
etudid,
|
||||
formsemestre_id,
|
||||
ue_id,
|
||||
moduleimpl_id,
|
||||
expected_mod_moy="NI",
|
||||
expected_moy_ue=0.0,
|
||||
expected_sum_coefs_ue=0.0,
|
||||
)
|
||||
# --- Maintenant avec 2 modules dans l'UE
|
||||
mod2 = G.create_module(
|
||||
matiere_id=mat["matiere_id"],
|
||||
code="TSM2",
|
||||
coefficient=coef_mod_2,
|
||||
titre="module test 2",
|
||||
ue_id=ue_id,
|
||||
formation_id=f["formation_id"],
|
||||
)
|
||||
mi2 = G.create_moduleimpl(
|
||||
module_id=mod2["module_id"],
|
||||
formsemestre_id=formsemestre_id,
|
||||
)
|
||||
# Re-inscription au premier module de l'UE
|
||||
sco_moduleimpl.do_moduleimpl_inscription_create(
|
||||
{"etudid": etudid, "moduleimpl_id": mi["moduleimpl_id"]},
|
||||
formsemestre_id=formsemestre_id,
|
||||
)
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etud, note=12.5)
|
||||
nt = sco_cache.NotesTableCache.get(formsemestre_id)
|
||||
ue_status = nt.get_etud_ue_status(etudid, ue_id)
|
||||
assert ue_status["nb_missing"] == 1 # 1 même si etud non inscrit à l'autre module
|
||||
assert ue_status["nb_notes"] == 1
|
||||
assert not ue_status["was_capitalized"]
|
||||
# Inscription au deuxième module de l'UE
|
||||
sco_moduleimpl.do_moduleimpl_inscription_create(
|
||||
{"etudid": etudid, "moduleimpl_id": mi2["moduleimpl_id"]},
|
||||
formsemestre_id=formsemestre_id,
|
||||
)
|
||||
nt = sco_cache.NotesTableCache.get(formsemestre_id)
|
||||
ue_status = nt.get_etud_ue_status(etudid, ue_id)
|
||||
assert ue_status["nb_missing"] == 1 # mi2 n'a pas encore de note
|
||||
assert ue_status["nb_notes"] == 1
|
||||
# Note dans module 2:
|
||||
e_m2 = G.create_evaluation(
|
||||
moduleimpl_id=mi2["moduleimpl_id"],
|
||||
jour="01/01/2020",
|
||||
description="evaluation mod 2",
|
||||
coefficient=1.0,
|
||||
)
|
||||
_, _, _ = G.create_note(evaluation=e_m2, etud=etud, note=19.5)
|
||||
nt = sco_cache.NotesTableCache.get(formsemestre_id)
|
||||
ue_status = nt.get_etud_ue_status(etudid, ue_id)
|
||||
assert ue_status["nb_missing"] == 0
|
||||
assert ue_status["nb_notes"] == 2
|
||||
|
||||
# Moyenne d'UE si l'un des modules est EXC ("NA0")
|
||||
# 2 modules, notes EXC dans le premier, note valide n dans le second
|
||||
# la moyenne de l'UE doit être n
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etud, note=scu.NOTES_NEUTRALISE) # EXC
|
||||
_, _, _ = G.create_note(evaluation=e2, etud=etud, note=scu.NOTES_NEUTRALISE) # EXC
|
||||
_, _, _ = G.create_note(evaluation=e_m2, etud=etud, note=12.5)
|
||||
_, _, _ = G.create_note(evaluation=e1, etud=etuds[1], note=11.0)
|
||||
_, _, _ = G.create_note(evaluation=e2, etud=etuds[1], note=11.0)
|
||||
_, _, _ = G.create_note(evaluation=e_m2, etud=etuds[1], note=11.0)
|
||||
b = sco_bulletins.formsemestre_bulletinetud_dict(
|
||||
sem["formsemestre_id"], etud["etudid"]
|
||||
)
|
||||
assert b["ues"][0]["ue_status"]["cur_moy_ue"] == 12.5
|
||||
assert b["ues"][0]["ue_status"]["moy"] == 12.5
|
||||
b2 = sco_bulletins.formsemestre_bulletinetud_dict(
|
||||
sem["formsemestre_id"], etuds[1]["etudid"]
|
||||
)
|
||||
assert b2["ues"][0]["ue_status"]["cur_moy_ue"] == 11.0
|
||||
assert b2["ues"][0]["ue_status"]["moy"] == 11
|
||||
|
Loading…
Reference in New Issue
Block a user