forked from ScoDoc/DocScoDoc
Fix API: /group/<int:group_id>/etudiants/query
This commit is contained in:
parent
8fa64476b6
commit
ae2a56cad3
@ -136,20 +136,22 @@ def etud_in_group(group_id: int):
|
||||
def etud_in_group_query(group_id: int):
|
||||
"""Etudiants du groupe, filtrés par état"""
|
||||
etat = request.args.get("etat")
|
||||
if etat not in {scu.INSCRIT, scu.DEMISSION, scu.DEF}:
|
||||
if etat not in {None, scu.INSCRIT, scu.DEMISSION, scu.DEF}:
|
||||
return json_error(404, "etat: valeur invalide")
|
||||
query = GroupDescr.query.filter_by(id=group_id)
|
||||
if g.scodoc_dept:
|
||||
query = (
|
||||
query.join(Partition).join(FormSemestre).filter_by(dept_id=g.scodoc_dept_id)
|
||||
)
|
||||
group = query.first_or_404() # just tro ckeck that group exists in accessible dept
|
||||
query = (
|
||||
Identite.query.join(FormSemestreInscription)
|
||||
.filter_by(formsemestre_id=group.partition.formsemestre_id, etat=etat)
|
||||
.join(group_membership)
|
||||
.filter_by(group_id=group_id)
|
||||
group = query.first_or_404() # just to ckeck that group exists in accessible dept
|
||||
|
||||
query = Identite.query.join(FormSemestreInscription).filter_by(
|
||||
formsemestre_id=group.partition.formsemestre_id
|
||||
)
|
||||
if etat is not None:
|
||||
query = query.filter_by(etat=etat)
|
||||
|
||||
query = query.join(group_membership).filter_by(group_id=group_id)
|
||||
|
||||
return jsonify([etud.to_dict_short() for etud in query])
|
||||
|
||||
|
@ -134,10 +134,10 @@ def test_etud_in_group(api_headers):
|
||||
- /group/<int:group_id>/etudiants/query?etat=<string:etat>
|
||||
"""
|
||||
group_id = 1
|
||||
etudiants = GET(f"/group/{group_id}/etudiants", headers=api_headers)
|
||||
assert isinstance(etudiants, list)
|
||||
etuds = GET(f"/group/{group_id}/etudiants", headers=api_headers)
|
||||
assert isinstance(etuds, list)
|
||||
|
||||
for etud in etudiants:
|
||||
for etud in etuds:
|
||||
assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS)
|
||||
assert isinstance(etud["id"], int)
|
||||
assert isinstance(etud["dept_id"], int)
|
||||
@ -148,12 +148,14 @@ def test_etud_in_group(api_headers):
|
||||
assert isinstance(etud["code_nip"], str)
|
||||
assert isinstance(etud["code_ine"], str)
|
||||
|
||||
# query sans filtre:
|
||||
etuds_query = GET(f"/group/{group_id}/etudiants/query", headers=api_headers)
|
||||
assert etuds_query == etuds
|
||||
|
||||
etat = "I"
|
||||
etudiants = GET(
|
||||
f"/group/{group_id}/etudiants/query?etat={etat}", headers=api_headers
|
||||
)
|
||||
assert isinstance(etudiants, list)
|
||||
for etud in etudiants:
|
||||
etuds = GET(f"/group/{group_id}/etudiants/query?etat={etat}", headers=api_headers)
|
||||
assert isinstance(etuds, list)
|
||||
for etud in etuds:
|
||||
assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS)
|
||||
assert isinstance(etud["id"], int)
|
||||
assert isinstance(etud["dept_id"], int)
|
||||
|
Loading…
Reference in New Issue
Block a user