Projet

Général

Profil

0001-caluire-axel-fix-register_activity-endpoint-54400.patch

Lauréline Guérin, 28 mai 2021 18:39

Télécharger (15,1 ko)

Voir les différences:

Subject: [PATCH] caluire-axel: fix register_activity endpoint (#54400)

 passerelle/contrib/caluire_axel/models.py     |  1 +
 passerelle/contrib/caluire_axel/schemas.py    |  2 +-
 .../xsd/R_CreateInscriptionActivite.xsd       |  2 +-
 passerelle/contrib/utils/axel.py              |  5 +-
 tests/test_caluire_axel.py                    | 49 +++++++++----------
 5 files changed, 30 insertions(+), 29 deletions(-)
passerelle/contrib/caluire_axel/models.py
367 367
            raise APIError('Child not found', err_code='not-found')
368 368
        child_data.pop('id', None)
369 369
        child_data.pop('text', None)
370
        child_data.pop('FAMILLE', None)
370 371

  
371 372
        start_date = datetime.datetime.strptime(
372 373
            post_data['registration_start_date'], axel.json_date_format
passerelle/contrib/caluire_axel/schemas.py
77 77
get_individu = Operation('GetIndividu')
78 78
get_list_ecole = Operation('GetListEcole')
79 79
get_list_activites = Operation('GetListActivites')
80
create_inscription_activite = Operation('CreateInscriptionActivite')
80
create_inscription_activite = Operation('CreateInscriptionActivite', data_method='setData')
81 81

  
82 82

  
83 83
LINK_SCHEMA = copy.deepcopy(
passerelle/contrib/caluire_axel/xsd/R_CreateInscriptionActivite.xsd
24 24
	<xsd:complexType name="CREATEINSCRIPTIONACTIVITEType">
25 25
		<xsd:sequence>
26 26
			<xsd:element ref="CODE" />
27
			<xsd:element ref="IDENTINDIVIDU"/>
27
			<xsd:element ref="IDENTINDIVIDU" minOccurs="0" maxOccurs="1"/>
28 28
		</xsd:sequence> 
29 29
	</xsd:complexType>
30 30
	
passerelle/contrib/utils/axel.py
201 201
    default_prefix = ''
202 202
    axel_schema = AxelSchema
203 203

  
204
    def __init__(self, operation, prefix=None, request_root_element='PORTAIL'):
204
    def __init__(self, operation, prefix=None, request_root_element='PORTAIL', data_method='getData'):
205 205
        if prefix is None:
206 206
            prefix = self.default_prefix
207 207
        self.operation = operation
......
215 215
            '(.?)([A-Z])', lambda s: s.group(1) + ('-' if s.group(1) else '') + s.group(2).lower(), operation
216 216
        )
217 217
        self.snake_name = self.name.replace('-', '_')
218
        self.data_method = data_method
218 219

  
219 220
    @property
220 221
    def request_schema(self):
......
239 240
            except xmlschema.XMLSchemaValidationError as e:
240 241
                raise AxelError('invalid request %s' % str(e), xml_request=serialized_request)
241 242

  
242
        result = client.service.getData(
243
        result = getattr(client.service, self.data_method)(
243 244
            self.operation, serialized_request, ''
244 245
        )  # FIXME: What is the user parameter for ?
245 246

  
tests/test_caluire_axel.py
85 85

  
86 86

  
87 87
@contextmanager
88
def mock_getdata(content, operation):
88
def mock_data(content, operation, data_method='getData'):
89 89
    with mock.patch('passerelle.contrib.caluire_axel.models.CaluireAxel.soap_client') as client:
90 90
        resp = '''
91 91
        <?xml version="1.0"?>
......
104 104
            operation,
105 105
            content,
106 106
        )
107
        client.return_value.service.getData.return_value = resp
107
        getattr(client.return_value.service, data_method).return_value = resp
108 108
        yield
109 109

  
110 110

  
......
171 171
</PORTAIL>
172 172
"""
173 173

  
174
    with mock_getdata('', 'FindIndividus'):
174
    with mock_data('', 'FindIndividus'):
175 175
        with mock.patch('xmlschema.XMLSchema.validate') as xml_validate:
176 176
            xml_validate.side_effect = xmlschema.XMLSchemaValidationError(None, None)
177 177
            resp = app.post_json('/caluire-axel/test/link?NameID=yyy', params=link_params)
......
238 238
</PORTAILSERVICE>"""
239 239
        % content
240 240
    )
241
    with mock_getdata(content, 'FindIndividus'):
241
    with mock_data(content, 'FindIndividus'):
242 242
        with mock.patch('passerelle.contrib.utils.axel.AxelSchema.decode') as decode:
243 243
            decode.side_effect = xmlschema.XMLSchemaValidationError(None, None)
244 244
            resp = app.post_json('/caluire-axel/test/link?NameID=yyy', params=link_params)
......
291 291
</PORTAIL>'''
292 292
        % xml_response
293 293
    )
294
    with mock_getdata(content, 'FindIndividus'):
294
    with mock_data(content, 'FindIndividus'):
295 295
        resp = app.post_json('/caluire-axel/test/link?NameID=yyy', params=link_params)
296 296
    assert resp.json['err_desc'] == "Person not found"
297 297
    assert resp.json['err'] == 'not-found'
......
312 312
</FINDINDIVIDUS></PORTAIL>"""
313 313
    # existing link but family_id is wrong
314 314
    link = Link.objects.create(resource=resource, name_id='yyy', family_id='YYY', person_id='42')
315
    with mock_getdata(content, 'FindIndividus'):
315
    with mock_data(content, 'FindIndividus'):
316 316
        resp = app.post_json('/caluire-axel/test/link?NameID=yyy', params=link_params)
317 317
    assert resp.json['err_desc'] == "Data conflict"
318 318
    assert resp.json['err'] == 'conflict'
......
321 321
    link.family_id = '12345'
322 322
    link.person_id = '35'
323 323
    link.save()
324
    with mock_getdata(content, 'FindIndividus'):
324
    with mock_data(content, 'FindIndividus'):
325 325
        resp = app.post_json('/caluire-axel/test/link?NameID=yyy', params=link_params)
326 326
    assert resp.json['err_desc'] == "Data conflict"
327 327
    assert resp.json['err'] == 'conflict'
......
344 344
</FINDINDIVIDUS></PORTAIL>"""
345 345
        % place
346 346
    )
347
    with mock_getdata(content, 'FindIndividus'):
347
    with mock_data(content, 'FindIndividus'):
348 348
        resp = app.post_json('/caluire-axel/test/link?NameID=yyy', params=link_params)
349 349
    assert set(resp.json.keys()) == set(['err', 'link', 'created', 'family_id', 'data'])
350 350
    assert resp.json['err'] == 0
......
354 354
    assert 'xml_response' in resp.json['data']
355 355

  
356 356
    # again
357
    with mock_getdata(content, 'FindIndividus'):
357
    with mock_data(content, 'FindIndividus'):
358 358
        resp = app.post_json('/caluire-axel/test/link?NameID=yyy', params=link_params)
359 359
    assert set(resp.json.keys()) == set(['err', 'link', 'created', 'family_id', 'data'])
360 360
    assert resp.json['err'] == 0
......
400 400
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
401 401
    with open(filepath) as xml:
402 402
        content = xml.read()
403
    with mock_getdata(content, 'GetFamilleIndividus'):
403
    with mock_data(content, 'GetFamilleIndividus'):
404 404
        resp = app.get('/caluire-axel/test/family_info?NameID=yyy')
405 405
    assert resp.json['err'] == 0
406 406
    assert set(resp.json['data'].keys()) == set(
......
441 441
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
442 442
    with open(filepath) as xml:
443 443
        content = xml.read()
444
    with mock_getdata(content, 'GetFamilleIndividus'):
444
    with mock_data(content, 'GetFamilleIndividus'):
445 445
        resp = app.get('/caluire-axel/test/children_info?NameID=yyy')
446 446
    assert resp.json['err'] == 0
447 447
    assert len(resp.json['data']) == 4
......
477 477
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
478 478
    with open(filepath) as xml:
479 479
        content = xml.read()
480
    with mock_getdata(content, 'GetFamilleIndividus'):
480
    with mock_data(content, 'GetFamilleIndividus'):
481 481
        resp = app.get('/caluire-axel/test/child_info?NameID=yyy&idpersonne=zzz')
482 482
    assert resp.json['err_desc'] == "Child not found"
483 483
    assert resp.json['err'] == 'not-found'
......
488 488
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
489 489
    with open(filepath) as xml:
490 490
        content = xml.read()
491
    with mock_getdata(content, 'GetFamilleIndividus'):
491
    with mock_data(content, 'GetFamilleIndividus'):
492 492
        resp = app.get('/caluire-axel/test/child_info?NameID=yyy&idpersonne=50632')
493 493
    assert resp.json['err'] == 0
494 494
    assert set(resp.json['data'].keys()) == set(
......
533 533
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/school_list.xml')
534 534
    with open(filepath) as xml:
535 535
        content = xml.read()
536
    with mock_getdata(content, 'GetListEcole'):
536
    with mock_data(content, 'GetListEcole'):
537 537
        resp = app.get(
538 538
            '/caluire-axel/test/school_list?num=42&street=street=rue%20Pasteur&zipcode=69300&city=Caluire%20et%20Cuire&schooling_date=2021-05-10'
539 539
        )
......
559 559
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
560 560
    with open(filepath) as xml:
561 561
        content = xml.read()
562
    with mock_getdata(content, 'GetFamilleIndividus'):
562
    with mock_data(content, 'GetFamilleIndividus'):
563 563
        with mock.patch('passerelle.contrib.caluire_axel.schemas.get_individu') as operation:
564 564
            operation.side_effect = AxelError('FooBar')
565 565
            resp = app.get(
......
591 591
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
592 592
    with open(filepath) as xml:
593 593
        content = xml.read()
594
    with mock_getdata(content, 'GetFamilleIndividus'):
594
    with mock_data(content, 'GetFamilleIndividus'):
595 595
        resp = app.get(
596 596
            '/caluire-axel/test/child_schooling_info?NameID=yyy&idpersonne=zzz&schooling_date=2021-05-10'
597 597
        )
......
604 604
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/schooling_info.xml')
605 605
    with open(filepath) as xml:
606 606
        content = xml.read()
607
    with mock_getdata(content, 'GetIndividu'):
607
    with mock_data(content, 'GetIndividu'):
608 608
        with mock.patch(
609 609
            'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
610 610
            return_value=family_data,
......
629 629
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
630 630
    with open(filepath) as xml:
631 631
        content = xml.read()
632
    with mock_getdata(content, 'GetFamilleIndividus'):
632
    with mock_data(content, 'GetFamilleIndividus'):
633 633
        with mock.patch('passerelle.contrib.caluire_axel.schemas.get_list_activites') as operation:
634 634
            operation.side_effect = AxelError('FooBar')
635 635
            resp = app.get(
......
661 661
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
662 662
    with open(filepath) as xml:
663 663
        content = xml.read()
664
    with mock_getdata(content, 'GetFamilleIndividus'):
664
    with mock_data(content, 'GetFamilleIndividus'):
665 665
        resp = app.get(
666 666
            '/caluire-axel/test/child_activities_info?NameID=yyy&idpersonne=zzz&schooling_date=2021-05-10'
667 667
        )
......
674 674
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/activities_info.xml')
675 675
    with open(filepath) as xml:
676 676
        content = xml.read()
677
    with mock_getdata(content, 'GetListActivites'):
677
    with mock_data(content, 'GetListActivites'):
678 678
        with mock.patch(
679 679
            'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
680 680
            return_value=family_data,
......
699 699
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
700 700
    with open(filepath) as xml:
701 701
        content = xml.read()
702
    with mock_getdata(content, 'GetFamilleIndividus'):
702
    with mock_data(content, 'GetFamilleIndividus'):
703 703
        with mock.patch('passerelle.contrib.caluire_axel.schemas.create_inscription_activite') as operation:
704 704
            operation.side_effect = AxelError('FooBar')
705 705
            resp = app.post_json(
......
720 720
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
721 721
    with open(filepath) as xml:
722 722
        content = xml.read()
723
    with mock_getdata(content, 'GetFamilleIndividus'):
723
    with mock_data(content, 'GetFamilleIndividus'):
724 724
        resp = app.post_json('/caluire-axel/test/register_activity?NameID=yyy', params=params)
725 725
    assert resp.json['err_desc'] == "Child not found"
726 726
    assert resp.json['err'] == 'not-found'
......
734 734
        <IDENTINDIVIDU>50632</IDENTINDIVIDU>
735 735
    </CREATEINSCRIPTIONACTIVITE>
736 736
</PORTAIL>'''
737
    with mock_getdata(content, 'CreateInscriptionActivite'):
737
    with mock_data(content, 'CreateInscriptionActivite', data_method='setData'):
738 738
        with mock.patch(
739 739
            'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
740 740
            return_value=family_data,
......
755 755
        '''<PORTAIL>
756 756
    <CREATEINSCRIPTIONACTIVITE>
757 757
        <CODE>%s</CODE>
758
        <IDENTINDIVIDU>50632</IDENTINDIVIDU>
759 758
    </CREATEINSCRIPTIONACTIVITE>
760 759
</PORTAIL>'''
761 760
        % code
762 761
    )
763
    with mock_getdata(content, 'CreateInscriptionActivite'):
762
    with mock_data(content, 'CreateInscriptionActivite', data_method='setData'):
764 763
        with mock.patch(
765 764
            'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
766 765
            return_value=family_data,
767
-