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
|
# JSON ENCODING
|
||||||
# used by some internal finctions
|
# 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):
|
class ScoDocJSONEncoder(json.JSONEncoder):
|
||||||
def default(self, o): # pylint: disable=E0202
|
def default(self, o): # pylint: disable=E0202
|
||||||
if isinstance(o, (datetime.date, datetime.datetime)):
|
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)
|
CAS(app, url_prefix="/cas", configuration_function=cas.set_cas_configuration)
|
||||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
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:
|
# Pour conserver l'ordre des objets dans les JSON:
|
||||||
# e.g. l'ordre des UE dans les bulletins
|
# e.g. l'ordre des UE dans les bulletins
|
||||||
|
@ -17,6 +17,7 @@ Utilisation :
|
|||||||
pytest tests/api/test_api_etudiants.py
|
pytest tests/api/test_api_etudiants.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
import requests
|
import requests
|
||||||
from app.scodoc import sco_utils as scu
|
from app.scodoc import sco_utils as scu
|
||||||
|
|
||||||
@ -100,6 +101,7 @@ def test_etudiants_courant(api_headers):
|
|||||||
|
|
||||||
etud = etudiants[-1]
|
etud = etudiants[-1]
|
||||||
assert verify_fields(etud, ETUD_FIELDS) is True
|
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):
|
def test_etudiant(api_headers):
|
||||||
|
Loading…
Reference in New Issue
Block a user