exemple API

This commit is contained in:
Emmanuel Viennet 2022-08-10 15:21:47 +02:00
parent d072af8da5
commit 9940e6f01d

View File

@ -27,7 +27,6 @@ avec la config du client API:
``` ```
""" """
from email import message
from pprint import pprint as pp from pprint import pprint as pp
import urllib3 import urllib3
from setup_test_api import ( from setup_test_api import (
@ -62,30 +61,39 @@ print(f"{len(etuds)} étudiants courants")
raise Exception("arret en mode interactif") raise Exception("arret en mode interactif")
# ---------------- DIVERS ESSAIS EN MODE INTERACTIF
# ---------------- A ADAPTER A VOS BESOINS
# Bulletin d'un BUT # Bulletin d'un BUT
formsemestre_id = 1063 # A adapter formsemestre_id = 1063 # A adapter
etudid = 16450 etudid = 16450
bul = GET(f"/etudiant/etudid/{etudid}/formsemestre/{formsemestre_id}/bulletin") bul = GET(
f"/etudiant/etudid/{etudid}/formsemestre/{formsemestre_id}/bulletin",
headers=HEADERS,
)
# d'un DUT # d'un DUT
formsemestre_id = 1062 # A adapter formsemestre_id = 1062 # A adapter
etudid = 16309 etudid = 16309
bul_dut = GET(f"/etudiant/etudid/{etudid}/formsemestre/{formsemestre_id}/bulletin") bul_dut = GET(
f"/etudiant/etudid/{etudid}/formsemestre/{formsemestre_id}/bulletin",
headers=HEADERS,
)
# Infos sur un étudiant # Infos sur un étudiant
etudid = 3561 etudid = 3561
code_nip = "11303314" code_nip = "11303314"
etud = GET(f"/etudiant/etudid/{etudid}") etud = GET(f"/etudiant/etudid/{etudid}", headers=HEADERS)
print(etud) print(etud)
etud = GET(f"/etudiant/nip/{code_nip}") etud = GET(f"/etudiant/nip/{code_nip}", headers=HEADERS)
print(etud) print(etud)
sems = GET(f"/etudiant/etudid/{etudid}/formsemestres") sems = GET(f"/etudiant/etudid/{etudid}/formsemestres", headers=HEADERS)
print("\n".join([s["titre_num"] for s in sems])) print("\n".join([s["titre_num"] for s in sems]))
sems = GET(f"/etudiant/nip/{code_nip}/formsemestres") sems = GET(f"/etudiant/nip/{code_nip}/formsemestres", headers=HEADERS)
print("\n".join([s["titre_num"] for s in sems])) print("\n".join([s["titre_num"] for s in sems]))
# Evaluation # Evaluation
@ -93,35 +101,37 @@ evals = GET("/evaluations/1")
# Partitions d'un BUT # Partitions d'un BUT
formsemestre_id = 1063 # A adapter formsemestre_id = 1063 # A adapter
partitions = GET(f"/formsemestre/{formsemestre_id}/partitions") partitions = GET(f"/formsemestre/{formsemestre_id}/partitions", headers=HEADERS)
print(partitions) print(partitions)
pid = partitions[1]["id"] pid = partitions[1]["id"]
partition = GET(f"/partition/{pid}") partition = GET(f"/partition/{pid}", headers=HEADERS)
print(partition) print(partition)
group_id = partition["groups"][0]["id"] group_id = partition["groups"][0]["id"]
etuds = GET(f"/group/{group_id}/etudiants") etuds = GET(f"/group/{group_id}/etudiants", headers=HEADERS)
print(f"{len(etuds)} étudiants") print(f"{len(etuds)} étudiants")
pp(etuds[1]) pp(etuds[1])
etuds_dem = GET(f"/group/{group_id}/etudiants/query?etat=D") etuds_dem = GET(f"/group/{group_id}/etudiants/query?etat=D", headers=HEADERS)
print(f"{len(etuds_dem)} étudiants") print(f"{len(etuds_dem)} étudiants")
etudid = 16650 etudid = 16650
group_id = 5315 group_id = 5315
POST(f"/group/{group_id}/set_etudiant/{etudid}") POST(f"/group/{group_id}/set_etudiant/{etudid}", headers=HEADERS)
POST_JSON(f"/partition/{pid}/group/create", data={"group_name": "Omega10"}) POST_JSON(
partitions = GET(f"/formsemestre/{formsemestre_id}/partitions") f"/partition/{pid}/group/create", data={"group_name": "Omega10"}, headers=HEADERS
)
partitions = GET(f"/formsemestre/{formsemestre_id}/partitions", headers=HEADERS)
pp(partitions) pp(partitions)
POST_JSON(f"/group/5559/delete") POST_JSON(f"/group/5559/delete", headers=HEADERS)
POST_JSON(f"/group/5327/edit", data={"group_name": "TDXXX"}) POST_JSON(f"/group/5327/edit", data={"group_name": "TDXXX"}, headers=HEADERS)
# --------- XXX à passer en dans les tests unitaires # --------- XXX à passer en dans les tests unitaires
# 0- Prend un étudiant au hasard dans le semestre # 0- Prend un étudiant au hasard dans le semestre
etud = GET(f"/formsemestre/{formsemestre_id}/etudiants")[10] etud = GET(f"/formsemestre/{formsemestre_id}/etudiants", headers=HEADERS)[10]
etudid = etud["id"] etudid = etud["id"]
# 1- Crée une partition, puis la change de nom # 1- Crée une partition, puis la change de nom
@ -133,30 +143,43 @@ partition_id = js["id"]
POST_JSON( POST_JSON(
f"/partition/{partition_id}/edit", f"/partition/{partition_id}/edit",
data={"partition_name": "PART1", "show_in_lists": True}, data={"partition_name": "PART1", "show_in_lists": True},
headers=HEADERS,
) )
# 2- Crée un groupe # 2- Crée un groupe
js = POST_JSON(f"/partition/{partition_id}/group/create", data={"group_name": "G1"}) js = POST_JSON(
f"/partition/{partition_id}/group/create",
data={"group_name": "G1"},
headers=HEADERS,
)
group_1 = js["id"] group_1 = js["id"]
# 3- Crée deux autres groupes # 3- Crée deux autres groupes
js = POST_JSON(f"/partition/{partition_id}/group/create", data={"group_name": "G2"}) js = POST_JSON(
js = POST_JSON(f"/partition/{partition_id}/group/create", data={"group_name": "G3"}) f"/partition/{partition_id}/group/create",
data={"group_name": "G2"},
headers=HEADERS,
)
js = POST_JSON(
f"/partition/{partition_id}/group/create",
data={"group_name": "G3"},
headers=HEADERS,
)
# 4- Affecte étudiant au groupe G1 # 4- Affecte étudiant au groupe G1
POST_JSON(f"/group/{group_1}/set_etudiant/{etudid}") POST_JSON(f"/group/{group_1}/set_etudiant/{etudid}", headers=HEADERS)
# 5- retire du groupe # 5- retire du groupe
POST_JSON(f"/group/{group_1}/remove_etudiant/{etudid}") POST_JSON(f"/group/{group_1}/remove_etudiant/{etudid}", headers=HEADERS)
# 6- affecte au groupe G2 # 6- affecte au groupe G2
partition = GET(f"/partition/{partition_id}") partition = GET(f"/partition/{partition_id}")
assert len(partition["groups"]) == 3 assert len(partition["groups"]) == 3
group_2 = [g for g in partition["groups"].values() if g["group_name"] == "G2"][0]["id"] group_2 = [g for g in partition["groups"].values() if g["group_name"] == "G2"][0]["id"]
POST_JSON(f"/group/{group_2}/set_etudiant/{etudid}") POST_JSON(f"/group/{group_2}/set_etudiant/{etudid}", headers=HEADERS)
# 7- Membres du groupe # 7- Membres du groupe
etuds_g2 = GET(f"/group/{group_2}/etudiants") etuds_g2 = GET(f"/group/{group_2}/etudiants", headers=HEADERS)
assert len(etuds_g2) == 1 assert len(etuds_g2) == 1
assert etuds_g2[0]["id"] == etudid assert etuds_g2[0]["id"] == etudid
@ -166,9 +189,13 @@ group_3 = [g for g in partition["groups"].values() if g["group_name"] == "G3"][0
POST_JSON( POST_JSON(
f"/partition/{partition_id}/groups/order", f"/partition/{partition_id}/groups/order",
data=[group_2, group_1, group_3], data=[group_2, group_1, group_3],
headers=HEADERS,
) )
new_groups = [g["id"] for g in GET(f"/partition/{partition_id}")["groups"].values()] new_groups = [
g["id"]
for g in GET(f"/partition/{partition_id}", headers=HEADERS)["groups"].values()
]
assert new_groups == [group_2, group_1, group_3] assert new_groups == [group_2, group_1, group_3]
# 9- Suppression # 9- Suppression
@ -193,23 +220,25 @@ POST_JSON(f"/partition/{partition_id}/delete")
POST_JSON( POST_JSON(
"/partition/2264/groups/order", "/partition/2264/groups/order",
data=[5563, 5562, 5561, 5560, 5558, 5557, 5316, 5315], data=[5563, 5562, 5561, 5560, 5558, 5557, 5316, 5315],
headers=HEADERS,
) )
POST_JSON( POST_JSON(
"/formsemestre/1063/partitions/order", "/formsemestre/1063/partitions/order",
data=[2264, 2263, 2265, 2266, 2267, 2372, 2378], data=[2264, 2263, 2265, 2266, 2267, 2372, 2378],
headers=HEADERS,
) )
GET(f"/partition/2264") GET(f"/partition/2264", headers=HEADERS)
# Recherche de formsemestres # Recherche de formsemestres
sems = GET(f"/formsemestres/query?etape_apo=V1RT&annee_scolaire=2021") sems = GET(f"/formsemestres/query?etape_apo=V1RT&annee_scolaire=2021", headers=HEADERS)
# Table récap: # Table récap:
pp(GET(f"/formsemestre/1063/resultats")[0]) pp(GET(f"/formsemestre/1063/resultats", headers=HEADERS)[0])
pp(GET(f"/formsemestre/880/resultats")[0]) pp(GET(f"/formsemestre/880/resultats", headers=HEADERS)[0])
# # sems est une liste de semestres (dictionnaires) # # sems est une liste de semestres (dictionnaires)
# for sem in sems: # for sem in sems: