Project

General

Profile

0002-toulouse-maelis-allow-to-send-an-empty-dietcode-7164.patch

Nicolas Roche, 24 November 2022 11:47 AM

Download (4.73 KB)

View differences:

Subject: [PATCH 2/4] toulouse-maelis: allow to send an empty dietcode (#71643)

 passerelle/contrib/toulouse_maelis/models.py |  4 ++--
 tests/test_toulouse_maelis.py                | 16 +---------------
 2 files changed, 3 insertions(+), 17 deletions(-)
passerelle/contrib/toulouse_maelis/models.py
284 284
        keys = parent_keys or []
285 285
        self.assert_post_data_in_referential('Sex', post_data, keys + ['sexe'])
286 286

  
287 287
        data = post_data
288 288
        for key in keys:
289 289
            data = data[key]
290 290

  
291 291
        if 'dietcode' in data:
292
            self.assert_post_data_in_referential('DietCode', post_data, keys + ['dietcode'])
292
            self.assert_post_data_in_referential('DietCode', post_data, keys + ['dietcode'], required=False)
293 293
        if 'paiInfoBean' in data:
294 294
            self.assert_child_pai_payoad_in_referential(post_data, keys + ['paiInfoBean'])
295 295
        if 'medicalRecord' in data:
296 296
            # dead code as updateFamily seems not to modify medicalRecord
297 297
            self.assert_child_medical_record_payload_in_referential(post_data, keys + ['medicalRecord'])
298 298

  
299 299
    def assert_person_payload_in_referential(self, post_data, parent_keys=None):
300 300
        keys = parent_keys or []
......
1048 1048
            'NameID': {'description': 'Publik NameID'},
1049 1049
            'child_id': {'description': "Numéro de l'enfant"},
1050 1050
            'dietcode': {'description': 'code du régime alimentaire'},
1051 1051
        },
1052 1052
        methods=['post'],
1053 1053
    )
1054 1054
    def update_child_dietcode(self, request, NameID, child_id, dietcode):
1055 1055
        self.get_link(NameID)
1056
        self.assert_key_in_referential('DietCode', dietcode, 'dietcode parameter')
1056
        self.assert_key_in_referential('DietCode', dietcode, 'dietcode parameter', required=False)
1057 1057

  
1058 1058
        self.call('Family', 'createOrUpdateChildDiet', personNumber=child_id, code=dietcode)
1059 1059
        return {'data': 'ok'}
1060 1060

  
1061 1061
    @endpoint(
1062 1062
        display_category='Famille',
1063 1063
        description="Créer ou mettre à jour les informations relatives au PAI d'un enfant",
1064 1064
        name='update-child-pai',
tests/test_toulouse_maelis.py
2611 2611
def test_update_child_dietcode_not_linked_error(con, app):
2612 2612
    url = get_endpoint('update-child-dietcode')
2613 2613

  
2614 2614
    resp = app.post_json(url + '?NameID=local&child_id=613878&dietcode=RVS')
2615 2615
    assert resp.json['err'] == 'not-linked'
2616 2616
    assert resp.json['err_desc'] == 'User not linked to family'
2617 2617

  
2618 2618

  
2619
@mock.patch('passerelle.utils.Request.get')
2620
@mock.patch('passerelle.utils.Request.post')
2621
def test_update_child_dietcode_empty_referential_key_error(mocked_post, mocked_get, con, app):
2622
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2623
    mocked_post.side_effect = [READ_DIETCODE, UPDATE_DIETCODE]
2624
    url = get_endpoint('update-child-dietcode')
2625

  
2626
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2627
    resp = app.post_json(url + '?NameID=local&child_id=613878&dietcode=')
2628
    assert resp.json['err'] == 'field-required'
2629
    assert resp.json['err_desc'] == "dietcode parameter is required and could not be None"
2630

  
2631

  
2632 2619
@mock.patch('passerelle.utils.Request.get')
2633 2620
@mock.patch('passerelle.utils.Request.post')
2634 2621
def test_update_child_dietcode_wrong_referential_key_error(mocked_post, mocked_get, con, app):
2635 2622
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2636 2623
    mocked_post.side_effect = [READ_DIETCODE, UPDATE_DIETCODE]
2637 2624
    url = get_endpoint('update-child-dietcode')
2638 2625

  
2639 2626
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2640 2627
    resp = app.post_json(url + '?NameID=local&child_id=613878&dietcode=plop')
2641 2628
    assert resp.json['err'] == 'wrong-key'
2642 2629
    assert (
2643
        resp.json['err_desc']
2644
        == "dietcode parameter key value 'plop' do not belong to 'DietCode' required referential"
2630
        resp.json['err_desc'] == "dietcode parameter key value 'plop' do not belong to 'DietCode' referential"
2645 2631
    )
2646 2632

  
2647 2633

  
2648 2634
@mock.patch('passerelle.utils.Request.get')
2649 2635
@mock.patch('passerelle.utils.Request.post')
2650 2636
def test_update_child_pai(mocked_post, mocked_get, con, app):
2651 2637
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2652 2638
    mocked_post.side_effect = [READ_PAI, UPDATE_PAI]
2653
-