Projet

Général

Profil

0001-toulouse-maelis-add-endpoint-to-create-or-update-quo.patch

Nicolas Roche, 28 novembre 2022 17:10

Télécharger (25,2 ko)

Voir les différences:

Subject: [PATCH 1/2] toulouse-maelis: add endpoint to create or update
 quotients (#71698)

 functests/toulouse_maelis/conftest.py         |   8 +-
 .../data/test_update_quotient.json            |  29 +++++
 functests/toulouse_maelis/test_family.py      |  46 ++++++++
 passerelle/contrib/toulouse_maelis/models.py  |  25 ++++
 passerelle/contrib/toulouse_maelis/schemas.py |  36 ++++++
 .../Q_create_update_quotient.xml              |  23 ++++
 .../R_create_update_quotient.xml              |   5 +
 .../R_create_update_quotient_soap_error.xml   |  13 +++
 tests/data/toulouse_maelis/R_read_family.xml  |  14 +++
 .../toulouse_maelis/R_read_family_relax.xml   |  14 +++
 .../R_read_family_reordered.xml               |  14 +++
 tests/test_toulouse_maelis.py                 | 108 +++++++++++++++++-
 12 files changed, 332 insertions(+), 3 deletions(-)
 create mode 100644 functests/toulouse_maelis/data/test_update_quotient.json
 create mode 100644 tests/data/toulouse_maelis/Q_create_update_quotient.xml
 create mode 100644 tests/data/toulouse_maelis/R_create_update_quotient.xml
 create mode 100644 tests/data/toulouse_maelis/R_create_update_quotient_soap_error.xml
functests/toulouse_maelis/conftest.py
283 283
    remove_id_on_child(child)
284 284
    if not key:
285 285
        assert diff(child, expected_file)
286 286
    else:
287 287
        assert diff(child[key], expected_file)
288 288
    return data
289 289

  
290 290

  
291
def diff_rlg(conn, name_id, index, expected_file):
291
def diff_rlg(conn, name_id, index, expected_file, key=None):
292 292
    data = read_family(conn, name_id)
293 293
    rlg = copy.deepcopy(data['RL%s' % index])
294 294
    remove_id_on_rlg(rlg)
295
    assert diff(rlg, expected_file)
295
    if not key:
296
        assert diff(rlg, expected_file)
297
    else:
298
        assert diff(rlg[key], expected_file)
296 299
    return data
297 300

  
298 301

  
299 302
def diff_family(conn, name_id, expected_file, key=None):
300 303
    data = read_family(conn, name_id)
301 304
    family = copy.deepcopy(data)
302 305
    remove_id_on_family(family)
303 306
    if not key:
......
333 336
    assert create_result['err'] == 0
334 337
    print('\ncreate DUI: %s' % str(create_result['data']['number']))
335 338
    data = diff_family(conn, name_id, 'test_create_family.json')
336 339

  
337 340
    return {
338 341
        'name_id': name_id,  # linked
339 342
        'family_id': str(create_result['data']['number']),
340 343
        'lastname': lastname,
344
        'rl1_num': data['RL1']['num'],
341 345
        'family_payload': create_family_payload,
342 346
        'data': data,
343 347
    }
344 348

  
345 349

  
346 350
@pytest.fixture(scope='session')
347 351
def update_data(request, conn):
348 352
    name_id = request.config.getoption('--nameid')
functests/toulouse_maelis/data/test_update_quotient.json
1
[
2
  {
3
    "yearRev": 2021,
4
    "dateStart": "2022-01-02T00:00:00+01:00",
5
    "dateEnd": "2022-12-31T00:00:00+01:00",
6
    "mtt": 1500.33,
7
    "cdquo": "QS",
8
    "codeUti": null,
9
    "cdquo_text": "QUOTIENT SCOLAIRE"
10
  },
11
  {
12
    "yearRev": 2020,
13
    "dateStart": "2022-01-02T00:00:00+01:00",
14
    "dateEnd": "2022-12-31T00:00:00+01:00",
15
    "mtt": 1500.33,
16
    "cdquo": "QS",
17
    "codeUti": null,
18
    "cdquo_text": "QUOTIENT SCOLAIRE"
19
  },
20
  {
21
    "yearRev": 2021,
22
    "dateStart": "2022-01-01T00:00:00+01:00",
23
    "dateEnd": "2022-01-01T00:00:00+01:00",
24
    "mtt": 1500.33,
25
    "cdquo": "QS",
26
    "codeUti": null,
27
    "cdquo_text": "QUOTIENT SCOLAIRE"
28
  }
29
]
functests/toulouse_maelis/test_family.py
686 686
        update_data['bart_num'],
687 687
        abi_num,
688 688
    )
689 689
    payload = update_data['family_payload']['childList'][0]['authorizedPersonList'][0]
690 690
    resp = requests.post(url, json=payload)
691 691
    resp.raise_for_status()
692 692
    assert resp.json()['err'] == 0
693 693
    assert diff_family(conn, update_data['name_id'], 'test_update_family.json')
694

  
695

  
696
def test_update_quotient(conn, create_data):
697
    unlink(conn, create_data['name_id'])
698
    link(conn, create_data)
699

  
700
    # add quotient
701
    url = conn + '/update-quotient?NameID=%s&rl_id=%s' % (create_data['name_id'], create_data['rl1_num'])
702
    payload = {
703
        'yearRev': '2021',
704
        'dateStart': '2022-01-01',
705
        'dateEnd': '2022-12-31',
706
        'mtt': '1500.33',
707
        'cdquo': 'QS',
708
    }
709
    resp = requests.post(url, json=payload)
710
    resp.raise_for_status()
711
    assert resp.json()['err'] == 0
712
    data = read_family(conn, create_data['name_id'])
713
    assert data['RL1']['quotientList'] == [
714
        {
715
            'yearRev': 2021,
716
            'dateStart': '2022-01-01T00:00:00+01:00',
717
            'dateEnd': '2022-12-31T00:00:00+01:00',
718
            'mtt': 1500.33,
719
            'cdquo': 'QS',
720
            'codeUti': None,
721
            'cdquo_text': 'QUOTIENT SCOLAIRE',
722
        }
723
    ]
724

  
725
    # add quotient
726
    payload['dateStart'] = '2022-01-02'
727
    resp = requests.post(url, json=payload)
728
    resp.raise_for_status()
729
    assert resp.json()['err'] == 0
730
    data = read_family(conn, create_data['name_id'])
731
    assert len(data['RL1']['quotientList']) == 2
732

  
733
    # add quotient on another income year
734
    payload['yearRev'] = '2020'
735
    resp = requests.post(url, json=payload)
736
    resp.raise_for_status()
737
    assert resp.json()['err'] == 0
738
    data = diff_rlg(conn, create_data['name_id'], 1, 'test_update_quotient.json', 'quotientList')
739
    assert len(data['RL1']['quotientList']) == 3
passerelle/contrib/toulouse_maelis/models.py
188 188
        self.add_text_value('Sex', data, ['sexe'])
189 189

  
190 190
    def add_text_value_to_rl(self, data):
191 191
        self.add_text_value('Civility', data, ['civility'])
192 192
        self.add_text_value('Quality', data, ['quality'])
193 193
        self.add_text_value('Complement', data, ['adresse', 'numComp'])
194 194
        self.add_text_value('CSP', data, ['profession', 'codeCSP'])
195 195
        self.add_text_value('Organ', data, ['CAFInfo', 'organ'])
196
        for quotient in data['quotientList']:
197
            self.add_text_value('Quotient', quotient, ['cdquo'])
196 198

  
197 199
    def add_text_value_to_family(self, data):
198 200
        self.add_text_value('Category', data, ['category'])
199 201
        self.add_text_value('Situation', data, ['situation'])
200 202
        for rlg in 'RL1', 'RL2':
201 203
            if data.get(rlg):
202 204
                self.add_text_value_to_rl(data[rlg])
203 205
        for child in data['childList']:
......
837 839
    def update_coordinate(self, request, NameID, rl_id, post_data):
838 840
        family_id = self.get_link(NameID).family_id
839 841
        self.assert_update_coordinate_payload_in_referential(post_data)
840 842
        self.replace_null_values(post_data)
841 843

  
842 844
        self.call('Family', 'updateCoordinate', numDossier=family_id, numPerson=rl_id, **post_data)
843 845
        return {'data': 'ok'}
844 846

  
847
    @endpoint(
848
        display_category='Famille',
849
        description="Créer ou mettre à jour un quotient d'un responsable légal",
850
        name='update-quotient',
851
        perm='can_access',
852
        parameters={
853
            'NameID': {'description': 'Publik NameID'},
854
            'rl_id': {'description': "Numéro du responsable légal"},
855
        },
856
        post={'request_body': {'schema': {'application/json': schemas.UPDATE_QUOTIENT_SCHEMA}}},
857
    )
858
    def update_quotient(self, request, NameID, rl_id, post_data):
859
        family_id = self.get_link(NameID).family_id
860
        self.assert_post_data_in_referential('Quotient', post_data, ['cdquo'])
861

  
862
        payload = {
863
            'dossierNumber': family_id,
864
            'personNumber': rl_id,
865
            'quotient': post_data,
866
        }
867
        self.call('Family', 'createUpdateQuotient', **payload)
868
        return {'data': 'ok'}
869

  
845 870
    @endpoint(
846 871
        display_category='Famille',
847 872
        description="Création d'une personne à prévenir en cas d'urgence",
848 873
        name='create-person',
849 874
        perm='can_access',
850 875
        parameters={
851 876
            'NameID': {'description': 'Publik NameID'},
852 877
        },
passerelle/contrib/toulouse_maelis/schemas.py
650 650
        'adresse': ADDRESS_SCHEMA,
651 651
        'contact': {'oneOf': [CONTACT_SCHEMA, {'type': 'null'}]},
652 652
        'profession': {'oneOf': [PROFESSION_SCHEMA, {'type': 'null'}]},
653 653
        'CAFInfo': {'oneOf': [CAFINFO_SCHEMA, {'type': 'null'}]},
654 654
    },
655 655
    'unflatten': True,
656 656
    'additionalProperties': False,
657 657
}
658

  
659
UPDATE_QUOTIENT_SCHEMA = {
660
    '$schema': 'http://json-schema.org/draft-04/schema#',
661
    'title': 'Family persons',
662
    'description': "Informations sur les personnes autorisées à venir chercher l'enfant avec leur qualité",
663
    'type': 'object',
664
    'required': ['yearRev', 'dateStart', 'dateEnd', 'mtt', 'cdquo'],
665
    'properties': {
666
        'yearRev': {
667
            'description': 'Année de revenu',
668
            'type': 'string',
669
            'pattern': '^[0-9]{4}$',
670
        },
671
        'dateStart': {
672
            'description': 'Date de début',
673
            'type': 'string',
674
            'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
675
        },
676
        'dateEnd': {
677
            'description': 'Date de fin',
678
            'type': 'string',
679
            'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
680
        },
681
        'mtt': {
682
            'description': 'Montant',
683
            'type': 'string',
684
            'pattern': r'^[0-9]+\.?[0-9]*$',
685
        },
686
        'cdquo': {
687
            'description': 'Code du quotient (depuis référentiel)',
688
            'type': 'string',
689
            'pattern': '.+',
690
        },
691
    },
692
    'additionalProperties': False,
693
}
tests/data/toulouse_maelis/Q_create_update_quotient.xml
1
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
2
  <soap-env:Header>
3
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
4
      <wsse:UsernameToken>
5
        <wsse:Username>maelis-webservice</wsse:Username>
6
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
7
      </wsse:UsernameToken>
8
    </wsse:Security>
9
  </soap-env:Header>
10
  <soap-env:Body>
11
    <ns0:createUpdateQuotient xmlns:ns0="family.ws.maelis.sigec.com">
12
      <dossierNumber>1312</dossierNumber>
13
      <personNumber>613878</personNumber>
14
      <quotient>
15
        <yearRev>2021</yearRev>
16
        <dateStart>2022-10-01</dateStart>
17
        <dateEnd>2023-01-31</dateEnd>
18
        <mtt>1500.33</mtt>
19
        <cdquo>QS</cdquo>
20
      </quotient>
21
    </ns0:createUpdateQuotient>
22
  </soap-env:Body>
23
</soap-env:Envelope>
tests/data/toulouse_maelis/R_create_update_quotient.xml
1
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
2
  <soap:Body>
3
    <ns2:createUpdateQuotientResponse xmlns:ns2="family.ws.maelis.sigec.com"/>
4
  </soap:Body>
5
</soap:Envelope>
tests/data/toulouse_maelis/R_create_update_quotient_soap_error.xml
1
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
2
  <soap:Body>
3
    <soap:Fault>
4
      <faultcode>soap:Server</faultcode>
5
      <faultstring>E07 : Il existe d&#233;j&#224; un quotient post&#233;rieur pour cette p&#233;riode</faultstring>
6
      <detail>
7
        <ns1:MaelisFamilyException xmlns:ns1="family.ws.maelis.sigec.com">
8
          <message xmlns:ns2="family.ws.maelis.sigec.com">E07 : Il existe d&#233;j&#224; un quotient post&#233;rieur pour cette p&#233;riode</message>
9
        </ns1:MaelisFamilyException>
10
      </detail>
11
    </soap:Fault>
12
  </soap:Body>
13
</soap:Envelope>
tests/data/toulouse_maelis/R_read_family.xml
31 31
            <mail>djhon@example.org</mail>
32 32
            <isContactMail>true</isContactMail>
33 33
            <isContactSms>true</isContactSms>
34 34
            <isInvoicePdf>true</isInvoicePdf>
35 35
          </contact>
36 36
          <profession>
37 37
            <addressPro/>
38 38
          </profession>
39
          <quotientList>
40
            <yearRev>2020</yearRev>
41
            <dateStart>2021-01-01T00:00:00+01:00</dateStart>
42
            <dateEnd>2021-12-31T00:00:00+01:00</dateEnd>
43
            <mtt>1500.33</mtt>
44
            <cdquo>QS</cdquo>
45
          </quotientList>
46
          <quotientList>
47
            <yearRev>2021</yearRev>
48
            <dateStart>2022-01-01T00:00:00+01:00</dateStart>
49
            <dateEnd>2022-12-31T00:00:00+01:00</dateEnd>
50
            <mtt>1500.44</mtt>
51
            <cdquo>MOY ECO</cdquo>
52
          </quotientList>
39 53
        </RL1>
40 54
        <RL2>
41 55
          <num>613879</num>
42 56
          <lastname>DOE</lastname>
43 57
          <firstname>JANE</firstname>
44 58
          <maidenName>SMITH</maidenName>
45 59
          <quality>MERE</quality>
46 60
          <civility>MME</civility>
tests/data/toulouse_maelis/R_read_family_relax.xml
31 31
            <mail>djhon@example.org</mail>
32 32
            <isContactMail>true</isContactMail>
33 33
            <isContactSms>true</isContactSms>
34 34
            <isInvoicePdf>true</isInvoicePdf>
35 35
          </contact>
36 36
          <profession>
37 37
            <addressPro/>
38 38
          </profession>
39
          <quotientList>
40
            <yearRev>2020</yearRev>
41
            <dateStart>2021-01-01T00:00:00+01:00</dateStart>
42
            <dateEnd>2021-12-31T00:00:00+01:00</dateEnd>
43
            <mtt>1500.33</mtt>
44
            <cdquo>QS</cdquo>
45
          </quotientList>
46
          <quotientList>
47
            <yearRev>2021</yearRev>
48
            <dateStart>2022-01-01T00:00:00+01:00</dateStart>
49
            <dateEnd>2022-12-31T00:00:00+01:00</dateEnd>
50
            <mtt>1500.44</mtt>
51
            <cdquo>MOY ECO</cdquo>
52
          </quotientList>
39 53
        </RL1>
40 54
        <RL2>
41 55
          <num>613879</num>
42 56
          <lastname>DOE</lastname>
43 57
          <firstname>JANE</firstname>
44 58
          <civility>MME</civility>
45 59
          <birth>
46 60
            <dateBirth>1940-06-22T00:00:00+02:00</dateBirth>
tests/data/toulouse_maelis/R_read_family_reordered.xml
31 31
            <mail>djhon@example.org</mail>
32 32
            <isContactMail>true</isContactMail>
33 33
            <isContactSms>true</isContactSms>
34 34
            <isInvoicePdf>true</isInvoicePdf>
35 35
          </contact>
36 36
          <profession>
37 37
            <addressPro/>
38 38
          </profession>
39
          <quotientList>
40
            <yearRev>2020</yearRev>
41
            <dateStart>2021-01-01T00:00:00+01:00</dateStart>
42
            <dateEnd>2021-12-31T00:00:00+01:00</dateEnd>
43
            <mtt>1500.33</mtt>
44
            <cdquo>QS</cdquo>
45
          </quotientList>
46
          <quotientList>
47
            <yearRev>2021</yearRev>
48
            <dateStart>2022-01-01T00:00:00+01:00</dateStart>
49
            <dateEnd>2022-12-31T00:00:00+01:00</dateEnd>
50
            <mtt>1500.44</mtt>
51
            <cdquo>MOY ECO</cdquo>
52
          </quotientList>
39 53
        </RL1>
40 54
        <RL2>
41 55
          <num>613879</num>
42 56
          <lastname>DOE</lastname>
43 57
          <firstname>JANE</firstname>
44 58
          <quality>MERE</quality>
45 59
          <civility>MME</civility>
46 60
          <birth>
tests/test_toulouse_maelis.py
63 63
)
64 64
CREATE_FAMILY = FakedResponse(content=get_xml_file('R_create_family.xml'), status_code=200)
65 65
CREATE_FAMILY_ERR = FakedResponse(content=get_xml_file('R_create_family_error.xml'), status_code=200)
66 66
CREATE_CHILD = FakedResponse(content=get_xml_file('R_create_child.xml'), status_code=200)
67 67
CREATE_CHILD_ERR = FakedResponse(content=get_xml_file('R_create_child_error.xml'), status_code=200)
68 68
UPDATE_FAMILY = FakedResponse(content=get_xml_file('R_update_family.xml'), status_code=200)
69 69
UPDATE_FAMILY_ERR = FakedResponse(content=get_xml_file('R_update_family_error.xml'), status_code=200)
70 70
UPDATE_FAMILY_500 = FakedResponse(content=get_xml_file('R_update_family_soap_error.xml'), status_code=500)
71
UPDATE_QUOTIENT = FakedResponse(content=get_xml_file('R_create_update_quotient.xml'), status_code=200)
72
UPDATE_QUOTIENT_500 = FakedResponse(
73
    content=get_xml_file('R_create_update_quotient_soap_error.xml'), status_code=500
74
)
71 75
UPDATE_DIETCODE = FakedResponse(content=get_xml_file('R_update_child_dietcode.xml'), status_code=200)
72 76
UPDATE_PAI = FakedResponse(content=get_xml_file('R_update_child_pai.xml'), status_code=200)
73 77
UPDATE_PAI_500 = FakedResponse(content=get_xml_file('R_update_child_pai_soap_error.xml'), status_code=500)
74 78
UPDATE_MEDICAL = FakedResponse(content=get_xml_file('R_update_child_medical_record.xml'), status_code=200)
75 79
UPDATE_MEDICAL_500 = FakedResponse(
76 80
    content=get_xml_file('R_update_child_medical_record_soap_error.xml'), status_code=500
77 81
)
78 82
UPDATE_CHILD_AUTO = FakedResponse(content=get_xml_file('R_update_child_authorization.xml'), status_code=200)
......
544 548
def test_read_family(mocked_post, mocked_get, read_family, con, app):
545 549
    mocked_get.return_value = FAMILY_SERVICE_WSDL
546 550
    mocked_post.side_effect = [
547 551
        read_family,
548 552
        READ_CATEGORIES,
549 553
        READ_SITUATIONS,
550 554
        READ_CIVILITIES,
551 555
        READ_QUALITIES,
556
        READ_QUOTIENT,
552 557
        READ_CSP,
553 558
        READ_ORGAN,
554 559
        READ_DIETCODE,
555 560
        READ_PAI,
556 561
    ]
557 562
    url = get_endpoint('read-family')
558 563
    Link.objects.create(resource=con, family_id='1312', name_id='local')
559 564

  
......
608 613
            'mail': 'djhon@example.org',
609 614
            'isContactMail': True,
610 615
            'isContactSms': True,
611 616
            'isInvoicePdf': True,
612 617
        },
613 618
        'CAFInfo': None,
614 619
        'civility_text': 'Monsieur',
615 620
        'quality_text': 'PERE',
616
        'quotientList': [],
621
        'quotientList': [
622
            {
623
                'cdquo': 'QS',
624
                'cdquo_text': 'QUOTIENT SCOLAIRE',
625
                'codeUti': None,
626
                'dateEnd': '2021-12-31T00:00:00+01:00',
627
                'dateStart': '2021-01-01T00:00:00+01:00',
628
                'mtt': 1500.33,
629
                'yearRev': 2020,
630
            },
631
            {
632
                'cdquo': 'MOY ECO',
633
                'cdquo_text': 'REVENU MOYEN ( MENSUEL OU ANNUEL)',
634
                'codeUti': None,
635
                'dateEnd': '2022-12-31T00:00:00+01:00',
636
                'dateStart': '2022-01-01T00:00:00+01:00',
637
                'mtt': 1500.44,
638
                'yearRev': 2021,
639
            },
640
        ],
617 641
        'indicatorList': [],
618 642
        'subscribeActivityList': [],
619 643
    }
620 644
    data = resp.json['data']['childList'][0]
621 645
    del data['medicalRecord']
622 646
    del data['authorizedPersonList']
623 647
    del data['paiInfoBean']
624 648
    assert data == {
......
736 760
@mock.patch('passerelle.utils.Request.post')
737 761
def test_read_rl1(mocked_post, mocked_get, con, app):
738 762
    mocked_get.return_value = FAMILY_SERVICE_WSDL
739 763
    mocked_post.side_effect = [
740 764
        READ_FAMILY,
741 765
        READ_CIVILITIES,
742 766
        READ_QUALITIES,
743 767
        READ_CSP,
768
        READ_QUOTIENT,
744 769
    ]
745 770
    url = get_endpoint('read-rl')
746 771
    Link.objects.create(resource=con, family_id='1312', name_id='local')
747 772

  
748 773
    resp = app.get(url + '?NameID=local&rl_id=613878')
749 774
    assert resp.json['err'] == 0
750 775
    assert resp.json['data']['firstname'] == 'JHON'
751 776

  
......
2116 2141
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2117 2142
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
2118 2143
    assert resp.json['err'] == 'wrong-key'
2119 2144
    assert (
2120 2145
        resp.json['err_desc'] == "adresse/numComp key value 'plop' do not belong to 'Complement' referential"
2121 2146
    )
2122 2147

  
2123 2148

  
2149
@mock.patch('passerelle.utils.Request.get')
2150
@mock.patch('passerelle.utils.Request.post')
2151
def test_update_quotient(mocked_post, mocked_get, con, app):
2152
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2153
    mocked_post.side_effect = [READ_QUOTIENT, UPDATE_QUOTIENT]
2154
    url = get_endpoint('update-quotient')
2155
    params = {
2156
        'yearRev': '2021',
2157
        'dateStart': '2022-10-01',
2158
        'dateEnd': '2023-01-31',
2159
        'mtt': '1500.33',
2160
        'cdquo': 'QS',
2161
    }
2162

  
2163
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2164
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
2165
    assert_sent_payload(mocked_post, 'Q_create_update_quotient.xml')
2166
    assert resp.json['err'] == 0
2167
    assert resp.json['data'] == 'ok'
2168

  
2169

  
2170
@mock.patch('passerelle.utils.Request.get')
2171
@mock.patch('passerelle.utils.Request.post')
2172
def test_update_quotient_schema_error(mocked_post, mocked_get, con, app):
2173
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2174
    mocked_post.side_effect = [READ_QUOTIENT, UPDATE_QUOTIENT]
2175
    url = get_endpoint('update-quotient')
2176
    params = {
2177
        'yearRev': '2021',
2178
        'dateStart': '2022-10-01',
2179
        'dateEnd': '2023-01-31',
2180
        'mtt': '1500,33',
2181
        'cdquo': 'QS',
2182
    }
2183

  
2184
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2185
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params, status=400)
2186
    assert resp.json['err'] == 1
2187
    assert resp.json['err_desc'] == "mtt: '1500,33' does not match '^[0-9]+\\\\.?[0-9]*$'"
2188

  
2189

  
2190
@mock.patch('passerelle.utils.Request.get')
2191
@mock.patch('passerelle.utils.Request.post')
2192
def test_update_quotient_soap_error(mocked_post, mocked_get, con, app):
2193
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2194
    mocked_post.side_effect = [READ_QUOTIENT, UPDATE_QUOTIENT_500]
2195
    url = get_endpoint('update-quotient')
2196
    params = {
2197
        'yearRev': '2021',
2198
        'dateStart': '2022-10-01',
2199
        'dateEnd': '2023-01-31',
2200
        'mtt': '1500.33',
2201
        'cdquo': 'QS',
2202
    }
2203

  
2204
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2205
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
2206
    assert resp.json['err'] == 'Family-createUpdateQuotient-soap:Server'
2207
    assert 'E07 : Il existe déjà un quotient postérieur' in resp.json['err_desc']
2208

  
2209

  
2210
@mock.patch('passerelle.utils.Request.get')
2211
@mock.patch('passerelle.utils.Request.post')
2212
def test_update_quotient_wrong_referential_key_error(mocked_post, mocked_get, con, app):
2213
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2214
    mocked_post.return_value = READ_QUOTIENT
2215
    url = get_endpoint('update-quotient')
2216
    params = {
2217
        'yearRev': '2021',
2218
        'dateStart': '2023-10-01',
2219
        'dateEnd': '2023-01-31',
2220
        'mtt': '1500.33',
2221
        'cdquo': 'plop',
2222
    }
2223

  
2224
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2225
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
2226
    assert resp.json['err'] == 'wrong-key'
2227
    assert resp.json['err_desc'] == "cdquo key value 'plop' do not belong to 'Quotient' required referential"
2228

  
2229

  
2124 2230
@mock.patch('passerelle.utils.Request.get')
2125 2231
@mock.patch('passerelle.utils.Request.post')
2126 2232
def test_create_person(mocked_post, mocked_get, con, app):
2127 2233
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2128 2234
    mocked_post.side_effect = [READ_FAMILY, READ_QUALITIES, UPDATE_FAMILY]
2129 2235
    url = get_endpoint('create-person')
2130 2236
    params = {
2131 2237
        'civility': None,
2132
-