diff --git a/app/api/formsemestres.py b/app/api/formsemestres.py index e46258f2..24a98f33 100644 --- a/app/api/formsemestres.py +++ b/app/api/formsemestres.py @@ -33,6 +33,7 @@ from app.models import ( Departement, Evaluation, FormSemestre, + FormSemestreDescription, FormSemestreEtape, FormSemestreInscription, Identite, @@ -812,6 +813,30 @@ def formsemestre_get_description(formsemestre_id: int): return formsemestre.description.to_dict() if formsemestre.description else {} +@bp.post("/formsemestre//description/edit") +@api_web_bp.post("/formsemestre//description/edit") +@login_required +@scodoc +@permission_required(Permission.ScoView) +@as_json +def formsemestre_edit_description(formsemestre_id: int): + """Modifie description externe du formsemestre + + formsemestre_id : l'id du formsemestre + + SAMPLES + ------- + /formsemestre//description/edit;{""description"":""descriptif du semestre"", ""dispositif"":1} + """ + formsemestre = FormSemestre.get_formsemestre(formsemestre_id) + args = request.get_json(force=True) # may raise 400 Bad Request + if not formsemestre.description: + formsemestre.description = FormSemestreDescription() + formsemestre.description.from_dict(args) + db.session.commit() + return formsemestre.description.to_dict() + + @bp.route("/formsemestre//description/image") @api_web_bp.route("/formsemestre//description/image") @login_required diff --git a/tests/api/test_api_formsemestre.py b/tests/api/test_api_formsemestre.py index 23d55ccc..923f4c79 100644 --- a/tests/api/test_api_formsemestre.py +++ b/tests/api/test_api_formsemestre.py @@ -28,8 +28,10 @@ from tests.api.setup_test_api import ( API_URL, CHECK_CERTIFICATE, GET, + POST, api_headers, api_admin_headers, + set_headers, ) from tests.api.tools_test_api import ( @@ -780,3 +782,49 @@ def _compare_formsemestre_resultat(res: list[dict], ref: list[dict]): if "nbabs" in k: continue assert res_d[k] == ref_d[k], f"values for key {k} differ." + + +def test_formsemestre_description(api_admin_headers): + """ + Test accès et modification de la description + """ + set_headers(api_admin_headers) + formsemestre_id = 1 + r = GET(f"/formsemestre/{formsemestre_id}") + assert "description" not in r + r = POST( + f"/formsemestre/{formsemestre_id}/description/edit", + data={ + "description": "une description", + "horaire": "un horaire", + "salle": "une salle", + "dispositif": 1, + "wip": True, + }, + ) + assert r["description"] == "une description" + assert r["horaire"] == "un horaire" + assert r["salle"] == "une salle" + assert r["dispositif"] == 1 + assert r["wip"] is True + r = GET(f"/formsemestre/{formsemestre_id}/description") + assert r["description"] == "une description" + assert r["horaire"] == "un horaire" + assert r["salle"] == "une salle" + assert r["dispositif"] == 1 + assert r["wip"] is True + r = POST( + f"/formsemestre/{formsemestre_id}/description/edit", + data={ + "description": "", + "horaire": "", + "salle": "", + "dispositif": 0, + "wip": False, + }, + ) + assert r["description"] == "" + assert r["horaire"] == "" + assert r["salle"] == "" + assert r["dispositif"] == 0 + assert r["wip"] is False diff --git a/tests/api/test_api_permissions.py b/tests/api/test_api_permissions.py index ae3dad92..f94ce12e 100755 --- a/tests/api/test_api_permissions.py +++ b/tests/api/test_api_permissions.py @@ -100,7 +100,7 @@ def test_permissions(api_headers): verify=CHECK_CERTIFICATE, timeout=scu.SCO_TEST_API_TIMEOUT, ) - assert r.status_code == 200 + assert r.status_code // 100 == 2 # 2xx success # Même chose sans le jeton: for rule in api_rules: