MonScoDocEssai/tests/unit/test_abs_counts.py

118 lines
3.7 KiB
Python
Raw Normal View History

2021-07-31 23:05:53 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
2021-07-19 19:53:01 +02:00
2021-07-31 23:05:53 +02:00
"""
Comptage des absences
"""
# test écrit par Fares Amer, mai 2021 et porté sur ScoDoc 8 en juillet 2021
2021-07-31 23:05:53 +02:00
from tests.unit import sco_fake_gen
2022-01-15 21:36:06 +01:00
from app.scodoc import sco_abs, sco_formsemestre
2021-07-31 23:05:53 +02:00
from app.scodoc import sco_abs_views
2021-07-31 23:05:53 +02:00
def test_abs_counts(test_client):
"""Comptage des absences"""
G = sco_fake_gen.ScoFake(verbose=False)
2021-07-31 23:05:53 +02:00
# --- Création d'étudiants
etud = G.create_etud(code_nip=None)
2021-07-31 23:05:53 +02:00
# --- 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-31 23:05:53 +02:00
code="TSM1",
coefficient=1.0,
titre="module test",
)
2021-07-31 23:05:53 +02:00
# --- Mise place d'un semestre
2022-01-15 21:36:06 +01:00
formsemestre_id = G.create_formsemestre(
formation_id=formation_id,
2021-07-31 23:05:53 +02:00
semestre_id=1,
date_debut="01/01/2021",
date_fin="30/06/2021",
)
2022-01-15 21:36:06 +01:00
sem = sco_formsemestre.get_formsemestre(formsemestre_id)
_ = G.create_moduleimpl(
module_id=module_id,
formsemestre_id=formsemestre_id,
2021-07-31 23:05:53 +02:00
)
2021-07-31 23:05:53 +02:00
# --- Inscription des étudiants
2022-01-15 21:36:06 +01:00
G.inscrit_etudiant(formsemestre_id, etud)
2021-07-31 23:05:53 +02:00
# --- Saisie absences
etudid = etud["etudid"]
for debut, fin, demijournee in [
("01/01/2020", "31/01/2020", 2), # hors semestre
("15/01/2021", "15/01/2021", 1),
("18/01/2021", "18/01/2021", 0),
("19/01/2021", "19/01/2021", 2),
("22/01/2021", "22/01/2021", 1),
("30/06/2021", "30/06/2021", 2), # dernier jour
]:
sco_abs_views.doSignaleAbsence(
datedebut=debut,
datefin=fin,
demijournee=demijournee,
etudid=etudid,
)
# --- Justification de certaines absences
for debut, fin, demijournee in [
("15/01/2021", "15/01/2021", 1),
("18/01/2021", "18/01/2021", 0),
("19/01/2021", "19/01/2021", 2),
]:
sco_abs_views.doJustifAbsence(
datedebut=debut,
datefin=fin,
demijournee=demijournee,
etudid=etudid,
)
# --- Utilisation de get_abs_count() de sco_abs
nbabs, nbabsjust = sco_abs.get_abs_count(etudid, sem)
# --- Utilisation de sco_abs.count_abs()
nb_abs2 = sco_abs.count_abs(etudid=etudid, debut="2021-01-01", fin="2021-06-30")
nb_absj2 = sco_abs.count_abs_just(
etudid=etudid, debut="2021-01-01", fin="2021-06-30"
)
2021-07-31 23:05:53 +02:00
assert nbabs == nb_abs2 == 7
assert nbabsjust == nb_absj2 == 4
2021-07-31 23:05:53 +02:00
# --- Nombre de justificatifs:
justifs = sco_abs.list_abs_justifs(etudid, "2021-01-01", datefin="2021-06-30")
assert len(justifs) == 4
2021-07-31 23:05:53 +02:00
# --- Suppression d'absence
_ = sco_abs_views.doAnnuleAbsence("19/01/2021", "19/01/2021", 2, etudid=etudid)
2021-07-31 23:05:53 +02:00
# --- Vérification
justifs_2 = sco_abs.list_abs_justifs(etudid, "2021-01-01", datefin="2021-06-30")
assert len(justifs_2) == len(justifs)
new_nbabs, _ = sco_abs.get_abs_count(etudid, sem) # version cachée
new_nbabs2 = sco_abs.count_abs(etudid=etudid, debut="2021-01-01", fin="2021-06-30")
assert new_nbabs == new_nbabs2
assert new_nbabs == (nbabs - 2) # on a supprimé deux absences
# --- annulation absence sans supprimer le justificatif
sco_abs_views.AnnuleAbsencesDatesNoJust(etudid, ["2021-01-15"])
2021-07-31 23:05:53 +02:00
nbabs_3, nbjust_3 = sco_abs.get_abs_count(etudid, sem)
assert nbabs_3 == new_nbabs
justifs_3 = sco_abs.list_abs_justifs(etudid, "2021-01-01", datefin="2021-06-30")
assert len(justifs_3) == len(justifs_2)
2022-01-15 21:36:06 +01:00
# XXX à continuer