1
0
forked from ScoDoc/ScoDoc

API evaluation: ajout /create (manque poids APC)

This commit is contained in:
Emmanuel Viennet 2023-08-25 18:00:49 +02:00
parent c84c10ad89
commit 1dbeb5f7e5
3 changed files with 45 additions and 17 deletions

View File

@ -7,8 +7,6 @@
"""
ScoDoc 9 API : accès aux évaluations
"""
import datetime
from flask import g, request
from flask_json import as_json
from flask_login import current_user, login_required
@ -18,7 +16,7 @@ from app import db
from app.api import api_bp as bp, api_web_bp
from app.decorators import scodoc, permission_required
from app.models import Evaluation, ModuleImpl, FormSemestre
from app.scodoc import sco_evaluation_db, sco_permissions_check, sco_saisie_notes
from app.scodoc import sco_evaluation_db, sco_saisie_notes
from app.scodoc.sco_exceptions import AccessDenied, ScoValueError
from app.scodoc.sco_permissions import Permission
import app.scodoc.sco_utils as scu
@ -49,7 +47,7 @@ def evaluation(evaluation_id: int):
'UE1.3': 1.0
},
'publish_incomplete': False,
'visi_bulletin': True
'visibulletin': True
}
"""
query = Evaluation.query.filter_by(id=evaluation_id)
@ -197,10 +195,9 @@ def evaluation_create(moduleimpl_id: int):
and contains:
{
"description" : str,
"evaluation_type" : int, // {0,1,2} default 0 (normale)
"jour" : date_iso, // si non spécifié, vide
"evaluation_type" : int, // {0,1,2} default 0 (normale)
"date_debut" : date_iso, // optionnel
"date_fin" : date_iso, // si non spécifié, 08:00
"date_fin" : date_iso, // optionnel
"note_max" : float, // si non spécifié, 20.0
"numero" : int, // ordre de présentation, default tri sur date
"visibulletin" : boolean , //default true
@ -228,8 +225,9 @@ def evaluation_create(moduleimpl_id: int):
except ValueError:
return scu.json_error(400, "paramètre incorrect")
except ScoValueError as exc:
breakpoint() # XXX WIP
return scu.json_error(400, f"paramètre de type incorrect ({exc.msg})")
return scu.json_error(
400, f"paramètre de type incorrect ({exc.args[0] if exc.args else ''})"
)
db.session.add(evaluation)
db.session.commit()

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Test APi evaluations
"""Test API evaluations
Utilisation :
créer les variables d'environnement: (indiquer les valeurs
@ -18,14 +18,17 @@ Utilisation :
"""
import requests
from types import NoneType
from app.scodoc import sco_utils as scu
from tests.api.setup_test_api import (
API_URL,
CHECK_CERTIFICATE,
GET,
POST_JSON,
api_admin_headers,
api_headers,
check_failure_post,
)
from tests.api.tools_test_api import (
verify_fields,
@ -54,17 +57,17 @@ def test_evaluations(api_headers):
assert isinstance(evaluations, list)
for e in evaluations:
assert verify_fields(e, EVALUATIONS_FIELDS)
assert isinstance(e["date_debut"], (str, NoneType))
assert isinstance(e["date_fin"], (str, NoneType))
assert isinstance(e["id"], int)
assert isinstance(e["note_max"], float)
assert isinstance(e["visi_bulletin"], bool)
assert isinstance(e["visibulletin"], 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
@ -115,13 +118,40 @@ def test_evaluation_create(api_admin_headers):
# 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 not e["date_debut"]
assert not e["date_fin"]
assert e["visibulletin"] is True
assert e["publish_incomplete"] is False
assert e["coefficient"] == 1.0
# 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)",
)
# 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,
}
e = POST_JSON(
f"/moduleimpl/{moduleimpl_id}/evaluation/create",
data,
api_admin_headers,
)
e2 = GET(f"/evaluation/{e['id']}", headers=api_admin_headers)
for k, v in data.items():
assert e2[k] == v, f"received '{e2[k]}'"
# TODO
# - tester creation UE externe

View File

@ -39,7 +39,7 @@ echo
echo Server PID "$pid" running on port "$PORT"
# ------------------
if [ "$#" -eq 1 ]
if [ "$#" -eq 0 ]
then
echo "Starting pytest tests/api"
pytest tests/api