Emmanuel Viennet
9d18ed4671
- Nouveau point API: /evaluation/<int:evaluation_id>/notes/set - Corrige API /evaluation/<int:evaluation_id>/notes - Modernisation de code. - Améliore tests unitaires APi evaluation.
95 lines
2.9 KiB
Python
95 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""Test Logos
|
|
|
|
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
|
|
"""
|
|
|
|
import requests
|
|
|
|
from app.scodoc import sco_utils as scu
|
|
from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers
|
|
from tests.api.tools_test_api import (
|
|
verify_fields,
|
|
EVALUATIONS_FIELDS,
|
|
NOTES_FIELDS,
|
|
)
|
|
|
|
|
|
def test_evaluations(api_headers):
|
|
"""
|
|
Test 'evaluations'
|
|
|
|
Route :
|
|
- /moduleimpl/<int:moduleimpl_id>/evaluations
|
|
"""
|
|
moduleimpl_id = 20
|
|
r = requests.get(
|
|
f"{API_URL}/moduleimpl/{moduleimpl_id}/evaluations",
|
|
headers=api_headers,
|
|
verify=CHECK_CERTIFICATE,
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
|
)
|
|
assert r.status_code == 200
|
|
list_eval = r.json()
|
|
assert list_eval
|
|
assert isinstance(list_eval, list)
|
|
for eval in list_eval:
|
|
assert verify_fields(eval, EVALUATIONS_FIELDS) is True
|
|
assert isinstance(eval["id"], int)
|
|
assert isinstance(eval["note_max"], float)
|
|
assert isinstance(eval["visi_bulletin"], bool)
|
|
assert isinstance(eval["evaluation_type"], int)
|
|
assert isinstance(eval["moduleimpl_id"], int)
|
|
assert eval["description"] is None or isinstance(eval["description"], str)
|
|
assert isinstance(eval["coefficient"], float)
|
|
assert isinstance(eval["publish_incomplete"], bool)
|
|
assert isinstance(eval["numero"], int)
|
|
assert eval["date_debut"] is None or isinstance(eval["date_debut"], str)
|
|
assert eval["date_fin"] is None or isinstance(eval["date_fin"], str)
|
|
assert isinstance(eval["poids"], dict)
|
|
|
|
assert eval["moduleimpl_id"] == moduleimpl_id
|
|
|
|
|
|
def test_evaluation_notes(api_headers):
|
|
"""
|
|
Test 'evaluation_notes'
|
|
|
|
Route :
|
|
- /evaluation/<int:evaluation_id>/notes
|
|
"""
|
|
eval_id = 20
|
|
r = requests.get(
|
|
f"{API_URL}/evaluation/{eval_id}/notes",
|
|
headers=api_headers,
|
|
verify=CHECK_CERTIFICATE,
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
|
)
|
|
assert r.status_code == 200
|
|
eval_notes = r.json()
|
|
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)
|
|
|
|
assert eval_id == note["evaluation_id"]
|