forked from ScoDoc/ScoDoc
API evaluation: ajout /create (manque poids APC)
This commit is contained in:
parent
c84c10ad89
commit
1dbeb5f7e5
@ -7,8 +7,6 @@
|
|||||||
"""
|
"""
|
||||||
ScoDoc 9 API : accès aux évaluations
|
ScoDoc 9 API : accès aux évaluations
|
||||||
"""
|
"""
|
||||||
import datetime
|
|
||||||
|
|
||||||
from flask import g, request
|
from flask import g, request
|
||||||
from flask_json import as_json
|
from flask_json import as_json
|
||||||
from flask_login import current_user, login_required
|
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.api import api_bp as bp, api_web_bp
|
||||||
from app.decorators import scodoc, permission_required
|
from app.decorators import scodoc, permission_required
|
||||||
from app.models import Evaluation, ModuleImpl, FormSemestre
|
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_exceptions import AccessDenied, ScoValueError
|
||||||
from app.scodoc.sco_permissions import Permission
|
from app.scodoc.sco_permissions import Permission
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
@ -49,7 +47,7 @@ def evaluation(evaluation_id: int):
|
|||||||
'UE1.3': 1.0
|
'UE1.3': 1.0
|
||||||
},
|
},
|
||||||
'publish_incomplete': False,
|
'publish_incomplete': False,
|
||||||
'visi_bulletin': True
|
'visibulletin': True
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
query = Evaluation.query.filter_by(id=evaluation_id)
|
query = Evaluation.query.filter_by(id=evaluation_id)
|
||||||
@ -198,9 +196,8 @@ def evaluation_create(moduleimpl_id: int):
|
|||||||
{
|
{
|
||||||
"description" : str,
|
"description" : str,
|
||||||
"evaluation_type" : int, // {0,1,2} default 0 (normale)
|
"evaluation_type" : int, // {0,1,2} default 0 (normale)
|
||||||
"jour" : date_iso, // si non spécifié, vide
|
|
||||||
"date_debut" : date_iso, // optionnel
|
"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
|
"note_max" : float, // si non spécifié, 20.0
|
||||||
"numero" : int, // ordre de présentation, default tri sur date
|
"numero" : int, // ordre de présentation, default tri sur date
|
||||||
"visibulletin" : boolean , //default true
|
"visibulletin" : boolean , //default true
|
||||||
@ -228,8 +225,9 @@ def evaluation_create(moduleimpl_id: int):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return scu.json_error(400, "paramètre incorrect")
|
return scu.json_error(400, "paramètre incorrect")
|
||||||
except ScoValueError as exc:
|
except ScoValueError as exc:
|
||||||
breakpoint() # XXX WIP
|
return scu.json_error(
|
||||||
return scu.json_error(400, f"paramètre de type incorrect ({exc.msg})")
|
400, f"paramètre de type incorrect ({exc.args[0] if exc.args else ''})"
|
||||||
|
)
|
||||||
|
|
||||||
db.session.add(evaluation)
|
db.session.add(evaluation)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""Test APi evaluations
|
"""Test API evaluations
|
||||||
|
|
||||||
Utilisation :
|
Utilisation :
|
||||||
créer les variables d'environnement: (indiquer les valeurs
|
créer les variables d'environnement: (indiquer les valeurs
|
||||||
@ -18,14 +18,17 @@ Utilisation :
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from types import NoneType
|
||||||
|
|
||||||
from app.scodoc import sco_utils as scu
|
from app.scodoc import sco_utils as scu
|
||||||
from tests.api.setup_test_api import (
|
from tests.api.setup_test_api import (
|
||||||
API_URL,
|
API_URL,
|
||||||
CHECK_CERTIFICATE,
|
CHECK_CERTIFICATE,
|
||||||
|
GET,
|
||||||
POST_JSON,
|
POST_JSON,
|
||||||
api_admin_headers,
|
api_admin_headers,
|
||||||
api_headers,
|
api_headers,
|
||||||
|
check_failure_post,
|
||||||
)
|
)
|
||||||
from tests.api.tools_test_api import (
|
from tests.api.tools_test_api import (
|
||||||
verify_fields,
|
verify_fields,
|
||||||
@ -54,17 +57,17 @@ def test_evaluations(api_headers):
|
|||||||
assert isinstance(evaluations, list)
|
assert isinstance(evaluations, list)
|
||||||
for e in evaluations:
|
for e in evaluations:
|
||||||
assert verify_fields(e, EVALUATIONS_FIELDS)
|
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["id"], int)
|
||||||
assert isinstance(e["note_max"], float)
|
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["evaluation_type"], int)
|
||||||
assert isinstance(e["moduleimpl_id"], int)
|
assert isinstance(e["moduleimpl_id"], int)
|
||||||
assert e["description"] is None or isinstance(e["description"], str)
|
assert e["description"] is None or isinstance(e["description"], str)
|
||||||
assert isinstance(e["coefficient"], float)
|
assert isinstance(e["coefficient"], float)
|
||||||
assert isinstance(e["publish_incomplete"], bool)
|
assert isinstance(e["publish_incomplete"], bool)
|
||||||
assert isinstance(e["numero"], int)
|
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 isinstance(e["poids"], dict)
|
||||||
|
|
||||||
assert e["moduleimpl_id"] == moduleimpl_id
|
assert e["moduleimpl_id"] == moduleimpl_id
|
||||||
@ -115,13 +118,40 @@ def test_evaluation_create(api_admin_headers):
|
|||||||
# Check default values
|
# Check default values
|
||||||
assert e["note_max"] == 20.0
|
assert e["note_max"] == 20.0
|
||||||
assert e["evaluation_type"] == 0
|
assert e["evaluation_type"] == 0
|
||||||
assert e["jour"] is None
|
assert not e["date_debut"]
|
||||||
assert e["date_debut"] is None
|
assert not e["date_fin"]
|
||||||
assert e["date_fin"] is None
|
|
||||||
assert e["visibulletin"] is True
|
assert e["visibulletin"] is True
|
||||||
assert e["publish_incomplete"] is False
|
assert e["publish_incomplete"] is False
|
||||||
assert e["coefficient"] == 1.0
|
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
|
# TODO
|
||||||
# - tester creation UE externe
|
# - tester creation UE externe
|
||||||
|
@ -39,7 +39,7 @@ echo
|
|||||||
echo Server PID "$pid" running on port "$PORT"
|
echo Server PID "$pid" running on port "$PORT"
|
||||||
# ------------------
|
# ------------------
|
||||||
|
|
||||||
if [ "$#" -eq 1 ]
|
if [ "$#" -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "Starting pytest tests/api"
|
echo "Starting pytest tests/api"
|
||||||
pytest tests/api
|
pytest tests/api
|
||||||
|
Loading…
Reference in New Issue
Block a user