amélioration des asserts de departement et etudiant

This commit is contained in:
leonard_montalbano 2022-03-11 16:18:50 +01:00
parent 8e36201482
commit a43f1e0e22
4 changed files with 57 additions and 76 deletions

View File

@ -16,8 +16,8 @@ from app.scodoc.sco_saisie_notes import notes_add
@bp.route("/departements", methods=["GET"]) @bp.route("/departements", methods=["GET"])
# @token_auth.login_required # Commenté le temps des tests @token_auth.login_required # Commenté le temps des tests
# @permission_required(Permission.APIView) # @permission_required(Permission.ScoView)
def departements(): def departements():
""" """
Retourne la liste des ids de départements visibles Retourne la liste des ids de départements visibles
@ -35,7 +35,7 @@ def departements():
@bp.route("/departements/<string:dept>/etudiants/liste", methods=["GET"]) @bp.route("/departements/<string:dept>/etudiants/liste", methods=["GET"])
@bp.route("/departements/<string:dept>/etudiants/liste/<int:formsemestre_id>", methods=["GET"]) @bp.route("/departements/<string:dept>/etudiants/liste/<int:formsemestre_id>", methods=["GET"])
# @token_auth.login_required @token_auth.login_required
# @permission_required(Permission.APIView) # @permission_required(Permission.APIView)
def liste_etudiants(dept: str, formsemestre_id=None): def liste_etudiants(dept: str, formsemestre_id=None):
""" """
@ -94,51 +94,6 @@ def liste_etudiants(dept: str, formsemestre_id=None):
return jsonify(list_etu) 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/<string:dept>/semestres_courants", methods=["GET"]) @bp.route("/departements/<string:dept>/semestres_courants", methods=["GET"])
# @token_auth.login_required # Commenté le temps des tests # @token_auth.login_required # Commenté le temps des tests
# @permission_required(Permission.APIView) # @permission_required(Permission.APIView)

View File

@ -43,8 +43,6 @@ def get_departement():
get_token() get_token()
print("ééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé")
global HEADERS global HEADERS
global CHECK_CERTIFICATE global CHECK_CERTIFICATE
global SCODOC_USER global SCODOC_USER
@ -57,8 +55,6 @@ def get_departement():
headers=HEADERS, verify=CHECK_CERTIFICATE, headers=HEADERS, verify=CHECK_CERTIFICATE,
) )
print("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii")
if r.status_code == 200: if r.status_code == 200:
dept_id = r.json()[0] dept_id = r.json()[0]
# print(dept_id) # print(dept_id)

View File

@ -28,30 +28,34 @@ def test_departements():
headers=HEADERS, verify=CHECK_CERTIFICATE headers=HEADERS, verify=CHECK_CERTIFICATE
) )
assert r.status_code == 200 assert r.status_code == 200
assert len(r.json()) == 1
# liste_etudiants # liste_etudiants
def test_etudiants(): def test_liste_etudiants():
r = requests.get( r = requests.get(
SCODOC_URL + "/ScoDoc/api/departements/TAPI/etudiants/liste", SCODOC_URL + "/ScoDoc/api/departements/TAPI/etudiants/liste",
headers=HEADERS, verify=CHECK_CERTIFICATE headers=HEADERS, verify=CHECK_CERTIFICATE
) )
assert r.status_code == 200 assert r.status_code == 200
assert len(r.json()) == 16
r = requests.get( r = requests.get(
SCODOC_URL + "/ScoDoc/api/departements/TAPI/etudiants/liste/1", SCODOC_URL + "/ScoDoc/api/departements/TAPI/etudiants/liste/1",
headers=HEADERS, verify=CHECK_CERTIFICATE headers=HEADERS, verify=CHECK_CERTIFICATE
) )
assert r.status_code == 200 assert r.status_code == 200
assert len(r.json()) == 16
# liste_semestres_courant # liste_semestres_courant
def test_semestres_courant(): def test_semestres_courant():
r = requests.get( 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 headers=HEADERS, verify=CHECK_CERTIFICATE
) )
assert r.status_code == 200 assert r.status_code == 200
assert len(r.json()) == 1
# referenciel_competences # referenciel_competences

View File

@ -16,6 +16,7 @@ Utilisation :
Lancer : Lancer :
pytest tests/api/test_api_etudiants.py pytest tests/api/test_api_etudiants.py
""" """
from random import randint
import requests import requests
from tests.api.setup_test_api import SCODOC_URL, HEADERS, CHECK_CERTIFICATE from tests.api.setup_test_api import SCODOC_URL, HEADERS, CHECK_CERTIFICATE
@ -28,6 +29,23 @@ def test_etudiants():
headers=HEADERS, verify=CHECK_CERTIFICATE headers=HEADERS, verify=CHECK_CERTIFICATE
) )
assert r.status_code == 200 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 # etudiants_courant
def test_etudiants_courant(): def test_etudiants_courant():
@ -36,6 +54,8 @@ def test_etudiants_courant():
headers=HEADERS, verify=CHECK_CERTIFICATE headers=HEADERS, verify=CHECK_CERTIFICATE
) )
assert r.status_code == 200 assert r.status_code == 200
assert len(r.json()) == 0
# etudiant # etudiant
def test_etudiant(): def test_etudiant():
@ -44,6 +64,7 @@ def test_etudiant():
headers=HEADERS, verify=CHECK_CERTIFICATE headers=HEADERS, verify=CHECK_CERTIFICATE
) )
assert r.status_code == 200 assert r.status_code == 200
assert len(r.json()) == 10
# r = requests.get( # r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>", # SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>",
@ -64,6 +85,7 @@ def test_etudiant_formsemestres():
headers=HEADERS, verify=CHECK_CERTIFICATE headers=HEADERS, verify=CHECK_CERTIFICATE
) )
assert r.status_code == 200 assert r.status_code == 200
assert len(r.json()) == 1
# r = requests.get( # r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>/formsemestres", # SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>/formsemestres",
@ -79,12 +101,14 @@ def test_etudiant_formsemestres():
# etudiant_bulletin_semestre # etudiant_bulletin_semestre
def test_etudiant_bulletin_semestre(): # def test_etudiant_bulletin_semestre():
r = requests.get( # r = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/formsemestre/1/bulletin", # SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/formsemestre/1/bulletin",
headers=HEADERS, verify=CHECK_CERTIFICATE # headers=HEADERS, verify=CHECK_CERTIFICATE
) # )
assert r.status_code == 200 # assert r.status_code == 200
# assert len(r.json()) == 1
# r = requests.get( # r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>/formsemestre/<int:formsemestre_id>/bulletin", # SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>/formsemestre/<int:formsemestre_id>/bulletin",
@ -106,6 +130,8 @@ def test_etudiant_groups():
headers=HEADERS, verify=CHECK_CERTIFICATE headers=HEADERS, verify=CHECK_CERTIFICATE
) )
assert r.status_code == 200 assert r.status_code == 200
assert len(r.json()) == 1
# r = requests.get( # r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>/semestre/<int:formsemestre_id>/groups", # SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>/semestre/<int:formsemestre_id>/groups",