Projet

Général

Profil

0004-toulouse-maelis-add-endpoint-to-update-child-person-.patch

Nicolas Roche, 05 octobre 2022 09:14

Télécharger (9,12 ko)

Voir les différences:

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

 passerelle/contrib/toulouse_maelis/models.py  | 37 ++++++++
 .../toulouse_maelis/Q_update_child_person.xml | 37 ++++++++
 tests/test_toulouse_maelis.py                 | 87 +++++++++++++++++++
 3 files changed, 161 insertions(+)
 create mode 100644 tests/data/toulouse_maelis/Q_update_child_person.xml
passerelle/contrib/toulouse_maelis/models.py
878 878
            'numPerson': child_id,
879 879
            'bLeaveAlone': child['bLeaveAlone'],
880 880
            'bPhoto': child['bPhoto'],
881 881
            'personList': personList,
882 882
        }
883 883
        self.call('Family', 'updateChildAutorization', updateChildAutorizationRequest=req)
884 884
        return {'data': 'ok'}
885 885

  
886
    @endpoint(
887
        display_category='Famille',
888
        description="Mise à jour d'une personne autorisée à récupérer l'enfant",
889
        name='update-child-person',
890
        perm='can_access',
891
        parameters={
892
            'NameID': {'description': 'Publik NameID'},
893
            'child_id': {'description': "Numéro de l'enfant"},
894
            'person_id': {'description': 'Numéro de la personne'},
895
        },
896
        post={'request_body': {'schema': {'application/json': schemas.CHILDPERSON2_SCHEMA}}},
897
    )
898
    def update_child_person(self, request, NameID, child_id, person_id, post_data):
899
        family_id = self.get_link(NameID).family_id
900
        child = self.get_child_raw(family_id, child_id)
901
        self.replace_null_values(post_data)
902

  
903
        personList = child['authorizedPersonList']
904
        for i, person in enumerate(personList):
905
            if str(person['personInfo']['num']) == person_id:
906
                personList[i] = post_data
907
                personList[i]['personInfo']['num'] = person_id
908
                break
909
        else:
910
            raise APIError(
911
                "No '%s' authorized person on '%s' child" % (person_id, child_id), err_code='not-found'
912
            )
913
        req = {
914
            'numFamily': family_id,
915
            'numPerson': child_id,
916
            'bLeaveAlone': child['bLeaveAlone'],
917
            'bPhoto': child['bPhoto'],
918
            'personList': personList,
919
        }
920
        self.call('Family', 'updateChildAutorization', updateChildAutorizationRequest=req)
921
        return {'data': 'ok'}
922

  
886 923
    @endpoint(
887 924
        display_category='Famille',
888 925
        description="Créer ou mettre à jour le régime alimentaire d'un enfant",
889 926
        name='update-child-dietcode',
890 927
        perm='can_access',
891 928
        parameters={
892 929
            'NameID': {'description': 'Publik NameID'},
893 930
            'child_id': {'description': "Numéro de l'enfant"},
tests/data/toulouse_maelis/Q_update_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
        <personList>
16
          <personInfo>
17
            <num>614719</num>
18
            <civility>M.</civility>
19
            <lastname>Bent</lastname>
20
            <firstname>Angelo</firstname>
21
            <dateBirth>1985-06-22</dateBirth>
22
            <contact>
23
              <phone>0102030405</phone>
24
              <mobile/>
25
              <mail/>
26
            </contact>
27
          </personInfo>
28
          <personQuality>
29
            <code>O</code>
30
          </personQuality>
31
        </personList>
32
        <bLeaveAlone>false</bLeaveAlone>
33
        <bPhoto>true</bPhoto>
34
      </updateChildAutorizationRequest>
35
    </ns0:updateChildAutorization>
36
  </soap-env:Body>
37
</soap-env:Envelope>
tests/test_toulouse_maelis.py
1897 1897
    }
1898 1898

  
1899 1899
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1900 1900
    resp = app.post_json(url + '?NameID=local&child_id=42', params=params)
1901 1901
    assert resp.json['err'] == 'not-found'
1902 1902
    assert resp.json['err_desc'] == "no '42' child on '1312' family"
1903 1903

  
1904 1904

  
1905
@mock.patch('passerelle.utils.Request.get')
1906
@mock.patch('passerelle.utils.Request.post')
1907
def test_update_child_person(mocked_post, mocked_get, con, app):
1908
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1909
    mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
1910
    url = get_endpoint('update-child-person')
1911
    params = {
1912
        'personInfo/civility': 'M.',
1913
        'personInfo/firstname': 'Angelo',
1914
        'personInfo/lastname': 'Bent',
1915
        'personInfo/dateBirth': '1985-06-22',
1916
        'personInfo/contact/phone': '0102030405',
1917
        'personInfo/contact/mobile': None,
1918
        'personInfo/contact/mail': None,
1919
        'personQuality/code': 'O',
1920
    }
1921

  
1922
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1923
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=614719', params=params)
1924
    assert_sent_payload(mocked_post, 'Q_update_child_person.xml')
1925
    assert resp.json['err'] == 0
1926

  
1927

  
1928
def test_update_child_person_not_linked_error(con, app):
1929
    url = get_endpoint('update-child-person')
1930
    params = {
1931
        'personInfo/civility': 'M.',
1932
        'personInfo/firstname': 'Angelo',
1933
        'personInfo/lastname': 'Bent',
1934
        'personInfo/dateBirth': '1985-06-22',
1935
        'personInfo/contact/phone': '0102030405',
1936
        'personInfo/contact/mobile': None,
1937
        'personInfo/contact/mail': None,
1938
        'personQuality/code': 'O',
1939
    }
1940

  
1941
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=614719', params=params)
1942
    assert resp.json['err'] == 'not-linked'
1943
    assert resp.json['err_desc'] == 'User not linked to family'
1944

  
1945

  
1946
@mock.patch('passerelle.utils.Request.get')
1947
@mock.patch('passerelle.utils.Request.post')
1948
def test_update_child_person_no_child_error(mocked_post, mocked_get, con, app):
1949
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1950
    mocked_post.side_effect = [READ_FAMILY]
1951
    url = get_endpoint('update-child-person')
1952
    params = {
1953
        'personInfo/civility': 'M.',
1954
        'personInfo/firstname': 'Angelo',
1955
        'personInfo/lastname': 'Bent',
1956
        'personInfo/dateBirth': '1985-06-22',
1957
        'personInfo/contact/phone': '0102030405',
1958
        'personInfo/contact/mobile': None,
1959
        'personInfo/contact/mail': None,
1960
        'personQuality/code': 'O',
1961
    }
1962

  
1963
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1964
    resp = app.post_json(url + '?NameID=local&child_id=42&person_id=614719', params=params)
1965
    assert resp.json['err'] == 'not-found'
1966
    assert resp.json['err_desc'] == "no '42' child on '1312' family"
1967

  
1968

  
1969
@mock.patch('passerelle.utils.Request.get')
1970
@mock.patch('passerelle.utils.Request.post')
1971
def test_update_child_person_not_found(mocked_post, mocked_get, con, app):
1972
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1973
    mocked_post.side_effect = [READ_FAMILY]
1974
    url = get_endpoint('update-child-person')
1975
    params = {
1976
        'personInfo/civility': 'M.',
1977
        'personInfo/firstname': 'Angelo',
1978
        'personInfo/lastname': 'Bent',
1979
        'personInfo/dateBirth': '1985-06-22',
1980
        'personInfo/contact/phone': '0102030405',
1981
        'personInfo/contact/mobile': None,
1982
        'personInfo/contact/mail': None,
1983
        'personQuality/code': 'O',
1984
    }
1985

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

  
1991

  
1905 1992
@mock.patch('passerelle.utils.Request.get')
1906 1993
@mock.patch('passerelle.utils.Request.post')
1907 1994
def test_update_child_dietcode(mocked_post, mocked_get, con, app):
1908 1995
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1909 1996
    mocked_post.return_value = UPDATE_DIETCODE
1910 1997
    url = get_endpoint('update-child-dietcode')
1911 1998

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