forked from ScoDoc/ScoDoc
Update opolka/ScoDoc from ScoDoc/ScoDoc #2
@ -72,8 +72,6 @@ def test_general(test_client):
|
||||
verifier_comptage_et_filtrage_assiduites(etuds, moduleimpls[:4], formsemestres)
|
||||
verifier_filtrage_justificatifs(etuds[0], justificatifs)
|
||||
|
||||
essais_cache(etuds[0].etudid, formsemestres[:2], moduleimpls)
|
||||
|
||||
editer_supprimer_assiduites(etuds, moduleimpls)
|
||||
editer_supprimer_justificatif(etuds[0])
|
||||
|
||||
@ -402,54 +400,6 @@ def _get_justi(
|
||||
).first()
|
||||
|
||||
|
||||
def essais_cache(etudid, sems: tuple[FormSemestre], moduleimpls: list[ModuleImpl]):
|
||||
"""Vérification des fonctionnalités du cache"""
|
||||
# TODO faire un test séparé du test_general
|
||||
# voir test_calcul_assiduites pour faire
|
||||
|
||||
date_deb: str = "2022-09-01T07:00"
|
||||
date_fin: str = "2023-01-31T19:00"
|
||||
|
||||
assiduites_count_no_cache = scass.get_assiduites_count_in_interval(
|
||||
etudid, date_deb, date_fin
|
||||
)
|
||||
assiduites_count_cache = scass.get_assiduites_count_in_interval(
|
||||
etudid, date_deb, date_fin
|
||||
)
|
||||
|
||||
assert (
|
||||
assiduites_count_cache == assiduites_count_no_cache == (2, 1)
|
||||
), "Erreur cache classique"
|
||||
|
||||
assert scass.formsemestre_get_assiduites_count(etudid, sems[0]) == (
|
||||
2,
|
||||
1,
|
||||
), "Erreur formsemestre_get_assiduites_count (sans module) A"
|
||||
assert scass.formsemestre_get_assiduites_count(etudid, sems[1]) == (
|
||||
0,
|
||||
0,
|
||||
), "Erreur formsemestre_get_assiduites_count (sans module) B"
|
||||
|
||||
assert scass.formsemestre_get_assiduites_count(
|
||||
etudid, sems[0], moduleimpl_id=moduleimpls[0].id
|
||||
) == (
|
||||
1,
|
||||
1,
|
||||
), "Erreur formsemestre_get_assiduites_count (avec module) A"
|
||||
assert scass.formsemestre_get_assiduites_count(
|
||||
etudid, sems[0], moduleimpl_id=moduleimpls[1].id
|
||||
) == (
|
||||
1,
|
||||
0,
|
||||
), "Erreur formsemestre_get_assiduites_count (avec module) A"
|
||||
assert scass.formsemestre_get_assiduites_count(
|
||||
etudid, sems[0], moduleimpl_id=moduleimpls[2].id
|
||||
) == (
|
||||
0,
|
||||
0,
|
||||
), "Erreur formsemestre_get_assiduites_count (avec module) A"
|
||||
|
||||
|
||||
def ajouter_justificatifs(etud):
|
||||
"""test de l'ajout des justificatifs"""
|
||||
|
||||
@ -1414,6 +1364,7 @@ def test_cas_justificatifs(test_client):
|
||||
Tests de certains cas particuliers des justificatifs
|
||||
- Création du justificatif avant ou après assiduité
|
||||
- Assiduité complétement couverte ou non
|
||||
- Modification de la couverture (edition du justificatif)
|
||||
"""
|
||||
|
||||
data = _setup_fake_db(
|
||||
@ -1503,3 +1454,279 @@ def test_cas_justificatifs(test_client):
|
||||
assert (
|
||||
len(scass.justifies(justif_4)) == 0
|
||||
), "Justification complète non prise en compte (c2)"
|
||||
|
||||
# <- Vérification modification de la couverture ->
|
||||
|
||||
# Deux assiduités, 8/01/2024 de 8h à 10h et 14h à 16h
|
||||
|
||||
assi_2: Assiduite = Assiduite.create_assiduite(
|
||||
etud=etud_1,
|
||||
date_debut=scu.is_iso_formated("2024-01-08T08:00", True),
|
||||
date_fin=scu.is_iso_formated("2024-01-08T10:00", True),
|
||||
etat=scu.EtatAssiduite.ABSENT,
|
||||
)
|
||||
assi_3: Assiduite = Assiduite.create_assiduite(
|
||||
etud=etud_1,
|
||||
date_debut=scu.is_iso_formated("2024-01-08T14:00", True),
|
||||
date_fin=scu.is_iso_formated("2024-01-08T16:00", True),
|
||||
etat=scu.EtatAssiduite.ABSENT,
|
||||
)
|
||||
|
||||
# <=>Justification complète<=>
|
||||
# les deux assiduités sont couvertes
|
||||
|
||||
justif_5: Justificatif = Justificatif.create_justificatif(
|
||||
etudiant=etud_1,
|
||||
date_debut=scu.is_iso_formated("2024-01-08T00:00:00", True),
|
||||
date_fin=scu.is_iso_formated("2024-01-08T23:59:59", True),
|
||||
etat=scu.EtatJustificatif.VALIDE,
|
||||
)
|
||||
|
||||
# Justification des assiduités
|
||||
assi_ids: list[int] = justif_5.justifier_assiduites()
|
||||
assert len(assi_ids) == 2, "Vérification Modification couverture (d1)"
|
||||
assert assi_2.assiduite_id in assi_ids, "Vérification Modification couverture (d2)"
|
||||
assert assi_3.assiduite_id in assi_ids, "Vérification Modification couverture (d3)"
|
||||
assert assi_2.est_just is True, "Vérification Modification couverture (d4)"
|
||||
assert assi_3.est_just is True, "Vérification Modification couverture (d5)"
|
||||
|
||||
# Déjustification des assiduités
|
||||
justif_5.dejustifier_assiduites()
|
||||
assi_ids: list[int] = justif_5.dejustifier_assiduites()
|
||||
assert len(assi_ids) == 2, "Vérification Modification couverture (d6)"
|
||||
assert assi_2.assiduite_id in assi_ids, "Vérification Modification couverture (d7)"
|
||||
assert assi_3.assiduite_id in assi_ids, "Vérification Modification couverture (d8)"
|
||||
assert assi_2.est_just is False, "Vérification Modification couverture (d9)"
|
||||
assert assi_3.est_just is False, "Vérification Modification couverture (d10)"
|
||||
|
||||
# <=>Justification Partielle<=>
|
||||
# Seule la première assiduité est couverte
|
||||
|
||||
justif_5.date_fin = scu.is_iso_formated("2024-01-08T11:00", True)
|
||||
db.session.add(justif_5)
|
||||
db.session.commit()
|
||||
|
||||
assi_ids: list[int] = justif_5.justifier_assiduites()
|
||||
assert len(assi_ids) == 1, "Vérification Modification couverture (e1)"
|
||||
assert assi_2.assiduite_id in assi_ids, "Vérification Modification couverture (e2)"
|
||||
assert (
|
||||
assi_3.assiduite_id not in assi_ids
|
||||
), "Vérification Modification couverture (e3)"
|
||||
assert assi_2.est_just is True, "Vérification Modification couverture (e4)"
|
||||
assert assi_3.est_just is False, "Vérification Modification couverture (e5)"
|
||||
|
||||
assi_ids: list[int] = justif_5.dejustifier_assiduites()
|
||||
assert len(assi_ids) == 1, "Vérification Modification couverture (e6)"
|
||||
assert assi_2.assiduite_id in assi_ids, "Vérification Modification couverture (e7)"
|
||||
assert (
|
||||
assi_3.assiduite_id not in assi_ids
|
||||
), "Vérification Modification couverture (e3)"
|
||||
assert assi_2.est_just is False, "Vérification Modification couverture (e8)"
|
||||
assert assi_3.est_just is False, "Vérification Modification couverture (e9)"
|
||||
|
||||
# <=>Justification Multiple<=>
|
||||
# Deux justificatifs couvrent une même assiduité
|
||||
|
||||
# on justifie la première assiduité avec le premier justificatif
|
||||
justif_5.justifier_assiduites()
|
||||
|
||||
# deuxième justificatif
|
||||
justif_6: Justificatif = Justificatif.create_justificatif(
|
||||
etudiant=etud_1,
|
||||
date_debut=scu.is_iso_formated("2024-01-08T08:00", True),
|
||||
date_fin=scu.is_iso_formated("2024-01-08T10:00", True),
|
||||
etat=scu.EtatJustificatif.VALIDE,
|
||||
)
|
||||
|
||||
assi_ids: list[int] = justif_6.justifier_assiduites()
|
||||
assert len(assi_ids) == 1, "Vérification Modification couverture (f1)"
|
||||
assert assi_2.assiduite_id in assi_ids, "Vérification Modification couverture (f2)"
|
||||
assert (
|
||||
assi_3.assiduite_id not in assi_ids
|
||||
), "Vérification Modification couverture (f3)"
|
||||
assert assi_2.est_just is True, "Vérification Modification couverture (f4)"
|
||||
assert assi_3.est_just is False, "Vérification Modification couverture (f5)"
|
||||
|
||||
# on déjustifie le justificatif 5
|
||||
justif_5.etat = scu.EtatJustificatif.NON_VALIDE
|
||||
db.session.add(justif_5)
|
||||
db.session.commit()
|
||||
|
||||
assi_ids: list[int] = justif_5.dejustifier_assiduites()
|
||||
assert len(assi_ids) == 0, "Vérification Modification couverture (f6)"
|
||||
assert (
|
||||
assi_2.assiduite_id not in assi_ids
|
||||
), "Vérification Modification couverture (f7)"
|
||||
assert assi_2.est_just is True, "Vérification Modification couverture (f8)"
|
||||
|
||||
# on déjustifie le justificatif 6
|
||||
justif_6.etat = scu.EtatJustificatif.NON_VALIDE
|
||||
db.session.add(justif_6)
|
||||
db.session.commit()
|
||||
assi_ids: list[int] = justif_6.dejustifier_assiduites()
|
||||
assert len(assi_ids) == 1, "Vérification Modification couverture (f9)"
|
||||
assert assi_2.assiduite_id in assi_ids, "Vérification Modification couverture (f10)"
|
||||
assert assi_2.est_just is False, "Vérification Modification couverture (f11)"
|
||||
|
||||
# <=>Justification Chevauchée<=>
|
||||
# 1 justificatif chevauche une assiduité (8h -> 10h) (9h -> 11h)
|
||||
|
||||
justif_7: Justificatif = Justificatif.create_justificatif(
|
||||
etudiant=etud_1,
|
||||
date_debut=scu.is_iso_formated("2024-01-08T09:00", True),
|
||||
date_fin=scu.is_iso_formated("2024-01-08T11:00", True),
|
||||
etat=scu.EtatJustificatif.VALIDE,
|
||||
)
|
||||
|
||||
assi_ids: list[int] = justif_7.justifier_assiduites()
|
||||
assert len(assi_ids) == 0, "Vérification Modification couverture (g1)"
|
||||
assert (
|
||||
assi_2.assiduite_id not in assi_ids
|
||||
), "Vérification Modification couverture (g2)"
|
||||
assert assi_2.est_just is False, "Vérification Modification couverture (g3)"
|
||||
|
||||
# Modification pour correspondre à l'assiduité
|
||||
justif_7.date_debut = scu.is_iso_formated("2024-01-08T08:00", True)
|
||||
db.session.add(justif_7)
|
||||
db.session.commit()
|
||||
|
||||
assi_ids: list[int] = justif_7.justifier_assiduites()
|
||||
assert len(assi_ids) == 1, "Vérification Modification couverture (g4)"
|
||||
assert assi_2.assiduite_id in assi_ids, "Vérification Modification couverture (g5)"
|
||||
assert assi_2.est_just is True, "Vérification Modification couverture (g6)"
|
||||
|
||||
|
||||
def test_cache_assiduites(test_client):
|
||||
"""Vérification du bon fonctionnement du cache des assiduités"""
|
||||
|
||||
data = _setup_fake_db(
|
||||
[("2024-01-01", "2024-06-30"), ("2024-07-01", "2024-12-31")],
|
||||
1,
|
||||
1,
|
||||
)
|
||||
|
||||
formsemestre1: FormSemestre = data["formsemestres"][0]
|
||||
formsemestre2: FormSemestre = data["formsemestres"][1]
|
||||
|
||||
moduleimpl: ModuleImpl = data["moduleimpls"][0]
|
||||
etud: Identite = data["etuds"][0]
|
||||
|
||||
# Création des assiduités
|
||||
assiduites: list[dict] = [
|
||||
# Semestre 1
|
||||
{
|
||||
"date_debut": "2024-01-08T08:00",
|
||||
"date_fin": "2024-01-08T10:00",
|
||||
"moduleimpl": moduleimpl,
|
||||
},
|
||||
{
|
||||
"date_debut": "2024-01-08T14:00",
|
||||
"date_fin": "2024-01-08T16:00",
|
||||
"moduleimpl": moduleimpl,
|
||||
},
|
||||
{
|
||||
"date_debut": "2024-01-09T08:00",
|
||||
"date_fin": "2024-01-09T10:00",
|
||||
"moduleimpl": None,
|
||||
},
|
||||
{
|
||||
"date_debut": "2024-01-09T14:00",
|
||||
"date_fin": "2024-01-09T16:00",
|
||||
"moduleimpl": None,
|
||||
},
|
||||
{
|
||||
"date_debut": "2024-01-10T08:00",
|
||||
"date_fin": "2024-01-10T10:00",
|
||||
"moduleimpl": None,
|
||||
},
|
||||
{
|
||||
"date_debut": "2024-01-10T14:00",
|
||||
"date_fin": "2024-01-10T16:00",
|
||||
"moduleimpl": moduleimpl,
|
||||
},
|
||||
# Semestre 2
|
||||
{
|
||||
"date_debut": "2024-07-09T14:00",
|
||||
"date_fin": "2024-07-09T16:00",
|
||||
"moduleimpl": None,
|
||||
},
|
||||
{
|
||||
"date_debut": "2024-07-10T08:00",
|
||||
"date_fin": "2024-07-10T10:00",
|
||||
"moduleimpl": None,
|
||||
},
|
||||
{
|
||||
"date_debut": "2024-07-10T14:00",
|
||||
"date_fin": "2024-07-10T16:00",
|
||||
"moduleimpl": None,
|
||||
},
|
||||
]
|
||||
|
||||
justificatifs: list[dict] = [
|
||||
{
|
||||
"date_debut": "2024-01-10T00:00",
|
||||
"date_fin": "2024-01-10T23:59",
|
||||
},
|
||||
{
|
||||
"date_debut": "2024-07-09T00:00",
|
||||
"date_fin": "2024-07-09T23:59",
|
||||
},
|
||||
]
|
||||
|
||||
# On ajoute les assiduités et les justificatifs
|
||||
|
||||
for assi in assiduites:
|
||||
Assiduite.create_assiduite(
|
||||
etud=etud,
|
||||
date_debut=scu.is_iso_formated(assi["date_debut"], True),
|
||||
date_fin=scu.is_iso_formated(assi["date_fin"], True),
|
||||
moduleimpl=assi["moduleimpl"],
|
||||
etat=scu.EtatAssiduite.ABSENT,
|
||||
)
|
||||
|
||||
for justi in justificatifs:
|
||||
Justificatif.create_justificatif(
|
||||
etudiant=etud,
|
||||
date_debut=scu.is_iso_formated(justi["date_debut"], True),
|
||||
date_fin=scu.is_iso_formated(justi["date_fin"], True),
|
||||
etat=scu.EtatJustificatif.VALIDE,
|
||||
).justifier_assiduites()
|
||||
|
||||
# Premier semestre 4nj / 2j / 6t
|
||||
assert scass.get_assiduites_count(etud.id, formsemestre1.to_dict()) == (4, 2, 6)
|
||||
assert scass.formsemestre_get_assiduites_count(etud.id, formsemestre1) == (4, 2, 6)
|
||||
|
||||
# ModuleImpl 2nj / 1j / 3t
|
||||
assert scass.formsemestre_get_assiduites_count(
|
||||
etud.id, formsemestre1, moduleimpl.id
|
||||
) == (2, 1, 3)
|
||||
# Deuxième semestre 2nj / 1j / 3t
|
||||
assert scass.get_assiduites_count(etud.id, formsemestre2.to_dict()) == (2, 1, 3)
|
||||
|
||||
# On supprime la première assiduité (sans invalider le cache)
|
||||
assi: Assiduite = Assiduite.query.filter_by(etudid=etud.id).first()
|
||||
db.session.delete(assi)
|
||||
db.session.commit()
|
||||
|
||||
# Premier semestre 4nj / 2j / 6t (Identique car cache)
|
||||
assert scass.get_assiduites_count(etud.id, formsemestre1.to_dict()) == (4, 2, 6)
|
||||
assert scass.formsemestre_get_assiduites_count(etud.id, formsemestre1) == (4, 2, 6)
|
||||
# ModuleImpl 1nj / 1j / 2t (Change car non cache)
|
||||
assert scass.formsemestre_get_assiduites_count(
|
||||
etud.id, formsemestre1, moduleimpl.id
|
||||
) == (1, 1, 2)
|
||||
# Deuxième semestre 2nj / 1j / 3t (Identique car cache et non modifié)
|
||||
assert scass.get_assiduites_count(etud.id, formsemestre2.to_dict()) == (2, 1, 3)
|
||||
|
||||
# On invalide maintenant le cache
|
||||
scass.invalidate_assiduites_count(etud.id, formsemestre1.to_dict())
|
||||
|
||||
# Premier semestre 3nj / 2j / 5t (Change car cache invalidé)
|
||||
assert scass.get_assiduites_count(etud.id, formsemestre1.to_dict()) == (3, 2, 5)
|
||||
assert scass.formsemestre_get_assiduites_count(etud.id, formsemestre1) == (3, 2, 5)
|
||||
# ModuleImpl 1nj / 1j / 2t (Ne change pas car pas de changement)
|
||||
assert scass.formsemestre_get_assiduites_count(
|
||||
etud.id, formsemestre1, moduleimpl.id
|
||||
) == (1, 1, 2)
|
||||
# Deuxième semestre 2nj / 1j / 3t (Identique car cache et non modifié)
|
||||
assert scass.get_assiduites_count(etud.id, formsemestre2.to_dict()) == (2, 1, 3)
|
||||
|
@ -191,7 +191,7 @@ def run_sco_basic(verbose=False, dept=None) -> FormSemestre:
|
||||
etudid = etuds[0]["etudid"]
|
||||
|
||||
_signal_absences_justificatifs(etudid)
|
||||
nbabs, nbabsjust = scass.get_assiduites_count(etudid, sem)
|
||||
_, nbabsjust, nbabs = scass.get_assiduites_count(etudid, sem)
|
||||
assert nbabs == 6, f"incorrect nbabs ({nbabs})"
|
||||
assert nbabsjust == 2, f"incorrect nbabsjust ({nbabsjust})"
|
||||
|
||||
|
@ -396,7 +396,7 @@ def ajouter_assiduites_justificatifs(formsemestre: FormSemestre):
|
||||
|
||||
for etud in formsemestre.etuds:
|
||||
base_date = datetime.datetime(
|
||||
2022, 9, [5, 12, 19, 26][random.randint(0, 3)], 8, 0, 0
|
||||
2021, 9, [6, 13, 20, 27][random.randint(0, 3)], 8, 0, 0
|
||||
)
|
||||
base_date = localize_datetime(base_date)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user