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 |
|
-
|