From 4cb2db61bcd8c91ad8fa99ea169974e6f81fa9da Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 20 Jul 2022 16:12:20 +0200 Subject: [PATCH] WIP: API group/partition --- app/api/partitions.py | 8 ++++---- tests/api/exemple-api-basic.py | 29 +++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/api/partitions.py b/app/api/partitions.py index ccd6124ae..d783a7e49 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -94,7 +94,7 @@ def etud_in_group(group_id: int): @token_permission_required(Permission.APIView) def etud_in_group_query(group_id: int): """Etudiants du groupe, filtrés par état""" - etat = request.get("etat", "") + etat = request.args.get("etat") if etat not in {scu.INSCRIT, scu.DEMISSION, scu.DEF}: abort(404, "etat invalid") group = GroupDescr.query.get_or_404(group_id) @@ -123,11 +123,11 @@ def set_etud_group(etudid: int, group_id: int): .filter_by(etudid=etudid) ) ok = False - for group in groups: - if group.id == group_id: + for g in groups: + if g.id == group_id: ok = True else: - group.etuds.remove(etud) + g.etuds.remove(etud) if not ok: group.etuds.append(etud) db.session.commit() diff --git a/tests/api/exemple-api-basic.py b/tests/api/exemple-api-basic.py index 50b4a11f0..4a04abd28 100644 --- a/tests/api/exemple-api-basic.py +++ b/tests/api/exemple-api-basic.py @@ -53,16 +53,18 @@ def GET(path: str, headers={}, errmsg=None): """Get and returns as JSON""" r = requests.get(API_URL + "/" + path, headers=headers or HEADERS, verify=CHK_CERT) if r.status_code != 200: - raise ScoError(errmsg or "erreur !") + raise ScoError(errmsg or f"erreur status={r.status_code} !") return r.json() # decode la reponse JSON -def POST(s, path: str, data: dict, errmsg=None): +def POST(path: str, data: dict = {}, headers={}, errmsg=None): """Post""" - r = s.post(API_URL + "/" + path, data=data, verify=CHK_CERT) + r = requests.post( + API_URL + "/" + path, data=data, headers=headers or HEADERS, verify=CHK_CERT + ) if r.status_code != 200: raise ScoError(errmsg or "erreur !") - return r.text + return r.json() # decode la reponse JSON # --- Obtention du jeton (token) @@ -113,6 +115,25 @@ print("\n".join([s["titre_num"] for s in sems])) # Evaluation evals = GET("/evaluations/1") +# Partitions d'un BUT +formsemestre_id = 1063 # A adapter +partitions = GET(f"/formsemestre/{formsemestre_id}/partitions") +print(partitions) +pid = partitions[1]["id"] +partition = GET(f"/partition/{pid}") +print(partition) +group_id = partition["groups"][0]["id"] +etuds = GET(f"/group/{group_id}/etudiants") +print(f"{len(etuds)} étudiants") +pp(etuds[1]) + +etuds_dem = GET(f"/group/{group_id}/etudiants/query?etat=D") +print(f"{len(etuds_dem)} étudiants") + +etudid = 16650 +group_id = 5315 +POST(f"/group/{group_id}/set_etudiant/{etudid}") + # # --- Recupere la liste de tous les semestres: # sems = GET(s, "Notes/formsemestre_list?format=json", "Aucun semestre !")