MonScoDocEssai/tests/api/test_api_evaluations.py

129 lines
3.7 KiB
Python

# -*- coding: utf-8 -*-
"""Test APi evaluations
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,
POST_JSON,
api_admin_headers,
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
evaluations = r.json()
assert evaluations
assert isinstance(evaluations, list)
for e in evaluations:
assert verify_fields(e, EVALUATIONS_FIELDS)
assert isinstance(e["id"], int)
assert isinstance(e["note_max"], float)
assert isinstance(e["visi_bulletin"], bool)
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 e["date_debut"] is None or isinstance(e["date_debut"], str)
assert e["date_fin"] is None or isinstance(e["date_fin"], str)
assert isinstance(e["poids"], dict)
assert e["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"]
def test_evaluation_create(api_admin_headers):
"""
Test /moduleimpl/<int:moduleimpl_id>/evaluation/create
"""
moduleimpl_id = 20
e = POST_JSON(
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
assert e["jour"] is None
assert e["date_debut"] is None
assert e["date_fin"] is None
assert e["visibulletin"] is True
assert e["publish_incomplete"] is False
assert e["coefficient"] == 1.0
# TODO
# - tester creation UE externe
# - tester création base test et test API