Project

General

Profile

0001-toulouse-maelis-correct-child-payload-check-71643.patch

Nicolas Roche, 24 November 2022 11:47 AM

Download (4.41 KB)

View differences:

Subject: [PATCH 1/4] toulouse-maelis: correct child payload check (#71643)

 passerelle/contrib/toulouse_maelis/models.py |  2 +-
 tests/test_toulouse_maelis.py                | 40 ++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)
passerelle/contrib/toulouse_maelis/models.py
760 760
                'type': 'bool',
761 761
                'example_value': 'false',
762 762
            },
763 763
        },
764 764
        post={'request_body': {'schema': {'application/json': schemas.CREATE_CHILD_SCHEMA}}},
765 765
    )
766 766
    def create_child(self, request, NameID, post_data, force=False):
767 767
        family_id = self.get_link(NameID).family_id
768
        self.assert_update_coordinate_payload_in_referential(post_data)
768
        self.assert_child_payload_in_referential(post_data)
769 769

  
770 770
        payload = {
771 771
            'numDossier': family_id,
772 772
            'isForceCreateChild': force,
773 773
            'child': post_data,
774 774
        }
775 775
        response = self.call('Family', 'createChild', **payload)
776 776
        data = serialize_object(response)
tests/test_toulouse_maelis.py
1886 1886
        'birth/place': 'Port Arthur',
1887 1887
    }
1888 1888

  
1889 1889
    resp = app.post_json(url + '?NameID=local', params=params)
1890 1890
    assert resp.json['err'] == 'not-linked'
1891 1891
    assert resp.json['err_desc'] == 'User not linked to family'
1892 1892

  
1893 1893

  
1894
@mock.patch('passerelle.utils.Request.get')
1895
@mock.patch('passerelle.utils.Request.post')
1896
def test_create_child_wrong_referential_key_error(mocked_post, mocked_get, con, app):
1897
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1898
    mocked_post.side_effect = []
1899
    url = get_endpoint('create-child')
1900
    params = {
1901
        'lastname': 'DOE',
1902
        'firstname': 'JANNIS',
1903
        'sexe': 'plop',
1904
        'birth/dateBirth': '1943-01-19',
1905
        'birth/place': 'Port Arthur',
1906
    }
1907

  
1908
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1909
    resp = app.post_json(url + '?NameID=local', params=params)
1910
    assert resp.json['err'] == 'wrong-key'
1911
    assert resp.json['err_desc'] == "sexe key value 'plop' do not belong to 'Sex' required referential"
1912

  
1913

  
1894 1914
@mock.patch('passerelle.utils.Request.get')
1895 1915
@mock.patch('passerelle.utils.Request.post')
1896 1916
def test_create_child_connection_error(mocked_post, mocked_get, con, app):
1897 1917
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1898 1918
    mocked_post.side_effect = CONNECTION_ERROR
1899 1919
    url = get_endpoint('create-child')
1900 1920
    params = {
1901 1921
        'lastname': 'DOE',
......
1963 1983
        'birth/place': 'Port Arthur',
1964 1984
    }
1965 1985

  
1966 1986
    resp = app.post_json(url + '?NameID=local&child_id=613880', params=params)
1967 1987
    assert resp.json['err'] == 'not-linked'
1968 1988
    assert resp.json['err_desc'] == 'User not linked to family'
1969 1989

  
1970 1990

  
1991
@mock.patch('passerelle.utils.Request.get')
1992
@mock.patch('passerelle.utils.Request.post')
1993
def test_update_child_wrong_referential_key_error(mocked_post, mocked_get, con, app):
1994
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1995
    mocked_post.side_effect = []
1996
    url = get_endpoint('create-child')
1997
    params = {
1998
        'lastname': 'DOE',
1999
        'firstname': 'JANNIS',
2000
        'sexe': 'plop',
2001
        'birth/dateBirth': '1943-01-19',
2002
        'birth/place': 'Port Arthur',
2003
    }
2004

  
2005
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2006
    resp = app.post_json(url + '?NameID=local', params=params)
2007
    assert resp.json['err'] == 'wrong-key'
2008
    assert resp.json['err_desc'] == "sexe key value 'plop' do not belong to 'Sex' required referential"
2009

  
2010

  
1971 2011
@mock.patch('passerelle.utils.Request.get')
1972 2012
@mock.patch('passerelle.utils.Request.post')
1973 2013
def test_update_child_connection_error(mocked_post, mocked_get, con, app):
1974 2014
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1975 2015
    mocked_post.side_effect = CONNECTION_ERROR
1976 2016
    url = get_endpoint('update-child')
1977 2017
    params = {
1978 2018
        'lastname': 'DOE',
1979
-