From 07123089e285d0e1a7b0d2edca7bb69bf0374f6c Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Thu, 21 Apr 2022 15:57:02 +0200 Subject: [PATCH] =?UTF-8?q?test=20d=C3=A9partement,=20=C3=A9tudiant=20fini?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/departements.py | 31 +++++++- tests/api/test_api_departements.py | 112 +++++++++++++++++++++++++---- 2 files changed, 126 insertions(+), 17 deletions(-) diff --git a/app/api/departements.py b/app/api/departements.py index c4b689a1f..6eacf566c 100644 --- a/app/api/departements.py +++ b/app/api/departements.py @@ -1,5 +1,5 @@ ############################################### Departements ########################################################## -from flask import g +import app from flask import jsonify from app import models @@ -196,4 +196,31 @@ def semestre_index(dept: str, formsemestre_id: int): Retourne la liste des Ues, ressources et SAE d'un semestre """ - return error_response(501, message="not implemented") + app.set_sco_dept(dept) + + formsemestre = models.FormSemestre.query.filter_by(id=formsemestre_id).first() + + ues = formsemestre.query_ues() + + ues_dict = [] + for ue in ues: + ues_dict.append(ue.to_dict()) + ressources = ue.get_ressources() + saes = ue.get_saes() + + data_ressources = [] + for ressource in ressources: + data_ressources.append(ressource.to_dict()) + + data_saes = [] + for sae in saes: + data_saes.append(sae.to_dict()) + + data = { + "ues": ues_dict, + "ressources": data_ressources, + "saes": data_saes, + } + + return data + #return error_response(501, message="not implemented") diff --git a/tests/api/test_api_departements.py b/tests/api/test_api_departements.py index ac4f33397..9e04e8d54 100644 --- a/tests/api/test_api_departements.py +++ b/tests/api/test_api_departements.py @@ -55,9 +55,9 @@ def test_liste_etudiants(): #XXX TODO pour Seb # liste_semestres_courant def test_semestres_courant(): #XXX TODO pour Seb r = requests.get( - SCODOC_URL + "/ScoDoc/api/departements/TAPI/semestres_courants", - headers=HEADERS, - verify=CHECK_CERTIFICATE, + SCODOC_URL + "/ScoDoc/api/departements/TAPI/semestres_courants", + headers=HEADERS, + verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 assert len(r.json()) == 1 @@ -66,18 +66,100 @@ def test_semestres_courant(): #XXX TODO pour Seb # referenciel_competences def test_referenciel_competences(): r = requests.get( - SCODOC_URL - + "/ScoDoc/api/departements/TAPI/formations/1/referentiel_competences", - headers=HEADERS, - verify=CHECK_CERTIFICATE, - ) + SCODOC_URL + + "/ScoDoc/api/departements/TAPI/formations/1/referentiel_competences", + headers=HEADERS, + verify=CHECK_CERTIFICATE, + ) assert r.status_code == 200 or 204 -# # semestre_index -# def test_semestre_index(): #XXX TODO pour Seb -# r = requests.get( -# SCODOC_URL + "/ScoDoc/api/departements/TAPI/formsemestre/1/programme", -# headers=HEADERS, verify=CHECK_CERTIFICATE -# ) -# assert r.status_code == 200 +# semestre_index +def test_semestre_index(): #XXX TODO pour Seb + + 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", + ] + + r = requests.get( + SCODOC_URL + "/ScoDoc/api/departements/TAPI/formsemestre/1/programme", + headers=HEADERS, + verify=CHECK_CERTIFICATE, + ) + assert r.status_code == 200 + assert len(r.json()) == 3 + + ue = r.json()["ues"][0] + ressource = r.json()["ressources"][0] + sae = r.json()["saes"][0] + + fields_OK = True + + # Vérifie si tous les champs sont bien présents + for field in ue: + if field not in ue_fields: + fields_OK = False + + for field in ressource: + if field not in ressource_fields: + fields_OK = False + + for field in sae: + if field not in sae_fields: + fields_OK = False + + assert fields_OK is True