0001-toulouse-maelis-add-enpoints-to-list-family-members-.patch
functests/toulouse_maelis/test_family.py | ||
---|---|---|
807 | 807 | |
808 | 808 |
# test read-family with reference year |
809 | 809 |
url = conn + '/read-family?NameID=%s&income_year=%s' % (create_data['name_id'], '2020') |
810 | 810 |
resp = requests.get(url) |
811 | 811 |
resp.raise_for_status() |
812 | 812 |
res = resp.json() |
813 | 813 |
assert res['err'] == 0 |
814 | 814 |
return len(res['data']['RL1']['quotientList']) == 1 |
815 | ||
816 | ||
817 |
def test_read_family_members(conn, update_data): |
|
818 |
unlink(conn, update_data['name_id']) |
|
819 |
link(conn, update_data) |
|
820 | ||
821 |
# list RLs |
|
822 |
text_template = '{{ firstname }}' |
|
823 |
url = conn + '/read-rl-list?NameID=%s&text_template=%s' % (update_data['name_id'], text_template) |
|
824 |
resp = requests.get(url) |
|
825 |
resp.raise_for_status() |
|
826 |
res = resp.json() |
|
827 |
assert res['err'] == 0 |
|
828 |
assert len(res['data']) == 2 |
|
829 |
assert res['data'][1]['text'] == 'HOMER' |
|
830 | ||
831 |
# get RL |
|
832 |
rl_id = res['data'][1]['id'] |
|
833 |
url = conn + '/read-rl?NameID=%s&rl_id=%s' % (update_data['name_id'], rl_id) |
|
834 |
resp = requests.get(url) |
|
835 |
resp.raise_for_status() |
|
836 |
res = resp.json() |
|
837 |
assert res['err'] == 0 |
|
838 |
assert res['data']['firstname'] == 'HOMER' |
|
839 | ||
840 |
# list persons |
|
841 |
text_template = '{{ firstname }}' |
|
842 |
url = conn + '/read-person-list?NameID=%s&text_template=%s' % (update_data['name_id'], text_template) |
|
843 |
resp = requests.get(url) |
|
844 |
resp.raise_for_status() |
|
845 |
res = resp.json() |
|
846 |
assert res['err'] == 0 |
|
847 |
assert len(res['data']) == 2 |
|
848 |
assert res['data'][1]['text'] == 'SELMA' |
|
849 | ||
850 |
# get person |
|
851 |
person_id = res['data'][1]['id'] |
|
852 |
url = conn + '/read-person?NameID=%s&person_id=%s' % (update_data['name_id'], person_id) |
|
853 |
resp = requests.get(url) |
|
854 |
resp.raise_for_status() |
|
855 |
res = resp.json() |
|
856 |
assert res['err'] == 0 |
|
857 |
assert res['data']['firstname'] == 'SELMA' |
|
858 | ||
859 |
# list childs |
|
860 |
text_template = '{{ firstname }}' |
|
861 |
url = conn + '/read-child-list?NameID=%s&text_template=%s' % (update_data['name_id'], text_template) |
|
862 |
resp = requests.get(url) |
|
863 |
resp.raise_for_status() |
|
864 |
res = resp.json() |
|
865 |
assert res['err'] == 0 |
|
866 |
assert len(res['data']) == 3 |
|
867 |
assert res['data'][0]['text'] == 'BART' |
|
868 | ||
869 |
# get child |
|
870 |
child_id = res['data'][0]['id'] |
|
871 |
url = conn + '/read-child?NameID=%s&child_id=%s' % (update_data['name_id'], child_id) |
|
872 |
resp = requests.get(url) |
|
873 |
resp.raise_for_status() |
|
874 |
res = resp.json() |
|
875 |
assert res['err'] == 0 |
|
876 |
assert res['data']['firstname'] == 'BART' |
|
877 | ||
878 |
# list child persons |
|
879 |
text_template = '{{ personInfo.firstname }}' |
|
880 |
url = conn + '/read-child-person-list?NameID=%s&child_id=%s&text_template=%s' % ( |
|
881 |
update_data['name_id'], |
|
882 |
child_id, |
|
883 |
text_template, |
|
884 |
) |
|
885 |
resp = requests.get(url) |
|
886 |
resp.raise_for_status() |
|
887 |
res = resp.json() |
|
888 |
assert res['err'] == 0 |
|
889 |
assert len(res['data']) == 2 |
|
890 |
assert res['data'][0]['text'] == 'ABRAHAM JEBEDIAH' |
|
891 | ||
892 |
# get child person |
|
893 |
person_id = res['data'][0]['id'] |
|
894 |
url = conn + '/read-child-person?NameID=%s&child_id=%s&person_id=%s' % ( |
|
895 |
update_data['name_id'], |
|
896 |
child_id, |
|
897 |
person_id, |
|
898 |
) |
|
899 |
resp = requests.get(url) |
|
900 |
resp.raise_for_status() |
|
901 |
res = resp.json() |
|
902 |
assert res['err'] == 0 |
|
903 |
assert res['data']['personInfo']['firstname'] == 'ABRAHAM JEBEDIAH' |
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
21 | 21 |
from django.utils.timezone import now |
22 | 22 |
from zeep.helpers import serialize_object |
23 | 23 |
from zeep.wsse.username import UsernameToken |
24 | 24 | |
25 | 25 |
from passerelle.base.models import BaseResource, HTTPResource |
26 | 26 |
from passerelle.utils.api import endpoint |
27 | 27 |
from passerelle.utils.conversion import simplify |
28 | 28 |
from passerelle.utils.jsonresponse import APIError |
29 |
from passerelle.utils.templates import render_to_string |
|
29 | 30 | |
30 | 31 |
from . import schemas |
31 | 32 | |
32 | 33 | |
33 | 34 |
class UpdateError(Exception): |
34 | 35 |
pass |
35 | 36 | |
36 | 37 | |
... | ... | |
734 | 735 |
'income_year': {'description': 'Année de revenu pour filtrer les quotients'}, |
735 | 736 |
}, |
736 | 737 |
) |
737 | 738 |
def read_family(self, request, NameID, income_year=None): |
738 | 739 |
family_id = self.get_link(NameID).family_id |
739 | 740 |
data = self.get_family(family_id, incomeYear=income_year) |
740 | 741 |
return {'data': data} |
741 | 742 | |
743 |
@endpoint( |
|
744 |
display_category='Famille', |
|
745 |
description="Liste des responsables légaux", |
|
746 |
perm='can_access', |
|
747 |
name='read-rl-list', |
|
748 |
parameters={ |
|
749 |
'NameID': {'description': 'Publik NameID'}, |
|
750 |
'text_template': { |
|
751 |
'description': 'template utilisée pour la valeur text', |
|
752 |
'example_value': '{{ lastname }} {{ firstname }}', |
|
753 |
}, |
|
754 |
'income_year': {'description': 'Année de revenu pour filtrer les quotients'}, |
|
755 |
}, |
|
756 |
) |
|
757 |
def read_rl_list(self, request, NameID, text_template=None, income_year=None): |
|
758 |
family_id = self.get_link(NameID).family_id |
|
759 |
result = self.get_family_raw(family_id, incomeYear=income_year) |
|
760 |
if not text_template: |
|
761 |
text_template = '{{ lastname }} {{ firstname }}' |
|
762 | ||
763 |
data = [] |
|
764 |
for rlg in 'RL1', 'RL2': |
|
765 |
item = result.get(rlg) |
|
766 |
self.add_text_value_to_rl(item) |
|
767 |
if not item: |
|
768 |
break |
|
769 |
item['id'] = item['num'] |
|
770 |
item['text'] = render_to_string(text_template, item).strip() |
|
771 |
item['family_id'] = family_id |
|
772 |
data.append(item) |
|
773 |
return {'data': data} |
|
774 | ||
775 |
@endpoint( |
|
776 |
display_category='Famille', |
|
777 |
description="Liste des personnes à prévenir en cas d'urgence", |
|
778 |
perm='can_access', |
|
779 |
name='read-person-list', |
|
780 |
parameters={ |
|
781 |
'NameID': {'description': 'Publik NameID'}, |
|
782 |
'text_template': { |
|
783 |
'description': 'template utilisée pour la valeur text', |
|
784 |
'example_value': '{{ lastname }} {{ firstname }}', |
|
785 |
}, |
|
786 |
}, |
|
787 |
) |
|
788 |
def read_person_list(self, request, NameID, text_template=None): |
|
789 |
family_id = self.get_link(NameID).family_id |
|
790 |
result = self.get_family_raw(family_id) |
|
791 |
if not text_template: |
|
792 |
text_template = '{{ lastname }} {{ firstname }}' |
|
793 | ||
794 |
data = [] |
|
795 |
for item in result['emergencyPersonList']: |
|
796 |
self.add_text_value_to_person(item) |
|
797 |
item['id'] = item['numPerson'] |
|
798 |
item['text'] = render_to_string(text_template, item).strip() |
|
799 |
item['family_id'] = family_id |
|
800 |
data.append(item) |
|
801 |
return {'data': data} |
|
802 | ||
803 |
@endpoint( |
|
804 |
display_category='Famille', |
|
805 |
description="Liste des enfants", |
|
806 |
perm='can_access', |
|
807 |
name='read-child-list', |
|
808 |
parameters={ |
|
809 |
'NameID': {'description': 'Publik NameID'}, |
|
810 |
'text_template': { |
|
811 |
'description': 'template utilisée pour la valeur text', |
|
812 |
'example_value': '{{ lastname }} {{ firstname }}', |
|
813 |
}, |
|
814 |
}, |
|
815 |
) |
|
816 |
def read_child_list(self, request, NameID, text_template=None): |
|
817 |
family_id = self.get_link(NameID).family_id |
|
818 |
result = self.get_family_raw(family_id) |
|
819 |
if not text_template: |
|
820 |
text_template = '{{ lastname }} {{ firstname }}' |
|
821 | ||
822 |
data = [] |
|
823 |
for item in result['childList']: |
|
824 |
self.add_text_value_to_child(item) |
|
825 |
item['id'] = item['num'] |
|
826 |
item['text'] = render_to_string(text_template, item).strip() |
|
827 |
item['family_id'] = family_id |
|
828 |
data.append(item) |
|
829 |
return {'data': data} |
|
830 | ||
831 |
@endpoint( |
|
832 |
display_category='Famille', |
|
833 |
description="Liste des personnes autorisées à récupérer l'enfant", |
|
834 |
perm='can_access', |
|
835 |
name='read-child-person-list', |
|
836 |
parameters={ |
|
837 |
'NameID': {'description': 'Publik NameID'}, |
|
838 |
'child_id': {'description': "Numéro de l'enfant"}, |
|
839 |
'text_template': { |
|
840 |
'description': 'template utilisée pour la valeur text', |
|
841 |
'example_value': '{{ personInfo.lastname }} {{ personInfo.firstname }}', |
|
842 |
}, |
|
843 |
}, |
|
844 |
) |
|
845 |
def read_child_person_list(self, request, NameID, child_id, text_template=None): |
|
846 |
family_id = self.get_link(NameID).family_id |
|
847 |
result = self.get_child_raw(family_id, child_id) |
|
848 |
if not text_template: |
|
849 |
text_template = '{{ personInfo.lastname }} {{ personInfo.firstname }}' |
|
850 | ||
851 |
data = [] |
|
852 |
for item in result['authorizedPersonList']: |
|
853 |
self.add_text_value_to_child_person(item) |
|
854 |
item['id'] = item['personInfo']['num'] |
|
855 |
item['text'] = render_to_string(text_template, item).strip() |
|
856 |
item['family_id'] = family_id |
|
857 |
data.append(item) |
|
858 |
return {'data': data} |
|
859 | ||
742 | 860 |
@endpoint( |
743 | 861 |
display_category='Famille', |
744 | 862 |
description="Informations sur un responsable légal", |
745 | 863 |
perm='can_access', |
746 | 864 |
name='read-rl', |
747 | 865 |
parameters={ |
748 | 866 |
'NameID': {'description': 'Publik NameID'}, |
749 | 867 |
'rl_id': {'description': 'Numéro du représentant légal'}, |
... | ... | |
752 | 870 |
) |
753 | 871 |
def read_rl(self, request, NameID, rl_id, income_year=None): |
754 | 872 |
family_id = self.get_link(NameID).family_id |
755 | 873 |
data = self.get_rl(family_id, rl_id, incomeYear=income_year) |
756 | 874 |
return {'data': data} |
757 | 875 | |
758 | 876 |
@endpoint( |
759 | 877 |
display_category='Famille', |
760 |
description="Informations sur une personne autorisée à récupérer les enfants ou à prévenir en cas d'urgence",
|
|
878 |
description="Informations sur une personne autorisée à récupérer les enfants", |
|
761 | 879 |
perm='can_access', |
762 | 880 |
name='read-person', |
763 | 881 |
parameters={ |
764 | 882 |
'NameID': {'description': 'Publik NameID'}, |
765 | 883 |
'person_id': {'description': 'Numéro de la personne'}, |
766 | 884 |
}, |
767 | 885 |
) |
768 | 886 |
def read_person(self, request, NameID, person_id): |
tests/test_toulouse_maelis.py | ||
---|---|---|
661 | 661 |
'id': 'DTC', |
662 | 662 |
'code': 'DTC', |
663 | 663 |
'text': 'DIPHTERIE TETANOS COQUELUCHE', |
664 | 664 |
'libelle': 'DIPHTERIE TETANOS COQUELUCHE', |
665 | 665 |
}, |
666 | 666 |
] |
667 | 667 | |
668 | 668 | |
669 |
def test_read_rl_list(family_service, con, app): |
|
670 |
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml')) |
|
671 |
url = get_endpoint('read-rl-list') |
|
672 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
673 | ||
674 |
resp = app.get(url + '?NameID=local') |
|
675 |
assert resp.json['err'] == 0 |
|
676 |
assert [(x['id'], x['text']) for x in resp.json['data']] == [ |
|
677 |
('613878', 'DOE JHON'), |
|
678 |
('613879', 'DOE JANE'), |
|
679 |
] |
|
680 | ||
681 |
resp = app.get(url + '?NameID=local&text_template={{ birth.dateBirth|date:"d/m/Y" }}') |
|
682 |
assert resp.json['err'] == 0 |
|
683 |
assert [(x['id'], x['text']) for x in resp.json['data']] == [ |
|
684 |
('613878', '25/07/1938'), |
|
685 |
('613879', '21/06/1940'), |
|
686 |
] |
|
687 | ||
688 | ||
689 |
def test_read_rl_list_not_linked_error(con, app): |
|
690 |
url = get_endpoint('read-rl-list') |
|
691 | ||
692 |
resp = app.get(url + '?NameID=local') |
|
693 |
assert resp.json['err'] == 'not-linked' |
|
694 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
695 | ||
696 | ||
697 |
def test_read_person_list(family_service, con, app): |
|
698 |
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml')) |
|
699 |
url = get_endpoint('read-person-list') |
|
700 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
701 | ||
702 |
resp = app.get(url + '?NameID=local') |
|
703 |
assert resp.json['err'] == 0 |
|
704 |
assert [(x['id'], x['text']) for x in resp.json['data']] == [(614059, 'ARKANA KENY')] |
|
705 | ||
706 |
resp = app.get(url + '?NameID=local&text_template={{ dateBirth|date:"d/m/Y" }}') |
|
707 |
assert resp.json['err'] == 0 |
|
708 |
assert [(x['id'], x['text']) for x in resp.json['data']] == [(614059, '19/12/1982')] |
|
709 | ||
710 | ||
711 |
def test_read_person_list_not_linked_error(con, app): |
|
712 |
url = get_endpoint('read-person-list') |
|
713 | ||
714 |
resp = app.get(url + '?NameID=local') |
|
715 |
assert resp.json['err'] == 'not-linked' |
|
716 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
717 | ||
718 | ||
719 |
def test_read_child_list(family_service, con, app): |
|
720 |
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml')) |
|
721 |
url = get_endpoint('read-child-list') |
|
722 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
723 | ||
724 |
resp = app.get(url + '?NameID=local') |
|
725 |
assert resp.json['err'] == 0 |
|
726 |
assert [(x['id'], x['text']) for x in resp.json['data']] == [ |
|
727 |
('613880', 'DOE JANNIS'), |
|
728 |
('613987', 'DOE JOHNNY ALLEN'), |
|
729 |
('614051', 'DOE ROBERT'), |
|
730 |
] |
|
731 | ||
732 |
resp = app.get(url + '?NameID=local&text_template={{ birth.dateBirth|date:"d/m/Y" }}') |
|
733 |
assert resp.json['err'] == 0 |
|
734 |
assert [(x['id'], x['text']) for x in resp.json['data']] == [ |
|
735 |
('613880', '18/01/1943'), |
|
736 |
('613987', '26/11/1942'), |
|
737 |
('614051', '23/05/1941'), |
|
738 |
] |
|
739 | ||
740 | ||
741 |
def test_read_child_list_not_linked_error(con, app): |
|
742 |
url = get_endpoint('read-child-list') |
|
743 | ||
744 |
resp = app.get(url + '?NameID=local') |
|
745 |
assert resp.json['err'] == 'not-linked' |
|
746 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
747 | ||
748 | ||
749 |
def test_read_child_person_list(family_service, con, app): |
|
750 |
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml')) |
|
751 |
url = get_endpoint('read-child-person-list') |
|
752 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
753 | ||
754 |
resp = app.get(url + '?NameID=local&child_id=613880') |
|
755 |
assert resp.json['err'] == 0 |
|
756 |
assert [(x['id'], x['text']) for x in resp.json['data']] == [(614719, 'BENT AMEL')] |
|
757 | ||
758 |
resp = app.get( |
|
759 |
url + '?NameID=local&child_id=613880&text_template={{ personInfo.dateBirth|date:"d/m/Y" }}' |
|
760 |
) |
|
761 |
assert resp.json['err'] == 0 |
|
762 |
assert [(x['id'], x['text']) for x in resp.json['data']] == [(614719, '20/06/1985')] |
|
763 | ||
764 | ||
765 |
def test_read_child_person_list_not_linked_error(con, app): |
|
766 |
url = get_endpoint('read-child-person-list') |
|
767 | ||
768 |
resp = app.get(url + '?NameID=local&child_id=613880') |
|
769 |
assert resp.json['err'] == 'not-linked' |
|
770 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
771 | ||
772 | ||
773 |
def test_read_child_person_list_not_exists_error(family_service, con, app): |
|
774 |
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml')) |
|
775 |
url = get_endpoint('read-child-person-list') |
|
776 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
777 | ||
778 |
resp = app.get(url + '?NameID=local&child_id=42') |
|
779 |
assert resp.json['err'] == 'not-found' |
|
780 |
assert resp.json['err_desc'] == "no '42' child on '1312' family" |
|
781 | ||
782 | ||
669 | 783 |
@pytest.mark.parametrize( |
670 | 784 |
"xml", ['R_read_family.xml', 'R_read_family_relax.xml', 'R_read_family_reordered.xml'] |
671 | 785 |
) |
672 | 786 |
def test_read_family(family_service, xml, con, app): |
673 | 787 |
family_service.add_soap_response('readFamily', get_xml_file(xml)) |
674 | 788 |
url = get_endpoint('read-family') |
675 | 789 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
676 | 790 | |
677 |
- |