toulouse-maelis: do not allow empty payload (#70851)

This commit is contained in:
Nicolas Roche 2022-10-23 15:33:38 +02:00
parent 2a60072e53
commit 87055032a0
2 changed files with 217 additions and 245 deletions

View File

@ -104,121 +104,101 @@ CONTACT_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Contact',
'description': 'Informations sur le contact',
'oneOf': [
{'type': 'null'},
{
'type': 'object',
'properties': {
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mobile': {
'description': 'Portable',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mail': {
'description': 'Mail',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'isContactMail': {
'description': 'Accepte de recevoir des mails',
'oneOf': BOOLEAN_TYPES,
},
'isContactSms': {
'description': 'Accepte de recevoir des sms',
'oneOf': BOOLEAN_TYPES,
},
'isInvoicePdf': {
'description': 'Accepte de ne plus recevoir de facture papier',
'oneOf': BOOLEAN_TYPES,
},
},
'type': 'object',
'properties': {
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
],
'mobile': {
'description': 'Portable',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mail': {
'description': 'Mail',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'isContactMail': {
'description': 'Accepte de recevoir des mails',
'oneOf': BOOLEAN_TYPES,
},
'isContactSms': {
'description': 'Accepte de recevoir des sms',
'oneOf': BOOLEAN_TYPES,
},
'isInvoicePdf': {
'description': 'Accepte de ne plus recevoir de facture papier',
'oneOf': BOOLEAN_TYPES,
},
},
}
ADDRESSPROF_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Adresse pro',
'description': "Informations sur l'adresse professionnelle",
'oneOf': [
{'type': 'null'},
{
'type': 'object',
'properties': {
'num': {
'description': "Numéro de l'adresse",
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'street': {
'description': 'Nom de la voie',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'town': {
'description': 'Ville',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'zipcode': {
'description': 'Code postal',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
'type': 'object',
'properties': {
'num': {
'description': "Numéro de l'adresse",
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
],
'street': {
'description': 'Nom de la voie',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'town': {
'description': 'Ville',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'zipcode': {
'description': 'Code postal',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
}
PROFESSION_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Profession',
'description': 'Informations sur la profession',
'oneOf': [
{'type': 'null'},
{
'type': 'object',
'properties': {
'codeCSP': {
'description': 'Catégorie socio-professionnelle (depuis référentiel)',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'profession': {
'description': 'Profession',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'employerName': {
'description': "Nom de l'employeur",
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'addressPro': ADDRESSPROF_SCHEMA,
},
'type': 'object',
'properties': {
'codeCSP': {
'description': 'Catégorie socio-professionnelle (depuis référentiel)',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
],
'profession': {
'description': 'Profession',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'employerName': {
'description': "Nom de l'employeur",
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'addressPro': ADDRESSPROF_SCHEMA,
},
}
CAFINFO_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'CAF',
'description': 'Informations sur la CAF',
'oneOf': [
{'type': 'null'},
{
'type': 'object',
'properties': {
'number': {
'description': "Numéro d'allocataire",
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'organ': {
'description': "Nom de l'organisme (depuis référentiel)",
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
'type': 'object',
'properties': {
'number': {
'description': "Numéro d'allocataire",
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
],
'organ': {
'description': "Nom de l'organisme (depuis référentiel)",
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
}
RLINFO_SCHEMA = {
@ -239,9 +219,9 @@ RLINFO_SCHEMA = {
'pattern': '.+',
},
'adresse': ADDRESS_SCHEMA,
'contact': CONTACT_SCHEMA,
'profession': PROFESSION_SCHEMA,
'CAFInfo': CAFINFO_SCHEMA,
'contact': {'oneOf': [CONTACT_SCHEMA, {'type': 'null'}]},
'profession': {'oneOf': [PROFESSION_SCHEMA, {'type': 'null'}]},
'CAFInfo': {'oneOf': [CAFINFO_SCHEMA, {'type': 'null'}]},
},
'additionalProperties': False,
}
@ -270,102 +250,97 @@ FSL_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'FSL',
'description': 'Informations sur la fiche sanitaire',
'oneOf': [
{'type': 'null'},
{
'type': 'object',
'properties': {
'dateDeb': {
'description': 'Date de début',
'type': 'string',
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
},
'dateFin': {
'description': 'Date de fin',
'type': 'string',
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
},
'allergieAlimentaire': {
'description': 'Allergie alimentaire',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'allergieRespiratoire': {
'description': 'Allergie respiratoire',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'allergieAutre': {
'description': 'Allergie autre',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'allergieMedicament': {
'description': 'Allergie médicament',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'asthme': {
'description': 'Asthmatique',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'flPAI': {
'description': 'PAI',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'flImage': {
'description': 'Autorisation photo',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'dtcPrap1': {
'description': 'Date du dernier rappel DT Polio',
'type': 'string',
'pattern': '^([0-9]{4}-[0-9]{2}-[0-9]{2}){0,1}$',
},
'obsMed1': {
'description': 'Observation médecin 1',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsMed2': {
'description': 'Observation médecin 2',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsMed3': {
'description': 'Observation médecin 3',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsDir1': {
'description': 'Observation directeur 1',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsDir2': {
'description': 'Observation directeur 2',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsDir3': {
'description': 'Observation directeur 3',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsAssist1': {
'description': 'Observation assistant sanitaire 1',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsAssist2': {
'description': 'Observation assistant sanitaire 2',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsAssist3': {
'description': 'Observation assistant sanitaire 3',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'cons1Med': {
'description': 'Conseil médecin 1',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'cons2Med': {
'description': 'Conseil médecin 2',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
'additionalProperties': False,
'type': 'object',
'properties': {
'dateDeb': {
'description': 'Date de début',
'type': 'string',
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
},
],
'dateFin': {
'description': 'Date de fin',
'type': 'string',
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
},
'allergieAlimentaire': {
'description': 'Allergie alimentaire',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'allergieRespiratoire': {
'description': 'Allergie respiratoire',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'allergieAutre': {
'description': 'Allergie autre',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'allergieMedicament': {
'description': 'Allergie médicament',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'asthme': {
'description': 'Asthmatique',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'flPAI': {
'description': 'PAI',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'flImage': {
'description': 'Autorisation photo',
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'dtcPrap1': {
'description': 'Date du dernier rappel DT Polio',
'type': 'string',
'pattern': '^([0-9]{4}-[0-9]{2}-[0-9]{2}){0,1}$',
},
'obsMed1': {
'description': 'Observation médecin 1',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsMed2': {
'description': 'Observation médecin 2',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsMed3': {
'description': 'Observation médecin 3',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsDir1': {
'description': 'Observation directeur 1',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsDir2': {
'description': 'Observation directeur 2',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsDir3': {
'description': 'Observation directeur 3',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsAssist1': {
'description': 'Observation assistant sanitaire 1',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsAssist2': {
'description': 'Observation assistant sanitaire 2',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsAssist3': {
'description': 'Observation assistant sanitaire 3',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'cons1Med': {
'description': 'Conseil médecin 1',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'cons2Med': {
'description': 'Conseil médecin 2',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
'additionalProperties': False,
}
DOCTORADDRESS_SCHEMA = {
@ -459,35 +434,30 @@ PAIINFO_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'PAI',
'description': "Informations médicales",
'oneOf': [
{
'type': 'object',
'required': ['code'],
'properties': {
'code': {
'description': 'Code (depuis référentiel)',
'type': 'string',
'pattern': '.+',
},
'dateDeb': {
'description': 'Date de début',
'type': 'string',
'pattern': '^([0-9]{4}-[0-9]{2}-[0-9]{2}){0,1}$',
},
'dateFin': {
'description': 'Date de fin',
'type': 'string',
'pattern': '^([0-9]{4}-[0-9]{2}-[0-9]{2}){0,1}$',
},
'description': {
'description': 'Texte libre de description (max 500 caractères)',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
'additionalProperties': False,
'type': 'object',
'required': ['code'],
'properties': {
'code': {
'description': 'Code (depuis référentiel)',
'type': 'string',
'pattern': '.+',
},
{'type': 'null'},
],
'dateDeb': {
'description': 'Date de début',
'type': 'string',
'pattern': '^([0-9]{4}-[0-9]{2}-[0-9]{2}){0,1}$',
},
'dateFin': {
'description': 'Date de fin',
'type': 'string',
'pattern': '^([0-9]{4}-[0-9]{2}-[0-9]{2}){0,1}$',
},
'description': {
'description': 'Texte libre de description (max 500 caractères)',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
'additionalProperties': False,
}
CHILD_SCHEMA = {
@ -519,9 +489,9 @@ CHILD_SCHEMA = {
'description': 'Autorisation à partir seul',
'oneOf': BOOLEAN_TYPES,
},
'fsl': FSL_SCHEMA,
'medicalRecord': MEDICALRECORD_SCHEMA,
'paiInfoBean': PAIINFO_SCHEMA,
'fsl': {'oneOf': [FSL_SCHEMA, {'type': 'null'}]},
'medicalRecord': {'oneOf': [MEDICALRECORD_SCHEMA, {'type': 'null'}]},
'paiInfoBean': {'oneOf': [PAIINFO_SCHEMA, {'type': 'null'}]},
},
'additionalProperties': False,
}
@ -531,26 +501,21 @@ CONTACTLIGHT_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Contact light',
'description': "Informations de contact pour les personnes autorisées à récupérer les enfants ou à prévenir en cas d'urgence",
'oneOf': [
{
'type': 'object',
'properties': {
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mobile': {
'description': 'Portable',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mail': {
'description': 'Mail',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
'type': 'object',
'properties': {
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
{'type': 'null'},
],
'mobile': {
'description': 'Portable',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mail': {
'description': 'Mail',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
}
FAMILYPERSON_SCHEMA = {
@ -573,7 +538,7 @@ FAMILYPERSON_SCHEMA = {
'description': 'Sexe (depuis référentiel)',
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'contact': CONTACTLIGHT_SCHEMA,
'contact': {'oneOf': [CONTACTLIGHT_SCHEMA, {'type': 'null'}]},
},
'unflatten': True,
'additionalProperties': False,
@ -714,9 +679,9 @@ UPDATE_COORDINATE_SCHEMA = {
'required': ['adresse'],
'properties': {
'adresse': ADDRESS_SCHEMA,
'contact': CONTACT_SCHEMA,
'profession': PROFESSION_SCHEMA,
'CAFInfo': CAFINFO_SCHEMA,
'contact': {'oneOf': [CONTACT_SCHEMA, {'type': 'null'}]},
'profession': {'oneOf': [PROFESSION_SCHEMA, {'type': 'null'}]},
'CAFInfo': {'oneOf': [CAFINFO_SCHEMA, {'type': 'null'}]},
},
'unflatten': True,
'additionalProperties': False,

View File

@ -2586,6 +2586,13 @@ def test_update_child_pai(mocked_post, mocked_get, con, app):
assert resp.json['data'] == 'ok'
def test_update_child_pai_empty_payload_error(con, app):
url = get_endpoint('update-child-pai')
resp = app.post_json(url + '?NameID=local&child_id=613878', params=None, status=400)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == "None is not of type 'object'"
def test_update_child_pai_wrong_payload_type_error(con, app):
url = get_endpoint('update-child-pai')
params = {