From 23c035e252b07cc1864b2c112b9569fc3404eae8 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 4 Feb 2023 02:17:30 +0100 Subject: [PATCH] API: formsemestre_resultat avec nouvelle table + test unitaire --- app/api/formsemestres.py | 9 +-- tests/api/test_api_formsemestre.py | 19 ++++-- .../results/formsemestre_resultat.json | 64 +++++++++---------- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/app/api/formsemestres.py b/app/api/formsemestres.py index e7231e556..9078cebb1 100644 --- a/app/api/formsemestres.py +++ b/app/api/formsemestres.py @@ -477,14 +477,9 @@ def formsemestre_resultat(formsemestre_id: int): formsemestre: FormSemestre = query.first_or_404(formsemestre_id) app.set_sco_dept(formsemestre.departement.acronym) res: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) - table = TableRecap() - table = res.get_table_recap( - convert_values=convert_values, - include_evaluations=False, - mode_jury=False, - allow_html=False, + table = TableRecap( + res, convert_values=convert_values, include_evaluations=False, mode_jury=False ) - raise NotImplementedError() # A COMPLETER XXX # Supprime les champs inutiles (mise en forme) rows = table.to_list() # Ajoute le groupe de chaque partition: diff --git a/tests/api/test_api_formsemestre.py b/tests/api/test_api_formsemestre.py index 8b33c7e38..6b96e2ce9 100644 --- a/tests/api/test_api_formsemestre.py +++ b/tests/api/test_api_formsemestre.py @@ -16,7 +16,7 @@ Utilisation : Lancer : pytest tests/api/test_api_formsemestre.py """ - +import json import requests from tests.api.setup_test_api import ( @@ -695,10 +695,21 @@ def test_formsemestre_resultat(api_headers): verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 - json_response = r.text.translate({32: None, 9: None}).strip() + res = r.json() with open( "tests/ressources/results/formsemestre_resultat.json", encoding="utf8" ) as f: - json_reference = f.read().translate({32: None, 9: None}).strip() + json_reference = f.read() + ref = json.loads(json_reference) + _compare_formsemestre_resultat(res, ref) - assert json_response == json_reference + +def _compare_formsemestre_resultat(res: list[dict], ref: list[dict]): + """compare les deux dict de résultats de formsemestre_resultat""" + assert len(res) == len(ref) # même nb d'étudiants + res.sort(key=lambda e: e["etudid"]) + ref.sort(key=lambda e: e["etudid"]) + for res_d, ref_d in zip(res, ref): + assert sorted(res_d.keys()) == sorted(ref_d.keys()) + for k in res_d: + assert res_d[k] == ref_d[k] diff --git a/tests/ressources/results/formsemestre_resultat.json b/tests/ressources/results/formsemestre_resultat.json index e24c5a2cd..1bd3a0e6a 100644 --- a/tests/ressources/results/formsemestre_resultat.json +++ b/tests/ressources/results/formsemestre_resultat.json @@ -7,6 +7,8 @@ "nom_disp": "FLEURY", "prenom": "MADELEINE", "nom_short": "FLEURY Ma.", + "code_cursus": "S1", + "ues_validables": "3/3", "moy_gen": "14.36", "moy_ue_1": "14.94", "moy_res_1_1": "~", @@ -45,8 +47,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "17.83", "moy_sae_15_3": "~", - "ues_validables": "3/3", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -63,6 +63,8 @@ "nom_disp": "SAUNIER", "prenom": "JACQUES", "nom_short": "SAUNIER Ja.", + "code_cursus": "S1", + "ues_validables": "3/3", "moy_gen": "12.67", "moy_ue_1": "13.51", "moy_res_1_1": "~", @@ -101,8 +103,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "10.74", "moy_sae_15_3": "~", - "ues_validables": "3/3", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -119,6 +119,8 @@ "nom_disp": "LENFANT", "prenom": "MAXIME", "nom_short": "LENFANT Ma.", + "code_cursus": "S1", + "ues_validables": "2/3", "moy_gen": "12.02", "moy_ue_1": "14.34", "moy_res_1_1": "~", @@ -157,8 +159,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "05.70", "moy_sae_15_3": "~", - "ues_validables": "2/3", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -175,6 +175,8 @@ "nom_disp": "CUNY", "prenom": "CAMILLE", "nom_short": "CUNY Ca.", + "code_cursus": "S1", + "ues_validables": "2/3", "moy_gen": "11.88", "moy_ue_1": "07.09", "moy_res_1_1": "~", @@ -213,8 +215,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "10.52", "moy_sae_15_3": "~", - "ues_validables": "2/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -231,6 +231,8 @@ "nom_disp": "GAUTIER", "prenom": "G\u00c9RARD", "nom_short": "GAUTIER G\u00e9.", + "code_cursus": "S1", + "ues_validables": "1/3", "moy_gen": "11.08", "moy_ue_1": "13.52", "moy_res_1_1": "~", @@ -269,8 +271,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "10.67", "moy_sae_15_3": "~", - "ues_validables": "1/3", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -287,6 +287,8 @@ "nom_disp": "MOUTON", "prenom": "CLAUDE", "nom_short": "MOUTON Cl.", + "code_cursus": "S1", + "ues_validables": "1/3", "moy_gen": "10.52", "moy_ue_1": "08.93", "moy_res_1_1": "~", @@ -325,8 +327,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "11.09", "moy_sae_15_3": "~", - "ues_validables": "1/3", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -343,6 +343,8 @@ "nom_disp": "VILLENEUVE", "prenom": "FRAN\u00c7OISE", "nom_short": "VILLENEUVE Fr.", + "code_cursus": "S1", + "ues_validables": "1/3", "moy_gen": "10.42", "moy_ue_1": "09.27", "moy_res_1_1": "~", @@ -381,8 +383,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "13.21", "moy_sae_15_3": "~", - "ues_validables": "1/3", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -399,6 +399,8 @@ "nom_disp": "BOUTET", "prenom": "MARGUERITE", "nom_short": "BOUTET Ma.", + "code_cursus": "S1", + "ues_validables": "2/3", "moy_gen": "10.26", "moy_ue_1": "12.57", "moy_res_1_1": "~", @@ -437,8 +439,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "15.82", "moy_sae_15_3": "~", - "ues_validables": "2/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -455,6 +455,8 @@ "nom_disp": "R\u00c9GNIER", "prenom": "PATRICK", "nom_short": "R\u00c9GNIER Pa.", + "code_cursus": "S1", + "ues_validables": "2/3", "moy_gen": "10.04", "moy_ue_1": "13.06", "moy_res_1_1": "~", @@ -493,8 +495,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "01.55", "moy_sae_15_3": "~", - "ues_validables": "2/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -511,6 +511,8 @@ "nom_disp": "ROLLIN", "prenom": "DERC'HEN", "nom_short": "ROLLIN De.", + "code_cursus": "S1", + "ues_validables": "2/3", "moy_gen": "09.59", "moy_ue_1": "11.92", "moy_res_1_1": "~", @@ -549,8 +551,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "00.94", "moy_sae_15_3": "~", - "ues_validables": "2/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -567,6 +567,8 @@ "nom_disp": "ESTEVE", "prenom": "ALIX", "nom_short": "ESTEVE Al.", + "code_cursus": "S1", + "ues_validables": "1/3", "moy_gen": "08.59", "moy_ue_1": "07.24", "moy_res_1_1": "~", @@ -605,8 +607,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "05.17", "moy_sae_15_3": "~", - "ues_validables": "1/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -623,6 +623,8 @@ "nom_disp": "SCHMITT", "prenom": "EMMANUEL", "nom_short": "SCHMITT Em.", + "code_cursus": "S1", + "ues_validables": "1/3", "moy_gen": "08.31", "moy_ue_1": "07.70", "moy_res_1_1": "~", @@ -661,8 +663,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "02.59", "moy_sae_15_3": "~", - "ues_validables": "1/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -679,6 +679,8 @@ "nom_disp": "DIOT", "prenom": "CAMILLE", "nom_short": "DIOT Ca.", + "code_cursus": "S1", + "ues_validables": "0/3", "moy_gen": "07.24", "moy_ue_1": "06.48", "moy_res_1_1": "~", @@ -717,8 +719,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "03.49", "moy_sae_15_3": "~", - "ues_validables": "0/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -735,6 +735,8 @@ "nom_disp": "GILLES", "prenom": "MAXIME", "nom_short": "GILLES Ma.", + "code_cursus": "S1", + "ues_validables": "0/3", "moy_gen": "07.21", "moy_ue_1": "06.86", "moy_res_1_1": "~", @@ -773,8 +775,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "03.32", "moy_sae_15_3": "~", - "ues_validables": "0/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -791,6 +791,8 @@ "nom_disp": "NAUDIN", "prenom": "SIMONE", "nom_short": "NAUDIN Si.", + "code_cursus": "S1", + "ues_validables": "0/3", "moy_gen": "07.02", "moy_ue_1": "06.82", "moy_res_1_1": "~", @@ -829,8 +831,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "02.10", "moy_sae_15_3": "~", - "ues_validables": "0/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "", @@ -847,6 +847,8 @@ "nom_disp": "COSTA", "prenom": "SACHA", "nom_short": "COSTA Sa.", + "code_cursus": "S1", + "ues_validables": "0/3", "moy_gen": "05.31", "moy_ue_1": "03.73", "moy_res_1_1": "~", @@ -885,8 +887,6 @@ "moy_res_21_3": "~", "moy_sae_14_3": "07.17", "moy_sae_15_3": "~", - "ues_validables": "0/3 ⚠️", - "code_cursus": "S1", "bac": "", "specialite": "", "type_admission": "",