API: test partitions. Fix #465.

This commit is contained in:
Emmanuel Viennet 2022-08-02 16:21:41 +02:00
parent 4a3ceb291a
commit 1b3bf87617
4 changed files with 39 additions and 11 deletions

View File

@ -205,9 +205,10 @@ def group_remove_etud(group_id: int, etudid: int):
query.join(Partition).join(FormSemestre).filter_by(dept_id=g.scodoc_dept_id) query.join(Partition).join(FormSemestre).filter_by(dept_id=g.scodoc_dept_id)
) )
group = query.first_or_404() group = query.first_or_404()
group.etuds.remove(etud) if etud in group.etuds:
db.session.commit() group.etuds.remove(etud)
sco_cache.invalidate_formsemestre(group.partition.formsemestre_id) db.session.commit()
sco_cache.invalidate_formsemestre(group.partition.formsemestre_id)
return jsonify({"group_id": group_id, "etudid": etudid}) return jsonify({"group_id": group_id, "etudid": etudid})

View File

@ -25,11 +25,13 @@ from app import models
from app.auth.models import User, Role, UserRole from app.auth.models import User, Role, UserRole
from app.scodoc.sco_logos import make_logo_local from app.scodoc.sco_logos import make_logo_local
from app.models import departements
from app.models import Formation, UniteEns, Matiere, Module from app.models import Formation, UniteEns, Matiere, Module
from app.models import FormSemestre, FormSemestreInscription from app.models import FormSemestre, FormSemestreInscription
from app.models import ModuleImpl, ModuleImplInscription from app.models import GroupDescr
from app.models import Identite from app.models import Identite
from app.models import departements from app.models import ModuleImpl, ModuleImplInscription
from app.models import Partition
from app.models.evaluations import Evaluation from app.models.evaluations import Evaluation
from app.entreprises.models import entreprises_reset_database from app.entreprises.models import entreprises_reset_database
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
@ -62,6 +64,7 @@ def make_shell_context():
"Formation": Formation, "Formation": Formation,
"FormSemestre": FormSemestre, "FormSemestre": FormSemestre,
"FormSemestreInscription": FormSemestreInscription, "FormSemestreInscription": FormSemestreInscription,
"GroupDescr": GroupDescr,
"Identite": Identite, "Identite": Identite,
"login_user": login_user, "login_user": login_user,
"logout_user": logout_user, "logout_user": logout_user,
@ -71,6 +74,7 @@ def make_shell_context():
"Module": Module, "Module": Module,
"ModuleImpl": ModuleImpl, "ModuleImpl": ModuleImpl,
"ModuleImplInscription": ModuleImplInscription, "ModuleImplInscription": ModuleImplInscription,
"Partition": Partition,
"ndb": ndb, "ndb": ndb,
"notes": notes, "notes": notes,
"np": np, "np": np,

View File

@ -50,7 +50,7 @@ def GET(path: str, headers={}, errmsg=None, dept=None):
url = SCODOC_URL + f"/ScoDoc/{dept}/api" + path url = SCODOC_URL + f"/ScoDoc/{dept}/api" + path
else: else:
url = API_URL + path url = API_URL + path
r = requests.get(url, headers=headers, verify=CHECK_CERTIFICATE) r = requests.get(url, headers=headers or CUR_HEADERS, verify=CHECK_CERTIFICATE)
if r.status_code != 200: if r.status_code != 200:
raise APIError(errmsg or f"""erreur status={r.status_code} !\n{r.text}""") raise APIError(errmsg or f"""erreur status={r.status_code} !\n{r.text}""")
return r.json() # decode la reponse JSON return r.json() # decode la reponse JSON

View File

@ -62,9 +62,11 @@ def test_formsemestre_partition(api_headers):
/partition/<int:partition_id>/group/create /partition/<int:partition_id>/group/create
/partition/<int:partition_id> /partition/<int:partition_id>
/partition/<int:partition_id/delete /partition/<int:partition_id/delete
/group/<int:group_id>/set_etudiant/<int:etudid>
""" """
headers = api_headers
formsemestre_id = 1 formsemestre_id = 1
partitions = GET(f"/formsemestre/{formsemestre_id}/partitions", headers=api_headers) partitions = GET(f"/formsemestre/{formsemestre_id}/partitions", headers=headers)
# au départ, pas de partitions # au départ, pas de partitions
assert partitions == {} assert partitions == {}
# --- Création partition # --- Création partition
@ -76,7 +78,7 @@ def test_formsemestre_partition(api_headers):
partition_r = POST_JSON( partition_r = POST_JSON(
f"/formsemestre/{formsemestre_id}/partition/create", f"/formsemestre/{formsemestre_id}/partition/create",
partition_d, partition_d,
headers=api_headers, headers=headers,
) )
assert isinstance(partition_r, dict) assert isinstance(partition_r, dict)
assert partition_r["partition_name"] == partition_d["partition_name"] assert partition_r["partition_name"] == partition_d["partition_name"]
@ -86,12 +88,12 @@ def test_formsemestre_partition(api_headers):
group_r = POST_JSON( group_r = POST_JSON(
f"/partition/{partition_r['id']}/group/create", f"/partition/{partition_r['id']}/group/create",
group_d, group_d,
headers=api_headers, headers=headers,
) )
assert isinstance(group_r, dict) assert isinstance(group_r, dict)
assert group_r["group_name"] == group_d["group_name"] assert group_r["group_name"] == group_d["group_name"]
# --- Liste groupes de la partition # --- Liste groupes de la partition
partition = GET(f"/partition/{partition_r['id']}", headers=api_headers) partition = GET(f"/partition/{partition_r['id']}", headers=headers)
assert isinstance(partition, dict) assert isinstance(partition, dict)
assert partition["id"] == partition_r["id"] assert partition["id"] == partition_r["id"]
assert isinstance(partition["groups"], dict) assert isinstance(partition["groups"], dict)
@ -99,8 +101,29 @@ def test_formsemestre_partition(api_headers):
group = partition["groups"][str(group_r["id"])] # nb: str car clés json en string group = partition["groups"][str(group_r["id"])] # nb: str car clés json en string
assert group["group_name"] == group_d["group_name"] assert group["group_name"] == group_d["group_name"]
# Place un étudiant dans le groupe
etud = GET(f"/formsemestre/{formsemestre_id}/etudiants", headers=headers)[0]
repl = POST_JSON(f"/group/{group['id']}/set_etudiant/{etud['id']}", headers=headers)
assert isinstance(repl, dict)
assert repl["group_id"] == group["id"]
assert repl["etudid"] == etud["id"]
#
etuds = GET(f"/group/{group['id']}/etudiants", headers=headers)
assert len(etuds) == 1
assert etuds[0]["id"] == etud["id"]
# Retire l'étudiant du groupe
repl = POST_JSON(
f"/group/{group['id']}/remove_etudiant/{etud['id']}", headers=headers
)
assert len(GET(f"/group/{group['id']}/etudiants", headers=headers)) == 0
# Le retire à nouveau ! (bug #465)
repl = POST_JSON(
f"/group/{group['id']}/remove_etudiant/{etud['id']}", headers=headers
)
assert repl["group_id"] == group["id"]
# Delete partition # Delete partition
repl = POST_JSON(f"/partition/{partition_r['id']}/delete", headers=api_headers) repl = POST_JSON(f"/partition/{partition_r['id']}/delete", headers=headers)
assert repl["OK"] is True assert repl["OK"] is True