forked from ScoDoc/ScoDoc
ajout de tests unitaire pour la route etat_evals
This commit is contained in:
parent
d0e179fb7c
commit
39b913adfd
@ -21,7 +21,12 @@ import requests
|
|||||||
from app.api.formsemestres import formsemestre
|
from app.api.formsemestres import formsemestre
|
||||||
|
|
||||||
from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers
|
from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers
|
||||||
from tests.api.tools_test_api import MODIMPL_FIELDS, verify_fields
|
from tests.api.tools_test_api import (
|
||||||
|
MODIMPL_FIELDS,
|
||||||
|
verify_fields,
|
||||||
|
EVAL_FIELDS,
|
||||||
|
SAISIE_NOTES_FIELDS,
|
||||||
|
)
|
||||||
from tests.api.tools_test_api import FSEM_FIELDS, UE_FIELDS, MODULE_FIELDS
|
from tests.api.tools_test_api import FSEM_FIELDS, UE_FIELDS, MODULE_FIELDS
|
||||||
|
|
||||||
# Etudiant pour les tests
|
# Etudiant pour les tests
|
||||||
@ -159,7 +164,9 @@ def test_formsemestre_programme(api_headers):
|
|||||||
# assert r.status_code == 200
|
# assert r.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_etat_evals(api_headers):
|
def test_etat_evals(
|
||||||
|
api_headers,
|
||||||
|
): # XXX TODO Vérifier les champs, vérifier qu'il n'y a pas de répétition, vérifier que les dates de "saisie_notes" sont corrects (date_debut avant celle de fin mediane OK etc..)
|
||||||
"""
|
"""
|
||||||
Route : /formsemestre/<int:formsemestre_id>/etat_evals
|
Route : /formsemestre/<int:formsemestre_id>/etat_evals
|
||||||
"""
|
"""
|
||||||
@ -169,3 +176,159 @@ def test_etat_evals(api_headers):
|
|||||||
verify=CHECK_CERTIFICATE,
|
verify=CHECK_CERTIFICATE,
|
||||||
)
|
)
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
|
|
||||||
|
etat_evals = r.json()
|
||||||
|
|
||||||
|
assert len(etat_evals) == 3
|
||||||
|
|
||||||
|
ue = etat_evals[0]
|
||||||
|
assert len(ue) == 3
|
||||||
|
assert isinstance(ue["id"], int)
|
||||||
|
assert isinstance(ue["titre"], str)
|
||||||
|
assert isinstance(ue["evaluations"], list)
|
||||||
|
|
||||||
|
eval = ue["evaluations"][0]
|
||||||
|
assert len(eval) == 11
|
||||||
|
assert verify_fields(eval, EVAL_FIELDS)
|
||||||
|
assert isinstance(eval["id"], int)
|
||||||
|
assert eval["description"] is None or isinstance(eval["description"], str)
|
||||||
|
assert isinstance(eval["datetime_epreuve"], str)
|
||||||
|
assert isinstance(eval["heure_fin"], str)
|
||||||
|
assert isinstance(eval["coef"], float)
|
||||||
|
assert isinstance(eval["comptee"], str)
|
||||||
|
assert isinstance(eval["inscrits"], int)
|
||||||
|
assert isinstance(eval["manquantes"], int)
|
||||||
|
assert isinstance(eval["ABS"], int)
|
||||||
|
assert isinstance(eval["ATT"], int)
|
||||||
|
assert isinstance(eval["EXC"], int)
|
||||||
|
assert isinstance(eval["saisie_notes"], list)
|
||||||
|
|
||||||
|
list_eval_id = [e["id"] for e in ue["evaluations"]]
|
||||||
|
all_unique = True
|
||||||
|
for id in list_eval_id:
|
||||||
|
if list_eval_id.count(id) > 1:
|
||||||
|
all_unique = False
|
||||||
|
assert all_unique is True
|
||||||
|
|
||||||
|
saisie_notes = eval["saisie_notes"]
|
||||||
|
assert verify_fields(saisie_notes, SAISIE_NOTES_FIELDS)
|
||||||
|
assert isinstance(eval["saisie_notes"]["datetime_debut"], str)
|
||||||
|
assert isinstance(eval["saisie_notes"]["datetime_fin"], str)
|
||||||
|
assert isinstance(eval["saisie_notes"]["datetime_mediane"], str)
|
||||||
|
assert (
|
||||||
|
eval["saisie_notes"]["datetime_fin"] > eval["saisie_notes"]["datetime_mediane"]
|
||||||
|
)
|
||||||
|
assert eval["saisie_notes"]["datetime_fin"] > eval["saisie_notes"]["datetime_debut"]
|
||||||
|
assert (
|
||||||
|
eval["saisie_notes"]["datetime_mediane"]
|
||||||
|
> eval["saisie_notes"]["datetime_debut"]
|
||||||
|
)
|
||||||
|
|
||||||
|
ue2 = etat_evals[1]
|
||||||
|
assert len(ue2) == 3
|
||||||
|
assert isinstance(ue2["id"], int)
|
||||||
|
assert isinstance(ue2["titre"], str)
|
||||||
|
assert isinstance(ue2["evaluations"], list)
|
||||||
|
|
||||||
|
eval2 = ue2["evaluations"][0]
|
||||||
|
assert len(eval2) == 11
|
||||||
|
assert verify_fields(eval2, EVAL_FIELDS)
|
||||||
|
assert isinstance(eval2["id"], int)
|
||||||
|
assert eval2["description"] is None or isinstance(eval2["description"], str)
|
||||||
|
assert isinstance(eval2["datetime_epreuve"], str)
|
||||||
|
assert isinstance(eval2["heure_fin"], str)
|
||||||
|
assert isinstance(eval2["coef"], float)
|
||||||
|
assert isinstance(eval2["comptee"], str)
|
||||||
|
assert isinstance(eval2["inscrits"], int)
|
||||||
|
assert isinstance(eval2["manquantes"], int)
|
||||||
|
assert isinstance(eval2["ABS"], int)
|
||||||
|
assert isinstance(eval2["ATT"], int)
|
||||||
|
assert isinstance(eval2["EXC"], int)
|
||||||
|
assert isinstance(eval2["saisie_notes"], list)
|
||||||
|
|
||||||
|
list_eval_id2 = [e["id"] for e in ue["evaluations"]]
|
||||||
|
all_unique2 = True
|
||||||
|
for id in list_eval_id2:
|
||||||
|
if list_eval_id2.count(id) > 1:
|
||||||
|
all_unique2 = False
|
||||||
|
assert all_unique2 is True
|
||||||
|
|
||||||
|
saisie_notes2 = eval2["saisie_notes"]
|
||||||
|
assert verify_fields(saisie_notes2, SAISIE_NOTES_FIELDS)
|
||||||
|
assert isinstance(eval2["saisie_notes"]["datetime_debut"], str)
|
||||||
|
assert isinstance(eval2["saisie_notes"]["datetime_fin"], str)
|
||||||
|
assert isinstance(eval2["saisie_notes"]["datetime_mediane"], str)
|
||||||
|
assert (
|
||||||
|
eval2["saisie_notes"]["datetime_fin"]
|
||||||
|
> eval2["saisie_notes"]["datetime_mediane"]
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
eval2["saisie_notes"]["datetime_fin"] > eval2["saisie_notes"]["datetime_debut"]
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
eval2["saisie_notes"]["datetime_mediane"]
|
||||||
|
> eval2["saisie_notes"]["datetime_debut"]
|
||||||
|
)
|
||||||
|
|
||||||
|
ue3 = etat_evals[2]
|
||||||
|
assert len(ue3) == 3
|
||||||
|
assert isinstance(ue3["id"], int)
|
||||||
|
assert isinstance(ue3["titre"], str)
|
||||||
|
assert isinstance(ue3["evaluations"], list)
|
||||||
|
|
||||||
|
eval3 = ue3["evaluations"][0]
|
||||||
|
assert len(eval3) == 11
|
||||||
|
assert verify_fields(eval3, EVAL_FIELDS)
|
||||||
|
assert isinstance(eval3["id"], int)
|
||||||
|
assert eval3["description"] is None or isinstance(eval3["description"], str)
|
||||||
|
assert isinstance(eval3["datetime_epreuve"], str)
|
||||||
|
assert isinstance(eval3["heure_fin"], str)
|
||||||
|
assert isinstance(eval3["coef"], float)
|
||||||
|
assert isinstance(eval3["comptee"], str)
|
||||||
|
assert isinstance(eval3["inscrits"], int)
|
||||||
|
assert isinstance(eval3["manquantes"], int)
|
||||||
|
assert isinstance(eval3["ABS"], int)
|
||||||
|
assert isinstance(eval3["ATT"], int)
|
||||||
|
assert isinstance(eval3["EXC"], int)
|
||||||
|
assert isinstance(eval3["saisie_notes"], list)
|
||||||
|
|
||||||
|
list_eval_id3 = [e["id"] for e in ue["evaluations"]]
|
||||||
|
all_unique3 = True
|
||||||
|
for id in list_eval_id3:
|
||||||
|
if list_eval_id3.count(id) > 1:
|
||||||
|
all_unique3 = False
|
||||||
|
assert all_unique3 is True
|
||||||
|
|
||||||
|
saisie_notes3 = eval2["saisie_notes"]
|
||||||
|
assert verify_fields(saisie_notes3, SAISIE_NOTES_FIELDS)
|
||||||
|
assert isinstance(eval3["saisie_notes"]["datetime_debut"], str)
|
||||||
|
assert isinstance(eval3["saisie_notes"]["datetime_fin"], str)
|
||||||
|
assert isinstance(eval3["saisie_notes"]["datetime_mediane"], str)
|
||||||
|
assert (
|
||||||
|
eval3["saisie_notes"]["datetime_fin"]
|
||||||
|
> eval3["saisie_notes"]["datetime_mediane"]
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
eval3["saisie_notes"]["datetime_fin"] > eval3["saisie_notes"]["datetime_debut"]
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
eval3["saisie_notes"]["datetime_mediane"]
|
||||||
|
> eval3["saisie_notes"]["datetime_debut"]
|
||||||
|
)
|
||||||
|
|
||||||
|
assert ue["id"] != ue2["id"]
|
||||||
|
assert ue["id"] != ue3["id"]
|
||||||
|
assert ue2["id"] != ue3["id"]
|
||||||
|
|
||||||
|
assert ue["titre"] != ue2["titre"]
|
||||||
|
assert ue["titre"] != ue3["titre"]
|
||||||
|
assert ue2["titre"] != ue3["titre"]
|
||||||
|
|
||||||
|
##### ERROR #####
|
||||||
|
fake_eval_id = 153165161656849846516511321651651
|
||||||
|
r = requests.get(
|
||||||
|
f"{API_URL}/formsemestre/{fake_eval_id}/etat_evals",
|
||||||
|
headers=api_headers,
|
||||||
|
verify=CHECK_CERTIFICATE,
|
||||||
|
)
|
||||||
|
assert r.status_code == 404
|
||||||
|
Loading…
Reference in New Issue
Block a user