1
0
forked from ScoDoc/ScoDoc

API: Fix accès par INE et NIP alphanumériques

This commit is contained in:
Emmanuel Viennet 2022-05-07 08:23:30 +02:00
parent bba7906493
commit 34d64b3fd8
5 changed files with 88 additions and 50 deletions

View File

@ -14,8 +14,8 @@ from app.scodoc.sco_permissions import Permission
@bp.route("/absences/etudid/<int:etudid>", methods=["GET"]) @bp.route("/absences/etudid/<int:etudid>", methods=["GET"])
@bp.route("/absences/nip/<int:nip>", methods=["GET"]) @bp.route("/absences/nip/<string:nip>", methods=["GET"])
@bp.route("/absences/ine/<int:ine>", methods=["GET"]) @bp.route("/absences/ine/<string:ine>", methods=["GET"])
@token_auth.login_required @token_auth.login_required
@token_permission_required(Permission.APIView) @token_permission_required(Permission.APIView)
def absences(etudid: int = None, nip: int = None, ine: int = None): def absences(etudid: int = None, nip: int = None, ine: int = None):

View File

@ -55,8 +55,8 @@ def etudiants_courant(long=False):
@bp.route("/etudiant/etudid/<int:etudid>", methods=["GET"]) @bp.route("/etudiant/etudid/<int:etudid>", methods=["GET"])
@bp.route("/etudiant/nip/<int:nip>", methods=["GET"]) @bp.route("/etudiant/nip/<string:nip>", methods=["GET"])
@bp.route("/etudiant/ine/<int:ine>", methods=["GET"]) @bp.route("/etudiant/ine/<string:ine>", methods=["GET"])
@token_auth.login_required @token_auth.login_required
@token_permission_required(Permission.APIView) @token_permission_required(Permission.APIView)
def etudiant(etudid: int = None, nip: int = None, ine: int = None): def etudiant(etudid: int = None, nip: int = None, ine: int = None):
@ -109,8 +109,8 @@ def etudiant(etudid: int = None, nip: int = None, ine: int = None):
@bp.route("/etudiant/etudid/<int:etudid>/formsemestres") @bp.route("/etudiant/etudid/<int:etudid>/formsemestres")
@bp.route("/etudiant/nip/<int:nip>/formsemestres") @bp.route("/etudiant/nip/<string:nip>/formsemestres")
@bp.route("/etudiant/ine/<int:ine>/formsemestres") @bp.route("/etudiant/ine/<string:ine>/formsemestres")
@token_auth.login_required @token_auth.login_required
@token_permission_required(Permission.APIView) @token_permission_required(Permission.APIView)
def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None): def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None):
@ -175,12 +175,12 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None)
defaults={"version": "long"}, defaults={"version": "long"},
) )
@bp.route( @bp.route(
"/etudiant/nip/<int:nip>/formsemestre/<int:formsemestre_id>/bulletin", "/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin",
methods=["GET"], methods=["GET"],
defaults={"version": "long"}, defaults={"version": "long"},
) )
@bp.route( @bp.route(
"/etudiant/ine/<int:ine>/formsemestre/<int:formsemestre_id>/bulletin", "/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin",
methods=["GET"], methods=["GET"],
defaults={"version": "long"}, defaults={"version": "long"},
) )
@ -190,12 +190,12 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None)
defaults={"version": "short"}, defaults={"version": "short"},
) )
@bp.route( @bp.route(
"/etudiant/nip/<int:nip>/formsemestre/<int:formsemestre_id>/bulletin/short", "/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin/short",
methods=["GET"], methods=["GET"],
defaults={"version": "short"}, defaults={"version": "short"},
) )
@bp.route( @bp.route(
"/etudiant/ine/<int:ine>/formsemestre/<int:formsemestre_id>/bulletin/short", "/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin/short",
methods=["GET"], methods=["GET"],
defaults={"version": "short"}, defaults={"version": "short"},
) )
@ -408,10 +408,12 @@ def etudiant_bulletin_semestre(
methods=["GET"], methods=["GET"],
) )
@bp.route( @bp.route(
"/etudiant/nip/<int:nip>/formsemestre/<int:formsemestre_id>/groups", methods=["GET"] "/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/groups",
methods=["GET"],
) )
@bp.route( @bp.route(
"/etudiant/ine/<int:ine>/formsemestre/<int:formsemestre_id>/groups", methods=["GET"] "/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/groups",
methods=["GET"],
) )
@token_auth.login_required @token_auth.login_required
@token_permission_required(Permission.APIView) @token_permission_required(Permission.APIView)

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Test Logos """Test API: accès aux étudiants
Utilisation : Utilisation :
créer les variables d'environnement: (indiquer les valeurs créer les variables d'environnement: (indiquer les valeurs
@ -58,7 +58,7 @@ def test_etudiants_courant(api_headers):
def test_etudiant(api_headers): def test_etudiant(api_headers):
""" """
Route: Routes: /etudiant/etudid, /etudiant/nip, /etudiant/ine
""" """
######### Test etudid ######### ######### Test etudid #########
@ -87,7 +87,7 @@ def test_etudiant(api_headers):
######### Test code ine ######### ######### Test code ine #########
r = requests.get( r = requests.get(
API_URL + "/etudiant/ine/1", API_URL + "/etudiant/ine/INE1",
headers=api_headers, headers=api_headers,
verify=CHECK_CERTIFICATE, verify=CHECK_CERTIFICATE,
) )
@ -97,6 +97,39 @@ def test_etudiant(api_headers):
fields_ok = verify_fields(etud, ETUD_FIELDS) fields_ok = verify_fields(etud, ETUD_FIELDS)
assert fields_ok is True assert fields_ok is True
# Vérifie le requetage des 3 1er étudiants
for etudid in (1, 2, 3):
r = requests.get(
f"{API_URL }/etudiant/etudid/{etudid}",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
etud = r.json()
nip = etud["code_nip"]
ine = etud["code_ine"]
assert isinstance(etud["id"], int)
assert isinstance(nip, str)
assert isinstance(ine, str)
r = requests.get(
f"{API_URL }/etudiant/nip/{nip}",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
etud_nip = r.json()
# On doit avoir obtenue le même étudiant
assert etud_nip == etud
r = requests.get(
f"{API_URL }/etudiant/ine/{ine}",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
etud_ine = r.json()
# On doit avoir obtenue le même étudiant
assert etud_ine == etud
def test_etudiant_formsemestres(api_headers): def test_etudiant_formsemestres(api_headers):
""" """
@ -132,7 +165,7 @@ def test_etudiant_formsemestres(api_headers):
######### Test code ine ######### ######### Test code ine #########
r = requests.get( r = requests.get(
API_URL + "/etudiant/ine/1/formsemestres", API_URL + "/etudiant/ine/INE1/formsemestres",
headers=api_headers, headers=api_headers,
verify=CHECK_CERTIFICATE, verify=CHECK_CERTIFICATE,
) )
@ -172,7 +205,7 @@ def test_etudiant_bulletin_semestre(api_headers):
######### Test code ine ######### ######### Test code ine #########
r = requests.get( r = requests.get(
API_URL + "/etudiant/ine/1/formsemestre/1/bulletin", API_URL + "/etudiant/ine/INE1/formsemestre/1/bulletin",
headers=api_headers, headers=api_headers,
verify=CHECK_CERTIFICATE, verify=CHECK_CERTIFICATE,
) )
@ -235,7 +268,7 @@ def test_etudiant_groups(api_headers):
######### Test code ine ######### ######### Test code ine #########
r = requests.get( r = requests.get(
API_URL + "/etudiant/ine/1/formsemestre/1/groups", API_URL + "/etudiant/ine/INE1/formsemestre/1/groups",
headers=api_headers, headers=api_headers,
verify=CHECK_CERTIFICATE, verify=CHECK_CERTIFICATE,
) )

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Test Logos """Test API Jurys XXX TODO A ECRIRE
Utilisation : Utilisation :
créer les variables d'environnement: (indiquer les valeurs créer les variables d'environnement: (indiquer les valeurs
@ -77,30 +77,30 @@ def test_set_decision_jury(api_headers):
assert r.status_code == 200 assert r.status_code == 200
def test_annule_decision_jury(api_headers): # def test_annule_decision_jury(api_headers):
""" # """
Route: # Route:
""" # """
r = requests.get( # r = requests.get(
SCODOC_URL # SCODOC_URL
+ "/ScoDoc/api/jury/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/annule_decision", # + "/ScoDoc/api/jury/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/annule_decision",
headers=api_headers, # headers=api_headers,
verify=CHECK_CERTIFICATE, # verify=CHECK_CERTIFICATE,
) # )
assert r.status_code == 200 # assert r.status_code == 200
r = requests.get( # r = requests.get(
SCODOC_URL # SCODOC_URL
+ "/ScoDoc/api/jury/nip/<int:nip>/formsemestre/<int:formsemestre_id>/annule_decision", # + "/ScoDoc/api/jury/nip/<int:nip>/formsemestre/<int:formsemestre_id>/annule_decision",
headers=api_headers, # headers=api_headers,
verify=CHECK_CERTIFICATE, # verify=CHECK_CERTIFICATE,
) # )
assert r.status_code == 200 # assert r.status_code == 200
r = requests.get( # r = requests.get(
SCODOC_URL # SCODOC_URL
+ "/ScoDoc/api/jury/ine/<int:ine>/formsemestre/<int:formsemestre_id>/annule_decision", # + "/ScoDoc/api/jury/ine/<int:ine>/formsemestre/<int:formsemestre_id>/annule_decision",
headers=api_headers, # headers=api_headers,
verify=CHECK_CERTIFICATE, # verify=CHECK_CERTIFICATE,
) # )
assert r.status_code == 200 # assert r.status_code == 200

View File

@ -28,7 +28,7 @@ import sys
from app.auth.models import Role, User from app.auth.models import Role, User
from app import models from app import models
from app.models import Departement, Formation, FormSemestre from app.models import Departement, Formation, FormSemestre, Identite
from app import db from app import db
from app.scodoc import ( from app.scodoc import (
sco_cache, sco_cache,
@ -95,15 +95,18 @@ def create_users(dept: Departement) -> tuple:
return user, other return user, other
def create_fake_etud(dept: Departement) -> models.Identite: def create_fake_etud(dept: Departement) -> Identite:
"""Créé un faux étudiant et l'insère dans la base""" """Créé un faux étudiant et l'insère dans la base."""
civilite = random.choice(("M", "F", "X")) civilite = random.choice(("M", "F", "X"))
nom, prenom = nomprenom(civilite) nom, prenom = nomprenom(civilite)
etud = models.Identite(civilite=civilite, nom=nom, prenom=prenom, dept_id=dept.id) etud: Identite = Identite(
civilite=civilite, nom=nom, prenom=prenom, dept_id=dept.id
)
db.session.add(etud) db.session.add(etud)
db.session.commit() db.session.commit()
etud.code_nip = etud.id # créé un étudiant sur deux avec un NIP et INE alphanumérique
etud.code_ine = etud.id etud.code_nip = f"{etud.id}" if (etud.id % 2) else f"NIP{etud.id}"
etud.code_ine = f"INE{etud.id}" if (etud.id % 2) else f"{etud.id}"
db.session.add(etud) db.session.add(etud)
db.session.commit() db.session.commit()
adresse = models.Adresse( adresse = models.Adresse(