From aba6330065c1691c2cbcd057175648f3ba36bad9 Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Thu, 28 Apr 2022 16:12:15 +0200 Subject: [PATCH] ajout des tests pour la version 'long' de etudiant_courant + correction routes et doc sur les fichiers api --- app/api/absences.py | 8 +- app/api/etudiants.py | 2 +- app/api/evaluations.py | 42 +++++------ app/api/formations.py | 10 +-- app/api/formsemestres.py | 29 ++++++++ app/api/partitions.py | 6 +- tests/api/test_api_etudiants.py | 128 ++++++++++++++------------------ 7 files changed, 119 insertions(+), 106 deletions(-) diff --git a/app/api/absences.py b/app/api/absences.py index 35abe34ff..35056a05b 100644 --- a/app/api/absences.py +++ b/app/api/absences.py @@ -93,7 +93,7 @@ def absences_just(etudid: int = None, nip: int = None, ine: int = None): "jour": "Fri, 15 Apr 2022 00:00:00 GMT", "matin": false, "estabs": true, - "estjust": false, + "estjust": true, "description": "", "begin": "2022-04-15 12:00:00", "end": "2022-04-15 17:59:59" @@ -120,7 +120,11 @@ def absences_just(etudid: int = None, nip: int = None, ine: int = None): @bp.route( - "/absences/abs_group_etat/?group_id=&date_debut=date_debut&date_fin=date_fin", + "/absences/abs_group_etat/", + methods=["GET"], +) +@bp.route( + "/absences/abs_group_etat/group_id//date_debut//date_fin/", methods=["GET"], ) @token_permission_required(Permission.APIView) diff --git a/app/api/etudiants.py b/app/api/etudiants.py index 1f22463ec..4cab02a09 100644 --- a/app/api/etudiants.py +++ b/app/api/etudiants.py @@ -59,7 +59,7 @@ def etudiants_courant(long=False): data = [etud.to_dict_bul(include_urls=False) for etud in etuds] else: data = [etud.to_dict_short() for etud in etuds] - + print(jsonify(data)) return jsonify(data) diff --git a/app/api/evaluations.py b/app/api/evaluations.py index 2f6049d99..4cbfa9f33 100644 --- a/app/api/evaluations.py +++ b/app/api/evaluations.py @@ -62,27 +62,27 @@ def evaluation_notes(evaluation_id: int): evaluation_id : l'id d'une évaluation Exemple de résultat : - { - "1": { - "id": 1, - "etudid": 10, - "evaluation_id": 1, - "value": 15.0, - "comment": "", - "date": "Wed, 20 Apr 2022 06:49:05 GMT", - "uid": 2 - }, - "2": { - "id": 2, - "etudid": 1, - "evaluation_id": 1, - "value": 12.0, - "comment": "", - "date": "Wed, 20 Apr 2022 06:49:06 GMT", - "uid": 2 - }, - ... - } + { + "1": { + "id": 1, + "etudid": 10, + "evaluation_id": 1, + "value": 15.0, + "comment": "", + "date": "Wed, 20 Apr 2022 06:49:05 GMT", + "uid": 2 + }, + "2": { + "id": 2, + "etudid": 1, + "evaluation_id": 1, + "value": 12.0, + "comment": "", + "date": "Wed, 20 Apr 2022 06:49:06 GMT", + "uid": 2 + }, + ... + } """ # Fonction utilisée : app.scodoc.sco_evaluation_db.do_evaluation_get_all_notes() diff --git a/app/api/formations.py b/app/api/formations.py index f7d1a6424..ee017514d 100644 --- a/app/api/formations.py +++ b/app/api/formations.py @@ -177,7 +177,7 @@ def formation_export_by_formation_id(formation_id: int, export_ids=False): try: # Utilisation de la fonction formation_export - data = formation_export(formation_id) + data = formation_export(formation_id, export_ids) except ValueError: return error_response( 409, @@ -192,15 +192,15 @@ def formation_export_by_formation_id(formation_id: int, export_ids=False): @token_permission_required(Permission.APIView) def moduleimpls(moduleimpl_id: int): """ - Retourne la liste des moduleimpl + Retourne un module moduleimpl en fonction de son id moduleimpl_id : l'id d'un moduleimpl """ # Récupération des tous les moduleimpl - list_moduleimpls = models.ModuleImpl.query.filter_by(id=moduleimpl_id) + moduleimpl = models.ModuleImpl.query.filter_by(id=moduleimpl_id).first_or_404() # Mise en forme des données - data = [moduleimpl.to_dict() for moduleimpl in list_moduleimpls] + data = moduleimpl.to_dict() return jsonify(data) @@ -208,7 +208,7 @@ def moduleimpls(moduleimpl_id: int): @bp.route( "/formations/moduleimpl/formsemestre//liste", methods=["GET"], -) # XXX TODO penser à changer la route sur la doc +) @token_permission_required(Permission.APIView) def moduleimpls_sem(formsemestre_id: int): """ diff --git a/app/api/formsemestres.py b/app/api/formsemestres.py index 9704d753c..4ab86132e 100644 --- a/app/api/formsemestres.py +++ b/app/api/formsemestres.py @@ -68,6 +68,35 @@ def formsemestre_apo(etape_apo: str): Retourne les informations sur les formsemestres etape_apo : l'id d'une étape apogée + + Exemple de résultat : + { + "date_fin": "31/08/2022", + "resp_can_edit": false, + "dept_id": 1, + "etat": true, + "resp_can_change_ens": true, + "id": 1, + "modalite": "FI", + "ens_can_edit_eval": false, + "formation_id": 1, + "gestion_compensation": false, + "elt_sem_apo": null, + "semestre_id": 1, + "bul_hide_xml": false, + "elt_annee_apo": null, + "titre": "Semestre test", + "block_moyennes": false, + "scodoc7_id": null, + "date_debut": "01/09/2021", + "gestion_semestrielle": false, + "bul_bgcolor": "white", + "formsemestre_id": 1, + "titre_num": "Semestre test semestre 1", + "date_debut_iso": "2021-09-01", + "date_fin_iso": "2022-08-31", + "responsables": [] + } """ formsemestres = FormSemestre.query.filter( FormSemestreEtape.etape_apo == etape_apo, diff --git a/app/api/partitions.py b/app/api/partitions.py index 2af2f7cf7..d925d1749 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -121,13 +121,13 @@ def etud_in_group(group_id: int, etat=None): @bp.route( - "/partitions/set_groups?partition_id=&groups_lists=&" - "groups_to_create=&groups_to_delete=", + "/partitions/set_groups/partition//groups//delete/" + "/create/", methods=["POST"], ) @token_permission_required(Permission.APIEtudChangeGroups) def set_groups( - partition_id: int, groups_lists: int, groups_to_delete: int, groups_to_create: int + partition_id: int, groups_lists: str, groups_to_delete: str, groups_to_create: str ): """ Set les groups diff --git a/tests/api/test_api_etudiants.py b/tests/api/test_api_etudiants.py index e568a4f9b..6ebecbc7a 100644 --- a/tests/api/test_api_etudiants.py +++ b/tests/api/test_api_etudiants.py @@ -23,85 +23,16 @@ import requests from tests.api.setup_test_api import SCODOC_URL, CHECK_CERTIFICATE, HEADERS -# # etudiants -# def test_etudiants(): -# -# fields = [ -# "civilite", -# "code_ine", -# "code_nip", -# "date_naissance", -# "email", -# "emailperso", -# "etudid", -# "nom", -# "prenom", -# "nomprenom", -# "lieu_naissance", -# "dept_naissance", -# "nationalite", -# "boursier", -# "id", -# "domicile", -# "villedomicile", -# "telephone", -# "fax", -# "description", -# "codepostaldomicile", -# "paysdomicile", -# "telephonemobile", -# "typeadresse", -# ] -# -# r = requests.get( -# SCODOC_URL + "/ScoDoc/api/etudiants", -# headers=HEADERS, -# verify=CHECK_CERTIFICATE, -# ) -# assert r.status_code == 200 -# assert len(r.json()) == 16 -# -# # Choisis aléatoirement un étudiant dans la liste des étudiants -# etu = r.json()[randint(0, len(r.json())) - 1] -# -# fields_OK = True -# -# # Vérifie si tous les champs sont bien présents -# for field in etu: -# if field not in fields: -# fields_OK = False -# -# assert fields_OK is True - - # etudiants_courant def test_etudiants_courant(): # XXX TODO pour Seb fields = [ - "civilite", - "code_ine", - "code_nip", - "date_naissance", - "email", - "emailperso", - "etudid", - "nom", - "prenom", - "nomprenom", - "lieu_naissance", - "dept_naissance", - "nationalite", - "boursier", "id", - "domicile", - "villedomicile", - "telephone", - "fax", - "description", - "codepostaldomicile", - "paysdomicile", - "telephonemobile", - "typeadresse", + "nip", + "nom", + "nom_usuel", + "prenom", + "civilite", ] r = requests.get( @@ -124,6 +55,55 @@ def test_etudiants_courant(): # XXX TODO pour Seb assert fields_OK is True + ########## Version long################ + + fields_long = [ + "civilite", + "code_ine", + "code_nip", + "date_naissance", + "email", + "emailperso", + "etudid", + "nom", + "prenom", + "nomprenom", + "lieu_naissance", + "dept_naissance", + "nationalite", + "boursier", + "id", + "codepostaldomicile", + "paysdomicile", + "telephonemobile", + "typeadresse", + "domicile", + "villedomicile", + "telephone", + "fax", + "description", + ] + + r = requests.get( + SCODOC_URL + "/ScoDoc/api/etudiants/courant/long", + headers=HEADERS, + verify=CHECK_CERTIFICATE, + ) + assert r.status_code == 200 + assert len(r.json()) == 16 + + # Choisis aléatoirement un étudiant dans la liste des étudiants + etu = r.json()[randint(0, len(r.json())) - 1] + + fields_OK = True + + # Vérifie si tous les champs sont bien présents + for field in etu: + if field not in fields_long: + fields_OK = False + + assert fields_OK is True + # etudiant def test_etudiant(): # XXX TODO pour Seb