From a43f1e0e229b394d79d8d37731bc557a4944b8c4 Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Fri, 11 Mar 2022 16:18:50 +0100 Subject: [PATCH] =?UTF-8?q?am=C3=A9lioration=20des=20asserts=20de=20depart?= =?UTF-8?q?ement=20et=20etudiant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/departements.py | 51 ++-------------------- app/api/test_api.py | 4 -- tests/api/test_api_departements.py | 8 +++- tests/api/test_api_etudiants.py | 70 ++++++++++++++++++++---------- 4 files changed, 57 insertions(+), 76 deletions(-) diff --git a/app/api/departements.py b/app/api/departements.py index a7cbc496..43137cd9 100644 --- a/app/api/departements.py +++ b/app/api/departements.py @@ -16,8 +16,8 @@ from app.scodoc.sco_saisie_notes import notes_add @bp.route("/departements", methods=["GET"]) -# @token_auth.login_required # Commenté le temps des tests -# @permission_required(Permission.APIView) +@token_auth.login_required # Commenté le temps des tests +# @permission_required(Permission.ScoView) def departements(): """ Retourne la liste des ids de départements visibles @@ -35,7 +35,7 @@ def departements(): @bp.route("/departements//etudiants/liste", methods=["GET"]) @bp.route("/departements//etudiants/liste/", methods=["GET"]) -# @token_auth.login_required +@token_auth.login_required # @permission_required(Permission.APIView) def liste_etudiants(dept: str, formsemestre_id=None): """ @@ -94,51 +94,6 @@ def liste_etudiants(dept: str, formsemestre_id=None): return jsonify(list_etu) - # Si le formsemestre_id a été renseigné - # if formsemestre_id is not None: - # a = 0 - # Récupération du/des depts - # list_depts = models.Departement.query.filter( - # models.Departement.acronym == dept, - # models.FormSemestre.id == formsemestre_id, - # ) - # - # formsemestre = models.FormSemestre.query.get_or_404(formsemestre_id) - # list_depts = formsemestre.departement - # print(formsemestre) - # - # dept_id = list_depts - - - # list_etuds = [] - # for dept in list_depts: - # # Récupération des étudiants d'un département - # etudiants = models.Identite.query.filter_by(dept_id=dept.id).all() - # print(etudiants) - # for etu in etudiants: - # # Ajout des étudiants dans la liste global - # list_etuds.append(etu) - - # Si le formsemestre_id n'a pas été renseigné - # else: - - # # list_depts = models.Departement.query.filter( - # # models.Departement.acronym == dept, - # # models.FormSemestre.id == formsemestre_id, - # # ) - # - # list_etuds = [] - # for dept in list_depts: - # etudiants = models.Identite.query.filter_by(dept_id=dept.id).all() - # for etu in etudiants: - # list_etuds.append(etu) - # - # # Mise en forme des données - # data = [d.to_dict_bul() for d in list_etuds] - # return jsonify(data) - # return error_response(501, message="Not implemented") - - @bp.route("/departements//semestres_courants", methods=["GET"]) # @token_auth.login_required # Commenté le temps des tests # @permission_required(Permission.APIView) diff --git a/app/api/test_api.py b/app/api/test_api.py index c176342d..e269412f 100644 --- a/app/api/test_api.py +++ b/app/api/test_api.py @@ -43,8 +43,6 @@ def get_departement(): get_token() - print("ééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé") - global HEADERS global CHECK_CERTIFICATE global SCODOC_USER @@ -57,8 +55,6 @@ def get_departement(): headers=HEADERS, verify=CHECK_CERTIFICATE, ) - print("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii") - if r.status_code == 200: dept_id = r.json()[0] # print(dept_id) diff --git a/tests/api/test_api_departements.py b/tests/api/test_api_departements.py index ca904f0e..b35e6959 100644 --- a/tests/api/test_api_departements.py +++ b/tests/api/test_api_departements.py @@ -28,30 +28,34 @@ def test_departements(): headers=HEADERS, verify=CHECK_CERTIFICATE ) assert r.status_code == 200 + assert len(r.json()) == 1 # liste_etudiants -def test_etudiants(): +def test_liste_etudiants(): r = requests.get( SCODOC_URL + "/ScoDoc/api/departements/TAPI/etudiants/liste", headers=HEADERS, verify=CHECK_CERTIFICATE ) assert r.status_code == 200 + assert len(r.json()) == 16 r = requests.get( SCODOC_URL + "/ScoDoc/api/departements/TAPI/etudiants/liste/1", headers=HEADERS, verify=CHECK_CERTIFICATE ) assert r.status_code == 200 + assert len(r.json()) == 16 # liste_semestres_courant def test_semestres_courant(): r = requests.get( - SCODOC_URL + "/ScoDoc/api/departements/TAPI/etudiants/liste/1", + SCODOC_URL + "/ScoDoc/api/departements/TAPI/semestres_courants", headers=HEADERS, verify=CHECK_CERTIFICATE ) assert r.status_code == 200 + assert len(r.json()) == 1 # referenciel_competences diff --git a/tests/api/test_api_etudiants.py b/tests/api/test_api_etudiants.py index a5e114e6..f58c6e62 100644 --- a/tests/api/test_api_etudiants.py +++ b/tests/api/test_api_etudiants.py @@ -16,6 +16,7 @@ Utilisation : Lancer : pytest tests/api/test_api_etudiants.py """ +from random import randint import requests from tests.api.setup_test_api import SCODOC_URL, HEADERS, CHECK_CERTIFICATE @@ -24,26 +25,46 @@ from tests.api.setup_test_api import SCODOC_URL, HEADERS, CHECK_CERTIFICATE # etudiants def test_etudiants(): r = requests.get( - SCODOC_URL + "/ScoDoc/api/etudiants", - headers=HEADERS, verify=CHECK_CERTIFICATE - ) + 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 = ["civilite", "code_ine", "code_nip", "date_naissance", "email", "emailperso", "etudid", "nom", + "prenom", "nomprenom"] + + 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(): r = requests.get( - SCODOC_URL + "/ScoDoc/api/etudiants/courant", - headers=HEADERS, verify=CHECK_CERTIFICATE - ) + SCODOC_URL + "/ScoDoc/api/etudiants/courant", + headers=HEADERS, verify=CHECK_CERTIFICATE + ) assert r.status_code == 200 + assert len(r.json()) == 0 + # etudiant def test_etudiant(): r = requests.get( - SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1", - headers=HEADERS, verify=CHECK_CERTIFICATE - ) + SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1", + headers=HEADERS, verify=CHECK_CERTIFICATE + ) assert r.status_code == 200 + assert len(r.json()) == 10 # r = requests.get( # SCODOC_URL + "/ScoDoc/api/etudiant/nip/", @@ -60,10 +81,11 @@ def test_etudiant(): # etudiant_formsemestres def test_etudiant_formsemestres(): r = requests.get( - SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/formsemestres", - headers=HEADERS, verify=CHECK_CERTIFICATE - ) + SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/formsemestres", + headers=HEADERS, verify=CHECK_CERTIFICATE + ) assert r.status_code == 200 + assert len(r.json()) == 1 # r = requests.get( # SCODOC_URL + "/ScoDoc/api/etudiant/nip//formsemestres", @@ -79,12 +101,14 @@ def test_etudiant_formsemestres(): # etudiant_bulletin_semestre -def test_etudiant_bulletin_semestre(): - r = requests.get( - SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/formsemestre/1/bulletin", - headers=HEADERS, verify=CHECK_CERTIFICATE - ) - assert r.status_code == 200 +# def test_etudiant_bulletin_semestre(): +# r = requests.get( +# SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/formsemestre/1/bulletin", +# headers=HEADERS, verify=CHECK_CERTIFICATE +# ) +# assert r.status_code == 200 +# assert len(r.json()) == 1 + # r = requests.get( # SCODOC_URL + "/ScoDoc/api/etudiant/nip//formsemestre//bulletin", @@ -102,10 +126,12 @@ def test_etudiant_bulletin_semestre(): # etudiant_groups def test_etudiant_groups(): r = requests.get( - SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/semestre/1/groups", - headers=HEADERS, verify=CHECK_CERTIFICATE - ) + SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/semestre/1/groups", + headers=HEADERS, verify=CHECK_CERTIFICATE + ) assert r.status_code == 200 + assert len(r.json()) == 1 + # r = requests.get( # SCODOC_URL + "/ScoDoc/api/etudiant/nip//semestre//groups", @@ -117,4 +143,4 @@ def test_etudiant_groups(): # SCODOC_URL + "/ScoDoc/api/etudiant/ine//semestre//groups", # headers=HEADERS, verify=CHECK_CERTIFICATE # ) - # assert r.status_code == 200 \ No newline at end of file + # assert r.status_code == 200