2021-11-28 16:26:04 +01:00
|
|
|
"""
|
|
|
|
Quelques fonctions d'initialisation pour tests unitaires
|
|
|
|
"""
|
|
|
|
|
|
|
|
from app import models
|
|
|
|
|
2021-12-24 06:08:35 +01:00
|
|
|
import app.scodoc.sco_utils as scu
|
2021-11-28 16:26:04 +01:00
|
|
|
from app.scodoc import sco_codes_parcours
|
|
|
|
|
2022-11-22 13:13:16 +01:00
|
|
|
# Valeurs des notes saisies par les tests:
|
|
|
|
NOTES_T = [
|
|
|
|
float(x) for x in (20, 0, 10, 13 / 7.0, 12.5, 24.0 / 11) + tuple(range(1, 19))
|
|
|
|
]
|
|
|
|
|
2022-12-09 06:00:21 +01:00
|
|
|
from tests.unit import sco_fake_gen
|
|
|
|
|
2021-11-28 16:26:04 +01:00
|
|
|
|
2022-01-15 21:36:06 +01:00
|
|
|
def build_formation_test(
|
|
|
|
nb_mods=1, parcours=sco_codes_parcours.ParcoursBUT, with_ue_sport=False
|
|
|
|
):
|
2021-11-28 16:26:04 +01:00
|
|
|
G = sco_fake_gen.ScoFake(verbose=False)
|
2022-01-15 21:36:06 +01:00
|
|
|
formation_id = G.create_formation(
|
2021-11-28 16:26:04 +01:00
|
|
|
acronyme="F3",
|
|
|
|
titre="Formation 2",
|
|
|
|
titre_officiel="Titre officiel 2",
|
2022-01-15 21:36:06 +01:00
|
|
|
type_parcours=parcours.TYPE_PARCOURS,
|
2021-11-28 16:26:04 +01:00
|
|
|
)
|
|
|
|
_ue1 = G.create_ue(
|
2022-01-15 21:36:06 +01:00
|
|
|
formation_id=formation_id, acronyme="UE1", titre="ue 1", semestre_idx=2
|
2021-11-28 16:26:04 +01:00
|
|
|
)
|
|
|
|
_ue2 = G.create_ue(
|
2022-01-15 21:36:06 +01:00
|
|
|
formation_id=formation_id, acronyme="UE2", titre="ue 2", semestre_idx=2
|
2021-11-28 16:26:04 +01:00
|
|
|
)
|
|
|
|
_ue3 = G.create_ue(
|
2022-01-15 21:36:06 +01:00
|
|
|
formation_id=formation_id, acronyme="UE3", titre="ue 3", semestre_idx=2
|
2021-11-28 16:26:04 +01:00
|
|
|
)
|
2022-01-15 21:36:06 +01:00
|
|
|
ue_ids = [_ue1, _ue2, _ue3]
|
2021-11-28 16:26:04 +01:00
|
|
|
# une 4eme UE en dehors du semestre 2
|
|
|
|
_ = G.create_ue(
|
2022-01-15 21:36:06 +01:00
|
|
|
formation_id=formation_id, acronyme="UE41", titre="ue 41", semestre_idx=4
|
2021-11-28 16:26:04 +01:00
|
|
|
)
|
2022-01-15 21:36:06 +01:00
|
|
|
matiere_id = G.create_matiere(ue_id=_ue1, titre="matière test")
|
2021-11-28 16:26:04 +01:00
|
|
|
module_ids = []
|
|
|
|
for i in range(nb_mods):
|
2022-01-15 21:36:06 +01:00
|
|
|
module_id = G.create_module(
|
|
|
|
matiere_id=matiere_id,
|
2021-11-28 16:26:04 +01:00
|
|
|
code=f"TSM{i}",
|
|
|
|
coefficient=1.0,
|
|
|
|
titre=f"module test {i}",
|
2022-01-15 21:36:06 +01:00
|
|
|
semestre_id=2,
|
|
|
|
module_type=scu.ModuleType.RESSOURCE
|
|
|
|
if parcours.APC_SAE
|
|
|
|
else scu.ModuleType.STANDARD,
|
|
|
|
)
|
|
|
|
module_ids.append(module_id)
|
|
|
|
if with_ue_sport:
|
|
|
|
ue_sport = G.create_ue(
|
|
|
|
formation_id=formation_id,
|
|
|
|
acronyme="UESPO",
|
|
|
|
titre="ue sport",
|
|
|
|
semestre_idx=2,
|
|
|
|
type=sco_codes_parcours.UE_SPORT,
|
|
|
|
)
|
|
|
|
ue_ids.append(ue_sport)
|
|
|
|
mat_sport = G.create_matiere(ue_id=ue_sport, titre="matière spo")
|
|
|
|
mod_sport = G.create_module(
|
|
|
|
matiere_id=mat_sport,
|
|
|
|
code="BAD",
|
|
|
|
coefficient=1.0,
|
|
|
|
titre="module sport",
|
2021-11-28 16:26:04 +01:00
|
|
|
semestre_id=2,
|
|
|
|
)
|
2022-01-15 21:36:06 +01:00
|
|
|
module_ids.append(mod_sport)
|
|
|
|
return G, formation_id, ue_ids, module_ids
|
2021-11-28 16:26:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
def build_modules_with_evaluations(
|
|
|
|
ue_coefs=(1.0, 2.0, 3.0), nb_mods=1, nb_evals_per_modimpl=1
|
|
|
|
):
|
|
|
|
"""Utilisé dans plusieurs tests:
|
|
|
|
- création formation 3 UE, 1 module
|
|
|
|
- 1 semestre, nb_mod moduleimpl, 1 eval/moduleimpl
|
|
|
|
"""
|
|
|
|
nb_ues = len(ue_coefs) # 3 UEs par défaut dans ce test
|
2022-01-15 21:36:06 +01:00
|
|
|
G, formation_id, (ue1_id, ue2_id, ue3_id), module_ids = build_formation_test(
|
2021-11-28 16:26:04 +01:00
|
|
|
nb_mods=nb_mods
|
|
|
|
)
|
|
|
|
ue1 = models.UniteEns.query.get(ue1_id)
|
|
|
|
ue2 = models.UniteEns.query.get(ue2_id)
|
|
|
|
ue3 = models.UniteEns.query.get(ue3_id)
|
|
|
|
for module_id in module_ids:
|
|
|
|
mod = models.Module.query.get(module_id)
|
|
|
|
# Coef du module vers les UE
|
|
|
|
c1, c2, c3 = ue_coefs
|
|
|
|
coefs_mod = {ue1.id: c1, ue2.id: c2, ue3.id: c3}
|
|
|
|
mod.set_ue_coef_dict(coefs_mod)
|
|
|
|
assert mod.get_ue_coef_dict() == coefs_mod
|
|
|
|
# Mise en place:
|
2022-01-15 21:36:06 +01:00
|
|
|
formsemestre_id = G.create_formsemestre(
|
2021-11-28 16:26:04 +01:00
|
|
|
formation_id=formation_id,
|
|
|
|
semestre_id=2,
|
|
|
|
date_debut="01/01/2021",
|
|
|
|
date_fin="30/06/2021",
|
|
|
|
)
|
|
|
|
evaluation_ids = []
|
|
|
|
for module_id in module_ids:
|
2022-01-15 21:36:06 +01:00
|
|
|
moduleimpl_id = G.create_moduleimpl(
|
2021-11-28 16:26:04 +01:00
|
|
|
module_id=module_id,
|
2022-01-15 21:36:06 +01:00
|
|
|
formsemestre_id=formsemestre_id,
|
2021-11-28 16:26:04 +01:00
|
|
|
)
|
|
|
|
modimpl = models.ModuleImpl.query.get(moduleimpl_id)
|
|
|
|
assert modimpl.formsemestre.formation.get_parcours().APC_SAE # BUT
|
|
|
|
# Check ModuleImpl
|
|
|
|
ues = modimpl.formsemestre.query_ues().all()
|
|
|
|
assert len(ues) == 3
|
|
|
|
#
|
|
|
|
for _ in range(nb_evals_per_modimpl):
|
|
|
|
e = G.create_evaluation(
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
|
|
|
jour="01/01/2021",
|
|
|
|
description="evaluation 1",
|
|
|
|
coefficient=0,
|
|
|
|
)
|
|
|
|
evaluation_ids.append(e["evaluation_id"])
|
2022-01-15 21:36:06 +01:00
|
|
|
return G, formation_id, formsemestre_id, evaluation_ids, ue1, ue2, ue3
|