test et récupération de dept, formsemestre et etu en variable global pour les tests suivant

This commit is contained in:
leonard_montalbano 2022-03-01 16:00:41 +01:00
parent 1c271bbad4
commit 1cd7a84b15

View File

@ -70,7 +70,7 @@ from app.scodoc.sco_saisie_notes import notes_add
@bp.route("/departements", methods=["GET"]) @bp.route("/departements", methods=["GET"])
@token_auth.login_required #@token_auth.login_required
def departements(): def departements():
""" """
Retourne la liste des ids de départements Retourne la liste des ids de départements
@ -125,7 +125,7 @@ def liste_etudiants(dept: str, formsemestre_id=None): # XXX TODO A REVOIR
@bp.route("/departements/<string:dept>/semestres_courant", methods=["GET"]) @bp.route("/departements/<string:dept>/semestres_courant", methods=["GET"])
@token_auth.login_required # @token_auth.login_required
def liste_semestres_courant(dept: str): def liste_semestres_courant(dept: str):
""" """
Liste des semestres actifs d'un départements donné Liste des semestres actifs d'un départements donné
@ -142,7 +142,8 @@ def liste_semestres_courant(dept: str):
semestres = models.FormSemestre.query.filter_by(dept_id=id_dept, etat=True).all() semestres = models.FormSemestre.query.filter_by(dept_id=id_dept, etat=True).all()
# Mise en forme des données # Mise en forme des données
data = semestres[0].to_dict()
data = [d.to_dict() for d in semestres]
return jsonify(data) return jsonify(data)
@ -1184,11 +1185,205 @@ SCODOC_PASSWORD = ""
SCODOC_URL = "" SCODOC_URL = ""
CHECK_CERTIFICATE = bool(int(os.environ.get("CHECK_CERTIFICATE", False))) CHECK_CERTIFICATE = bool(int(os.environ.get("CHECK_CERTIFICATE", False)))
r0 = requests.post( # r0 = requests.post(
SCODOC_URL + "/ScoDoc/api/tokens", auth=(SCODOC_USER, SCODOC_PASSWORD) # SCODOC_URL + "/ScoDoc/api/tokens", auth=(SCODOC_USER, SCODOC_PASSWORD)
# )
# token = r0.json()["token"]
# HEADERS = {"Authorization": f"Bearer {token}"}
DEPT = None
FORMSEMESTRE = None
ETU = None
@bp.route("/test_dept", methods=["GET"])
def get_departement():
"""
Retourne un département pour les tests
"""
r = requests.get(
SCODOC_URL + "/ScoDoc/api/departements",
auth=(SCODOC_USER, SCODOC_PASSWORD)
) )
token = r0.json()["token"]
HEADERS = {"Authorization": f"Bearer {token}"} if r.status_code == 200:
dept_id = r.json()[0]
# print(dept_id)
dept = models.Departement.query.filter_by(id=dept_id).first()
dept = dept.to_dict()
if "id" in dept:
if "acronym" in dept:
if "description" in dept:
if "visible" in dept:
if "date_creation" in dept:
global DEPT
DEPT = dept
return error_response(200, "OK")
else:
return error_response(501, "date_creation field missing")
else:
return error_response(501, "visible field missing")
else:
return error_response(501, "description field missing")
else:
return error_response(501, "acronym field missing")
else:
return error_response(501, "id field missing")
return error_response(409, "La requête ne peut être traitée en létat actuel")
@bp.route("/test_formsemestre", methods=["GET"])
def get_formsemestre():
"""
Retourne un formsemestre pour les tests
"""
global DEPT
dept_acronym = DEPT["acronym"]
r = requests.get(
SCODOC_URL + "/ScoDoc/api/departements/" + dept_acronym + "/semestres_courant",
auth=(SCODOC_USER, SCODOC_PASSWORD)
)
if r.status_code == 200:
formsemestre = r.json()[0]
# print(r.json()[0])
if "titre" in formsemestre:
if "gestion_semestrielle" in formsemestre:
if "scodoc7_id" in formsemestre:
if "date_debut" in formsemestre:
if "bul_bgcolor" in formsemestre:
if "date_fin" in formsemestre:
if "resp_can_edit" in formsemestre:
if "semestre_id" in formsemestre:
if "bul_hide_xml" in formsemestre:
if "elt_annee_apo" in formsemestre:
if "block_moyennes" in formsemestre:
if "formsemestre_id" in formsemestre:
if "titre_num" in formsemestre:
if "date_debut_iso" in formsemestre:
if "date_fin_iso" in formsemestre:
if "responsables" in formsemestre:
global FORMSEMESTRE
FORMSEMESTRE = formsemestre
# print(FORMSEMESTRE)
return error_response(200, "OK")
else:
return error_response(501,
"responsables field "
"missing")
else:
return error_response(501,
"date_fin_iso field missing")
else:
return error_response(501,
"date_debut_iso field missing")
else:
return error_response(501,
"titre_num field missing")
else:
return error_response(501,
"formsemestre_id field missing")
else:
return error_response(501,
"block_moyennes field missing")
else:
return error_response(501,
"elt_annee_apo field missing")
else:
return error_response(501,
"bul_hide_xml field missing")
else:
return error_response(501,
"semestre_id field missing")
else:
return error_response(501,
"resp_can_edit field missing")
else:
return error_response(501,
"date_fin field missing")
else:
return error_response(501,
"bul_bgcolor field missing")
else:
return error_response(501,
"date_debut field missing")
else:
return error_response(501,
"scodoc7_id field missing")
else:
return error_response(501,
"gestion_semestrielle field missing")
else:
return error_response(501,
"titre field missing")
return error_response(409, "La requête ne peut être traitée en létat actuel")
@bp.route("/test_etu", methods=["GET"])
def get_etudiant():
"""
Retourne un étudiant pour les tests
"""
# print(DEPT.get_data().decode("utf-8"))
# dept = DEPT
r = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiants",
auth=(SCODOC_USER, SCODOC_PASSWORD)
)
if r.status_code == 200:
etu = r.json()[0]
if "civilite" in etu:
if "code_ine" in etu:
if "code_nip" in etu:
if "date_naissance" in etu:
if "email" in etu:
if "emailperso" in etu:
if "etudid" in etu:
if "nom" in etu:
if "prenom" in etu:
global ETU
ETU = etu
# print(ETU)
return error_response(200, "OK")
else:
return error_response(501, "prenom field missing")
else:
return error_response(501, "nom field missing")
else:
return error_response(501, "etudid field missing")
else:
return error_response(501, "emailperso field missing")
else:
return error_response(501, "email field missing")
else:
return error_response(501, "date_naissance field missing")
else:
return error_response(501, "code_nip field missing")
else:
return error_response(501, "code_ine field missing")
else:
return error_response(501, "civilite field missing")
return error_response(409, "La requête ne peut être traitée en létat actuel")
def test_routes_departements(): def test_routes_departements():
@ -1196,7 +1391,7 @@ def test_routes_departements():
Test les routes de la partie Département Test les routes de la partie Département
""" """
# departements # departements
r1 = requests.post( r1 = requests.get(
SCODOC_URL + "/ScoDoc/api/departements", SCODOC_URL + "/ScoDoc/api/departements",
auth=(SCODOC_USER, SCODOC_PASSWORD) auth=(SCODOC_USER, SCODOC_PASSWORD)
) )
@ -1230,31 +1425,37 @@ def test_routes_etudiants():
""" """
Test les routes de la partie Etudiants Test les routes de la partie Etudiants
""" """
r1 = requests.post( # etudiants
SCODOC_URL + "/ScoDoc/api", r1 = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiants",
auth=(SCODOC_USER, SCODOC_PASSWORD) auth=(SCODOC_USER, SCODOC_PASSWORD)
) )
# etudiants_courant
r2 = requests.post( r2 = requests.post(
SCODOC_URL + "/ScoDoc/api", SCODOC_URL + "/ScoDoc/api",
auth=(SCODOC_USER, SCODOC_PASSWORD) auth=(SCODOC_USER, SCODOC_PASSWORD)
) )
# etudiant
r3 = requests.post( r3 = requests.post(
SCODOC_URL + "/ScoDoc/api", SCODOC_URL + "/ScoDoc/api",
auth=(SCODOC_USER, SCODOC_PASSWORD) auth=(SCODOC_USER, SCODOC_PASSWORD)
) )
# etudiant_formsemestres
r4 = requests.post( r4 = requests.post(
SCODOC_URL + "/ScoDoc/api", SCODOC_URL + "/ScoDoc/api",
auth=(SCODOC_USER, SCODOC_PASSWORD) auth=(SCODOC_USER, SCODOC_PASSWORD)
) )
# etudiant_bulletin_semestre
r5 = requests.post( r5 = requests.post(
SCODOC_URL + "/ScoDoc/api", SCODOC_URL + "/ScoDoc/api",
auth=(SCODOC_USER, SCODOC_PASSWORD) auth=(SCODOC_USER, SCODOC_PASSWORD)
) )
# etudiant_groups
r6 = requests.post( r6 = requests.post(
SCODOC_URL + "/ScoDoc/api", SCODOC_URL + "/ScoDoc/api",
auth=(SCODOC_USER, SCODOC_PASSWORD) auth=(SCODOC_USER, SCODOC_PASSWORD)