From 2d40932b5021d9ff07b1caca2687f11541636b09 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 5 May 2022 19:50:09 +0200 Subject: [PATCH] API: tests: factorisation du code --- app/api/etudiants.py | 3 +- tests/api/test_api_departements.py | 15 +++++- tests/api/test_api_etudiants.py | 55 +------------------ tests/api/test_api_formations.py | 85 ++---------------------------- tests/api/test_api_formsemestre.py | 37 ++----------- tests/api/tools_test_api.py | 80 ++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 172 deletions(-) diff --git a/app/api/etudiants.py b/app/api/etudiants.py index ab41fc319..6ad762c55 100644 --- a/app/api/etudiants.py +++ b/app/api/etudiants.py @@ -20,8 +20,7 @@ from app.scodoc.sco_permissions import Permission @token_permission_required(Permission.APIView) def etudiants_courant(long=False): """ - Retourne la liste des étudiants inscrits dans un - formsemestre actuellement en cours. + Liste des étudiants inscrits dans un formsemestre actuellement en cours. Exemple de résultat : [ diff --git a/tests/api/test_api_departements.py b/tests/api/test_api_departements.py index cbb296fa9..436cab2b5 100644 --- a/tests/api/test_api_departements.py +++ b/tests/api/test_api_departements.py @@ -33,7 +33,7 @@ DEPARTEMENT_FIELDS = [ def test_departements(api_headers): """ " - Routes: /departements_ids, /departement + Routes: /departements_ids, /departement, /departement//formsemestres_ids """ # --- Liste des ids @@ -68,6 +68,19 @@ def test_departements(api_headers): dept_b = r.json() assert dept_a == dept_b + # Liste des formsemestres + r = requests.get( + f"{API_URL}/departement/{dept_a['acronym']}/formsemestres_ids", + headers=api_headers, + verify=CHECK_CERTIFICATE, + ) + assert r.status_code == 200 + dept_ids = r.json() + assert isinstance(dept_ids, list) + assert all(isinstance(x, int) for x in dept_ids) + assert len(dept_ids) > 0 + assert dept_id in dept_ids + def test_list_etudiants(api_headers): fields = {"id", "nip", "ine", "nom", "nom_usuel", "prenom", "civilite"} diff --git a/tests/api/test_api_etudiants.py b/tests/api/test_api_etudiants.py index 99997da01..d2984f8e2 100644 --- a/tests/api/test_api_etudiants.py +++ b/tests/api/test_api_etudiants.py @@ -21,60 +21,7 @@ import requests from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers from tests.api.tools_test_api import verify_fields - -ETUD_FIELDS = { - "boursier", - "civilite", - "code_ine", - "code_nip", - "codepostaldomicile", - "date_naissance", - "dept_naissance", - "description", - "domicile", - "email", - "emailperso", - "etudid", - "id", - "lieu_naissance", - "nationalite", - "nom", - "nomprenom", - "paysdomicile", - "prenom", - "telephone", - "telephonemobile", - "typeadresse", - "villedomicile", -} - -FSEM_FIELDS = { - "block_moyennes", - "bul_bgcolor", - "bul_hide_xml", - "date_debut_iso", - "date_debut", - "date_fin_iso", - "date_fin", - "dept_id", - "elt_annee_apo", - "elt_sem_apo", - "ens_can_edit_eval", - "etat", - "formation_id", - "formsemestre_id", - "gestion_compensation", - "gestion_semestrielle", - "id", - "modalite", - "resp_can_change_ens", - "resp_can_edit", - "responsables", - "semestre_id", - "titre_formation", - "titre_num", - "titre", -} +from tests.api.tools_test_api import ETUD_FIELDS, FSEM_FIELDS def test_etudiants_courant(api_headers): diff --git a/tests/api/test_api_formations.py b/tests/api/test_api_formations.py index e14fcb2c9..b61037da0 100644 --- a/tests/api/test_api_formations.py +++ b/tests/api/test_api_formations.py @@ -21,9 +21,9 @@ import requests from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers from tests.api.tools_test_api import verify_fields +from tests.api.tools_test_api import FORMATION_FIELDS, MODIMPL_FIELDS -# formations def test_formations_ids(api_headers): """ Route: /formations_ids @@ -41,25 +41,10 @@ def test_formations_ids(api_headers): assert all(isinstance(x, int) for x in formations_ids) -# formations_by_id def test_formations_by_id(api_headers): """ Route: /formation/ """ - fields = [ - "id", - "acronyme", - "titre_officiel", - "formation_code", - "code_specialite", - "dept_id", - "titre", - "version", - "type_parcours", - "referentiel_competence_id", - "formation_id", - ] - r = requests.get( API_URL + "/formation/1", headers=api_headers, @@ -67,9 +52,7 @@ def test_formations_by_id(api_headers): ) assert r.status_code == 200 formation = r.json() - - fields_ok = verify_fields(formation, fields) - assert fields_ok is True + assert verify_fields(formation, FORMATION_FIELDS) is True # TODO tester le contenu de certains champs @@ -77,31 +60,14 @@ def test_formation_export(api_headers): """ Route: /formation/formation_export/ """ - fields = [ - "id", - "acronyme", - "titre_officiel", - "formation_code", - "code_specialite", - "dept_id", - "titre", - "version", - "type_parcours", - "referentiel_competence_id", - "formation_id", - "ue", - ] r = requests.get( API_URL + "/formation/formation_export/1", headers=api_headers, verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 - export_formation = r.json() - - fields_ok = verify_fields(export_formation, fields) - assert fields_ok is True + assert verify_fields(export_formation, FORMATION_FIELDS) is True # TODO tester le contenu de certains champs @@ -119,17 +85,6 @@ def test_moduleimpl(api_headers): """ Route: /formation/moduleimpl/ """ - fields = [ - "id", - "formsemestre_id", - "computation_expr", - "module_id", - "responsable_id", - "moduleimpl_id", - "ens", - "module", - ] - r = requests.get( API_URL + "/formation/moduleimpl/1", headers=api_headers, @@ -137,42 +92,10 @@ def test_moduleimpl(api_headers): ) assert r.status_code == 200 moduleimpl = r.json() - - fields_ok = verify_fields(moduleimpl, fields) - assert fields_ok is True + assert verify_fields(moduleimpl, MODIMPL_FIELDS) is True # TODO tester le contenu de certains champs -def test_moduleimpls_sem(api_headers): - """ - Route: /formation/moduleimpl/formsemestre//list - """ - fields = [ - "id", - "formsemestre_id", - "computation_expr", - "module_id", - "responsable_id", - "moduleimpl_id", - "ens", - "module", - "moduleimpl_id", - "ens", - ] - r = requests.get( - API_URL + "/formation/moduleimpl/formsemestre/1/list", - headers=api_headers, - verify=CHECK_CERTIFICATE, - ) - assert r.status_code == 200 - moduleimpls = r.json() - moduleimpl = moduleimpls[0] - - fields_ok = verify_fields(moduleimpl, fields) - assert len(moduleimpls) == 21 # XXX HARDCODED ! - assert fields_ok is True - - def test_referentiel_competences(api_headers): """ Route: "/formation//referentiel_competences", diff --git a/tests/api/test_api_formsemestre.py b/tests/api/test_api_formsemestre.py index 724713a10..38f809335 100644 --- a/tests/api/test_api_formsemestre.py +++ b/tests/api/test_api_formsemestre.py @@ -21,11 +21,12 @@ import requests from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers from tests.api.tools_test_api import verify_fields +from tests.api.tools_test_api import ETUD_FIELDS, FSEM_FIELDS def test_formsemestre(api_headers): """ - Route: + Route: /formsemestre/ """ r = requests.get( API_URL + "/formsemestre/1", @@ -33,40 +34,8 @@ def test_formsemestre(api_headers): verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 - formsemestre = r.json() - - fields = [ - "date_fin", - "resp_can_edit", - "dept_id", - "etat", - "resp_can_change_ens", - "id", - "modalite", - "ens_can_edit_eval", - "formation_id", - "gestion_compensation", - "elt_sem_apo", - "semestre_id", - "bul_hide_xml", - "elt_annee_apo", - "titre", - "block_moyennes", - "scodoc7_id", - "date_debut", - "gestion_semestrielle", - "bul_bgcolor", - "formsemestre_id", - "titre_num", - "date_debut_iso", - "date_fin_iso", - "responsables", - ] - - fields_ok = verify_fields(formsemestre, fields) - - assert fields_ok is True + assert verify_fields(formsemestre, FSEM_FIELDS) def test_etudiant_bulletin(api_headers): diff --git a/tests/api/tools_test_api.py b/tests/api/tools_test_api.py index 7be43a891..5af41b9ed 100644 --- a/tests/api/tools_test_api.py +++ b/tests/api/tools_test_api.py @@ -12,3 +12,83 @@ def verify_fields(json_response: dict, expected_fields: set) -> bool: Retourne True ou False """ return all(field in json_response for field in expected_fields) + + +ETUD_FIELDS = { + "boursier", + "civilite", + "code_ine", + "code_nip", + "codepostaldomicile", + "date_naissance", + "dept_naissance", + "description", + "domicile", + "email", + "emailperso", + "etudid", + "id", + "lieu_naissance", + "nationalite", + "nom", + "nomprenom", + "paysdomicile", + "prenom", + "telephone", + "telephonemobile", + "typeadresse", + "villedomicile", +} + +FORMATION_FIELDS = { + "id", + "acronyme", + "titre_officiel", + "formation_code", + "code_specialite", + "dept_id", + "titre", + "version", + "type_parcours", + "referentiel_competence_id", + "formation_id", +} + +FSEM_FIELDS = { + "block_moyennes", + "bul_bgcolor", + "bul_hide_xml", + "date_debut_iso", + "date_debut", + "date_fin_iso", + "date_fin", + "dept_id", + "elt_annee_apo", + "elt_sem_apo", + "ens_can_edit_eval", + "etat", + "formation_id", + "formsemestre_id", + "gestion_compensation", + "gestion_semestrielle", + "id", + "modalite", + "resp_can_change_ens", + "resp_can_edit", + "responsables", + "semestre_id", + "titre_formation", + "titre_num", + "titre", +} + +MODIMPL_FIELDS = { + "id", + "formsemestre_id", + "computation_expr", + "module_id", + "responsable_id", + "moduleimpl_id", + "ens", + "module", +}