From 7fad9e0a71930ea4f438889327c8be3c0d49b1c3 Mon Sep 17 00:00:00 2001 From: iziram Date: Thu, 7 Sep 2023 10:34:51 +0200 Subject: [PATCH] =?UTF-8?q?Assiduites=20:=20remise=20en=20=C3=A9tat=20test?= =?UTF-8?q?=20unitaire=20migration=20#696?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unit/test_assiduites.py | 130 ++++++++++++++++++++++++++++------ 1 file changed, 110 insertions(+), 20 deletions(-) diff --git a/tests/unit/test_assiduites.py b/tests/unit/test_assiduites.py index 50f92c649..0ed1bb506 100644 --- a/tests/unit/test_assiduites.py +++ b/tests/unit/test_assiduites.py @@ -11,14 +11,23 @@ import pytest import app.scodoc.sco_assiduites as scass import app.scodoc.sco_utils as scu -from app import db -from app.models import Assiduite, FormSemestre, Identite, Justificatif, ModuleImpl +from app import db, log +from app.models import ( + Assiduite, + FormSemestre, + Identite, + Justificatif, + ModuleImpl, + Absence, +) from app.models.assiduites import compute_assiduites_justified from app.scodoc.sco_exceptions import ScoValueError from tests.unit import sco_fake_gen from tools import downgrade_module, migrate_abs_to_assiduites +import datetime as dt + class BiInt(int, scu.BiDirectionalEnum): """Classe pour tester la classe BiDirectionalEnum""" @@ -133,7 +142,7 @@ def test_general(test_client): etud_faux_dict = g_fake.create_etud(code_nip=None, prenom="etudfaux") etud_faux = Identite.query.filter_by(id=etud_faux_dict["id"]).first() - # verif_migration_abs_assiduites() // Test à revoir TODO-ASSIDUITE (issue #696) + verif_migration_abs_assiduites() ajouter_assiduites(etuds, moduleimpls, etud_faux) justificatifs: list[Justificatif] = ajouter_justificatifs(etuds[0]) @@ -307,14 +316,13 @@ def verif_migration_abs_assiduites(): False, ), # 3 assi 22-23-24/02/2023 08h > 13h (3dj) JUSTI(ext) ]: - continue - # sco_abs_views.doSignaleAbsence( # TODO-ASSIDUITE - # datedebut=debut, - # datefin=fin, - # demijournee=demijournee, - # etudid=etudid, - # estjust=justifiee, - # ) + _create_abs( + date_debut=debut, + date_fin=fin, + demijournee=demijournee, + etudid=etudid, + estjust=justifiee, + ) # --- Justification de certaines absences @@ -330,13 +338,14 @@ def verif_migration_abs_assiduites(): 2, ), ]: - continue - # sco_abs_views.doJustifAbsence( - # datedebut=debut, - # datefin=fin, - # demijournee=demijournee, - # etudid=etudid, - # ) + _create_abs( + date_debut=debut, + date_fin=fin, + demijournee=demijournee, + etudid=etudid, + estjust=True, + estabs=False, + ) migrate_abs_to_assiduites() @@ -442,8 +451,6 @@ def verif_migration_abs_assiduites(): _get_assi("2023-02-24T08:00", "2023-02-24T13:00", True) is not None ), "Migration : Abs n°27 mal migrée" - essais_cache(etudid) - downgrade_module(assiduites=True, justificatifs=True) @@ -1025,3 +1032,86 @@ def verifier_comptage_et_filtrage_assiduites( assert ( scass.filter_by_date(etu2.assiduites, Assiduite, date_fin=date).count() == 7 ), "Filtrage 'Date fin' mauvais 5" + + +def _create_abs( + date_debut, date_fin, demijournee, estjust=False, etudid=False, estabs=True +): + etud = Identite.from_request(etudid) + deb: dt.date = dt.datetime.strptime(date_debut, "%d/%m/%Y").date() + fin: dt.date = dt.datetime.strptime(date_fin, "%d/%m/%Y").date() + abs_list: list[Absence] = [] + while deb < fin: + if deb.weekday() in [5, 6]: + deb += dt.timedelta(days=1) + continue + if demijournee == 2: + abs_list.append( + Absence( + etudid=etud.id, + jour=deb.isoformat(), + estabs=estabs, + estjust=estjust, + matin=True, + ) + ) + abs_list.append( + Absence( + etudid=etud.id, + jour=deb.isoformat(), + estabs=estabs, + estjust=estjust, + matin=False, + ) + ) + else: + abs_list.append( + Absence( + etudid=etud.id, + jour=deb.isoformat(), + estabs=estabs, + estjust=estjust, + matin=demijournee, + ) + ) + log( + f"create_abs [{etudid}, {deb.isoformat()}, {estabs}, {estjust}, {['aprem', 'matin', 'journee'][demijournee]}]" + ) + deb += dt.timedelta(days=1) + + if deb == fin and deb.weekday() not in [5, 6]: + if demijournee == 2: + abs_list.append( + Absence( + etudid=etud.id, + jour=deb.isoformat(), + estabs=estabs, + estjust=estjust, + matin=True, + ) + ) + abs_list.append( + Absence( + etudid=etud.id, + jour=deb.isoformat(), + estabs=estabs, + estjust=estjust, + matin=False, + ) + ) + else: + abs_list.append( + Absence( + etudid=etud.id, + jour=deb.isoformat(), + estabs=estabs, + estjust=estjust, + matin=demijournee, + ) + ) + log( + f"create_abs [{etudid}, {deb.isoformat()}, {estabs}, {estjust}, {['aprem', 'matin', 'journee'][demijournee]}]" + ) + + db.session.add_all(abs_list) + db.session.commit()