2022-03-09 16:52:07 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-08-25 18:00:49 +02:00
|
|
|
"""Test API evaluations
|
2022-03-09 16:52:07 +01:00
|
|
|
|
|
|
|
Utilisation :
|
|
|
|
créer les variables d'environnement: (indiquer les valeurs
|
|
|
|
pour le serveur ScoDoc que vous voulez interroger)
|
|
|
|
|
|
|
|
export SCODOC_URL="https://scodoc.xxx.net/"
|
|
|
|
export SCODOC_USER="xxx"
|
|
|
|
export SCODOC_PASSWD="xxx"
|
|
|
|
export CHECK_CERTIFICATE=0 # ou 1 si serveur de production avec certif SSL valide
|
|
|
|
|
|
|
|
(on peut aussi placer ces valeurs dans un fichier .env du répertoire tests/api).
|
|
|
|
|
|
|
|
Lancer :
|
|
|
|
pytest tests/api/test_api_evaluations.py
|
|
|
|
"""
|
|
|
|
|
2022-03-10 17:43:12 +01:00
|
|
|
import requests
|
2023-08-25 18:00:49 +02:00
|
|
|
from types import NoneType
|
2022-03-09 16:52:07 +01:00
|
|
|
|
2023-04-06 10:38:31 +02:00
|
|
|
from app.scodoc import sco_utils as scu
|
2023-08-22 17:02:00 +02:00
|
|
|
from tests.api.setup_test_api import (
|
|
|
|
API_URL,
|
|
|
|
CHECK_CERTIFICATE,
|
2023-08-25 18:00:49 +02:00
|
|
|
GET,
|
2024-07-27 13:30:02 +02:00
|
|
|
POST,
|
2023-08-22 17:02:00 +02:00
|
|
|
api_admin_headers,
|
|
|
|
api_headers,
|
2023-08-25 18:00:49 +02:00
|
|
|
check_failure_post,
|
2023-08-22 17:02:00 +02:00
|
|
|
)
|
2022-06-23 16:20:19 +02:00
|
|
|
from tests.api.tools_test_api import (
|
|
|
|
verify_fields,
|
|
|
|
EVALUATIONS_FIELDS,
|
2023-06-03 22:43:04 +02:00
|
|
|
NOTES_FIELDS,
|
2022-06-23 16:20:19 +02:00
|
|
|
)
|
2022-03-09 16:52:07 +01:00
|
|
|
|
2022-04-13 12:39:10 +02:00
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
def test_evaluations(api_headers):
|
|
|
|
"""
|
2022-05-06 16:05:34 +02:00
|
|
|
Test 'evaluations'
|
|
|
|
|
|
|
|
Route :
|
2022-07-30 08:23:22 +02:00
|
|
|
- /moduleimpl/<int:moduleimpl_id>/evaluations
|
2022-05-04 23:11:20 +02:00
|
|
|
"""
|
2023-06-03 22:43:04 +02:00
|
|
|
moduleimpl_id = 20
|
2022-03-10 17:43:12 +01:00
|
|
|
r = requests.get(
|
2022-07-30 08:23:22 +02:00
|
|
|
f"{API_URL}/moduleimpl/{moduleimpl_id}/evaluations",
|
2022-05-04 23:11:20 +02:00
|
|
|
headers=api_headers,
|
2022-04-13 12:39:10 +02:00
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-04-13 12:39:10 +02:00
|
|
|
)
|
2022-03-10 17:43:12 +01:00
|
|
|
assert r.status_code == 200
|
2023-08-22 17:02:00 +02:00
|
|
|
evaluations = r.json()
|
|
|
|
assert evaluations
|
|
|
|
assert isinstance(evaluations, list)
|
|
|
|
for e in evaluations:
|
|
|
|
assert verify_fields(e, EVALUATIONS_FIELDS)
|
2023-08-25 18:00:49 +02:00
|
|
|
assert isinstance(e["date_debut"], (str, NoneType))
|
|
|
|
assert isinstance(e["date_fin"], (str, NoneType))
|
2023-08-22 17:02:00 +02:00
|
|
|
assert isinstance(e["id"], int)
|
|
|
|
assert isinstance(e["note_max"], float)
|
2023-08-25 18:00:49 +02:00
|
|
|
assert isinstance(e["visibulletin"], bool)
|
2023-08-22 17:02:00 +02:00
|
|
|
assert isinstance(e["evaluation_type"], int)
|
|
|
|
assert isinstance(e["moduleimpl_id"], int)
|
|
|
|
assert e["description"] is None or isinstance(e["description"], str)
|
|
|
|
assert isinstance(e["coefficient"], float)
|
|
|
|
assert isinstance(e["publish_incomplete"], bool)
|
|
|
|
assert isinstance(e["numero"], int)
|
|
|
|
assert isinstance(e["poids"], dict)
|
|
|
|
|
|
|
|
assert e["moduleimpl_id"] == moduleimpl_id
|
2022-06-23 16:20:19 +02:00
|
|
|
|
|
|
|
|
2023-06-03 22:43:04 +02:00
|
|
|
def test_evaluation_notes(api_headers):
|
2022-06-23 16:20:19 +02:00
|
|
|
"""
|
|
|
|
Test 'evaluation_notes'
|
|
|
|
|
|
|
|
Route :
|
2022-07-29 16:19:40 +02:00
|
|
|
- /evaluation/<int:evaluation_id>/notes
|
2022-06-23 16:20:19 +02:00
|
|
|
"""
|
2023-06-03 22:43:04 +02:00
|
|
|
eval_id = 20
|
2022-06-23 16:20:19 +02:00
|
|
|
r = requests.get(
|
2022-07-29 16:19:40 +02:00
|
|
|
f"{API_URL}/evaluation/{eval_id}/notes",
|
2022-06-23 16:20:19 +02:00
|
|
|
headers=api_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 11:48:36 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-06-23 16:20:19 +02:00
|
|
|
)
|
|
|
|
assert r.status_code == 200
|
|
|
|
eval_notes = r.json()
|
2023-06-03 22:43:04 +02:00
|
|
|
assert eval_notes
|
|
|
|
for etudid, note in eval_notes.items():
|
|
|
|
assert int(etudid) == note["etudid"]
|
|
|
|
assert verify_fields(note, NOTES_FIELDS)
|
|
|
|
assert isinstance(note["etudid"], int)
|
|
|
|
assert isinstance(note["evaluation_id"], int)
|
|
|
|
assert isinstance(note["value"], float)
|
|
|
|
assert isinstance(note["comment"], str)
|
|
|
|
assert isinstance(note["date"], str)
|
|
|
|
assert isinstance(note["uid"], int)
|
2022-06-23 16:20:19 +02:00
|
|
|
|
2023-06-03 22:43:04 +02:00
|
|
|
assert eval_id == note["evaluation_id"]
|
2023-08-22 17:02:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_evaluation_create(api_admin_headers):
|
|
|
|
"""
|
|
|
|
Test /moduleimpl/<int:moduleimpl_id>/evaluation/create
|
|
|
|
"""
|
|
|
|
moduleimpl_id = 20
|
2023-08-26 16:34:56 +02:00
|
|
|
# Nombre d'évaluations initial
|
|
|
|
evaluations = GET(
|
|
|
|
f"/moduleimpl/{moduleimpl_id}/evaluations", headers=api_admin_headers
|
|
|
|
)
|
|
|
|
nb_evals = len(evaluations)
|
|
|
|
#
|
2024-07-27 13:30:02 +02:00
|
|
|
e = POST(
|
2023-08-22 17:02:00 +02:00
|
|
|
f"/moduleimpl/{moduleimpl_id}/evaluation/create",
|
|
|
|
{"description": "eval test"},
|
|
|
|
api_admin_headers,
|
|
|
|
)
|
|
|
|
assert isinstance(e, dict)
|
|
|
|
assert verify_fields(e, EVALUATIONS_FIELDS)
|
|
|
|
# Check default values
|
|
|
|
assert e["note_max"] == 20.0
|
|
|
|
assert e["evaluation_type"] == 0
|
2023-08-25 18:00:49 +02:00
|
|
|
assert not e["date_debut"]
|
|
|
|
assert not e["date_fin"]
|
2023-08-22 17:02:00 +02:00
|
|
|
assert e["visibulletin"] is True
|
|
|
|
assert e["publish_incomplete"] is False
|
|
|
|
assert e["coefficient"] == 1.0
|
2023-08-26 16:34:56 +02:00
|
|
|
new_nb_evals = len(
|
|
|
|
GET(f"/moduleimpl/{moduleimpl_id}/evaluations", headers=api_admin_headers)
|
|
|
|
)
|
|
|
|
assert new_nb_evals == nb_evals + 1
|
|
|
|
nb_evals = new_nb_evals
|
2023-08-22 17:02:00 +02:00
|
|
|
|
2023-08-25 18:00:49 +02:00
|
|
|
# Avec une erreur
|
|
|
|
check_failure_post(
|
|
|
|
f"/moduleimpl/{moduleimpl_id}/evaluation/create",
|
|
|
|
api_admin_headers,
|
|
|
|
{"evaluation_type": 666},
|
|
|
|
err="paramètre de type incorrect (invalid evaluation_type value)",
|
|
|
|
)
|
2023-08-26 16:34:56 +02:00
|
|
|
new_nb_evals = len(
|
|
|
|
GET(f"/moduleimpl/{moduleimpl_id}/evaluations", headers=api_admin_headers)
|
|
|
|
)
|
|
|
|
assert new_nb_evals == nb_evals # inchangé
|
2023-08-25 18:00:49 +02:00
|
|
|
# Avec plein de valeurs
|
|
|
|
data = {
|
|
|
|
"coefficient": 12.0,
|
|
|
|
"date_debut": "2021-10-15T08:30:00+02:00",
|
|
|
|
"date_fin": "2021-10-15T10:30:00+02:00",
|
|
|
|
"description": "eval test2",
|
|
|
|
"evaluation_type": 1,
|
|
|
|
"visibulletin": False,
|
|
|
|
"publish_incomplete": True,
|
|
|
|
"note_max": 100.0,
|
|
|
|
}
|
2024-07-27 13:30:02 +02:00
|
|
|
e = POST(
|
2023-08-25 18:00:49 +02:00
|
|
|
f"/moduleimpl/{moduleimpl_id}/evaluation/create",
|
|
|
|
data,
|
|
|
|
api_admin_headers,
|
|
|
|
)
|
2023-08-26 16:34:56 +02:00
|
|
|
e_ret = GET(f"/evaluation/{e['id']}", headers=api_admin_headers)
|
2023-08-25 18:00:49 +02:00
|
|
|
for k, v in data.items():
|
2023-08-26 16:34:56 +02:00
|
|
|
assert e_ret[k] == v, f"received '{e_ret[k]}'"
|
2023-08-25 18:00:49 +02:00
|
|
|
|
2023-08-26 16:34:56 +02:00
|
|
|
# Avec des poids APC
|
|
|
|
nb_evals = len(
|
|
|
|
GET(f"/moduleimpl/{moduleimpl_id}/evaluations", headers=api_admin_headers)
|
|
|
|
)
|
|
|
|
data.update(
|
|
|
|
{
|
|
|
|
"description": "eval test apc erreur",
|
|
|
|
"poids": {"666": 666.0}, # poids erroné: UE inexistante
|
|
|
|
}
|
|
|
|
)
|
|
|
|
check_failure_post(
|
|
|
|
f"/moduleimpl/{moduleimpl_id}/evaluation/create",
|
|
|
|
api_admin_headers,
|
|
|
|
data,
|
|
|
|
)
|
|
|
|
new_nb_evals = len(
|
|
|
|
GET(f"/moduleimpl/{moduleimpl_id}/evaluations", headers=api_admin_headers)
|
|
|
|
)
|
|
|
|
assert new_nb_evals == nb_evals # inchangé
|
|
|
|
# Avec des poids absurdes
|
|
|
|
data.update({"description": "eval test apc erreur 2", "poids": "nimporte quoi"})
|
|
|
|
check_failure_post(
|
|
|
|
f"/moduleimpl/{moduleimpl_id}/evaluation/create",
|
|
|
|
api_admin_headers,
|
|
|
|
data,
|
|
|
|
)
|
|
|
|
new_nb_evals = len(
|
|
|
|
GET(f"/moduleimpl/{moduleimpl_id}/evaluations", headers=api_admin_headers)
|
|
|
|
)
|
|
|
|
assert new_nb_evals == nb_evals # inchangé
|
|
|
|
# Avec de bons poids
|
|
|
|
# pour cela il nous faut les UEs de ce formsemestre
|
|
|
|
# sachant que l'on a moduleimpl
|
|
|
|
modimpl = GET(f"/moduleimpl/{moduleimpl_id}", headers=api_admin_headers)
|
|
|
|
formation = GET(
|
|
|
|
f"/formsemestre/{modimpl['formsemestre_id']}/programme",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
)
|
|
|
|
ues = formation["ues"]
|
|
|
|
assert len(ues)
|
|
|
|
ue_ids = [ue["id"] for ue in ues]
|
|
|
|
poids = {ue_id: float(i) + 0.5 for i, ue_id in enumerate(ue_ids)}
|
|
|
|
data.update({"description": "eval avec poids", "poids": poids})
|
2024-07-27 13:30:02 +02:00
|
|
|
e = POST(
|
2023-08-26 16:34:56 +02:00
|
|
|
f"/moduleimpl/{moduleimpl_id}/evaluation/create",
|
|
|
|
data,
|
|
|
|
api_admin_headers,
|
|
|
|
)
|
|
|
|
assert e["poids"]
|
|
|
|
e_ret = GET(f"/evaluation/{e['id']}", headers=api_admin_headers)
|
|
|
|
assert e_ret["poids"] == e["poids"]
|
|
|
|
new_nb_evals = len(
|
|
|
|
GET(f"/moduleimpl/{moduleimpl_id}/evaluations", headers=api_admin_headers)
|
|
|
|
)
|
|
|
|
assert new_nb_evals == nb_evals + 1
|
|
|
|
nb_evals = new_nb_evals
|
|
|
|
# Delete
|
2024-07-27 13:30:02 +02:00
|
|
|
ans = POST(
|
2023-08-26 16:34:56 +02:00
|
|
|
f"/evaluation/{e_ret['id']}/delete",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
)
|
|
|
|
assert ans == "ok"
|
|
|
|
assert nb_evals - 1 == len(
|
|
|
|
GET(f"/moduleimpl/{moduleimpl_id}/evaluations", headers=api_admin_headers)
|
|
|
|
)
|