diff --git a/app/__init__.py b/app/__init__.py index 86646eb407..f1fba060a4 100755 --- a/app/__init__.py +++ b/app/__init__.py @@ -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 diff --git a/tests/api/test_api_etudiants.py b/tests/api/test_api_etudiants.py index 56f3193d33..c7d948ef2a 100644 --- a/tests/api/test_api_etudiants.py +++ b/tests/api/test_api_etudiants.py @@ -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):