Compare commits

...

2 Commits

Author SHA1 Message Date
leonard_montalbano
031dc409be correction d'erreurs diverses 2022-06-28 16:03:31 +02:00
leonard_montalbano
3297819892 gestion d'erreurs pour la route formsemestre_apo 2022-06-28 16:02:15 +02:00
3 changed files with 22 additions and 11 deletions

View File

@ -7,6 +7,7 @@ import app
from app import models
from app.api import bp
from app.api.auth import token_auth, token_permission_required
from app.api.errors import error_response
from app.comp import res_sem
from app.comp.moy_mod import ModuleImplResults
from app.comp.res_compat import NotesTableCompat
@ -91,7 +92,13 @@ def formsemestre_apo(etape_apo: str):
FormSemestreEtape.formsemestre_id == FormSemestre.id,
)
return jsonify([formsemestre.to_dict() for formsemestre in formsemestres])
res = [formsemestre.to_dict() for formsemestre in formsemestres]
if len(res) == 0:
return error_response(
404, message="Aucun formsemestre trouvé avec cette étape apogée"
)
else:
return jsonify(res)
@bp.route("/formsemestre/<int:formsemestre_id>/bulletins", methods=["GET"])

View File

@ -144,12 +144,12 @@ def test_formsemestre_apo(api_headers):
### ERROR ###
etape_apo_inexistante = "aoefiaozidaoẑidjnoaiznjd"
r = requests.get(
r_error = requests.get(
f"{API_URL}/formsemestre/apo/{etape_apo_inexistante}",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 404
assert r_error.status_code == 404
def test_bulletins(api_headers):
@ -180,16 +180,17 @@ def test_formsemestre_etudiants(api_headers):
/formsemestre/<int:formsemestre_id>/etudiants/demissionnaires,
/formsemestre/<int:formsemestre_id>/etudiants/defaillants
"""
formsemestre_id = 1
r = requests.get(
API_URL + "/formsemestre/1/etudiants",
f"{API_URL}/formsemestre/{formsemestre_id}/etudiants",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
formsemestre_etus = r.json()
assert isinstance(formsemestre_etus, list)
assert verify_fields(formsemestre_etus, FORMSEMESTRE_ETUS_FIELDS) is True
for etu in formsemestre_etus:
assert verify_fields(etu, FORMSEMESTRE_ETUS_FIELDS) is True
assert isinstance(etu["id"], int)
assert isinstance(etu["nip"], str)
assert isinstance(etu["ine"], str)
@ -214,15 +215,16 @@ def test_formsemestre_etudiants(api_headers):
### demissionnaires ###
r_demissionnaires = requests.get(
API_URL + "/formsemestre/<int:formsemestre_id>/etudiants/demissionnaires",
f"{API_URL}/formsemestre/{formsemestre_id}/etudiants/demissionnaires",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r_demissionnaires.status_code == 200
formsemestre_etus = r_demissionnaires.json()
assert isinstance(formsemestre_etus, list)
assert verify_fields(formsemestre_etus, FORMSEMESTRE_ETUS_FIELDS) is True
for etu in formsemestre_etus:
assert verify_fields(etu, FORMSEMESTRE_ETUS_FIELDS) is True
assert isinstance(etu["id"], int)
assert isinstance(etu["nip"], str)
assert isinstance(etu["ine"], str)
@ -247,7 +249,7 @@ def test_formsemestre_etudiants(api_headers):
### defaillants ###
r_defaillants = requests.get(
API_URL + "/formsemestre/<int:formsemestre_id>/etudiants/defaillants",
f"{API_URL}/formsemestre/{formsemestre_id}/etudiants/defaillants",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
@ -255,8 +257,8 @@ def test_formsemestre_etudiants(api_headers):
formsemestre_etus = r_defaillants.json()
assert isinstance(formsemestre_etus, list)
assert verify_fields(formsemestre_etus, FORMSEMESTRE_ETUS_FIELDS) is True
for etu in formsemestre_etus:
assert verify_fields(etu, FORMSEMESTRE_ETUS_FIELDS) is True
assert isinstance(etu["id"], int)
assert isinstance(etu["nip"], str)
assert isinstance(etu["ine"], str)
@ -279,7 +281,9 @@ def test_formsemestre_etudiants(api_headers):
assert isinstance(group["group_id"], int)
assert group["group_name"] is None or isinstance(group["group_name"], int)
assert r != r_demissionnaires != r_defaillants is True
assert r.json() != r_demissionnaires.json()
assert r.json() != r_defaillants.json()
assert r_demissionnaires.json() != r_defaillants.json()
### ERROR ###
id_formsemestre_inexistant = 265165689619851621685

View File

@ -543,7 +543,7 @@ FORMSEMESTRE_ETUS_FIELDS = {
"nom",
"nom_usuel",
"prenom",
"cvilite",
"civilite",
"groups",
}