Projet

Général

Profil

0001-toulouse_maelis-apply-correction-on-bateBirth-field-.patch

Nicolas Roche, 28 juillet 2022 16:00

Télécharger (9,42 ko)

Voir les différences:

Subject: [PATCH] toulouse_maelis: apply correction on bateBirth field (#67784)

 passerelle/contrib/toulouse_maelis/schemas.py | 93 +++++--------------
 tests/test_toulouse_maelis.py                 |  6 +-
 2 files changed, 28 insertions(+), 71 deletions(-)
passerelle/contrib/toulouse_maelis/schemas.py
20 20
    {'type': 'boolean'},
21 21
    {
22 22
        'type': 'string',
23 23
        'pattern': '^([Oo][Uu][Ii]|[Nn][Oo][Nn]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|1|0)$',
24 24
        'pattern_description': 'Les valeurs "0", "1", "true", "false", "oui" ou "non" sont autorisées (insensibles à la casse).',
25 25
    },
26 26
]
27 27

  
28

  
29
ID_PROPERTIES = {
30
    'firstname': {
31
        'description': 'Prénom',
32
        'type': 'string',
33
    },
34
    'lastname': {
35
        'description': 'Nom',
36
        'type': 'string',
37
    },
38
    'dateBirth': {
39
        'description': 'Date de naissance',
40
        'type': 'string',
41
        'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
42
    },
43
}
44

  
45

  
28 46
LINK_SCHEMA = {
29 47
    '$schema': 'http://json-schema.org/draft-04/schema#',
30 48
    'title': 'Link',
31 49
    'description': "Appairage d'un usager Publik à une famille dans Maelis",
32 50
    'type': 'object',
33 51
    'required': ['family_id', 'firstname', 'lastname', 'dateBirth'],
34 52
    'properties': {
35 53
        'family_id': {
36 54
            'description': 'Numéro DUI',
37 55
            'type': 'string',
38 56
        },
39
        'firstname': {
40
            'description': 'Prénom du RL1',
41
            'type': 'string',
42
        },
43
        'lastname': {
44
            'description': 'Nom du RL1',
45
            'type': 'string',
46
        },
47
        'dateBirth': {
48
            'description': 'Date de naissance du RL1',
49
            'type': 'string',
50
            'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
51
        },
52 57
    },
53 58
}
59
LINK_SCHEMA['properties'].update(ID_PROPERTIES)
60

  
54 61

  
55 62
ISEXISTS_SCHEMA = {
56 63
    '$schema': 'http://json-schema.org/draft-04/schema#',
57 64
    'title': 'Link',
58 65
    'description': "Appairage d'un usager Publik à une famille dans Maelis",
59 66
    'type': 'object',
60
    'required': ['firstname', 'lastname', 'datebirth'],
61
    'properties': {
62
        'firstname': {
63
            'description': 'Prénom',
64
            'type': 'string',
65
        },
66
        'lastname': {
67
            'description': 'Nom',
68
            'type': 'string',
69
        },
70
        'datebirth': {
71
            'description': 'Date de naissance',
72
            'type': 'string',
73
            'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
74
        },
75
    },
67
    'required': ['firstname', 'lastname', 'dateBirth'],
68
    'properties': ID_PROPERTIES,
76 69
}
77 70

  
78 71
ADDRESS_SCHEMA = {
79 72
    '$schema': 'http://json-schema.org/draft-04/schema#',
80 73
    'title': 'Address',
81 74
    'description': 'Informations sur une adresse',
82 75
    'type': 'object',
83 76
    'required': ['street1', 'town', 'zipcode'],
......
236 229
    'description': "Informations sur le responsable légal",
237 230
    'type': 'object',
238 231
    'required': ['firstname', 'lastname', 'quality', 'dateBirth', 'adresse'],
239 232
    'properties': {
240 233
        'civility': {
241 234
            'description': 'civilité (depuis référenciel)',
242 235
            'oneOf': [{'type': 'null'}, {'type': 'string'}],
243 236
        },
244
        'firstname': {
245
            'description': 'Prénom',
246
            'type': 'string',
247
        },
248
        'lastname': {
249
            'description': 'Nom',
250
            'type': 'string',
251
        },
252 237
        'quality': {
253 238
            'description': 'Qualité',
254 239
            'type': 'string',
255 240
        },
256
        'dateBirth': {
257
            'description': 'Date de naissance',
258
            'type': 'string',
259
            'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
260
        },
261 241
        'adresse': ADDRESS_SCHEMA,
262 242
        'contact': CONTACT_SCHEMA,
263 243
        'profession': PROFESSION_SCHEMA,
264 244
        'CAFInfo': CAFINFO_SCHEMA,
265 245
    },
266 246
}
247
RLINFO_SCHEMA['properties'].update(ID_PROPERTIES)
267 248

  
268 249
CHILDBIRTH_SCHEMA = {
269 250
    '$schema': 'http://json-schema.org/draft-04/schema#',
270 251
    'title': 'Child birth',
271 252
    'description': "Informations sur la naissance d'un enfant",
272 253
    'type': 'object',
273 254
    'required': ['dateBirth'],
274 255
    'properties': {
......
517 498
    'description': "Informations sur la création d'un enfant",
518 499
    'type': 'object',
519 500
    'required': ['sexe', 'firstname', 'lastname'],
520 501
    'oneOf': [
521 502
        {'required': ['dateBirth']},  # createFamily
522 503
        {'required': ['birth']},  # updateFamily
523 504
    ],
524 505
    'properties': {
525
        'firstname': {
526
            'description': 'Prénom',
527
            'type': 'string',
528
        },
529
        'lastname': {
530
            'description': 'Nom',
531
            'type': 'string',
532
        },
533 506
        'sexe': {
534 507
            'description': 'Sexe',
535 508
            'type': 'string',
536 509
        },
537
        'dateBirth': {
538
            'description': 'Date de naissance',
539
            'type': 'string',
540
            'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
541
        },
542 510
        'birth': CHILDBIRTH_SCHEMA,
543 511
        'dietcode': {
544 512
            'description': 'Code de régime alimentaire',
545 513
            'oneOf': [{'type': 'null'}, {'type': 'string'}],
546 514
        },
547 515
        'bPhoto': {
548 516
            'description': 'Autorisation photo',
549 517
            'oneOf': BOOLEAN_TYPES,
......
552 520
            'description': 'Autorisation à partir seul',
553 521
            'oneOf': BOOLEAN_TYPES,
554 522
        },
555 523
        'fsl': FSL_SCHEMA,
556 524
        'medicalRecord': MEDICALRECORD_SCHEMA,
557 525
        'paiInfoBean': PAIINFO_SCHEMA,
558 526
    },
559 527
}
528
CHILD_SCHEMA['properties'].update(ID_PROPERTIES)
560 529

  
561 530
CONTACTLIGHT_SCHEMA = {
562 531
    '$schema': 'http://json-schema.org/draft-04/schema#',
563 532
    'title': 'Contact',
564 533
    'description': "Informations de contact pour les personnes autorisées à récupérer les enfants ou à prévenir en cas d'urgence",
565 534
    'oneOf': [
566 535
        {'type': 'null'},
567 536
        {
......
590 559
    'description': "Informations sur les personnes autorisées à venir chercher les enfants ou à prévenir en cas d'urgence",
591 560
    'type': 'object',
592 561
    'required': ['firstname', 'lastname', 'dateBirth'],
593 562
    'properties': {
594 563
        'civility': {
595 564
            'description': 'civilité (depuis référenciel)',
596 565
            'oneOf': [{'type': 'null'}, {'type': 'string'}],
597 566
        },
598
        'firstname': {
599
            'description': 'Prénom',
600
            'type': 'string',
601
        },
602
        'lastname': {
603
            'description': 'Nom',
604
            'type': 'string',
605
        },
606 567
        'quality': {
607 568
            'description': 'Qualité',
608 569
            'oneOf': [{'type': 'null'}, {'type': 'string'}],
609 570
        },
610
        'dateBirth': {
611
            'description': 'Date de naissance',
612
            'type': 'string',
613
            'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
614
        },
615 571
        'contact': CONTACTLIGHT_SCHEMA,
616 572
    },
617 573
    'unflatten': True,
618 574
}
575
FAMILYPERSON_SCHEMA['properties'].update(ID_PROPERTIES)
619 576

  
620 577
AUTHORIZEDPERSON_SCHEMA = {
621 578
    '$schema': 'http://json-schema.org/draft-04/schema#',
622 579
    'title': 'Family',
623 580
    'description': "Informations sur les personnes autorisées à venir chercher les enfants ou à prévenir en cas d'urgence",
624 581
    'type': 'object',
625 582
    'properties': {
626 583
        'personList': {
tests/test_toulouse_maelis.py
637 637
def test_is_rl_exists(mocked_post, mocked_get, post_response, result, con, app):
638 638
    mocked_get.return_value = FAMILY_SERVICE_WSDL
639 639
    mocked_post.return_value = post_response
640 640
    url = get_endpoint('is-rl-exists')
641 641

  
642 642
    params = {
643 643
        'firstname': 'Damien',
644 644
        'lastname': 'Costanze',
645
        'datebirth': '1980-10-07',
645
        'dateBirth': '1980-10-07',
646 646
    }
647 647
    resp = app.post_json(url, params=params)
648 648
    assert resp.json['err'] == 0
649 649
    assert resp.json['data'] == result
650 650

  
651 651

  
652 652
def test_is_rl_exists_schema_error(con, app):
653 653
    url = get_endpoint('is-rl-exists')
654 654

  
655 655
    params = {
656 656
        'firstname': 'Damien',
657 657
        'lastname': 'Costanze',
658
        'datebirth': '1980-10-07 more text',
658
        'dateBirth': '1980-10-07 more text',
659 659
    }
660 660
    resp = app.post_json(url, params=params, status=400)
661 661
    assert resp.json['err'] == 1
662 662
    assert "does not match '^[0-9]{4}-[0-9]{2}-[0-9]{2}$'" in resp.json['err_desc']
663 663

  
664 664

  
665 665
@pytest.mark.parametrize(
666 666
    'post_response, result',
......
674 674
def test_is_child_exists(mocked_post, mocked_get, post_response, result, con, app):
675 675
    mocked_get.return_value = FAMILY_SERVICE_WSDL
676 676
    mocked_post.return_value = post_response
677 677
    url = get_endpoint('is-child-exists')
678 678

  
679 679
    params = {
680 680
        'firstname': 'Cassandra',
681 681
        'lastname': 'Costanze',
682
        'datebirth': '2021-06-22',
682
        'dateBirth': '2021-06-22',
683 683
    }
684 684
    resp = app.post_json(url, params=params)
685 685
    assert resp.json['err'] == 0
686 686
    assert resp.json['data'] == result
687 687

  
688 688

  
689 689
@mock.patch('passerelle.utils.Request.get')
690 690
@mock.patch('passerelle.utils.Request.post')
691
-