forked from ScoDoc/ScoDoc
84 lines
2.7 KiB
Python
84 lines
2.7 KiB
Python
"""
|
|
Test modèles évaluations avec poids BUT
|
|
"""
|
|
|
|
from tests.unit import sco_fake_gen
|
|
from app import db
|
|
from app import models
|
|
|
|
"""
|
|
mapp.set_sco_dept("RT")
|
|
from app.auth.models import get_super_admin
|
|
admin_user = get_super_admin()
|
|
ctx.push()
|
|
login_user(admin_user)
|
|
"""
|
|
|
|
|
|
def test_evaluation_poids(test_client):
|
|
"""Association de poids vers les UE"""
|
|
G = sco_fake_gen.ScoFake(verbose=False)
|
|
_f = G.create_formation(
|
|
acronyme="F3", titre="Formation 2", titre_officiel="Titre officiel 2"
|
|
)
|
|
_ue1 = G.create_ue(formation_id=_f["formation_id"], acronyme="UE1", titre="ue 1")
|
|
_ue2 = G.create_ue(formation_id=_f["formation_id"], acronyme="UE2", titre="ue 2")
|
|
_ue3 = G.create_ue(formation_id=_f["formation_id"], acronyme="UE3", titre="ue 3")
|
|
_mat = G.create_matiere(ue_id=_ue1["ue_id"], titre="matière test")
|
|
_mod = G.create_module(
|
|
matiere_id=_mat["matiere_id"],
|
|
code="TSM1",
|
|
coefficient=1.0,
|
|
titre="module test",
|
|
ue_id=_ue1["ue_id"],
|
|
formation_id=_f["formation_id"],
|
|
)
|
|
sem = G.create_formsemestre(
|
|
formation_id=_f["formation_id"],
|
|
semestre_id=1,
|
|
date_debut="01/01/2021",
|
|
date_fin="30/06/2021",
|
|
) # formsemestre_id=716
|
|
mi = G.create_moduleimpl(
|
|
module_id=_mod["module_id"],
|
|
formsemestre_id=sem["formsemestre_id"],
|
|
)
|
|
moduleimpl_id = mi["id"]
|
|
_e1 = G.create_evaluation(
|
|
moduleimpl_id=moduleimpl_id,
|
|
jour="01/01/2021",
|
|
description="evaluation 1",
|
|
coefficient=0,
|
|
)
|
|
evaluation_id = _e1["evaluation_id"] # evaluation_id=25246
|
|
ue1_id = _ue1["id"] # ue1_id=1684
|
|
formation_id = _f["id"] # formation_id=199
|
|
#
|
|
e1 = models.NotesEvaluation.query.get(evaluation_id)
|
|
ue1 = models.NotesUE.query.get(ue1_id)
|
|
assert e1.ue_poids == []
|
|
p1 = 3.14
|
|
e1.set_ue_poids(ue1, p1)
|
|
db.session.commit()
|
|
assert e1.get_ue_poids_dict()[ue1_id] == p1
|
|
ues = models.NotesUE.query.filter_by(formation_id=formation_id).all()
|
|
poids = [1.0, 2.0, 3.0]
|
|
for (ue, p) in zip(ues, poids):
|
|
e1.set_ue_poids(ue, p)
|
|
assert len(e1.ue_poids) == len(ues)
|
|
assert e1.get_ue_poids_dict()[ues[1].id] == poids[1]
|
|
e1.set_ue_poids(ue1, p1)
|
|
db.session.commit()
|
|
poids2 = [10, 20]
|
|
e1.update_ue_poids_dict({ue.id: p for (ue, p) in zip(ues[:-1], poids2)})
|
|
assert e1.get_ue_poids_dict()[ues[0].id] == poids2[0]
|
|
assert e1.get_ue_poids_dict()[ues[1].id] == poids2[1]
|
|
assert e1.get_ue_poids_dict()[ues[2].id] == poids[2]
|
|
# Delete UE
|
|
db.session.delete(ues[2])
|
|
db.session.commit()
|
|
# Delete eval
|
|
db.session.delete(e1)
|
|
db.session.commit()
|
|
assert len(models.EvaluationUEPoids.query.all()) == 0
|