Projet

Général

Profil

0005-toulouse-maelis-add-endpoint-to-delete-child-person-.patch

Nicolas Roche, 05 octobre 2022 09:14

Télécharger (7,03 ko)

Voir les différences:

Subject: [PATCH 5/5] toulouse-maelis: add endpoint to delete child person
 (#69891)

 passerelle/contrib/toulouse_maelis/models.py  | 35 ++++++++++++++
 .../toulouse_maelis/Q_delete_child_person.xml | 20 ++++++++
 tests/test_toulouse_maelis.py                 | 47 +++++++++++++++++++
 3 files changed, 102 insertions(+)
 create mode 100644 tests/data/toulouse_maelis/Q_delete_child_person.xml
passerelle/contrib/toulouse_maelis/models.py
915 915
            'numPerson': child_id,
916 916
            'bLeaveAlone': child['bLeaveAlone'],
917 917
            'bPhoto': child['bPhoto'],
918 918
            'personList': personList,
919 919
        }
920 920
        self.call('Family', 'updateChildAutorization', updateChildAutorizationRequest=req)
921 921
        return {'data': 'ok'}
922 922

  
923
    @endpoint(
924
        display_category='Famille',
925
        description="Suppression d'une personne autorisée à récupérer les enfants ou à prévenir en cas d'urgence",
926
        name='delete-child-person',
927
        perm='can_access',
928
        parameters={
929
            'NameID': {'description': 'Publik NameID'},
930
            'child_id': {'description': "Numéro de l'enfant"},
931
            'person_id': {'description': 'Numéro de la personne'},
932
        },
933
        methods=['post'],
934
    )
935
    def delete_child_person(self, request, NameID, child_id, person_id):
936
        family_id = self.get_link(NameID).family_id
937
        child = self.get_child_raw(family_id, child_id)
938

  
939
        personList = child['authorizedPersonList']
940
        for i, person in enumerate(personList):
941
            if str(person['personInfo']['num']) == person_id:
942
                del personList[i]
943
                break
944
        else:
945
            raise APIError(
946
                "No '%s' authorized person on '%s' child" % (person_id, child_id), err_code='not-found'
947
            )
948
        req = {
949
            'numFamily': family_id,
950
            'numPerson': child_id,
951
            'bLeaveAlone': child['bLeaveAlone'],
952
            'bPhoto': child['bPhoto'],
953
            'personList': personList,
954
        }
955
        self.call('Family', 'updateChildAutorization', updateChildAutorizationRequest=req)
956
        return {'data': 'ok'}
957

  
923 958
    @endpoint(
924 959
        display_category='Famille',
925 960
        description="Créer ou mettre à jour le régime alimentaire d'un enfant",
926 961
        name='update-child-dietcode',
927 962
        perm='can_access',
928 963
        parameters={
929 964
            'NameID': {'description': 'Publik NameID'},
930 965
            'child_id': {'description': "Numéro de l'enfant"},
tests/data/toulouse_maelis/Q_delete_child_person.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:updateChildAutorization xmlns:ns0="family.ws.maelis.sigec.com">
12
      <updateChildAutorizationRequest>
13
        <numFamily>1312</numFamily>
14
        <numPerson>613880</numPerson>
15
        <bLeaveAlone>false</bLeaveAlone>
16
        <bPhoto>true</bPhoto>
17
      </updateChildAutorizationRequest>
18
    </ns0:updateChildAutorization>
19
  </soap-env:Body>
20
</soap-env:Envelope>
tests/test_toulouse_maelis.py
1984 1984
    }
1985 1985

  
1986 1986
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1987 1987
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=000000', params=params)
1988 1988
    assert resp.json['err'] == 'not-found'
1989 1989
    assert resp.json['err_desc'] == "No '000000' authorized person on '613880' child"
1990 1990

  
1991 1991

  
1992
@mock.patch('passerelle.utils.Request.get')
1993
@mock.patch('passerelle.utils.Request.post')
1994
def test_delete_child_person(mocked_post, mocked_get, con, app):
1995
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1996
    mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
1997
    url = get_endpoint('delete-child-person')
1998

  
1999
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2000
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=614719')
2001
    assert_sent_payload(mocked_post, 'Q_delete_child_person.xml')
2002
    assert resp.json['err'] == 0
2003

  
2004

  
2005
def test_delete_child_person_not_linked_error(con, app):
2006
    url = get_endpoint('delete-child-person')
2007

  
2008
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=614719')
2009
    assert resp.json['err'] == 'not-linked'
2010
    assert resp.json['err_desc'] == 'User not linked to family'
2011

  
2012

  
2013
@mock.patch('passerelle.utils.Request.get')
2014
@mock.patch('passerelle.utils.Request.post')
2015
def test_delete_child_person_no_child_error(mocked_post, mocked_get, con, app):
2016
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2017
    mocked_post.side_effect = [READ_FAMILY]
2018
    url = get_endpoint('delete-child-person')
2019

  
2020
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2021
    resp = app.post_json(url + '?NameID=local&child_id=42&person_id=614719')
2022
    assert resp.json['err'] == 'not-found'
2023
    assert resp.json['err_desc'] == "no '42' child on '1312' family"
2024

  
2025

  
2026
@mock.patch('passerelle.utils.Request.get')
2027
@mock.patch('passerelle.utils.Request.post')
2028
def test_delete_child_person_no_person_error(mocked_post, mocked_get, con, app):
2029
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2030
    mocked_post.side_effect = [READ_FAMILY]
2031
    url = get_endpoint('delete-child-person')
2032

  
2033
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2034
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=000000')
2035
    assert resp.json['err'] == 'not-found'
2036
    assert resp.json['err_desc'] == "No '000000' authorized person on '613880' child"
2037

  
2038

  
1992 2039
@mock.patch('passerelle.utils.Request.get')
1993 2040
@mock.patch('passerelle.utils.Request.post')
1994 2041
def test_update_child_dietcode(mocked_post, mocked_get, con, app):
1995 2042
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1996 2043
    mocked_post.return_value = UPDATE_DIETCODE
1997 2044
    url = get_endpoint('update-child-dietcode')
1998 2045

  
1999 2046
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2000
-