From f4d2e5ffd23688fb504ebf0b0369cee33e6acf0d Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Tue, 26 Jul 2022 18:27:19 +0200 Subject: [PATCH] toulouse_maelis: apply correction on bateBirth field (#67782) --- passerelle/contrib/toulouse_maelis/schemas.py | 93 +++++-------------- tests/test_toulouse_maelis.py | 6 +- 2 files changed, 28 insertions(+), 71 deletions(-) diff --git a/passerelle/contrib/toulouse_maelis/schemas.py b/passerelle/contrib/toulouse_maelis/schemas.py index bbda2a8d..6fd88b1f 100644 --- a/passerelle/contrib/toulouse_maelis/schemas.py +++ b/passerelle/contrib/toulouse_maelis/schemas.py @@ -25,6 +25,24 @@ BOOLEAN_TYPES = [ }, ] + +ID_PROPERTIES = { + 'firstname': { + 'description': 'Prénom', + 'type': 'string', + }, + 'lastname': { + 'description': 'Nom', + 'type': 'string', + }, + 'dateBirth': { + 'description': 'Date de naissance', + 'type': 'string', + 'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', + }, +} + + LINK_SCHEMA = { '$schema': 'http://json-schema.org/draft-04/schema#', 'title': 'Link', @@ -36,43 +54,18 @@ LINK_SCHEMA = { 'description': 'Numéro DUI', 'type': 'string', }, - 'firstname': { - 'description': 'Prénom du RL1', - 'type': 'string', - }, - 'lastname': { - 'description': 'Nom du RL1', - 'type': 'string', - }, - 'dateBirth': { - 'description': 'Date de naissance du RL1', - 'type': 'string', - 'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', - }, }, } +LINK_SCHEMA['properties'].update(ID_PROPERTIES) + ISEXISTS_SCHEMA = { '$schema': 'http://json-schema.org/draft-04/schema#', 'title': 'Link', 'description': "Appairage d'un usager Publik à une famille dans Maelis", 'type': 'object', - 'required': ['firstname', 'lastname', 'datebirth'], - 'properties': { - 'firstname': { - 'description': 'Prénom', - 'type': 'string', - }, - 'lastname': { - 'description': 'Nom', - 'type': 'string', - }, - 'datebirth': { - 'description': 'Date de naissance', - 'type': 'string', - 'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', - }, - }, + 'required': ['firstname', 'lastname', 'dateBirth'], + 'properties': ID_PROPERTIES, } ADDRESS_SCHEMA = { @@ -241,29 +234,17 @@ RLINFO_SCHEMA = { 'description': 'civilité (depuis référenciel)', 'oneOf': [{'type': 'null'}, {'type': 'string'}], }, - 'firstname': { - 'description': 'Prénom', - 'type': 'string', - }, - 'lastname': { - 'description': 'Nom', - 'type': 'string', - }, 'quality': { 'description': 'Qualité', 'type': 'string', }, - 'dateBirth': { - 'description': 'Date de naissance', - 'type': 'string', - 'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', - }, 'adresse': ADDRESS_SCHEMA, 'contact': CONTACT_SCHEMA, 'profession': PROFESSION_SCHEMA, 'CAFInfo': CAFINFO_SCHEMA, }, } +RLINFO_SCHEMA['properties'].update(ID_PROPERTIES) CHILDBIRTH_SCHEMA = { '$schema': 'http://json-schema.org/draft-04/schema#', @@ -522,23 +503,10 @@ CHILD_SCHEMA = { {'required': ['birth']}, # updateFamily ], 'properties': { - 'firstname': { - 'description': 'Prénom', - 'type': 'string', - }, - 'lastname': { - 'description': 'Nom', - 'type': 'string', - }, 'sexe': { 'description': 'Sexe', 'type': 'string', }, - 'dateBirth': { - 'description': 'Date de naissance', - 'type': 'string', - 'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', - }, 'birth': CHILDBIRTH_SCHEMA, 'dietcode': { 'description': 'Code de régime alimentaire', @@ -557,6 +525,7 @@ CHILD_SCHEMA = { 'paiInfoBean': PAIINFO_SCHEMA, }, } +CHILD_SCHEMA['properties'].update(ID_PROPERTIES) CONTACTLIGHT_SCHEMA = { '$schema': 'http://json-schema.org/draft-04/schema#', @@ -595,27 +564,15 @@ FAMILYPERSON_SCHEMA = { 'description': 'civilité (depuis référenciel)', 'oneOf': [{'type': 'null'}, {'type': 'string'}], }, - 'firstname': { - 'description': 'Prénom', - 'type': 'string', - }, - 'lastname': { - 'description': 'Nom', - 'type': 'string', - }, 'quality': { 'description': 'Qualité', 'oneOf': [{'type': 'null'}, {'type': 'string'}], }, - 'dateBirth': { - 'description': 'Date de naissance', - 'type': 'string', - 'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', - }, 'contact': CONTACTLIGHT_SCHEMA, }, 'unflatten': True, } +FAMILYPERSON_SCHEMA['properties'].update(ID_PROPERTIES) AUTHORIZEDPERSON_SCHEMA = { '$schema': 'http://json-schema.org/draft-04/schema#', diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py index 5072e7ec..dec3f42d 100644 --- a/tests/test_toulouse_maelis.py +++ b/tests/test_toulouse_maelis.py @@ -642,7 +642,7 @@ def test_is_rl_exists(mocked_post, mocked_get, post_response, result, con, app): params = { 'firstname': 'Damien', 'lastname': 'Costanze', - 'datebirth': '1980-10-07', + 'dateBirth': '1980-10-07', } resp = app.post_json(url, params=params) assert resp.json['err'] == 0 @@ -655,7 +655,7 @@ def test_is_rl_exists_schema_error(con, app): params = { 'firstname': 'Damien', 'lastname': 'Costanze', - 'datebirth': '1980-10-07 more text', + 'dateBirth': '1980-10-07 more text', } resp = app.post_json(url, params=params, status=400) assert resp.json['err'] == 1 @@ -679,7 +679,7 @@ def test_is_child_exists(mocked_post, mocked_get, post_response, result, con, ap params = { 'firstname': 'Cassandra', 'lastname': 'Costanze', - 'datebirth': '2021-06-22', + 'dateBirth': '2021-06-22', } resp = app.post_json(url, params=params) assert resp.json['err'] == 0