forked from ScoDoc/ScoDoc
Update opolka/ScoDoc from ScoDoc/ScoDoc #2
@ -442,14 +442,14 @@ def assiduite_create(etudid: int = None, nip=None, ine=None):
|
||||
if not isinstance(create_list, list):
|
||||
return json_error(404, "Le contenu envoyé n'est pas une liste")
|
||||
|
||||
errors: dict[int, str] = {}
|
||||
success: dict[int, object] = {}
|
||||
errors: list = []
|
||||
success: list = []
|
||||
for i, data in enumerate(create_list):
|
||||
code, obj = _create_singular(data, etud)
|
||||
if code == 404:
|
||||
errors[i] = obj
|
||||
errors.append({"indice": i, "message": obj})
|
||||
else:
|
||||
success[i] = obj
|
||||
success.append({"indice": i, "message": obj})
|
||||
scass.simple_invalidate_cache(data, etud.id)
|
||||
|
||||
db.session.commit()
|
||||
@ -493,19 +493,19 @@ def assiduites_create():
|
||||
if not isinstance(create_list, list):
|
||||
return json_error(404, "Le contenu envoyé n'est pas une liste")
|
||||
|
||||
errors: dict[int, str] = {}
|
||||
success: dict[int, object] = {}
|
||||
errors: list = []
|
||||
success: list = []
|
||||
for i, data in enumerate(create_list):
|
||||
etud: Identite = Identite.query.filter_by(id=data["etudid"]).first()
|
||||
if etud is None:
|
||||
errors[i] = "Cet étudiant n'existe pas."
|
||||
errors.append({"indice": i, "message": "Cet étudiant n'existe pas."})
|
||||
continue
|
||||
|
||||
code, obj = _create_singular(data, etud)
|
||||
if code == 404:
|
||||
errors[i] = obj
|
||||
errors.append({"indice": i, "message": obj})
|
||||
else:
|
||||
success[i] = obj
|
||||
success.append({"indice": i, "message": obj})
|
||||
scass.simple_invalidate_cache(data)
|
||||
|
||||
return {"errors": errors, "success": success}
|
||||
@ -607,14 +607,14 @@ def assiduite_delete():
|
||||
if not isinstance(assiduites_list, list):
|
||||
return json_error(404, "Le contenu envoyé n'est pas une liste")
|
||||
|
||||
output = {"errors": {}, "success": {}}
|
||||
output = {"errors": [], "success": []}
|
||||
|
||||
for i, ass in enumerate(assiduites_list):
|
||||
code, msg = _delete_singular(ass, db)
|
||||
if code == 404:
|
||||
output["errors"][f"{i}"] = msg
|
||||
output["errors"].append({"indice": i, "message": msg})
|
||||
else:
|
||||
output["success"][f"{i}"] = {"OK": True}
|
||||
output["success"].append({"indice": i, "message": "OK"})
|
||||
|
||||
db.session.commit()
|
||||
return output
|
||||
@ -743,19 +743,28 @@ def assiduites_edit():
|
||||
if not isinstance(edit_list, list):
|
||||
return json_error(404, "Le contenu envoyé n'est pas une liste")
|
||||
|
||||
errors: dict[int, str] = {}
|
||||
success: dict[int, object] = {}
|
||||
errors: list[dict] = []
|
||||
success: list[dict] = []
|
||||
for i, data in enumerate(edit_list):
|
||||
assi: Identite = Assiduite.query.filter_by(id=data["assiduite_id"]).first()
|
||||
if assi is None:
|
||||
errors[i] = f"assiduité {data['assiduite_id']} n'existe pas."
|
||||
errors.append(
|
||||
{
|
||||
"indice": i,
|
||||
"message": f"assiduité {data['assiduite_id']} n'existe pas.",
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
code, obj = _edit_singular(assi, data)
|
||||
obj_retour = {
|
||||
"indice": i,
|
||||
"message": obj,
|
||||
}
|
||||
if code == 404:
|
||||
errors[i] = obj
|
||||
errors.append(obj_retour)
|
||||
else:
|
||||
success[i] = obj
|
||||
success.append(obj_retour)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
@ -187,14 +187,14 @@ def justif_create(etudid: int = None, nip = None, ine = None):
|
||||
if not isinstance(create_list, list):
|
||||
return json_error(404, "Le contenu envoyé n'est pas une liste")
|
||||
|
||||
errors: dict[int, str] = {}
|
||||
success: dict[int, object] = {}
|
||||
errors: list = []
|
||||
success: list = []
|
||||
for i, data in enumerate(create_list):
|
||||
code, obj = _create_singular(data, etud)
|
||||
if code == 404:
|
||||
errors[i] = obj
|
||||
errors.append({"indice": i, "message": obj})
|
||||
else:
|
||||
success[i] = obj
|
||||
success.append({"indice": i, "message": obj})
|
||||
scass.simple_invalidate_cache(data, etud.id)
|
||||
compute_assiduites_justified(Justificatif.query.filter_by(etudid=etudid), True)
|
||||
return {"errors": errors, "success": success}
|
||||
@ -383,14 +383,14 @@ def justif_delete():
|
||||
if not isinstance(justificatifs_list, list):
|
||||
return json_error(404, "Le contenu envoyé n'est pas une liste")
|
||||
|
||||
output = {"errors": {}, "success": {}}
|
||||
output = {"errors": [], "success": []}
|
||||
|
||||
for i, ass in enumerate(justificatifs_list):
|
||||
code, msg = _delete_singular(ass, db)
|
||||
if code == 404:
|
||||
output["errors"][f"{i}"] = msg
|
||||
output["errors"].append({"indice": i, "message": msg})
|
||||
else:
|
||||
output["success"][f"{i}"] = {"OK": True}
|
||||
output["success"].append({"indice": i, "message": "OK"})
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
@ -35,7 +35,7 @@ ASSIDUITES_FIELDS = {
|
||||
}
|
||||
|
||||
CREATE_FIELD = {"assiduite_id": int}
|
||||
BATCH_FIELD = {"errors": dict, "success": dict}
|
||||
BATCH_FIELD = {"errors": list, "success": list}
|
||||
|
||||
COUNT_FIELDS = {"compte": int, "journee": int, "demi": int, "heure": float}
|
||||
|
||||
@ -262,14 +262,14 @@ def test_route_create(api_admin_headers):
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["success"]) == 1
|
||||
|
||||
TO_REMOVE.append(res["success"]["0"]["assiduite_id"])
|
||||
TO_REMOVE.append(res["success"][0]["message"]["assiduite_id"])
|
||||
|
||||
data2 = create_data("absent", "02", MODULE, "desc")
|
||||
res = POST_JSON(f"/assiduite/{ETUDID}/create", [data2], api_admin_headers)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["success"]) == 1
|
||||
|
||||
TO_REMOVE.append(res["success"]["0"]["assiduite_id"])
|
||||
TO_REMOVE.append(res["success"][0]["message"]["assiduite_id"])
|
||||
|
||||
# Mauvais fonctionnement
|
||||
check_failure_post(f"/assiduite/{FAUX}/create", api_admin_headers, [data])
|
||||
@ -278,7 +278,7 @@ def test_route_create(api_admin_headers):
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["errors"]) == 1
|
||||
assert (
|
||||
res["errors"]["0"]
|
||||
res["errors"][0]["message"]
|
||||
== "Duplication des assiduités (la période rentrée rentre en conflit avec une assiduité enregistrée)"
|
||||
)
|
||||
|
||||
@ -289,7 +289,7 @@ def test_route_create(api_admin_headers):
|
||||
)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["errors"]) == 1
|
||||
assert res["errors"]["0"] == "param 'moduleimpl_id': invalide"
|
||||
assert res["errors"][0]["message"] == "param 'moduleimpl_id': invalide"
|
||||
|
||||
# -== Multiple ==-
|
||||
|
||||
@ -304,8 +304,8 @@ def test_route_create(api_admin_headers):
|
||||
res = POST_JSON(f"/assiduite/{ETUDID}/create", data, api_admin_headers)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
for dat in res["success"]:
|
||||
check_fields(res["success"][dat], CREATE_FIELD)
|
||||
TO_REMOVE.append(res["success"][dat]["assiduite_id"])
|
||||
check_fields(dat["message"], CREATE_FIELD)
|
||||
TO_REMOVE.append(dat["message"]["assiduite_id"])
|
||||
|
||||
# Mauvais Fonctionnement
|
||||
|
||||
@ -321,13 +321,13 @@ def test_route_create(api_admin_headers):
|
||||
assert len(res["errors"]) == 4
|
||||
|
||||
assert (
|
||||
res["errors"]["0"]
|
||||
res["errors"][0]["message"]
|
||||
== "Duplication des assiduités (la période rentrée rentre en conflit avec une assiduité enregistrée)"
|
||||
)
|
||||
assert res["errors"]["1"] == "param 'moduleimpl_id': invalide"
|
||||
assert res["errors"]["2"] == "param 'etat': invalide"
|
||||
assert res["errors"][1]["message"] == "param 'moduleimpl_id': invalide"
|
||||
assert res["errors"][2]["message"] == "param 'etat': invalide"
|
||||
assert (
|
||||
res["errors"]["3"]
|
||||
res["errors"][3]["message"]
|
||||
== "param 'date_debut': format invalide, param 'date_fin': format invalide"
|
||||
)
|
||||
|
||||
@ -367,7 +367,7 @@ def test_route_delete(api_admin_headers):
|
||||
res = POST_JSON("/assiduite/delete", [data], api_admin_headers)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
for dat in res["success"]:
|
||||
assert res["success"][dat] == {"OK": True}
|
||||
assert dat["message"] == "OK"
|
||||
|
||||
# Mauvais fonctionnement
|
||||
res = POST_JSON("/assiduite/delete", [data], api_admin_headers)
|
||||
@ -383,7 +383,7 @@ def test_route_delete(api_admin_headers):
|
||||
res = POST_JSON("/assiduite/delete", data, api_admin_headers)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
for dat in res["success"]:
|
||||
assert res["success"][dat] == {"OK": True}
|
||||
assert dat["message"] == "OK"
|
||||
|
||||
# Mauvais Fonctionnement
|
||||
|
||||
@ -397,4 +397,4 @@ def test_route_delete(api_admin_headers):
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["errors"]) == 3
|
||||
|
||||
assert all([res["errors"][i] == "Assiduite non existante" for i in res["errors"]])
|
||||
assert all(i["message"] == "Assiduite non existante" for i in res["errors"])
|
||||
|
@ -35,7 +35,7 @@ JUSTIFICATIFS_FIELDS = {
|
||||
}
|
||||
|
||||
CREATE_FIELD = {"justif_id": int, "couverture": list}
|
||||
BATCH_FIELD = {"errors": dict, "success": dict}
|
||||
BATCH_FIELD = {"errors": list, "success": list}
|
||||
|
||||
TO_REMOVE = []
|
||||
|
||||
@ -172,14 +172,14 @@ def test_route_create(api_admin_headers):
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["success"]) == 1
|
||||
|
||||
TO_REMOVE.append(res["success"]["0"]["justif_id"])
|
||||
TO_REMOVE.append(res["success"][0]["message"]["justif_id"])
|
||||
|
||||
data2 = create_data("modifie", "02", "raison")
|
||||
res = POST_JSON(f"/justificatif/{ETUDID}/create", [data2], api_admin_headers)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["success"]) == 1
|
||||
|
||||
TO_REMOVE.append(res["success"]["0"]["justif_id"])
|
||||
TO_REMOVE.append(res["success"][0]["message"]["justif_id"])
|
||||
|
||||
# Mauvais fonctionnement
|
||||
check_failure_post(f"/justificatif/{FAUX}/create", api_admin_headers, [data])
|
||||
@ -191,7 +191,7 @@ def test_route_create(api_admin_headers):
|
||||
)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["errors"]) == 1
|
||||
assert res["errors"]["0"] == "param 'etat': invalide"
|
||||
assert res["errors"][0]["message"] == "param 'etat': invalide"
|
||||
|
||||
# -== Multiple ==-
|
||||
|
||||
@ -206,8 +206,8 @@ def test_route_create(api_admin_headers):
|
||||
res = POST_JSON(f"/justificatif/{ETUDID}/create", data, api_admin_headers)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
for dat in res["success"]:
|
||||
check_fields(res["success"][dat], CREATE_FIELD)
|
||||
TO_REMOVE.append(res["success"][dat]["justif_id"])
|
||||
check_fields(dat["message"], CREATE_FIELD)
|
||||
TO_REMOVE.append(dat["message"]["justif_id"])
|
||||
|
||||
# Mauvais Fonctionnement
|
||||
|
||||
@ -221,10 +221,10 @@ def test_route_create(api_admin_headers):
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["errors"]) == 3
|
||||
|
||||
assert res["errors"]["0"] == "param 'etat': manquant"
|
||||
assert res["errors"]["1"] == "param 'etat': invalide"
|
||||
assert res["errors"][0]["message"] == "param 'etat': manquant"
|
||||
assert res["errors"][1]["message"] == "param 'etat': invalide"
|
||||
assert (
|
||||
res["errors"]["2"]
|
||||
res["errors"][2]["message"]
|
||||
== "param 'date_debut': format invalide, param 'date_fin': format invalide"
|
||||
)
|
||||
|
||||
@ -263,7 +263,7 @@ def test_route_delete(api_admin_headers):
|
||||
res = POST_JSON("/justificatif/delete", [data], api_admin_headers)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
for dat in res["success"]:
|
||||
assert res["success"][dat] == {"OK": True}
|
||||
assert dat["message"] == "OK"
|
||||
|
||||
# Mauvais fonctionnement
|
||||
res = POST_JSON("/justificatif/delete", [data], api_admin_headers)
|
||||
@ -279,7 +279,7 @@ def test_route_delete(api_admin_headers):
|
||||
res = POST_JSON("/justificatif/delete", data, api_admin_headers)
|
||||
check_fields(res, BATCH_FIELD)
|
||||
for dat in res["success"]:
|
||||
assert res["success"][dat] == {"OK": True}
|
||||
assert dat["message"] == "OK"
|
||||
|
||||
# Mauvais Fonctionnement
|
||||
|
||||
@ -293,7 +293,7 @@ def test_route_delete(api_admin_headers):
|
||||
check_fields(res, BATCH_FIELD)
|
||||
assert len(res["errors"]) == 3
|
||||
|
||||
assert all([res["errors"][i] == "Justificatif non existant" for i in res["errors"]])
|
||||
assert all(i["message"] == "Justificatif non existant" for i in res["errors"])
|
||||
|
||||
|
||||
# Gestion de l'archivage
|
||||
|
Loading…
Reference in New Issue
Block a user