API: exporte les date et datetime en ISO et non pas en RFC 822.
This commit is contained in:
parent
720ca7222c
commit
243268a0c3
@ -148,7 +148,7 @@ def handle_invalid_usage(error):
|
||||
|
||||
# JSON ENCODING
|
||||
# used by some internal finctions
|
||||
# the API is now using flask_son, NOT THIS ENCODER
|
||||
# the API is now using flask_json, NOT THIS ENCODER
|
||||
class ScoDocJSONEncoder(json.JSONEncoder):
|
||||
def default(self, o): # pylint: disable=E0202
|
||||
if isinstance(o, (datetime.date, datetime.datetime)):
|
||||
@ -260,7 +260,13 @@ def create_app(config_class=DevConfig):
|
||||
|
||||
CAS(app, url_prefix="/cas", configuration_function=cas.set_cas_configuration)
|
||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||
FlaskJSON(app)
|
||||
app_json = FlaskJSON(app)
|
||||
|
||||
@app_json.encoder
|
||||
def scodoc_json_encoder(o):
|
||||
"Overide default date encoding (RFC 822) and use ISO"
|
||||
if isinstance(o, (datetime.date, datetime.datetime)):
|
||||
return o.isoformat()
|
||||
|
||||
# Pour conserver l'ordre des objets dans les JSON:
|
||||
# e.g. l'ordre des UE dans les bulletins
|
||||
|
@ -17,6 +17,7 @@ Utilisation :
|
||||
pytest tests/api/test_api_etudiants.py
|
||||
"""
|
||||
|
||||
import re
|
||||
import requests
|
||||
from app.scodoc import sco_utils as scu
|
||||
|
||||
@ -100,6 +101,7 @@ def test_etudiants_courant(api_headers):
|
||||
|
||||
etud = etudiants[-1]
|
||||
assert verify_fields(etud, ETUD_FIELDS) is True
|
||||
assert re.match(r"^\d{4}-\d\d-\d\d$", etud["date_naissance"])
|
||||
|
||||
|
||||
def test_etudiant(api_headers):
|
||||
|
Loading…
Reference in New Issue
Block a user