From 0809cc4feb225ae65cc8266011b345aa4515bb1f Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 6 Dec 2022 13:06:50 +0100 Subject: [PATCH] Fix unit tests --- app/api/formsemestres.py | 2 +- app/scodoc/sco_bulletins_json.py | 6 ++-- app/scodoc/sco_formsemestre_inscriptions.py | 5 ++-- sco_version.py | 2 +- tests/api/test_api_etudiants.py | 1 + tests/unit/sco_fake_gen.py | 2 +- tests/unit/test_but_ues.py | 9 +++++- tests/unit/test_notes_modules.py | 32 ++++++++++++++------- tests/unit/test_notes_rattrapage.py | 24 +++++++++------- tests/unit/test_sco_basic.py | 17 +++++++---- 10 files changed, 66 insertions(+), 34 deletions(-) diff --git a/app/api/formsemestres.py b/app/api/formsemestres.py index 1c1db110af..1030ffbdf9 100644 --- a/app/api/formsemestres.py +++ b/app/api/formsemestres.py @@ -341,7 +341,7 @@ def formsemestre_etudiants( # XXX A REVOIR: trop inefficace ! for etud in etuds: etud["groups"] = sco_groups.get_etud_groups( - etud["id"], formsemestre_id, exclude_default=True + etud["etudid"], formsemestre_id, exclude_default=True ) return jsonify(sorted(etuds, key=lambda e: e["sort_key"])) diff --git a/app/scodoc/sco_bulletins_json.py b/app/scodoc/sco_bulletins_json.py index 789987970b..a1908bd421 100644 --- a/app/scodoc/sco_bulletins_json.py +++ b/app/scodoc/sco_bulletins_json.py @@ -284,9 +284,9 @@ def formsemestre_bulletinetud_published_dict( d["ue_capitalisee"].append( dict( id=ue_id, - numero=quote_xml_attr(ue.numero), - acronyme=quote_xml_attr(ue.acronyme), - titre=quote_xml_attr(ue.titre), + numero=quote_xml_attr(ue_st["numero"]), + acronyme=quote_xml_attr(ue_st["acronyme"]), + titre=quote_xml_attr(ue_st["titre"]), note=scu.fmt_note(ue_status["moy"]), coefficient_ue=scu.fmt_note(ue_status["coef_ue"]), date_capitalisation=ndb.DateDMYtoISO(ue_status["event_date"]), diff --git a/app/scodoc/sco_formsemestre_inscriptions.py b/app/scodoc/sco_formsemestre_inscriptions.py index 63ba060ad9..3a2bf6095d 100644 --- a/app/scodoc/sco_formsemestre_inscriptions.py +++ b/app/scodoc/sco_formsemestre_inscriptions.py @@ -286,7 +286,8 @@ def do_formsemestre_inscription_with_modules( args["etape"] = etape do_formsemestre_inscription_create(args, method=method) log( - f"do_formsemestre_inscription_with_modules: etudid={etudid} formsemestre_id={formsemestre_id}" + f"""do_formsemestre_inscription_with_modules: etudid={ + etudid} formsemestre_id={formsemestre_id}""" ) # inscriptions aux groupes # 1- inscrit au groupe 'tous' @@ -296,7 +297,7 @@ def do_formsemestre_inscription_with_modules( # 2- inscrit aux groupes for group_id in group_ids: - if group_id and not group_id in gdone: + if group_id and group_id not in gdone: group = GroupDescr.query.get_or_404(group_id) sco_groups.set_group(etudid, group_id) gdone[group_id] = 1 diff --git a/sco_version.py b/sco_version.py index a7bd76ccde..1b94df11b6 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.4.9" +SCOVERSION = "9.4.10" SCONAME = "ScoDoc" diff --git a/tests/api/test_api_etudiants.py b/tests/api/test_api_etudiants.py index b4fc97f3b9..7200909363 100644 --- a/tests/api/test_api_etudiants.py +++ b/tests/api/test_api_etudiants.py @@ -76,6 +76,7 @@ def test_etudiants_courant(api_headers): etud = etudiants[-1] assert verify_fields(etud, fields) is True + assert etud["id"] == etud["etudid"] assert isinstance(etud["id"], int) assert isinstance(etud["code_nip"], str) assert isinstance(etud["nom"], str) diff --git a/tests/unit/sco_fake_gen.py b/tests/unit/sco_fake_gen.py index 62bf599185..0c07a27eeb 100644 --- a/tests/unit/sco_fake_gen.py +++ b/tests/unit/sco_fake_gen.py @@ -421,7 +421,7 @@ class ScoFake(object): for idx, etud in enumerate(etuds): self.create_note( evaluation_id=e["id"], - etudid=etud["id"], + etudid=etud["etudid"], note=notes[idx % len(notes)], ) diff --git a/tests/unit/test_but_ues.py b/tests/unit/test_but_ues.py index 8585ec60fb..3c38a6e7ed 100644 --- a/tests/unit/test_but_ues.py +++ b/tests/unit/test_but_ues.py @@ -77,6 +77,7 @@ def test_ue_moy(test_client): modimpl_inscr_df, modimpl_coefs_df, modimpl_mask, + set(), ) return etud_moy_ue @@ -122,7 +123,13 @@ def test_ue_moy(test_client): modimpl.module.ue.type != UE_SPORT for modimpl in formsemestre.modimpls_sorted ] etud_moy_ue = moy_ue.compute_ue_moys_apc( - sem_cube, etuds, modimpls, modimpl_inscr_df, modimpl_coefs_df, modimpl_mask + sem_cube, + etuds, + modimpls, + modimpl_inscr_df, + modimpl_coefs_df, + modimpl_mask, + set(), ) assert etud_moy_ue[ue1.id][etudid] == n1 assert etud_moy_ue[ue2.id][etudid] == n1 diff --git a/tests/unit/test_notes_modules.py b/tests/unit/test_notes_modules.py index 55e123a746..55dad99994 100644 --- a/tests/unit/test_notes_modules.py +++ b/tests/unit/test_notes_modules.py @@ -106,13 +106,17 @@ def test_notes_modules(test_client): # --- Notes ordinaires note_1 = 12.0 note_2 = 13.0 - _, _, _ = G.create_note(evaluation_id=e1["id"], etudid=etuds[0]["id"], note=note_1) - _, _, _ = G.create_note(evaluation_id=e2["id"], etudid=etuds[0]["id"], note=note_2) _, _, _ = G.create_note( - evaluation_id=e1["id"], etudid=etuds[1]["id"], note=note_1 / 2 + evaluation_id=e1["id"], etudid=etuds[0]["etudid"], note=note_1 ) _, _, _ = G.create_note( - evaluation_id=e2["id"], etudid=etuds[1]["id"], note=note_2 / 3 + evaluation_id=e2["id"], etudid=etuds[0]["etudid"], note=note_2 + ) + _, _, _ = G.create_note( + evaluation_id=e1["id"], etudid=etuds[1]["etudid"], note=note_1 / 2 + ) + _, _, _ = G.create_note( + evaluation_id=e2["id"], etudid=etuds[1]["etudid"], note=note_2 / 3 ) b = sco_bulletins.formsemestre_bulletinetud_dict( sem["formsemestre_id"], etud["etudid"] @@ -316,9 +320,15 @@ def test_notes_modules(test_client): evaluation_id=e2["id"], etudid=etudid, note=scu.NOTES_NEUTRALISE ) # EXC _, _, _ = G.create_note(evaluation_id=e_m2["id"], etudid=etudid, note=12.5) - _, _, _ = G.create_note(evaluation_id=e1["id"], etudid=etuds[1]["id"], note=11.0) - _, _, _ = G.create_note(evaluation_id=e2["id"], etudid=etuds[1]["id"], note=11.0) - _, _, _ = G.create_note(evaluation_id=e_m2["id"], etudid=etuds[1]["id"], note=11.0) + _, _, _ = G.create_note( + evaluation_id=e1["id"], etudid=etuds[1]["etudid"], note=11.0 + ) + _, _, _ = G.create_note( + evaluation_id=e2["id"], etudid=etuds[1]["etudid"], note=11.0 + ) + _, _, _ = G.create_note( + evaluation_id=e_m2["id"], etudid=etuds[1]["etudid"], note=11.0 + ) b = sco_bulletins.formsemestre_bulletinetud_dict( sem["formsemestre_id"], etud["etudid"] @@ -381,10 +391,10 @@ def test_notes_modules_att_dem(test_client): ) # Attente (ATT) sur les 2 evals _, _, _ = G.create_note( - evaluation_id=e1["id"], etudid=etuds[0]["id"], note=scu.NOTES_ATTENTE + evaluation_id=e1["id"], etudid=etuds[0]["etudid"], note=scu.NOTES_ATTENTE ) # ATT _, _, _ = G.create_note( - evaluation_id=e1["id"], etudid=etuds[1]["id"], note=scu.NOTES_ATTENTE + evaluation_id=e1["id"], etudid=etuds[1]["etudid"], note=scu.NOTES_ATTENTE ) # ATT # Démission du premier étudiant sco_formsemestre_inscriptions.do_formsemestre_demission( @@ -424,7 +434,9 @@ def test_notes_modules_att_dem(test_client): assert note_e1 == scu.NOTES_ATTENTE # XXXX un peu contestable # Saisie note ABS pour le deuxième etud - _, _, _ = G.create_note(evaluation_id=e1["id"], etudid=etuds[1]["id"], note=None) + _, _, _ = G.create_note( + evaluation_id=e1["id"], etudid=etuds[1]["etudid"], note=None + ) nt = check_nt( etuds[1]["etudid"], sem["formsemestre_id"], diff --git a/tests/unit/test_notes_rattrapage.py b/tests/unit/test_notes_rattrapage.py index da23fa85a9..b4653009e0 100644 --- a/tests/unit/test_notes_rattrapage.py +++ b/tests/unit/test_notes_rattrapage.py @@ -71,8 +71,8 @@ def test_notes_rattrapage(test_client): evaluation_type=scu.EVALUATION_RATTRAPAGE, ) etud = etuds[0] - _, _, _ = G.create_note(evaluation_id=e["id"], etudid=etud["id"], note=12.0) - _, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["id"], note=11.0) + _, _, _ = G.create_note(evaluation_id=e["id"], etudid=etud["etudid"], note=12.0) + _, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["etudid"], note=11.0) # --- Vérifications internes structures ScoDoc formsemestre = FormSemestre.query.get(formsemestre_id) @@ -96,21 +96,23 @@ def test_notes_rattrapage(test_client): # Note moyenne: ici le ratrapage est inférieur à la note: assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(12.0) # rattrapage > moyenne: - _, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["id"], note=18.0) + _, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["etudid"], note=18.0) b = sco_bulletins.formsemestre_bulletinetud_dict( sem["formsemestre_id"], etud["etudid"] ) assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(18.0) # rattrapage vs absences - _, _, _ = G.create_note(evaluation_id=e["id"], etudid=etud["id"], note=None) # abs - _, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["id"], note=17.0) + _, _, _ = G.create_note( + evaluation_id=e["id"], etudid=etud["etudid"], note=None + ) # abs + _, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["etudid"], note=17.0) b = sco_bulletins.formsemestre_bulletinetud_dict( sem["formsemestre_id"], etud["etudid"] ) assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(17.0) # et sans note de rattrapage - _, _, _ = G.create_note(evaluation_id=e["id"], etudid=etud["id"], note=10.0) - _, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["id"], note=None) + _, _, _ = G.create_note(evaluation_id=e["id"], etudid=etud["etudid"], note=10.0) + _, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["etudid"], note=None) b = sco_bulletins.formsemestre_bulletinetud_dict( sem["formsemestre_id"], etud["etudid"] ) @@ -152,7 +154,9 @@ def test_notes_rattrapage(test_client): assert len(mod_res.get_evaluations_completes(moduleimpl)) == 2 # Saisie note session 2: - _, _, _ = G.create_note(evaluation_id=e_session2["id"], etudid=etud["id"], note=5.0) + _, _, _ = G.create_note( + evaluation_id=e_session2["id"], etudid=etud["etudid"], note=5.0 + ) b = sco_bulletins.formsemestre_bulletinetud_dict( sem["formsemestre_id"], etud["etudid"] ) @@ -160,7 +164,7 @@ def test_notes_rattrapage(test_client): assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(5.0) _, _, _ = G.create_note( - evaluation_id=e_session2["id"], etudid=etud["id"], note=20.0 + evaluation_id=e_session2["id"], etudid=etud["etudid"], note=20.0 ) b = sco_bulletins.formsemestre_bulletinetud_dict( sem["formsemestre_id"], etud["etudid"] @@ -169,7 +173,7 @@ def test_notes_rattrapage(test_client): assert b["ues"][0]["modules"][0]["mod_moy_txt"] == scu.fmt_note(20.0) _, _, _ = G.create_note( - evaluation_id=e_session2["id"], etudid=etud["id"], note=None + evaluation_id=e_session2["id"], etudid=etud["etudid"], note=None ) b = sco_bulletins.formsemestre_bulletinetud_dict( sem["formsemestre_id"], etud["etudid"] diff --git a/tests/unit/test_sco_basic.py b/tests/unit/test_sco_basic.py index c1e57fa47b..47631c0d19 100644 --- a/tests/unit/test_sco_basic.py +++ b/tests/unit/test_sco_basic.py @@ -82,9 +82,10 @@ def run_sco_basic(verbose=False) -> FormSemestre: # --- Inscription des étudiants for etud in etuds: G.inscrit_etudiant(formsemestre_id, etud) + # Vérification incription semestre: q = FormSemestreInscription.query.filter_by( - etudid=etuds[0]["id"], formsemestre_id=formsemestre_id + etudid=etuds[0]["etudid"], formsemestre_id=formsemestre_id ) assert q.count() == 1 ins = q.first() @@ -103,7 +104,9 @@ def run_sco_basic(verbose=False) -> FormSemestre: # --- Saisie toutes les notes de l'évaluation for idx, etud in enumerate(etuds): nb_changed, nb_suppress, existing_decisions = G.create_note( - evaluation_id=e["id"], etudid=etud["id"], note=NOTES_T[idx % len(NOTES_T)] + evaluation_id=e["id"], + etudid=etud["etudid"], + note=NOTES_T[idx % len(NOTES_T)], ) assert not existing_decisions assert nb_suppress == 0 @@ -134,7 +137,9 @@ def run_sco_basic(verbose=False) -> FormSemestre: # Saisie les notes des 5 premiers étudiants: for idx, etud in enumerate(etuds[:5]): nb_changed, nb_suppress, existing_decisions = G.create_note( - evaluation_id=e2["id"], etudid=etud["id"], note=NOTES_T[idx % len(NOTES_T)] + evaluation_id=e2["id"], + etudid=etud["etudid"], + note=NOTES_T[idx % len(NOTES_T)], ) # Cette éval n'est pas complète etat = sco_evaluations.do_evaluation_etat(e2["evaluation_id"]) @@ -154,7 +159,9 @@ def run_sco_basic(verbose=False) -> FormSemestre: # Saisie des notes qui manquent: for idx, etud in enumerate(etuds[5:]): nb_changed, nb_suppress, existing_decisions = G.create_note( - evaluation_id=e2["id"], etudid=etud["id"], note=NOTES_T[idx % len(NOTES_T)] + evaluation_id=e2["id"], + etudid=etud["etudid"], + note=NOTES_T[idx % len(NOTES_T)], ) etat = sco_evaluations.do_evaluation_etat(e2["evaluation_id"]) assert etat["evalcomplete"] @@ -232,7 +239,7 @@ def run_sco_basic(verbose=False) -> FormSemestre: # ---- Suppression d'un étudiant, vérification inscription # (permet de tester les cascades) - etud = Identite.query.get(etuds[0]["id"]) + etud = Identite.query.get(etuds[0]["etudid"]) assert etud is not None etudid = etud.id db.session.delete(etud)