From 6aba3a3ccdd6fc959ff28863210608b8fcdef8fc Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Fri, 15 Apr 2022 15:57:44 +0200 Subject: [PATCH] =?UTF-8?q?doc=20de=20create=5Ftest=5Fapi=5Fdatabase=20am?= =?UTF-8?q?=C3=A9lior=C3=A9=20+=20ajout=20du=20code=20nip=20et=20ine=20lor?= =?UTF-8?q?s=20de=20la=20cr=C3=A9ation=20des=20etud=20+=20test=20dept=20et?= =?UTF-8?q?=20etu=20presque=20fini?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/etudiants.py | 34 +++++++++---- app/api/formsemestres.py | 1 - tests/api/test_api_departements.py | 12 ++--- tests/api/test_api_etudiants.py | 48 +++++++++++++------ tests/api/test_api_formsemestre_.py | 12 ++--- .../fakedatabase/create_test_api_database.py | 4 ++ 6 files changed, 73 insertions(+), 38 deletions(-) diff --git a/app/api/etudiants.py b/app/api/etudiants.py index f1d03003..34f10a12 100644 --- a/app/api/etudiants.py +++ b/app/api/etudiants.py @@ -123,19 +123,32 @@ def etudiant(etudid: int = None, nip: int = None, ine: int = None): "prenom": "JACQUES" } """ - etu = [] + # etu = [] - if etudid is not None: # Si route etudid - # Récupération de l'étudiant + if etudid is None: + if nip is None: # si ine + etu = models.Identite.query.filter_by(code_ine=str(ine)).first() + else: # si nip + etu = models.Identite.query.filter_by(code_nip=str(nip)).first() + + else: # si etudid etu = models.Identite.query.filter_by(id=etudid).first() - if nip is not None: # Si route nip - # Récupération de l'étudiant - etu = models.Identite.query.filter_by(code_nip=nip).first() - if ine is not None: # Si route ine - # Récupération de l'étudiant - etu = models.Identite.query.filter_by(code_ine=ine).first() + + # if etudid is not None: # Si route etudid + # # Récupération de l'étudiant + # etu = models.Identite.query.filter_by(id=etudid).first() + # + # if nip is not None: # Si route nip + # # Récupération de l'étudiant + # etu = models.Identite.query.filter_by(code_nip=str(nip)).first() + # + # breakpoint() + # + # if ine is not None: # Si route ine + # # Récupération de l'étudiant + # etu = models.Identite.query.filter_by(code_ine=str(ine)).first() # Mise en forme des données data = etu.to_dict_bul(include_urls=False) @@ -321,9 +334,10 @@ def etudiant_groups(formsemestre_id: int, etudid: int = None, nip: int = None, i # Récupération du formsemestre sem = models.FormSemestre.query.filter_by(id=formsemestre_id).first() + #breakpoint() try: # Utilisation de la fonction get_etud_groups - data = get_etud_groups(etudid, sem.to_dict()) + data = get_etud_groups(etudid, sem.id) except ValueError: return error_response(409, message="La requête ne peut être traitée en l’état actuel") diff --git a/app/api/formsemestres.py b/app/api/formsemestres.py index 2b98c6d1..deba20bb 100644 --- a/app/api/formsemestres.py +++ b/app/api/formsemestres.py @@ -4,7 +4,6 @@ from flask import jsonify from app import models from app.api import bp from app.api.errors import error_response -from app.decorators import permission_required from app.api.auth import token_auth, token_permission_required from app.scodoc.sco_bulletins import formsemestre_bulletinetud_dict from app.scodoc.sco_permissions import Permission diff --git a/tests/api/test_api_departements.py b/tests/api/test_api_departements.py index 7e68d3cc..ac4f3339 100644 --- a/tests/api/test_api_departements.py +++ b/tests/api/test_api_departements.py @@ -75,9 +75,9 @@ def test_referenciel_competences(): # # 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 +# 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 diff --git a/tests/api/test_api_etudiants.py b/tests/api/test_api_etudiants.py index 3a71bc48..5f2e0c3f 100644 --- a/tests/api/test_api_etudiants.py +++ b/tests/api/test_api_etudiants.py @@ -22,6 +22,7 @@ import requests from tests.api.setup_test_api import SCODOC_URL, CHECK_CERTIFICATE, HEADERS + # etudiants def test_etudiants(): r = requests.get( @@ -46,6 +47,20 @@ def test_etudiants(): "nom", "prenom", "nomprenom", + "lieu_naissance", + "dept_naissance", + "nationalite", + "boursier", + "id", + "domicile", + "villedomicile", + "telephone", + "fax", + "description", + "codepostaldomicile", + "paysdomicile", + "telephonemobile", + "typeadresse", ] fields_OK = True @@ -59,40 +74,43 @@ def test_etudiants(): # etudiants_courant -def test_etudiants_courant(): #XXX TODO pour Seb +def test_etudiants_courant(): # XXX TODO pour Seb r = requests.get( SCODOC_URL + "/ScoDoc/api/etudiants/courant", headers=HEADERS, verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 - assert len(r.json()) == 0 + assert len(r.json()) == 16 # etudiant -def test_etudiant(): #XXX TODO pour Seb +def test_etudiant(): # XXX TODO pour Seb r = requests.get( SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1", headers=HEADERS, verify=CHECK_CERTIFICATE, ) assert r.status_code == 200 - assert len(r.json()) == 10 + assert len(r.json()) == 24 - # r = requests.get( - # SCODOC_URL + "/ScoDoc/api/etudiant/nip/", - # headers=HEADERS, verify=CHECK_CERTIFICATE - # ) - # assert r.status_code == 200 - # r = requests.get( - # SCODOC_URL + "/ScoDoc/api/etudiant/ine/", - # headers=HEADERS, verify=CHECK_CERTIFICATE - # ) - # assert r.status_code == 200 + r = requests.get( + SCODOC_URL + "/ScoDoc/api/etudiant/nip/1", + headers=HEADERS, verify=CHECK_CERTIFICATE + ) + assert r.status_code == 200 + assert len(r.json()) == 24 + + r = requests.get( + SCODOC_URL + "/ScoDoc/api/etudiant/ine/1", + headers=HEADERS, verify=CHECK_CERTIFICATE + ) + assert r.status_code == 200 + assert len(r.json()) == 24 # etudiant_formsemestres -def test_etudiant_formsemestres(): #XXX TODO pour Seb +def test_etudiant_formsemestres(): # XXX TODO pour Seb r = requests.get( SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/formsemestres", headers=HEADERS, diff --git a/tests/api/test_api_formsemestre_.py b/tests/api/test_api_formsemestre_.py index 4a702f37..fc926d1f 100644 --- a/tests/api/test_api_formsemestre_.py +++ b/tests/api/test_api_formsemestre_.py @@ -24,7 +24,7 @@ from tests.api.setup_test_api import SCODOC_URL, CHECK_CERTIFICATE, HEADERS # formsemestre def test_formsemestre(): r = requests.get( - SCODOC_URL + "/ScoDoc/api/formations/formsemestre/", + SCODOC_URL + "/ScoDoc/api/formations/formsemestre/1", headers=HEADERS, verify=CHECK_CERTIFICATE, ) @@ -35,7 +35,7 @@ def test_formsemestre(): def test_etudiant_bulletin(): #XXX TODO pour Seb r = requests.get( SCODOC_URL - + "/ScoDoc/api/formsemestre//departements//etudiant/etudid//bulletin", + + "/ScoDoc/api/formsemestre/1/departements/TAPI/etudiant/etudid/1/bulletin", headers=HEADERS, verify=CHECK_CERTIFICATE, ) @@ -43,7 +43,7 @@ def test_etudiant_bulletin(): #XXX TODO pour Seb r = requests.get( SCODOC_URL - + "/ScoDoc/api/formsemestre//departements//etudiant/nip//bulletin", + + "/ScoDoc/api/formsemestre/1/departements/TAPI/etudiant/nip/1/bulletin", headers=HEADERS, verify=CHECK_CERTIFICATE, ) @@ -51,7 +51,7 @@ def test_etudiant_bulletin(): #XXX TODO pour Seb r = requests.get( SCODOC_URL - + "/ScoDoc/api/formsemestre//departements//etudiant/ine//bulletin", + + "/ScoDoc/api/formsemestre/1/departements/TAPI/etudiant/ine/1/bulletin", headers=HEADERS, verify=CHECK_CERTIFICATE, ) @@ -61,7 +61,7 @@ def test_etudiant_bulletin(): #XXX TODO pour Seb # bulletins def test_bulletins(): r = requests.get( - SCODOC_URL + "/ScoDoc/api/formsemestre//bulletins", + SCODOC_URL + "/ScoDoc/api/formsemestre/1/bulletins", headers=HEADERS, verify=CHECK_CERTIFICATE, ) @@ -71,7 +71,7 @@ def test_bulletins(): # jury def test_jury(): r = requests.get( - SCODOC_URL + "/ScoDoc/api/formsemestre//jury", + SCODOC_URL + "/ScoDoc/api/formsemestre/1/jury", headers=HEADERS, verify=CHECK_CERTIFICATE, ) diff --git a/tools/fakedatabase/create_test_api_database.py b/tools/fakedatabase/create_test_api_database.py index 19e70074..aba8cec7 100644 --- a/tools/fakedatabase/create_test_api_database.py +++ b/tools/fakedatabase/create_test_api_database.py @@ -86,6 +86,10 @@ def create_fake_etud(dept): etud = models.Identite(civilite=civilite, nom=nom, prenom=prenom, dept_id=dept.id) db.session.add(etud) db.session.commit() + etud.code_nip = etud.id + etud.code_ine = etud.id + db.session.add(etud) + db.session.commit() adresse = models.Adresse( etudid=etud.id, email=f"{etud.prenom}.{etud.nom}@example.com" )