From 4ab43f59c10a21652b4528be7851858aca5a6f8f Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 5 May 2022 20:06:49 +0200 Subject: [PATCH] API: test_api_formsemestre --- tests/api/test_api_formsemestre.py | 114 ++++++++++------------------- tests/api/tools_test_api.py | 37 ++++++++++ 2 files changed, 74 insertions(+), 77 deletions(-) diff --git a/tests/api/test_api_formsemestre.py b/tests/api/test_api_formsemestre.py index 38f80933..57d79772 100644 --- a/tests/api/test_api_formsemestre.py +++ b/tests/api/test_api_formsemestre.py @@ -18,10 +18,11 @@ Utilisation : """ import requests +from app.api.formsemestres import formsemestre 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 +from tests.api.tools_test_api import MODIMPL_FIELDS, verify_fields +from tests.api.tools_test_api import FSEM_FIELDS, UE_FIELDS, MODULE_FIELDS def test_formsemestre(api_headers): @@ -42,26 +43,35 @@ def test_etudiant_bulletin(api_headers): """ Route: """ + formsemestre_id = 1 r = requests.get( - API_URL + "/formsemestre/1/etudiant/etudid/1/bulletin", + f"{API_URL}/etudiant/etudid/1/formsemestre/{formsemestre_id}/bulletin", headers=api_headers, verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 + bull_a = r.json() r = requests.get( - API_URL + "/formsemestre/1/etudiant/nip/1/bulletin", + f"{API_URL}/etudiant/nip/1/formsemestre/{formsemestre_id}/bulletin", headers=api_headers, verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 + bull_b = r.json() r = requests.get( - API_URL + "/formsemestre/1/etudiant/ine/1/bulletin", + f"{API_URL}/etudiant/ine/1/formsemestre/{formsemestre_id}/bulletin", headers=api_headers, verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 + bull_c = r.json() + # elimine les dates de publication pour comparer les autres champs + del bull_a["date"] + del bull_b["date"] + del bull_c["date"] + assert bull_a == bull_b == bull_c def test_bulletins(api_headers): @@ -85,67 +95,11 @@ def test_bulletins(api_headers): # ) # assert r.status_code == 200 -# TODO A revoir -def test_semestre_index(api_headers): - """ - Route: TODO - """ - ue_fields = [ - "semestre_idx", - "type", - "formation_id", - "ue_code", - "id", - "ects", - "acronyme", - "is_external", - "numero", - "code_apogee", - "titre", - "coefficient", - "color", - "ue_id", - ] - ressource_fields = [ - "heures_tp", - "code_apogee", - "titre", - "coefficient", - "module_type", - "id", - "ects", - "abbrev", - "ue_id", - "code", - "formation_id", - "heures_cours", - "matiere_id", - "heures_td", - "semestre_id", - "numero", - "module_id", - ] - - sae_fields = [ - "heures_tp", - "code_apogee", - "titre", - "coefficient", - "module_type", - "id", - "ects", - "abbrev", - "ue_id", - "code", - "formation_id", - "heures_cours", - "matiere_id", - "heures_td", - "semestre_id", - "numero", - "module_id", - ] +def test_formsemestre_programme(api_headers): + """ + Route: /formsemestre/1/programme + """ r = requests.get( API_URL + "/formsemestre/1/programme", @@ -153,16 +107,22 @@ def test_semestre_index(api_headers): verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 - assert len(r.json()) == 3 + prog = r.json() + assert isinstance(prog, dict) + assert "ues" in prog + assert "modules" in prog + assert "ressources" in prog + assert "saes" in prog + assert isinstance(prog["ues"], list) + assert isinstance(prog["modules"], list) + ue = prog["ues"][0] + modules = prog["modules"] + # Il y a toujours au moins une SAE et une ressources dans notre base de test + ressource = prog["ressources"][0] + sae = prog["saes"][0] - ue = r.json()["ues"][0] - ressource = r.json()["ressources"][0] - sae = r.json()["saes"][0] - - fields_ue_OK = verify_fields(ue, ue_fields) - fields_ressource_OK = verify_fields(ressource, ressource_fields) - fields_sae_OK = verify_fields(sae, sae_fields) - - assert fields_ue_OK is True - assert fields_ressource_OK is True - assert fields_sae_OK is True + assert verify_fields(ue, UE_FIELDS) + if len(modules) > 1: + assert verify_fields(modules[0], MODIMPL_FIELDS) + assert verify_fields(ressource, MODIMPL_FIELDS) + assert verify_fields(sae, MODIMPL_FIELDS) diff --git a/tests/api/tools_test_api.py b/tests/api/tools_test_api.py index 5af41b9e..582b03fb 100644 --- a/tests/api/tools_test_api.py +++ b/tests/api/tools_test_api.py @@ -92,3 +92,40 @@ MODIMPL_FIELDS = { "ens", "module", } + +MODULE_FIELDS = { + "heures_tp", + "code_apogee", + "titre", + "coefficient", + "module_type", + "id", + "ects", + "abbrev", + "ue_id", + "code", + "formation_id", + "heures_cours", + "matiere_id", + "heures_td", + "semestre_id", + "numero", + "module_id", +} + +UE_FIELDS = { + "semestre_idx", + "type", + "formation_id", + "ue_code", + "id", + "ects", + "acronyme", + "is_external", + "numero", + "code_apogee", + "titre", + "coefficient", + "color", + "ue_id", +}