forked from ScoDoc/ScoDoc
API FormSemestreDescription + test
This commit is contained in:
parent
513fb3d46d
commit
e6f86d655b
@ -33,6 +33,7 @@ from app.models import (
|
|||||||
Departement,
|
Departement,
|
||||||
Evaluation,
|
Evaluation,
|
||||||
FormSemestre,
|
FormSemestre,
|
||||||
|
FormSemestreDescription,
|
||||||
FormSemestreEtape,
|
FormSemestreEtape,
|
||||||
FormSemestreInscription,
|
FormSemestreInscription,
|
||||||
Identite,
|
Identite,
|
||||||
@ -812,6 +813,30 @@ def formsemestre_get_description(formsemestre_id: int):
|
|||||||
return formsemestre.description.to_dict() if formsemestre.description else {}
|
return formsemestre.description.to_dict() if formsemestre.description else {}
|
||||||
|
|
||||||
|
|
||||||
|
@bp.post("/formsemestre/<int:formsemestre_id>/description/edit")
|
||||||
|
@api_web_bp.post("/formsemestre/<int:formsemestre_id>/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/<int:formsemestre_id>/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/<int:formsemestre_id>/description/image")
|
@bp.route("/formsemestre/<int:formsemestre_id>/description/image")
|
||||||
@api_web_bp.route("/formsemestre/<int:formsemestre_id>/description/image")
|
@api_web_bp.route("/formsemestre/<int:formsemestre_id>/description/image")
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -28,8 +28,10 @@ from tests.api.setup_test_api import (
|
|||||||
API_URL,
|
API_URL,
|
||||||
CHECK_CERTIFICATE,
|
CHECK_CERTIFICATE,
|
||||||
GET,
|
GET,
|
||||||
|
POST,
|
||||||
api_headers,
|
api_headers,
|
||||||
api_admin_headers,
|
api_admin_headers,
|
||||||
|
set_headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.api.tools_test_api import (
|
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:
|
if "nbabs" in k:
|
||||||
continue
|
continue
|
||||||
assert res_d[k] == ref_d[k], f"values for key {k} differ."
|
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
|
||||||
|
@ -100,7 +100,7 @@ def test_permissions(api_headers):
|
|||||||
verify=CHECK_CERTIFICATE,
|
verify=CHECK_CERTIFICATE,
|
||||||
timeout=scu.SCO_TEST_API_TIMEOUT,
|
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:
|
# Même chose sans le jeton:
|
||||||
for rule in api_rules:
|
for rule in api_rules:
|
||||||
|
Loading…
Reference in New Issue
Block a user