2021-07-30 09:36:30 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""Test de base de ScoDoc
|
|
|
|
|
|
|
|
|
2023-12-22 15:18:20 +01:00
|
|
|
Utiliser comme:
|
2021-07-30 09:36:30 +02:00
|
|
|
pytest tests/unit/test_sco_basic.py
|
|
|
|
|
2021-08-13 00:34:58 +02:00
|
|
|
Au besoin, créer un base de test neuve:
|
|
|
|
./tools/create_database.sh SCODOC_TEST
|
2021-07-31 18:01:10 +02:00
|
|
|
|
2021-07-30 09:36:30 +02:00
|
|
|
"""
|
2023-08-25 17:58:57 +02:00
|
|
|
import datetime
|
|
|
|
|
2024-02-26 17:20:36 +01:00
|
|
|
from app.models import Evaluation, FormSemestreInscription, Identite, ModuleImpl
|
2021-07-30 09:36:30 +02:00
|
|
|
|
2021-08-10 12:57:38 +02:00
|
|
|
from config import TestConfig
|
2021-07-30 09:36:30 +02:00
|
|
|
from tests.unit import sco_fake_gen
|
2022-11-22 13:13:16 +01:00
|
|
|
from tests.unit.setup import NOTES_T
|
2021-07-30 09:36:30 +02:00
|
|
|
|
2021-08-13 00:34:58 +02:00
|
|
|
import app
|
2022-07-07 16:24:52 +02:00
|
|
|
from app import db
|
2022-02-13 23:53:11 +01:00
|
|
|
from app.comp import res_sem
|
2022-03-27 22:25:00 +02:00
|
|
|
from app.comp.res_compat import NotesTableCompat
|
2023-09-05 08:41:40 +02:00
|
|
|
from app.models import FormSemestre, Assiduite, Justificatif
|
2022-02-13 23:53:11 +01:00
|
|
|
from app.scodoc import sco_formsemestre
|
2021-07-30 09:36:30 +02:00
|
|
|
from app.scodoc import sco_bulletins
|
2023-02-12 13:36:47 +01:00
|
|
|
from app.scodoc import codes_cursus
|
2023-09-05 08:41:40 +02:00
|
|
|
from app.scodoc import sco_assiduites as scass
|
2021-07-31 18:01:10 +02:00
|
|
|
from app.scodoc import sco_evaluations
|
2021-07-30 09:36:30 +02:00
|
|
|
from app.scodoc import sco_formsemestre_validation
|
2022-07-07 16:24:52 +02:00
|
|
|
from app.scodoc import sco_cursus_dut
|
2021-07-31 18:01:10 +02:00
|
|
|
from app.scodoc import sco_saisie_notes
|
2023-09-05 08:41:40 +02:00
|
|
|
from app.scodoc.sco_utils import EtatAssiduite, EtatJustificatif, localize_datetime
|
2021-07-30 09:36:30 +02:00
|
|
|
|
2021-08-10 12:57:38 +02:00
|
|
|
DEPT = TestConfig.DEPT_TEST
|
2021-07-30 09:36:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_sco_basic(test_client):
|
|
|
|
"""Test quelques opérations élémentaires de ScoDoc
|
|
|
|
Création 10 étudiants, formation, semestre, inscription etudiant,
|
|
|
|
creation 1 evaluation, saisie 10 notes.
|
|
|
|
"""
|
2021-08-13 00:34:58 +02:00
|
|
|
app.set_sco_dept(DEPT)
|
2021-08-10 12:57:38 +02:00
|
|
|
run_sco_basic()
|
|
|
|
|
|
|
|
|
2023-10-15 14:42:03 +02:00
|
|
|
def run_sco_basic(verbose=False, dept=None) -> FormSemestre:
|
2021-08-10 12:57:38 +02:00
|
|
|
"""Scénario de base: création formation, semestre, étudiants, notes,
|
|
|
|
décisions jury
|
2022-11-22 13:13:16 +01:00
|
|
|
Renvoie le formsemestre créé.
|
2021-08-10 12:57:38 +02:00
|
|
|
"""
|
2023-10-15 14:42:03 +02:00
|
|
|
G = sco_fake_gen.ScoFake(verbose=verbose, dept=dept)
|
2021-07-30 09:36:30 +02:00
|
|
|
|
|
|
|
# --- Création d'étudiants
|
|
|
|
etuds = [G.create_etud(code_nip=None) for _ in range(10)]
|
|
|
|
|
|
|
|
# --- Création d'une formation
|
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-07-30 09:36:30 +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-07-30 09:36:30 +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-07-30 09:36:30 +02:00
|
|
|
)
|
2024-02-26 17:20:36 +01:00
|
|
|
moduleimpl: ModuleImpl = db.session.get(ModuleImpl, moduleimpl_id)
|
2021-07-30 09:36:30 +02:00
|
|
|
# --- Inscription des étudiants
|
|
|
|
for etud in etuds:
|
2022-01-15 21:36:06 +01:00
|
|
|
G.inscrit_etudiant(formsemestre_id, etud)
|
2022-12-06 13:06:50 +01:00
|
|
|
|
2022-05-26 03:55:03 +02:00
|
|
|
# Vérification incription semestre:
|
|
|
|
q = FormSemestreInscription.query.filter_by(
|
2022-12-06 13:06:50 +01:00
|
|
|
etudid=etuds[0]["etudid"], formsemestre_id=formsemestre_id
|
2022-05-26 03:55:03 +02:00
|
|
|
)
|
|
|
|
assert q.count() == 1
|
|
|
|
ins = q.first()
|
2022-11-22 13:13:16 +01:00
|
|
|
assert ins.etape is None
|
2022-05-26 03:55:03 +02:00
|
|
|
assert ins.etat == "I"
|
2022-11-22 13:13:16 +01:00
|
|
|
assert ins.parcour is None
|
2021-07-30 09:36:30 +02:00
|
|
|
|
2022-11-22 13:13:16 +01:00
|
|
|
# --- Création évaluation
|
2024-02-26 17:20:36 +01:00
|
|
|
e1 = Evaluation.create(
|
|
|
|
moduleimpl=moduleimpl,
|
2023-08-25 17:58:57 +02:00
|
|
|
date_debut=datetime.datetime(2020, 1, 1),
|
2021-07-30 09:36:30 +02:00
|
|
|
description="evaluation test",
|
|
|
|
coefficient=1.0,
|
|
|
|
)
|
2024-02-26 17:20:36 +01:00
|
|
|
db.session.commit()
|
2021-07-30 09:36:30 +02:00
|
|
|
|
|
|
|
# --- Saisie toutes les notes de l'évaluation
|
2022-11-22 13:13:16 +01:00
|
|
|
for idx, etud in enumerate(etuds):
|
2024-06-14 20:15:20 +02:00
|
|
|
etudids_changed, nb_suppress, existing_decisions, messages = G.create_note(
|
2024-02-26 17:20:36 +01:00
|
|
|
evaluation_id=e1.id,
|
2022-12-06 13:06:50 +01:00
|
|
|
etudid=etud["etudid"],
|
|
|
|
note=NOTES_T[idx % len(NOTES_T)],
|
2021-07-30 09:36:30 +02:00
|
|
|
)
|
2022-11-22 13:13:16 +01:00
|
|
|
assert not existing_decisions
|
|
|
|
assert nb_suppress == 0
|
2023-06-03 22:43:04 +02:00
|
|
|
assert len(etudids_changed) == 1
|
2024-06-14 20:15:20 +02:00
|
|
|
assert messages == []
|
2021-07-30 09:36:30 +02:00
|
|
|
|
|
|
|
# --- Vérifie que les notes sont prises en compte:
|
2022-01-15 21:36:06 +01:00
|
|
|
b = sco_bulletins.formsemestre_bulletinetud_dict(formsemestre_id, etud["etudid"])
|
2021-07-30 09:36:30 +02:00
|
|
|
# Toute les notes sont saisies, donc eval complète
|
2024-02-26 17:20:36 +01:00
|
|
|
etat = sco_evaluations.do_evaluation_etat(e1.id)
|
2021-07-30 09:36:30 +02:00
|
|
|
assert etat["evalcomplete"]
|
2021-07-31 18:01:10 +02:00
|
|
|
assert etat["nb_inscrits"] == len(etuds)
|
|
|
|
assert etat["nb_notes"] == len(etuds)
|
2021-07-30 09:36:30 +02:00
|
|
|
# Un seul module, donc moy gen == note module
|
|
|
|
assert b["ues"][0]["cur_moy_ue_txt"] == b["ues"][0]["modules"][0]["mod_moy_txt"]
|
|
|
|
# Note au module égale à celle de l'éval
|
|
|
|
assert (
|
|
|
|
b["ues"][0]["modules"][0]["mod_moy_txt"]
|
|
|
|
== b["ues"][0]["modules"][0]["evaluations"][0]["note_txt"]
|
|
|
|
)
|
|
|
|
|
|
|
|
# --- Une autre évaluation
|
2024-02-26 17:20:36 +01:00
|
|
|
e2 = Evaluation.create(
|
|
|
|
moduleimpl=moduleimpl,
|
2023-08-25 17:58:57 +02:00
|
|
|
date_debut=datetime.datetime(2020, 1, 2),
|
2021-07-30 09:36:30 +02:00
|
|
|
description="evaluation test 2",
|
|
|
|
coefficient=1.0,
|
|
|
|
)
|
2024-02-26 17:20:36 +01:00
|
|
|
db.session.commit()
|
2021-07-30 09:36:30 +02:00
|
|
|
# Saisie les notes des 5 premiers étudiants:
|
2022-11-22 13:13:16 +01:00
|
|
|
for idx, etud in enumerate(etuds[:5]):
|
2024-06-14 20:15:20 +02:00
|
|
|
etudids_changed, nb_suppress, existing_decisions, messages = G.create_note(
|
2024-02-26 17:20:36 +01:00
|
|
|
evaluation_id=e2.id,
|
2022-12-06 13:06:50 +01:00
|
|
|
etudid=etud["etudid"],
|
|
|
|
note=NOTES_T[idx % len(NOTES_T)],
|
2021-07-30 09:36:30 +02:00
|
|
|
)
|
2024-06-14 20:15:20 +02:00
|
|
|
assert messages == []
|
2021-07-30 09:36:30 +02:00
|
|
|
# Cette éval n'est pas complète
|
2024-02-26 17:20:36 +01:00
|
|
|
etat = sco_evaluations.do_evaluation_etat(e2.id)
|
2022-11-22 13:13:16 +01:00
|
|
|
assert etat["evalcomplete"] is False
|
2021-07-30 09:36:30 +02:00
|
|
|
# la première éval est toujours complète:
|
2024-02-26 17:20:36 +01:00
|
|
|
etat = sco_evaluations.do_evaluation_etat(e1.id)
|
2021-07-30 09:36:30 +02:00
|
|
|
assert etat["evalcomplete"]
|
|
|
|
|
|
|
|
# Modifie l'évaluation 2 pour "prise en compte immédiate"
|
2024-02-26 17:20:36 +01:00
|
|
|
e2.publish_incomplete = True
|
|
|
|
db.session.add(e2)
|
|
|
|
db.session.flush()
|
|
|
|
etat = sco_evaluations.do_evaluation_etat(e2.id)
|
2022-11-22 13:13:16 +01:00
|
|
|
assert etat["evalcomplete"] is False
|
2021-07-30 09:36:30 +02:00
|
|
|
assert etat["nb_att"] == 0 # il n'y a pas de notes (explicitement) en attente
|
|
|
|
assert etat["evalattente"] # mais l'eval est en attente (prise en compte immédiate)
|
|
|
|
|
|
|
|
# Saisie des notes qui manquent:
|
2022-11-22 13:13:16 +01:00
|
|
|
for idx, etud in enumerate(etuds[5:]):
|
2024-06-14 20:15:20 +02:00
|
|
|
etudids_changed, nb_suppress, existing_decisions, messages = G.create_note(
|
2024-02-26 17:20:36 +01:00
|
|
|
evaluation_id=e2.id,
|
2022-12-06 13:06:50 +01:00
|
|
|
etudid=etud["etudid"],
|
|
|
|
note=NOTES_T[idx % len(NOTES_T)],
|
2021-07-30 09:36:30 +02:00
|
|
|
)
|
2024-06-14 20:15:20 +02:00
|
|
|
assert messages == []
|
2024-02-26 17:20:36 +01:00
|
|
|
etat = sco_evaluations.do_evaluation_etat(e2.id)
|
2021-07-30 09:36:30 +02:00
|
|
|
assert etat["evalcomplete"]
|
|
|
|
assert etat["nb_att"] == 0
|
|
|
|
assert not etat["evalattente"] # toutes les notes sont présentes
|
|
|
|
|
2021-07-31 18:01:10 +02:00
|
|
|
# --- Suppression des notes
|
2024-02-26 17:20:36 +01:00
|
|
|
sco_saisie_notes.evaluation_suppress_alln(e1.id, dialog_confirmed=True)
|
|
|
|
etat = sco_evaluations.do_evaluation_etat(e1.id)
|
2021-07-31 18:01:10 +02:00
|
|
|
assert etat["nb_notes"] == 0
|
|
|
|
assert not etat["evalcomplete"]
|
|
|
|
# --- Saisie des notes manquantes
|
|
|
|
ans = sco_saisie_notes.do_evaluation_set_missing(
|
2024-02-26 17:20:36 +01:00
|
|
|
e1.id, 12.34, dialog_confirmed=True
|
2021-07-31 18:01:10 +02:00
|
|
|
)
|
|
|
|
assert f'{etat["nb_inscrits"]} notes changées' in ans
|
2024-02-26 17:20:36 +01:00
|
|
|
etat = sco_evaluations.do_evaluation_etat(e1.id)
|
2021-07-31 18:01:10 +02:00
|
|
|
assert etat["evalcomplete"]
|
2022-11-22 13:13:16 +01:00
|
|
|
|
|
|
|
# -----------------------
|
|
|
|
# --- Saisie absences ---
|
|
|
|
# -----------------------
|
2021-07-30 09:36:30 +02:00
|
|
|
etudid = etuds[0]["etudid"]
|
|
|
|
|
2023-09-05 08:41:40 +02:00
|
|
|
_signal_absences_justificatifs(etudid)
|
2024-03-01 12:37:38 +01:00
|
|
|
_, nbabsjust, nbabs = scass.get_assiduites_count(etudid, sem)
|
2023-09-05 08:41:40 +02:00
|
|
|
assert nbabs == 6, f"incorrect nbabs ({nbabs})"
|
|
|
|
assert nbabsjust == 2, f"incorrect nbabsjust ({nbabsjust})"
|
2021-07-30 09:36:30 +02:00
|
|
|
|
|
|
|
# --- Permission saisie notes et décisions de jury, avec ou sans démission ou défaillance
|
|
|
|
# on n'a pas encore saisi de décisions
|
2022-07-07 16:24:52 +02:00
|
|
|
assert not sco_cursus_dut.formsemestre_has_decisions(formsemestre_id)
|
2021-07-30 09:36:30 +02:00
|
|
|
# Saisie d'un décision AJ, non assidu
|
|
|
|
etudid = etuds[-1]["etudid"]
|
2022-07-07 16:24:52 +02:00
|
|
|
sco_cursus_dut.formsemestre_validate_ues(
|
2023-02-12 13:36:47 +01:00
|
|
|
formsemestre_id, etudid, codes_cursus.AJ, False
|
2021-07-30 09:36:30 +02:00
|
|
|
)
|
2022-07-07 16:24:52 +02:00
|
|
|
assert sco_cursus_dut.formsemestre_has_decisions(
|
2022-01-15 21:36:06 +01:00
|
|
|
formsemestre_id
|
2021-07-30 09:36:30 +02:00
|
|
|
), "décisions manquantes"
|
|
|
|
# Suppression de la décision
|
|
|
|
sco_formsemestre_validation.formsemestre_validation_suppress_etud(
|
2022-01-15 21:36:06 +01:00
|
|
|
formsemestre_id, etudid
|
2021-07-30 09:36:30 +02:00
|
|
|
)
|
2022-07-07 16:24:52 +02:00
|
|
|
assert not sco_cursus_dut.formsemestre_has_decisions(
|
2022-01-15 21:36:06 +01:00
|
|
|
formsemestre_id
|
2021-07-30 09:36:30 +02:00
|
|
|
), "décisions non effacées"
|
2021-09-30 14:35:21 +02:00
|
|
|
|
|
|
|
# --- Décision de jury et validations des ECTS d'UE
|
|
|
|
for etud in etuds[:5]: # les etudiants notés
|
|
|
|
sco_formsemestre_validation.formsemestre_validation_etud_manu(
|
2022-01-15 21:36:06 +01:00
|
|
|
formsemestre_id,
|
2021-09-30 14:35:21 +02:00
|
|
|
etud["etudid"],
|
2023-02-12 13:36:47 +01:00
|
|
|
code_etat=codes_cursus.ADJ,
|
2021-09-30 14:35:21 +02:00
|
|
|
assidu=True,
|
|
|
|
redirect=False,
|
|
|
|
)
|
|
|
|
# Vérifie que toutes les UE des étudiants notés ont été acquises:
|
2022-02-13 23:53:11 +01:00
|
|
|
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
|
|
|
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
2021-09-30 14:35:21 +02:00
|
|
|
for etud in etuds[:5]:
|
2023-02-19 23:06:44 +01:00
|
|
|
dec_ues = nt.get_etud_decisions_ue(etud["etudid"])
|
2021-09-30 14:35:21 +02:00
|
|
|
for ue_id in dec_ues:
|
|
|
|
assert dec_ues[ue_id]["code"] in {"ADM", "CMP"}
|
2022-05-26 03:55:03 +02:00
|
|
|
|
2022-11-22 13:13:16 +01:00
|
|
|
# ---- Suppression d'un étudiant, vérification inscription
|
2022-05-26 03:55:03 +02:00
|
|
|
# (permet de tester les cascades)
|
2023-03-20 11:17:38 +01:00
|
|
|
etud = Identite.get_etud(etuds[0]["etudid"])
|
2022-11-12 17:28:05 +01:00
|
|
|
assert etud is not None
|
2022-05-26 03:55:03 +02:00
|
|
|
etudid = etud.id
|
|
|
|
db.session.delete(etud)
|
|
|
|
db.session.commit()
|
|
|
|
# Vérification incription semestre:
|
|
|
|
q = FormSemestreInscription.query.filter_by(
|
|
|
|
etudid=etudid, formsemestre_id=formsemestre_id
|
|
|
|
)
|
|
|
|
assert q.count() == 0
|
2022-11-22 13:13:16 +01:00
|
|
|
return formsemestre
|
2023-09-05 08:41:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _signal_absences_justificatifs(etudid: int):
|
2024-08-06 23:18:17 +02:00
|
|
|
etud: Identite = db.session.get(Identite, etudid)
|
2023-09-05 08:41:40 +02:00
|
|
|
db.session.commit()
|
|
|
|
for i in range(15, 18):
|
|
|
|
db.session.add(
|
|
|
|
Assiduite.create_assiduite(
|
|
|
|
etud=etud,
|
|
|
|
date_debut=localize_datetime(datetime.datetime(2020, 1, i, 8, 0)),
|
|
|
|
date_fin=localize_datetime(datetime.datetime(2020, 1, i, 18, 0)),
|
|
|
|
etat=EtatAssiduite.ABSENT,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
db.session.commit()
|
|
|
|
justif: Justificatif = Justificatif.create_justificatif(
|
2023-12-22 15:18:20 +01:00
|
|
|
etud,
|
|
|
|
localize_datetime(datetime.datetime(2020, 1, 17, 8, 0)),
|
|
|
|
localize_datetime(datetime.datetime(2020, 1, 17, 18, 0)),
|
2023-09-05 08:41:40 +02:00
|
|
|
etat=EtatJustificatif.VALIDE,
|
|
|
|
)
|
|
|
|
db.session.add(justif)
|
|
|
|
db.session.commit()
|
2024-02-29 14:20:39 +01:00
|
|
|
justif.justifier_assiduites()
|