Projet

Général

Profil

0004-toulouse-maelis-use-responses-in-tests-72205.patch

Nicolas Roche, 12 décembre 2022 10:25

Télécharger (128 ko)

Voir les différences:

Subject: [PATCH 4/4] toulouse-maelis: use responses in tests (#72205)

 tests/data/toulouse_maelis/Q_create_child.xml |  25 -
 .../toulouse_maelis/Q_create_child_person.xml |  56 --
 .../data/toulouse_maelis/Q_create_family.xml  |  59 --
 .../data/toulouse_maelis/Q_create_person.xml  |  44 -
 tests/data/toulouse_maelis/Q_create_rl1.xml   |  31 -
 tests/data/toulouse_maelis/Q_create_rl2.xml   |  35 -
 .../Q_create_update_quotient.xml              |  23 -
 .../toulouse_maelis/Q_delete_child_person.xml |  20 -
 .../data/toulouse_maelis/Q_delete_person.xml  |  21 -
 tests/data/toulouse_maelis/Q_update_child.xml |  50 --
 .../Q_update_child_dietcode.xml               |  16 -
 .../Q_update_child_indicator.xml              |  24 -
 .../Q_update_child_medical_record.xml         |  44 -
 .../toulouse_maelis/Q_update_child_pai.xml    |  18 -
 .../toulouse_maelis/Q_update_child_person.xml |  36 -
 .../toulouse_maelis/Q_update_coordinate.xml   |  42 -
 .../data/toulouse_maelis/Q_update_family.xml  |  80 --
 .../data/toulouse_maelis/Q_update_person.xml  |  33 -
 tests/data/toulouse_maelis/Q_update_rl1.xml   |  35 -
 tests/data/toulouse_maelis/Q_update_rl2.xml   |  35 -
 .../toulouse_maelis/Q_update_rl_indicator.xml |  24 -
 tests/test_toulouse_maelis.py                 | 754 ++++++++----------
 tests/utils.py                                |  20 +-
 23 files changed, 338 insertions(+), 1187 deletions(-)
 delete mode 100644 tests/data/toulouse_maelis/Q_create_child.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_create_child_person.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_create_family.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_create_person.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_create_rl1.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_create_rl2.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_create_update_quotient.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_delete_child_person.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_delete_person.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_child.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_child_dietcode.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_child_indicator.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_child_medical_record.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_child_pai.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_child_person.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_coordinate.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_family.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_person.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_rl1.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_rl2.xml
 delete mode 100644 tests/data/toulouse_maelis/Q_update_rl_indicator.xml
tests/data/toulouse_maelis/Q_create_child.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:createChild xmlns:ns0="family.ws.maelis.sigec.com">
12
      <numDossier>1312</numDossier>
13
      <child>
14
        <firstname>JANNIS</firstname>
15
        <lastname>DOE</lastname>
16
        <sexe>F</sexe>
17
        <birth>
18
          <dateBirth>1943-01-19</dateBirth>
19
          <place>Port Arthur</place>
20
        </birth>
21
      </child>
22
      <isForceCreateChild>false</isForceCreateChild>
23
    </ns0:createChild>
24
  </soap-env:Body>
25
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_create_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>MME</civility>
19
            <lastname>BENT</lastname>
20
            <firstname>AMEL</firstname>
21
            <dateBirth>1985-06-21T00:00:00+02:00</dateBirth>
22
            <sexe>F</sexe>
23
            <contact>
24
              <phone>0123456789</phone>
25
              <mobile>0623456789</mobile>
26
              <mail>abent@example.org</mail>
27
            </contact>
28
          </personInfo>
29
          <personQuality>
30
            <code>T</code>
31
            <libelle>TANTE</libelle>
32
          </personQuality>
33
        </personList>
34
        <personList>
35
          <personInfo>
36
            <civility>MME</civility>
37
            <lastname>Ross</lastname>
38
            <firstname>Diana</firstname>
39
            <dateBirth>1944-03-26</dateBirth>
40
            <sexe>F</sexe>
41
            <contact>
42
              <phone>0199999999</phone>
43
              <mobile>0723456789</mobile>
44
              <mail>dross@example.org</mail>
45
            </contact>
46
          </personInfo>
47
          <personQuality>
48
            <code>TUTEUR</code>
49
          </personQuality>
50
        </personList>
51
        <bLeaveAlone>false</bLeaveAlone>
52
        <bPhoto>true</bPhoto>
53
      </updateChildAutorizationRequest>
54
    </ns0:updateChildAutorization>
55
  </soap-env:Body>
56
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_create_family.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
3
  <soap-env:Header>
4
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
5
      <wsse:UsernameToken>
6
        <wsse:Username>maelis-webservice</wsse:Username>
7
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
8
      </wsse:UsernameToken>
9
    </wsse:Security>
10
  </soap-env:Header>
11
  <soap-env:Body>
12
    <ns0:createFamily xmlns:ns0="family.ws.maelis.sigec.com">
13
      <category>ACCEUI</category>
14
      <situation>C</situation>
15
      <rl1>
16
        <firstname>Jhon</firstname>
17
        <lastname>Doe</lastname>
18
        <quality>AU</quality>
19
        <civility>M.</civility>
20
        <birth>
21
          <dateBirth>1938-07-26</dateBirth>
22
          <place>Rabbat</place>
23
          <countryCode>99350</countryCode>
24
        </birth>
25
        <adresse>
26
          <idStreet>AM0330</idStreet>
27
          <numComp>B</numComp>
28
          <street1>Chateau</street1>
29
          <town>Paris</town>
30
          <zipcode>75014</zipcode>
31
        </adresse>
32
        <profession>
33
          <codeCSP>ART</codeCSP>
34
        </profession>
35
        <CAFInfo>
36
          <organ>A10007752822</organ>
37
        </CAFInfo>
38
      </rl1>
39
      <childList>
40
        <firstname>Robert</firstname>
41
        <lastname>Zimmerman</lastname>
42
        <sexe>M</sexe>
43
        <birth>
44
          <dateBirth>1941-05-24</dateBirth>
45
          <place>Saint-louis</place>
46
          <communeCode>91122</communeCode>
47
          <countryCode>99100</countryCode>
48
        </birth>
49
        <dietcode>RSV</dietcode>
50
        <medicalRecord>
51
          <vaccinList>
52
            <code>DTC</code>
53
            <vaccinationDate>1940-07-26</vaccinationDate>
54
          </vaccinList>
55
        </medicalRecord>
56
      </childList>
57
    </ns0:createFamily>
58
  </soap-env:Body>
59
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_create_person.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
3
  <soap-env:Header>
4
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
5
      <wsse:UsernameToken>
6
        <wsse:Username>maelis-webservice</wsse:Username>
7
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
8
      </wsse:UsernameToken>
9
    </wsse:Security>
10
  </soap-env:Header>
11
  <soap-env:Body>
12
    <ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com">
13
      <dossierNumber>1312</dossierNumber>
14
      <category>BI</category>
15
      <situation>M</situation>
16
      <flagCom>true</flagCom>
17
      <nbChild>2</nbChild>
18
      <emergencyPersonList>
19
        <personList>
20
          <numPerson>614059</numPerson>
21
          <civility>MME</civility>
22
          <firstname>KENY</firstname>
23
          <lastname>ARKANA</lastname>
24
          <dateBirth>1982-12-20T00:00:00+01:00</dateBirth>
25
          <quality>T</quality>
26
          <contact>
27
            <phone>0123456789</phone>
28
            <mail>pueblo@example.org</mail>
29
          </contact>
30
        </personList>
31
        <personList>
32
          <firstname>Mathias</firstname>
33
          <lastname>Cassel</lastname>
34
          <dateBirth>1972-01-01</dateBirth>
35
          <sexe>M</sexe>
36
          <quality>O</quality>
37
          <contact>
38
            <mobile>0623456789</mobile>
39
          </contact>
40
        </personList>
41
      </emergencyPersonList>
42
    </ns0:updateFamily>
43
  </soap-env:Body>
44
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_create_rl1.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
3
  <soap-env:Header>
4
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
5
      <wsse:UsernameToken>
6
        <wsse:Username>maelis-webservice</wsse:Username>
7
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
8
      </wsse:UsernameToken>
9
    </wsse:Security>
10
  </soap-env:Header>
11
  <soap-env:Body>
12
    <ns0:createFamily xmlns:ns0="family.ws.maelis.sigec.com">
13
      <category>ACCEUI</category>
14
      <situation>C</situation>
15
      <rl1>
16
        <firstname>Jhon</firstname>
17
        <lastname>Doe</lastname>
18
        <quality>AU</quality>
19
        <civility>M.</civility>
20
        <birth>
21
          <dateBirth>1938-07-26</dateBirth>
22
        </birth>
23
        <adresse>
24
          <street1>Chateau</street1>
25
          <town>Paris</town>
26
          <zipcode>75014</zipcode>
27
        </adresse>
28
      </rl1>
29
    </ns0:createFamily>
30
  </soap-env:Body>
31
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_create_rl2.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:updateFamily xmlns:ns0="family.ws.maelis.sigec.com">
12
      <dossierNumber>1312</dossierNumber>
13
      <category>BI</category>
14
      <situation>M</situation>
15
      <flagCom>true</flagCom>
16
      <nbChild>2</nbChild>
17
      <rl2>
18
        <firstname>JANE</firstname>
19
        <lastname>DOE</lastname>
20
        <maidenName>Smith</maidenName>
21
        <quality>MERE</quality>
22
        <civility>MME</civility>
23
        <birth>
24
          <dateBirth>1940-06-22</dateBirth>
25
        </birth>
26
        <adresse>
27
          <num>170</num>
28
          <street1>Chateau d'eau</street1>
29
          <town>Paris</town>
30
          <zipcode>75014</zipcode>
31
        </adresse>
32
      </rl2>
33
    </ns0:updateFamily>
34
  </soap-env:Body>
35
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_create_update_quotient.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:createUpdateQuotient xmlns:ns0="family.ws.maelis.sigec.com">
12
      <dossierNumber>1312</dossierNumber>
13
      <personNumber>613878</personNumber>
14
      <quotient>
15
        <yearRev>2021</yearRev>
16
        <dateStart>2022-10-01</dateStart>
17
        <dateEnd>2023-01-31</dateEnd>
18
        <mtt>1500.33</mtt>
19
        <cdquo>QS</cdquo>
20
      </quotient>
21
    </ns0:createUpdateQuotient>
22
  </soap-env:Body>
23
</soap-env:Envelope>
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/data/toulouse_maelis/Q_delete_person.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
3
  <soap-env:Header>
4
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
5
      <wsse:UsernameToken>
6
        <wsse:Username>maelis-webservice</wsse:Username>
7
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
8
      </wsse:UsernameToken>
9
    </wsse:Security>
10
  </soap-env:Header>
11
  <soap-env:Body>
12
    <ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com">
13
      <dossierNumber>1312</dossierNumber>
14
      <category>BI</category>
15
      <situation>M</situation>
16
      <flagCom>true</flagCom>
17
      <nbChild>2</nbChild>
18
      <emergencyPersonList/>
19
    </ns0:updateFamily>
20
  </soap-env:Body>
21
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_child.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:updateFamily xmlns:ns0="family.ws.maelis.sigec.com">
12
      <dossierNumber>1312</dossierNumber>
13
      <category>BI</category>
14
      <situation>M</situation>
15
      <flagCom>true</flagCom>
16
      <nbChild>2</nbChild>
17
      <childList>
18
        <num>613880</num>
19
        <firstname>JANNIS</firstname>
20
        <lastname>DOE</lastname>
21
        <sexe>F</sexe>
22
        <birth>
23
          <dateBirth>1943-01-19</dateBirth>
24
          <place>Port Arthur</place>
25
        </birth>
26
        <bPhoto>true</bPhoto>
27
        <bLeaveAlone>false</bLeaveAlone>
28
        <authorizedPersonList>
29
          <personInfo>
30
            <num>614719</num>
31
            <lastname>BENT</lastname>
32
            <firstname>AMEL</firstname>
33
            <dateBirth>1985-06-21T00:00:00+02:00</dateBirth>
34
            <civility>MME</civility>
35
            <sexe>F</sexe>
36
            <contact>
37
              <phone>0123456789</phone>
38
              <mobile>0623456789</mobile>
39
              <mail>abent@example.org</mail>
40
            </contact>
41
          </personInfo>
42
          <personQuality>
43
            <code>T</code>
44
            <libelle>TANTE</libelle>
45
          </personQuality>
46
        </authorizedPersonList>
47
      </childList>
48
    </ns0:updateFamily>
49
  </soap-env:Body>
50
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_child_dietcode.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:createOrUpdateChildDiet xmlns:ns0="family.ws.maelis.sigec.com">
12
      <personNumber>613878</personNumber>
13
      <code>RSV</code>
14
    </ns0:createOrUpdateChildDiet>
15
  </soap-env:Body>
16
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_child_indicator.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:updatePersonIndicatorList xmlns:ns0="family.ws.maelis.sigec.com">
12
      <numPerson>613880</numPerson>
13
      <indicatorList>
14
        <code>LUNETTE</code>
15
        <isActive>true</isActive>
16
      </indicatorList>
17
      <indicatorList>
18
        <code>AUTRE</code>
19
        <note>rebellious</note>
20
        <isActive>true</isActive>
21
      </indicatorList>
22
    </ns0:updatePersonIndicatorList>
23
  </soap-env:Body>
24
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_child_medical_record.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:updateChildMedicalRecord xmlns:ns0="family.ws.maelis.sigec.com">
12
      <updateChildMedicalRecordRequest>
13
        <numPerson>613878</numPerson>
14
        <medicalRecord>
15
          <familyDoctor>
16
            <name>Dre</name>
17
            <phone>0612341234</phone>
18
            <address>
19
              <street1>Alameda</street1>
20
              <zipcode>90220</zipcode>
21
              <town>Compton</town>
22
            </address>
23
          </familyDoctor>
24
          <allergy1>butterscotch, imitation butterscotch, glow-in-the-dark monster make-up, and shrimp</allergy1>
25
          <allergy2>cauliflower</allergy2>
26
          <comment1>the shrimp allergy isn't fully identified</comment1>
27
          <comment2/>
28
          <observ1>Ay Caramba!</observ1>
29
          <observ2/>
30
          <isAuthHospital>true</isAuthHospital>
31
          <hospital>Springfield General Hospital</hospital>
32
          <vaccinList>
33
            <code>DTC</code>
34
            <vaccinationDate>2011-01-11</vaccinationDate>
35
          </vaccinList>
36
          <vaccinList>
37
            <code>ROR</code>
38
            <vaccinationDate>2022-02-22</vaccinationDate>
39
          </vaccinList>
40
        </medicalRecord>
41
      </updateChildMedicalRecordRequest>
42
    </ns0:updateChildMedicalRecord>
43
  </soap-env:Body>
44
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_child_pai.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:updateChildPAI xmlns:ns0="family.ws.maelis.sigec.com">
12
      <personNumber>613878</personNumber>
13
      <code>PAIALI</code>
14
      <dateDeb>2022-01-01</dateDeb>
15
      <description>some text</description>
16
    </ns0:updateChildPAI>
17
  </soap-env:Body>
18
</soap-env:Envelope>
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
            <sexe>M</sexe>
23
            <contact>
24
              <phone>0102030405</phone>
25
            </contact>
26
          </personInfo>
27
          <personQuality>
28
            <code>O</code>
29
          </personQuality>
30
        </personList>
31
        <bLeaveAlone>false</bLeaveAlone>
32
        <bPhoto>true</bPhoto>
33
      </updateChildAutorizationRequest>
34
    </ns0:updateChildAutorization>
35
  </soap-env:Body>
36
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_coordinate.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
3
  <soap-env:Header>
4
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
5
      <wsse:UsernameToken>
6
        <wsse:Username>maelis-webservice</wsse:Username>
7
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
8
      </wsse:UsernameToken>
9
    </wsse:Security>
10
  </soap-env:Header>
11
  <soap-env:Body>
12
    <ns0:updateCoordinate xmlns:ns0="family.ws.maelis.sigec.com">
13
      <numDossier>1312</numDossier>
14
      <numPerson>613878</numPerson>
15
      <adresse>
16
        <idStreet>AM0330</idStreet>
17
        <num>169</num>
18
        <numComp>B</numComp>
19
        <street1>Château</street1>
20
        <street2/>
21
        <town>Paris</town>
22
        <zipcode>75014</zipcode>
23
      </adresse>
24
      <profession>
25
        <codeCSP>ART</codeCSP>
26
        <profession>informaticien</profession>
27
        <employerName>EO</employerName>
28
        <phone>0123456789</phone>
29
        <addressPro>
30
          <num/>
31
          <street/>
32
          <zipcode/>
33
          <town>Orl&#233;ans</town>
34
        </addressPro>
35
      </profession>
36
      <CAFInfo>
37
        <number>789</number>
38
        <organ>A10007752822</organ>
39
      </CAFInfo>
40
    </ns0:updateCoordinate>
41
  </soap-env:Body>
42
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_family.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
3
  <soap-env:Header>
4
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
5
      <wsse:UsernameToken>
6
        <wsse:Username>maelis-webservice</wsse:Username>
7
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
8
      </wsse:UsernameToken>
9
    </wsse:Security>
10
  </soap-env:Header>
11
  <soap-env:Body>
12
    <ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com">
13
      <dossierNumber>1312</dossierNumber>
14
      <category>BI</category>
15
      <situation>C</situation>
16
      <rl1>
17
        <firstname>Jhon</firstname>
18
        <lastname>Doe</lastname>
19
        <quality>AU</quality>
20
        <civility>M.</civility>
21
        <birth>
22
          <dateBirth>1938-07-26</dateBirth>
23
          <place>Rabbat</place>
24
          <communeCode/>
25
          <countryCode>99350</countryCode>
26
        </birth>
27
        <adresse>
28
          <numComp>B</numComp>
29
          <street1>Chateau</street1>
30
          <town>Paris</town>
31
          <zipcode>75014</zipcode>
32
        </adresse>
33
        <profession>
34
          <codeCSP>ART</codeCSP>
35
        </profession>
36
        <CAFInfo>
37
          <organ>A10007752822</organ>
38
        </CAFInfo>
39
      </rl1>
40
      <childList>
41
        <firstname>Robert</firstname>
42
        <lastname>Zimmerman</lastname>
43
        <sexe>M</sexe>
44
        <birth>
45
          <dateBirth>1941-05-24</dateBirth>
46
          <place>Duluth</place>
47
        </birth>
48
        <dietcode>RSV</dietcode>
49
        <medicalRecord>
50
          <vaccinList>
51
            <code>DTC</code>
52
            <vaccinationDate>1940-07-26</vaccinationDate>
53
          </vaccinList>
54
        </medicalRecord>
55
        <paiInfoBean>
56
          <code>PAIALI</code>
57
        </paiInfoBean>
58
      </childList>
59
      <childList>
60
        <num>613880</num>
61
        <firstname>Brunelle</firstname>
62
        <lastname>Doe</lastname>
63
        <sexe>F</sexe>
64
        <birth>
65
          <dateBirth>1943-01-19</dateBirth>
66
        </birth>
67
      </childList>
68
      <emergencyPersonList>
69
        <personList>
70
          <civility>MME</civility>
71
          <firstname>Keny</firstname>
72
          <lastname>Arkana</lastname>
73
          <dateBirth>1982-12-20</dateBirth>
74
          <sexe>F</sexe>
75
          <quality>T</quality>
76
        </personList>
77
      </emergencyPersonList>
78
    </ns0:updateFamily>
79
  </soap-env:Body>
80
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_person.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
3
  <soap-env:Header>
4
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
5
      <wsse:UsernameToken>
6
        <wsse:Username>maelis-webservice</wsse:Username>
7
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
8
      </wsse:UsernameToken>
9
    </wsse:Security>
10
  </soap-env:Header>
11
  <soap-env:Body>
12
    <ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com">
13
      <dossierNumber>1312</dossierNumber>
14
      <category>BI</category>
15
      <situation>M</situation>
16
      <flagCom>true</flagCom>
17
      <nbChild>2</nbChild>
18
      <emergencyPersonList>
19
        <personList>
20
          <numPerson>614059</numPerson>
21
          <firstname>Mathias</firstname>
22
          <lastname>Cassel</lastname>
23
          <dateBirth>1972-01-01</dateBirth>
24
          <sexe>M</sexe>
25
          <quality>O</quality>
26
          <contact>
27
            <mobile>0623456789</mobile>
28
          </contact>
29
        </personList>
30
      </emergencyPersonList>
31
    </ns0:updateFamily>
32
  </soap-env:Body>
33
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_rl1.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
3
  <soap-env:Header>
4
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
5
      <wsse:UsernameToken>
6
        <wsse:Username>maelis-webservice</wsse:Username>
7
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
8
      </wsse:UsernameToken>
9
    </wsse:Security>
10
  </soap-env:Header>
11
  <soap-env:Body>
12
    <ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com">
13
      <dossierNumber>1312</dossierNumber>
14
      <category>BI</category>
15
      <situation>M</situation>
16
      <flagCom>true</flagCom>
17
      <nbChild>2</nbChild>
18
      <rl1>
19
        <firstname>Jhonny</firstname>
20
        <lastname>Doe</lastname>
21
        <quality>PERE</quality>
22
        <civility>M.</civility>
23
        <birth>
24
          <dateBirth>1943-06-15</dateBirth>
25
        </birth>
26
        <adresse>
27
          <num>170</num>
28
          <street1>Chateau d'eau</street1>
29
          <town>Paris</town>
30
          <zipcode>75014</zipcode>
31
        </adresse>
32
      </rl1>
33
    </ns0:updateFamily>
34
  </soap-env:Body>
35
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_rl2.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:updateFamily xmlns:ns0="family.ws.maelis.sigec.com">
12
      <dossierNumber>1312</dossierNumber>
13
      <category>BI</category>
14
      <situation>M</situation>
15
      <flagCom>true</flagCom>
16
      <nbChild>2</nbChild>
17
      <rl2>
18
        <firstname>JANE</firstname>
19
        <lastname>DOE</lastname>
20
        <maidenName>Smith</maidenName>
21
        <quality>MERE</quality>
22
        <civility>MME</civility>
23
        <birth>
24
          <dateBirth>1940-06-22</dateBirth>
25
        </birth>
26
        <adresse>
27
          <num>170</num>
28
          <street1>Chateau d'eau</street1>
29
          <town>Paris</town>
30
          <zipcode>75014</zipcode>
31
        </adresse>
32
      </rl2>
33
    </ns0:updateFamily>
34
  </soap-env:Body>
35
</soap-env:Envelope>
tests/data/toulouse_maelis/Q_update_rl_indicator.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:updatePersonIndicatorList xmlns:ns0="family.ws.maelis.sigec.com">
12
      <numPerson>613878</numPerson>
13
      <indicatorList>
14
        <code>AVL</code>
15
        <isActive>true</isActive>
16
      </indicatorList>
17
      <indicatorList>
18
        <code>ETABSPEC</code>
19
        <note>SNPP</note>
20
        <isActive>true</isActive>
21
      </indicatorList>
22
    </ns0:updatePersonIndicatorList>
23
  </soap-env:Body>
24
</soap-env:Envelope>
tests/test_toulouse_maelis.py
14 14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15 15

  
16 16
import logging
17 17
import os
18 18
from unittest import mock
19 19

  
20 20
import pytest
21 21
import responses
22
from lxml import etree
23 22
from requests.exceptions import ConnectionError
23
from zeep import Settings
24 24

  
25 25
from passerelle.contrib.toulouse_maelis.models import Link, Referential, ToulouseMaelis
26 26
from passerelle.utils.jsonresponse import APIError
27 27
from passerelle.utils.soap import SOAPError
28 28
from tests.utils import FakedResponse, ResponsesSoap, generic_endpoint_url, setup_access_rights
29 29

  
30 30
TEST_BASE_DIR = os.path.join(os.path.dirname(__file__), 'data', 'toulouse_maelis')
31 31

  
......
37 37

  
38 38
CONNECTION_ERROR = ConnectionError('No address associated with hostname')
39 39
FAMILY_SERVICE_WSDL = FakedResponse(content=get_xml_file('FamilyService.wsdl'), status_code=200)
40 40
ACTIVITY_SERVICE_WSDL = FakedResponse(content=get_xml_file('ActivityService.wsdl'), status_code=200)
41 41
INVOICE_SERVICE_WSDL = FakedResponse(content=get_xml_file('InvoiceService.wsdl'), status_code=200)
42 42
FAILED_AUTH = FakedResponse(content=get_xml_file('R_failed_authentication.xml'), status_code=500)
43 43
ISWSRUNNING_TRUE = FakedResponse(content=get_xml_file('R_is_ws_running.xml') % b'true', status_code=200)
44 44
ISWSRUNNING_FALSE = FakedResponse(content=get_xml_file('R_is_ws_running.xml') % b'false', status_code=200)
45
READ_FAMILY = FakedResponse(content=get_xml_file('R_read_family.xml'), status_code=200)
46
READ_FAMILY_LAX = FakedResponse(content=get_xml_file('R_read_family_relax.xml'), status_code=200)
47
READ_FAMILY_ORD = FakedResponse(content=get_xml_file('R_read_family_reordered.xml'), status_code=200)
48
READ_FAMILY_QUOTIENT = FakedResponse(
49
    content=get_xml_file('R_read_family_with_income_year.xml'), status_code=200
50
)
51
READ_RL1_FAMILY = FakedResponse(content=get_xml_file('R_read_family_with_only_rl1.xml'), status_code=200)
52
IS_RL_EXISTS_TRUE = FakedResponse(content=get_xml_file('R_is_rl_exists.xml') % b'true', status_code=200)
53
IS_RL_EXISTS_FALSE = FakedResponse(content=get_xml_file('R_is_rl_exists.xml') % b'false', status_code=200)
54
IS_CHILD_EXISTS_TRUE = FakedResponse(content=get_xml_file('R_is_child_exists.xml') % b'true', status_code=200)
55
IS_CHILD_EXISTS_FALSE = FakedResponse(
56
    content=get_xml_file('R_is_child_exists.xml') % b'false', status_code=200
57
)
58
CREATE_FAMILY = FakedResponse(content=get_xml_file('R_create_family.xml'), status_code=200)
59
CREATE_FAMILY_ERR = FakedResponse(content=get_xml_file('R_create_family_error.xml'), status_code=200)
60
CREATE_CHILD = FakedResponse(content=get_xml_file('R_create_child.xml'), status_code=200)
61
CREATE_CHILD_ERR = FakedResponse(content=get_xml_file('R_create_child_error.xml'), status_code=200)
62
UPDATE_FAMILY = FakedResponse(content=get_xml_file('R_update_family.xml'), status_code=200)
63
UPDATE_FAMILY_ERR = FakedResponse(content=get_xml_file('R_update_family_error.xml'), status_code=200)
64
UPDATE_FAMILY_500 = FakedResponse(content=get_xml_file('R_update_family_soap_error.xml'), status_code=500)
65
UPDATE_QUOTIENT = FakedResponse(content=get_xml_file('R_create_update_quotient.xml'), status_code=200)
66
UPDATE_QUOTIENT_500 = FakedResponse(
67
    content=get_xml_file('R_create_update_quotient_soap_error.xml'), status_code=500
68
)
69
UPDATE_DIETCODE = FakedResponse(content=get_xml_file('R_update_child_dietcode.xml'), status_code=200)
70
UPDATE_PAI = FakedResponse(content=get_xml_file('R_update_child_pai.xml'), status_code=200)
71
UPDATE_PAI_500 = FakedResponse(content=get_xml_file('R_update_child_pai_soap_error.xml'), status_code=500)
72
UPDATE_MEDICAL = FakedResponse(content=get_xml_file('R_update_child_medical_record.xml'), status_code=200)
73
UPDATE_MEDICAL_500 = FakedResponse(
74
    content=get_xml_file('R_update_child_medical_record_soap_error.xml'), status_code=500
75
)
76
UPDATE_CHILD_AUTO = FakedResponse(content=get_xml_file('R_update_child_authorization.xml'), status_code=200)
77
UPDATE_INDICATOR = FakedResponse(content=get_xml_file('R_update_indicator.xml'), status_code=200)
78

  
79

  
80
def assert_sent_payload(mocked_post, query_file):
81
    soap_sent = etree.tostring(etree.fromstring(mocked_post.call_args.kwargs['data']), pretty_print=True)
82
    expected = etree.tostring(etree.fromstring(get_xml_file(query_file)), pretty_print=True)
83
    assert soap_sent.decode() == expected.decode()
84 45

  
85 46

  
86 47
def get_endpoint(name):
87 48
    url = generic_endpoint_url('toulouse-maelis', name)
88 49
    assert url == '/toulouse-maelis/test/%s' % name
89 50
    return url
90 51

  
91 52

  
53
@pytest.fixture()
54
def family_service():
55
    with ResponsesSoap(
56
        wsdl_url='https://example.org/FamilyService?wsdl',
57
        wsdl_content=get_xml_file('FamilyService.wsdl'),
58
        settings=Settings(strict=False, xsd_ignore_sequence_order=True),
59
    )() as mock:
60
        yield mock
61

  
62

  
63
@pytest.fixture()
64
def activity_service():
65
    with ResponsesSoap(
66
        wsdl_url='https://example.org/ActivityService?wsdl',
67
        wsdl_content=get_xml_file('ActivityService.wsdl'),
68
        settings=Settings(strict=False, xsd_ignore_sequence_order=True),
69
    )() as mock:
70
        yield mock
71

  
72

  
73
@pytest.fixture()
74
def invoice_service():
75
    with ResponsesSoap(
76
        wsdl_url='https://example.org/InvoiceService?wsdl',
77
        wsdl_content=get_xml_file('InvoiceService.wsdl'),
78
        settings=Settings(strict=False, xsd_ignore_sequence_order=True),
79
    )() as mock:
80
        yield mock
81

  
82

  
92 83
@pytest.fixture(scope='module')
93 84
def django_db_setup(django_db_setup, django_db_blocker):
94 85
    with django_db_blocker.unblock():
95 86
        con = setup_access_rights(
96 87
            ToulouseMaelis.objects.get_or_create(
97 88
                slug='test',
89
                base_wsdl_url='https://example.org/',
98 90
                zeep_wsse_username='maelis-webservice',
99 91
                zeep_wsse_password='maelis-password',
100 92
            )[0]
101 93
        )
102
        with mock.patch('passerelle.utils.Request.get') as mocked_get:
103
            mocked_get.return_value = FAMILY_SERVICE_WSDL
104
            with mock.patch('passerelle.utils.Request.post') as mocked_post:
105
                mocked_post.side_effect = [
106
                    FakedResponse(content=get_xml_file('R_read_category_list.xml'), status_code=200),
107
                    FakedResponse(content=get_xml_file('R_read_child_indicator_list.xml'), status_code=200),
108
                    FakedResponse(content=get_xml_file('R_read_civility_list.xml'), status_code=200),
109
                    FakedResponse(content=get_xml_file('R_read_country_list.xml'), status_code=200),
110
                    FakedResponse(content=get_xml_file('R_read_csp_list.xml'), status_code=200),
111
                    FakedResponse(content=get_xml_file('R_read_dietcode_list.xml'), status_code=200),
112
                    FakedResponse(content=get_xml_file('R_read_organ_list.xml'), status_code=200),
113
                    FakedResponse(content=get_xml_file('R_read_pai_list.xml'), status_code=200),
114
                    FakedResponse(content=get_xml_file('R_read_quality_list.xml'), status_code=200),
115
                    FakedResponse(content=get_xml_file('R_read_quotient_list.xml'), status_code=200),
116
                    FakedResponse(content=get_xml_file('R_read_rl_indicator_list.xml'), status_code=200),
117
                    FakedResponse(content=get_xml_file('R_read_situation_list.xml'), status_code=200),
118
                    FakedResponse(content=get_xml_file('R_read_street_list.xml'), status_code=200),
119
                    FakedResponse(content=get_xml_file('R_read_vaccin_list.xml'), status_code=200),
120
                ]
121
                con.daily()
94

  
95
        with responses.RequestsMock() as mock:
96
            family_service = ResponsesSoap(
97
                wsdl_url='https://example.org/FamilyService?wsdl',
98
                wsdl_content=get_xml_file('FamilyService.wsdl'),
99
                settings=Settings(strict=False, xsd_ignore_sequence_order=True),
100
            )
101
            mock.add(responses.GET, family_service.wsdl_url, body=family_service.wsdl_content, status=200)
102
            family_service.add_soap_response(
103
                mock, 'readCategoryList', get_xml_file('R_read_category_list.xml')
104
            )
105
            family_service.add_soap_response(
106
                mock, 'readChildIndicatorList', get_xml_file('R_read_child_indicator_list.xml')
107
            )
108
            family_service.add_soap_response(
109
                mock, 'readCivilityList', get_xml_file('R_read_civility_list.xml')
110
            )
111
            family_service.add_soap_response(mock, 'readCountryList', get_xml_file('R_read_country_list.xml'))
112
            family_service.add_soap_response(mock, 'readCSPList', get_xml_file('R_read_csp_list.xml'))
113
            family_service.add_soap_response(
114
                mock, 'readDietCodeList', get_xml_file('R_read_dietcode_list.xml')
115
            )
116
            family_service.add_soap_response(mock, 'readOrganList', get_xml_file('R_read_organ_list.xml'))
117
            family_service.add_soap_response(mock, 'readPAIList', get_xml_file('R_read_pai_list.xml'))
118
            family_service.add_soap_response(mock, 'readQualityList', get_xml_file('R_read_quality_list.xml'))
119
            family_service.add_soap_response(
120
                mock, 'readQuotientList', get_xml_file('R_read_quotient_list.xml')
121
            )
122
            family_service.add_soap_response(
123
                mock, 'readRLIndicatorList', get_xml_file('R_read_rl_indicator_list.xml')
124
            )
125
            family_service.add_soap_response(
126
                mock, 'readSituationList', get_xml_file('R_read_situation_list.xml')
127
            )
128
            family_service.add_soap_response(mock, 'readStreetList', get_xml_file('R_read_street_list.xml'))
129
            family_service.add_soap_response(mock, 'readVaccinList', get_xml_file('R_read_vaccin_list.xml'))
130
            con.daily()
122 131

  
123 132
    # reset change in zeep private interface to bypass clear_cache fixture
124 133
    from zeep.cache import InMemoryCache
125 134

  
126 135
    InMemoryCache._cache = {}
127 136

  
128 137

  
129 138
@pytest.fixture()
......
136 145
    mocked_get.side_effect = CONNECTION_ERROR
137 146
    with pytest.raises(
138 147
        SOAPError,
139 148
        match='cannot be loaded: No address associated with hostname',
140 149
    ) as e:
141 150
        con.call('Family', 'isWSRunning')
142 151
    assert e.value.err == 1
143 152
    assert e.value.http_status == 200
144
    assert e.value.url == 'https://demo-toulouse.sigec.fr/maelisws-toulouse/services/FamilyService?wsdl'
153
    assert e.value.url == 'https://example.org/FamilyService?wsdl'
145 154

  
146 155

  
147
@mock.patch('passerelle.utils.Request.get')
148
@mock.patch('passerelle.utils.Request.post')
149
def test_call_with_wrong_credentials(mocked_post, mocked_get, con):
150
    mocked_get.side_effect = [FAMILY_SERVICE_WSDL]
151
    mocked_post.side_effect = [FAILED_AUTH]
156
def test_call_with_wrong_credentials(family_service, con):
157
    family_service.add_soap_response('isWSRunning', get_xml_file('R_failed_authentication.xml'), status=500)
152 158
    with pytest.raises(
153 159
        APIError,
154 160
        match='The security token could not be authenticated or authorized',
155 161
    ) as e:
156 162
        con.call('Family', 'isWSRunning')
157 163
    assert e.value.__dict__ == {
158 164
        'err': 1,
159 165
        'log_error': False,
160 166
        'http_status': 200,
161 167
        'err_code': 'Family-isWSRunning-ns1:FailedAuthentication',
162 168
    }
163 169

  
164 170

  
165
@mock.patch('passerelle.utils.Request.get')
166
@mock.patch('passerelle.utils.Request.post')
167
def test_call(mocked_post, mocked_get, con):
168
    mocked_get.side_effect = [FAMILY_SERVICE_WSDL]
169
    mocked_post.side_effect = [ISWSRUNNING_TRUE]
171
def test_call(family_service, con):
172
    family_service.add_soap_response('isWSRunning', get_xml_file('R_is_ws_running.xml') % b'true')
170 173
    resp = con.call('Family', 'isWSRunning')
171 174
    assert resp is True
172 175

  
173 176

  
174 177
@pytest.mark.parametrize(
175 178
    'get_responses, post_responses, exception',
176 179
    [
177 180
        (
......
290 293
        'Sex',
291 294
        'Situation',
292 295
        'Street',
293 296
        'Vaccin',
294 297
    ]
295 298
    assert Referential.objects.count() == 230
296 299

  
297 300

  
298
@pytest.fixture
299
def family_service():
300
    from zeep import Settings
301

  
302
    with ResponsesSoap(
303
        wsdl_url='https://demo-toulouse.sigec.fr/maelisws-toulouse/services/FamilyService?wsdl',
304
        wsdl_content=get_xml_file('FamilyService.wsdl'),
305
        settings=Settings(strict=False, xsd_ignore_sequence_order=True),
306
    )() as mock:
307
        yield mock
308

  
309

  
310 301
def test_link(family_service, con, app):
311 302
    def request_check(request):
312
        assert request.dossierNumber == 1313
303
        assert request.dossierNumber == 1312
313 304

  
314 305
    family_service.add_soap_response(
315 306
        'readFamily', get_xml_file('R_read_family.xml'), request_check=request_check
316 307
    )
317 308
    url = get_endpoint('link')
318 309
    assert Link.objects.count() == 0
319 310

  
320 311
    params = {
321 312
        'family_id': '1312',
322 313
        'firstname': 'Jhon',
323 314
        'lastname': 'Doe',
324 315
        'dateBirth': '1938-07-26',
325 316
    }
326
    resp = app.post_json(url + '?NameID=local&raise=1', params=params)
317
    resp = app.post_json(url + '?NameID=local', params=params)
327 318
    assert Link.objects.count() == 1
328 319
    assert resp.json['err'] == 0
329 320
    assert resp.json['data'] == 'ok'
330 321

  
331 322
    params['lastname'] = 'John'
332 323
    resp = app.post_json(url + '?NameID=local', params=params)
333 324
    assert Link.objects.count() == 1
334 325
    assert resp.json['err'] == 'not-found'
335 326
    assert resp.json['err_desc'] == "RL1 does not match '1312' family"
336 327

  
337 328

  
338 329
def test_link_additional_properties_error(con, app):
339 330
    url = get_endpoint('link')
340

  
341 331
    params = {
342 332
        'family_id': '1312',
343 333
        'firstname': 'Jhon',
344 334
        'lastname': 'Doe',
345 335
        'dateBirth': '1938-07-26',
346 336
        'plop': 42,
347 337
    }
338

  
348 339
    resp = app.post_json(url + '?NameID=local', params=params, status=400)
349 340
    assert resp.json['err'] == 1
350 341
    assert resp.json['err_desc'] == "Additional properties are not allowed ('plop' was unexpected)"
351 342

  
352 343

  
353 344
def test_unlink(con, app):
354 345
    url = get_endpoint('unlink')
355 346
    Link.objects.create(resource=con, family_id='1312', name_id='local')
......
381 372
    assert con.get_referential_value('Civility', 'MR') == 'MR'
382 373
    assert len(caplog.records) == 1
383 374
    assert caplog.records[0].levelno == logging.WARNING
384 375
    assert caplog.records[0].message == "No 'MR' key into Maelis 'Civility' referential"
385 376

  
386 377

  
387 378
def test_read_category_list(con, app):
388 379
    url = get_endpoint('read-category-list')
389

  
390 380
    resp = app.get(url)
391 381
    assert resp.json['err'] == 0
392 382
    assert resp.json['data'] == [
393 383
        {'id': 'BI', 'text': 'BIPARENTALE', 'code': 'BI', 'libelle': 'BIPARENTALE'},
394 384
        {'id': 'ACCEUI', 'text': "FAMILLE D'ACCUEIL", 'code': 'ACCEUI', 'libelle': "FAMILLE D'ACCUEIL"},
395 385
        {'id': 'MONO', 'text': 'MONOPARENTALE', 'code': 'MONO', 'libelle': 'MONOPARENTALE'},
396 386
    ]
397 387

  
398 388

  
399 389
def test_read_country_list(con, app):
400 390
    url = get_endpoint('read-country-list')
401

  
402 391
    resp = app.get(url)
403 392
    assert resp.json['err'] == 0
404 393
    assert len(resp.json['data']) == 3
405 394
    assert resp.json['data'] == [
406 395
        {'id': '212', 'code': '212', 'text': 'AFGHANISTAN', 'libelle': 'AFGHANISTAN'},
407 396
        {'id': '303', 'code': '303', 'text': 'AFRIQUE DU SUD', 'libelle': 'AFRIQUE DU SUD'},
408 397
        {'id': '125', 'code': '125', 'text': 'ALBANIE', 'libelle': 'ALBANIE'},
409 398
    ]
......
581 570
            'label': 'Etablissement spécialisé',
582 571
            'typeDesc': 'NOTE',
583 572
        },
584 573
    ]
585 574

  
586 575

  
587 576
def test_read_sex_list(con, app):
588 577
    url = get_endpoint('read-sex-list')
589

  
590 578
    resp = app.get(url)
591 579
    assert resp.json['err'] == 0
592 580
    assert resp.json['data'] == [
593 581
        {'id': 'F', 'text': 'Féminin'},
594 582
        {'id': 'M', 'text': 'Masculin'},
595 583
    ]
596 584

  
597 585

  
......
673 661
            'id': 'DTC',
674 662
            'code': 'DTC',
675 663
            'text': 'DIPHTERIE TETANOS COQUELUCHE',
676 664
            'libelle': 'DIPHTERIE TETANOS COQUELUCHE',
677 665
        },
678 666
    ]
679 667

  
680 668

  
681
@pytest.mark.parametrize("read_family", [READ_FAMILY, READ_FAMILY_LAX, READ_FAMILY_ORD])
682
@mock.patch('passerelle.utils.Request.get')
683
@mock.patch('passerelle.utils.Request.post')
684
def test_read_family(mocked_post, mocked_get, read_family, con, app):
685
    mocked_get.return_value = FAMILY_SERVICE_WSDL
686
    mocked_post.return_value = read_family
669
@pytest.mark.parametrize(
670
    "xml", ['R_read_family.xml', 'R_read_family_relax.xml', 'R_read_family_reordered.xml']
671
)
672
def test_read_family(family_service, xml, con, app):
673
    family_service.add_soap_response('readFamily', get_xml_file(xml))
687 674
    url = get_endpoint('read-family')
688 675
    Link.objects.create(resource=con, family_id='1312', name_id='local')
689 676

  
690 677
    resp = app.get(url + '?NameID=local')
691 678
    assert resp.json['err'] == 0
692 679
    data = resp.json['data']
693 680
    del data['RL1']
694 681
    del data['RL2']
......
805 792
        'bLeaveAlone': False,
806 793
        'insurance': None,
807 794
        'subscribeSchoolList': [],
808 795
        'mother': {'num': 613963, 'civility': 'MME', 'firstname': 'JANE', 'lastname': 'DOE'},
809 796
        'father': {'num': 613878, 'civility': 'M.', 'firstname': 'JHON', 'lastname': 'DOE'},
810 797
        'rl': None,
811 798
        'subscribeActivityList': [],
812 799
    }
813
    if read_family != READ_FAMILY_LAX:
800
    if xml != 'R_read_family_relax.xml':
814 801
        assert resp.json['data']['childList'][0]['paiInfoBean'] == {
815 802
            'code': 'PAIALI',
816 803
            'code_text': 'ALIMENTAIRE',
817 804
            'dateDeb': '2022-01-01T00:00:00+01:00',
818 805
            'dateFin': '2022-12-31T00:00:00+01:00',
819 806
            'description': 'bla bla PAI',
820 807
        }
821 808
    else:
......
902 889
def test_read_family_not_linked_error(con, app):
903 890
    url = get_endpoint('read-family')
904 891

  
905 892
    resp = app.get(url + '?NameID=')
906 893
    assert resp.json['err'] == 'not-linked'
907 894
    assert resp.json['err_desc'] == 'User not linked to family'
908 895

  
909 896

  
910
@mock.patch('passerelle.utils.Request.get')
911
@mock.patch('passerelle.utils.Request.post')
912
def test_read_rl1(mocked_post, mocked_get, con, app):
913
    mocked_get.return_value = FAMILY_SERVICE_WSDL
914
    mocked_post.return_value = READ_FAMILY
897
def test_read_rl1(family_service, con, app):
898
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
915 899
    url = get_endpoint('read-rl')
916 900
    Link.objects.create(resource=con, family_id='1312', name_id='local')
917 901

  
918 902
    resp = app.get(url + '?NameID=local&rl_id=613878')
919 903
    assert resp.json['err'] == 0
920 904
    assert resp.json['data']['firstname'] == 'JHON'
921 905

  
922 906

  
923
@mock.patch('passerelle.utils.Request.get')
924
@mock.patch('passerelle.utils.Request.post')
925
def test_read_rl1_with_income_year(mocked_post, mocked_get, con, app):
926
    mocked_get.return_value = FAMILY_SERVICE_WSDL
927
    mocked_post.return_value = READ_FAMILY_QUOTIENT
907
def test_read_rl1_with_income_year(family_service, con, app):
908
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family_with_income_year.xml'))
928 909
    url = get_endpoint('read-rl')
929 910
    Link.objects.create(resource=con, family_id='1312', name_id='local')
930 911

  
931 912
    resp = app.get(url + '?NameID=local&rl_id=613878&income_year=2020')
932 913
    assert resp.json['err'] == 0
933 914
    assert resp.json['data']['quotientList'] == [
934 915
        {
935 916
            'yearRev': 2020,
......
938 919
            'mtt': 1500.33,
939 920
            'cdquo': 'QS',
940 921
            'cdquo_text': 'QUOTIENT SCOLAIRE',
941 922
            'codeUti': None,
942 923
        }
943 924
    ]
944 925

  
945 926

  
946
@mock.patch('passerelle.utils.Request.get')
947
@mock.patch('passerelle.utils.Request.post')
948
def test_read_rl2(mocked_post, mocked_get, con, app):
949
    mocked_get.return_value = FAMILY_SERVICE_WSDL
950
    mocked_post.return_value = READ_FAMILY
927
def test_read_rl2(family_service, con, app):
928
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
951 929
    url = get_endpoint('read-rl')
952 930
    Link.objects.create(resource=con, family_id='1312', name_id='local')
953 931

  
954 932
    resp = app.get(url + '?NameID=local&rl_id=613879')
955 933
    assert resp.json['err'] == 0
956 934
    assert resp.json['data'] == {
957 935
        'num': '613879',
958 936
        'lastname': 'DOE',
......
1007 985
def test_read_rl_not_linked_error(con, app):
1008 986
    url = get_endpoint('read-rl')
1009 987

  
1010 988
    resp = app.get(url + '?NameID=local&rl_id=613879')
1011 989
    assert resp.json['err'] == 'not-linked'
1012 990
    assert resp.json['err_desc'] == 'User not linked to family'
1013 991

  
1014 992

  
1015
@mock.patch('passerelle.utils.Request.get')
1016
@mock.patch('passerelle.utils.Request.post')
1017
def test_read_rl_not_found(mocked_post, mocked_get, con, app):
1018
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1019
    mocked_post.return_value = READ_FAMILY
993
def test_read_rl_not_found(family_service, con, app):
994
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1020 995
    url = get_endpoint('read-rl')
1021 996
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1022 997

  
1023 998
    resp = app.get(url + '?NameID=local&rl_id=000000')
1024 999
    assert resp.json['err'] == 'not-found'
1025 1000
    assert resp.json['err_desc'] == "no '000000' RL on '1312' family"
1026 1001

  
1027 1002

  
1028
@mock.patch('passerelle.utils.Request.get')
1029
@mock.patch('passerelle.utils.Request.post')
1030
def test_read_person(mocked_post, mocked_get, con, app):
1031
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1032
    mocked_post.return_value = READ_FAMILY
1003
def test_read_person(family_service, con, app):
1004
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1033 1005
    url = get_endpoint('read-person')
1034 1006
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1035 1007

  
1036 1008
    resp = app.get(url + '?NameID=local&person_id=614059')
1037 1009
    assert resp.json['err'] == 0
1038 1010
    assert resp.json['data']['firstname'] == 'KENY'
1039 1011

  
1040 1012

  
1041 1013
def test_read_person_not_linked_error(con, app):
1042 1014
    url = get_endpoint('read-person')
1043 1015

  
1044 1016
    resp = app.get(url + '?NameID=local&person_id=614059')
1045 1017
    assert resp.json['err'] == 'not-linked'
1046 1018
    assert resp.json['err_desc'] == 'User not linked to family'
1047 1019

  
1048 1020

  
1049
@mock.patch('passerelle.utils.Request.get')
1050
@mock.patch('passerelle.utils.Request.post')
1051
def test_read_person_not_found(mocked_post, mocked_get, con, app):
1052
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1053
    mocked_post.return_value = READ_FAMILY
1021
def test_read_person_not_found(family_service, con, app):
1022
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1054 1023
    url = get_endpoint('read-person')
1055 1024
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1056 1025

  
1057 1026
    resp = app.get(url + '?NameID=local&person_id=000000')
1058 1027
    assert resp.json['err'] == 'not-found'
1059 1028
    assert resp.json['err_desc'] == "no '000000' emergency person on '1312' family"
1060 1029

  
1061 1030

  
1062
@mock.patch('passerelle.utils.Request.get')
1063
@mock.patch('passerelle.utils.Request.post')
1064
def test_read_child(mocked_post, mocked_get, con, app):
1065
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1066
    mocked_post.return_value = READ_FAMILY
1031
def test_read_child(family_service, con, app):
1032
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1067 1033
    url = get_endpoint('read-child')
1068 1034
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1069 1035

  
1070 1036
    resp = app.get(url + '?NameID=local&child_id=613880')
1071 1037
    assert resp.json['err'] == 0
1072 1038
    assert resp.json['data']['firstname'] == 'JANNIS'
1073 1039

  
1074 1040

  
1075 1041
def test_read_child_not_linked_error(con, app):
1076 1042
    url = get_endpoint('read-child')
1077 1043

  
1078 1044
    resp = app.get(url + '?NameID=local&child_id=613880')
1079 1045
    assert resp.json['err'] == 'not-linked'
1080 1046
    assert resp.json['err_desc'] == 'User not linked to family'
1081 1047

  
1082 1048

  
1083
@mock.patch('passerelle.utils.Request.get')
1084
@mock.patch('passerelle.utils.Request.post')
1085
def test_read_child_not_found(mocked_post, mocked_get, con, app):
1086
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1087
    mocked_post.return_value = READ_FAMILY
1049
def test_read_child_not_found(family_service, con, app):
1050
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1088 1051
    url = get_endpoint('read-child')
1089 1052
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1090 1053

  
1091 1054
    resp = app.get(url + '?NameID=local&child_id=000000')
1092 1055
    assert resp.json['err'] == 'not-found'
1093 1056
    assert resp.json['err_desc'] == "no '000000' child on '1312' family"
1094 1057

  
1095 1058

  
1096
@mock.patch('passerelle.utils.Request.get')
1097
@mock.patch('passerelle.utils.Request.post')
1098
def test_read_child_person(mocked_post, mocked_get, con, app):
1099
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1100
    mocked_post.return_value = READ_FAMILY
1059
def test_read_child_person(family_service, con, app):
1060
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1101 1061
    url = get_endpoint('read-child-person')
1102 1062
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1103 1063

  
1104 1064
    resp = app.get(url + '?NameID=local&child_id=613880&person_id=614719')
1105 1065
    assert resp.json['err'] == 0
1106 1066
    assert resp.json['data']['personInfo']['firstname'] == 'AMEL'
1107 1067

  
1108 1068

  
1109 1069
def test_read_child_person_not_linked_error(con, app):
1110 1070
    url = get_endpoint('read-child-person')
1111 1071

  
1112 1072
    resp = app.get(url + '?NameID=local&child_id=613880&person_id=614719')
1113 1073
    assert resp.json['err'] == 'not-linked'
1114 1074
    assert resp.json['err_desc'] == 'User not linked to family'
1115 1075

  
1116 1076

  
1117
@mock.patch('passerelle.utils.Request.get')
1118
@mock.patch('passerelle.utils.Request.post')
1119
def test_read_child_person_no_child_error(mocked_post, mocked_get, con, app):
1120
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1121
    mocked_post.return_value = READ_FAMILY
1077
def test_read_child_person_no_child_error(family_service, con, app):
1078
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1122 1079
    url = get_endpoint('read-child-person')
1123 1080
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1124 1081

  
1125 1082
    resp = app.get(url + '?NameID=local&child_id=42&person_id=614719')
1126 1083
    assert resp.json['err'] == 'not-found'
1127 1084
    assert resp.json['err_desc'] == "no '42' child on '1312' family"
1128 1085

  
1129 1086

  
1130
@mock.patch('passerelle.utils.Request.get')
1131
@mock.patch('passerelle.utils.Request.post')
1132
def test_read_child_person_no_person_error(mocked_post, mocked_get, con, app):
1133
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1134
    mocked_post.return_value = READ_FAMILY
1087
def test_read_child_person_no_person_error(family_service, con, app):
1088
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1135 1089
    url = get_endpoint('read-child-person')
1136 1090
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1137 1091

  
1138 1092
    resp = app.get(url + '?NameID=local&child_id=613880&person_id=000000')
1139 1093
    assert resp.json['err'] == 'not-found'
1140 1094
    assert resp.json['err_desc'] == "no '000000' authorized person on '613880' child"
1141 1095

  
1142 1096

  
1143
@pytest.mark.parametrize(
1144
    'post_response, result',
1145
    [
1146
        (IS_RL_EXISTS_TRUE, True),
1147
        (IS_RL_EXISTS_FALSE, False),
1148
    ],
1149
)
1150
@mock.patch('passerelle.utils.Request.get')
1151
@mock.patch('passerelle.utils.Request.post')
1152
def test_is_rl_exists(mocked_post, mocked_get, post_response, result, con, app):
1153
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1154
    mocked_post.return_value = post_response
1097
@pytest.mark.parametrize('string, result', [(b'true', True), (b'false', False)])
1098
def test_is_rl_exists(string, result, family_service, con, app):
1099
    family_service.add_soap_response('isRLExists', get_xml_file('R_is_rl_exists.xml') % string)
1155 1100
    url = get_endpoint('is-rl-exists')
1156

  
1157 1101
    params = {
1158 1102
        'firstname': 'Jhon',
1159 1103
        'lastname': 'Doe',
1160 1104
        'dateBirth': '1938-07-26',
1161 1105
    }
1106

  
1162 1107
    resp = app.post_json(url, params=params)
1163 1108
    assert resp.json['err'] == 0
1164 1109
    assert resp.json['data'] == result
1165 1110

  
1166 1111

  
1167 1112
def test_is_rl_exists_schema_error(con, app):
1168 1113
    url = get_endpoint('is-rl-exists')
1169

  
1170 1114
    params = {
1171 1115
        'firstname': 'Jhon',
1172 1116
        'lastname': 'Doe',
1173 1117
        'dateBirth': '1938-07-26 more text',
1174 1118
    }
1119

  
1175 1120
    resp = app.post_json(url, params=params, status=400)
1176 1121
    assert resp.json['err'] == 1
1177 1122
    assert "does not match '^[0-9]{4}-[0-9]{2}-[0-9]{2}$'" in resp.json['err_desc']
1178 1123

  
1179 1124

  
1180
@pytest.mark.parametrize(
1181
    'post_response, result',
1182
    [
1183
        (IS_CHILD_EXISTS_TRUE, True),
1184
        (IS_CHILD_EXISTS_FALSE, False),
1185
    ],
1186
)
1187
@mock.patch('passerelle.utils.Request.get')
1188
@mock.patch('passerelle.utils.Request.post')
1189
def test_is_child_exists(mocked_post, mocked_get, post_response, result, con, app):
1190
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1191
    mocked_post.return_value = post_response
1125
@pytest.mark.parametrize('string, result', [(b'true', True), (b'false', False)])
1126
def test_is_child_exists(family_service, string, result, con, app):
1127
    family_service.add_soap_response('isChildExists', get_xml_file('R_is_rl_exists.xml') % string)
1192 1128
    url = get_endpoint('is-child-exists')
1193

  
1194 1129
    params = {
1195 1130
        'firstname': 'Doe',
1196 1131
        'lastname': 'Jhonny allen',
1197 1132
        'dateBirth': '1942-11-27',
1198 1133
    }
1134

  
1199 1135
    resp = app.post_json(url, params=params)
1200 1136
    assert resp.json['err'] == 0
1201 1137
    assert resp.json['data'] == result
1202 1138

  
1203 1139

  
1204
@mock.patch('passerelle.utils.Request.get')
1205
@mock.patch('passerelle.utils.Request.post')
1206
def test_create_family(mocked_post, mocked_get, con, app):
1207
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1208
    mocked_post.return_value = CREATE_FAMILY
1140
def test_create_family(family_service, con, app):
1141
    def request_check(request):
1142
        assert request.emergencyPersonList[0]['firstname'] == 'Keny'
1143

  
1144
    family_service.add_soap_response(
1145
        'createFamily', get_xml_file('R_create_family.xml'), request_check=request_check
1146
    )
1209 1147
    url = get_endpoint('create-family')
1210 1148
    params = {
1211 1149
        'category': 'ACCEUI',
1212 1150
        'situation': 'C',
1213 1151
        'rl1/civility': 'M.',
1214 1152
        'rl1/firstname': 'Jhon',
1215 1153
        'rl1/lastname': 'Doe',
1216 1154
        'rl1/quality': 'AU',
......
1220 1158
        'rl1/birth/place': 'Rabbat',
1221 1159
        'rl1/adresse/idStreet': 'AM0330',
1222 1160
        'rl1/adresse/street1': 'Chateau',
1223 1161
        'rl1/adresse/town': 'Paris',
1224 1162
        'rl1/adresse/zipcode': '75014',
1225 1163
        'rl1/adresse/numComp': 'B',
1226 1164
        'rl1/profession/codeCSP': 'ART',
1227 1165
        'rl1/CAFInfo/organ': 'A10007752822',
1166
        'emergencyPersonList/0/civility': 'MME',
1167
        'emergencyPersonList/0/firstname': 'Keny',
1168
        'emergencyPersonList/0/lastname': 'Arkana',
1169
        'emergencyPersonList/0/sexe': 'F',
1170
        'emergencyPersonList/0/dateBirth': '1982-12-20',
1171
        'emergencyPersonList/0/quality': 'T',
1228 1172
        'childList/0/lastname': 'Zimmerman',
1229 1173
        'childList/0/firstname': 'Robert',
1230 1174
        'childList/0/sexe': 'M',
1231 1175
        'childList/0/birth/dateBirth': '1941-05-24',
1232 1176
        'childList/0/birth/place': 'Saint-louis',
1233 1177
        'childList/0/birth/communeCode': '91122',
1234 1178
        'childList/0/birth/countryCode': '99100',
1235 1179
        'childList/0/dietcode': 'RSV',
1236 1180
        'childList/0/medicalRecord/vaccinList/0/code': 'DTC',
1237 1181
        'childList/0/medicalRecord/vaccinList/0/vaccinationDate': '1940-07-26',
1238 1182
    }
1239 1183

  
1240 1184
    resp = app.post_json(url + '?NameID=local', params=params)
1241
    assert_sent_payload(mocked_post, 'Q_create_family.xml')
1242 1185
    assert resp.json['err'] == 0
1243 1186
    assert resp.json['data'] == {
1244 1187
        'number': 196545,
1245 1188
        'password': '394634V2',
1246 1189
        'rl1ErrorList': [],
1247 1190
        'childErrorList': [],
1248 1191
    }
1249 1192
    assert Link.objects.get(resource=con, family_id='196545', name_id='local')
......
1285 1228
    }
1286 1229

  
1287 1230
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1288 1231
    resp = app.post_json(url + '?NameID=local', params=params)
1289 1232
    assert resp.json['err'] == 'already-linked'
1290 1233
    assert resp.json['err_desc'] == 'User already linked to family'
1291 1234

  
1292 1235

  
1293
@mock.patch('passerelle.utils.Request.get')
1294
@mock.patch('passerelle.utils.Request.post')
1295
def test_create_family_maelis_error(mocked_post, mocked_get, con, app):
1296
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1297
    mocked_post.return_value = CREATE_FAMILY_ERR
1236
def test_create_family_maelis_error(family_service, con, app):
1237
    family_service.add_soap_response('createFamily', get_xml_file('R_create_family_error.xml'))
1298 1238
    url = get_endpoint('create-family')
1299 1239
    params = {
1300 1240
        'category': 'ACCEUI',
1301 1241
        'situation': 'C',
1302 1242
        'rl1/civility': 'M.',
1303 1243
        'rl1/firstname': 'Jhon',
1304 1244
        'rl1/lastname': 'Doe',
1305 1245
        'rl1/quality': 'AU',
......
1348 1288
    resp = app.post_json(url + '?NameID=local', params=params)
1349 1289
    assert resp.json['err'] == 'wrong-key'
1350 1290
    assert (
1351 1291
        resp.json['err_desc']
1352 1292
        == "childList/0/medicalRecord/vaccinList/0/code key value 'plop' do not belong to 'Vaccin' referential"
1353 1293
    )
1354 1294

  
1355 1295

  
1356
@mock.patch('passerelle.utils.Request.get')
1357
@mock.patch('passerelle.utils.Request.post')
1358
def test_update_family(mocked_post, mocked_get, con, app):
1359
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1360
    mocked_post.return_value = UPDATE_FAMILY
1296
def test_update_family(family_service, con, app):
1297
    def request_check(request):
1298
        assert request.emergencyPersonList['personList'][0]['firstname'] == 'Keny'
1299

  
1300
    family_service.add_soap_response(
1301
        'updateFamily', get_xml_file('R_update_family.xml'), request_check=request_check
1302
    )
1361 1303
    url = get_endpoint('update-family')
1362 1304
    params = {
1363 1305
        'category': 'BI',
1364 1306
        'situation': 'C',
1365 1307
        'rl1/civility': 'M.',
1366 1308
        'rl1/firstname': 'Jhon',
1367 1309
        'rl1/lastname': 'Doe',
1368 1310
        'rl1/quality': 'AU',
......
1395 1337
        'childList/1/firstname': 'Brunelle',
1396 1338
        'childList/1/lastname': 'Doe',
1397 1339
        'childList/1/birth/dateBirth': '1943-01-19',
1398 1340
        'childList/1/sexe': 'F',
1399 1341
    }
1400 1342

  
1401 1343
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1402 1344
    resp = app.post_json(url + '?NameID=local', params=params)
1403
    assert_sent_payload(mocked_post, 'Q_update_family.xml')
1404 1345
    assert resp.json['err'] == 0
1405 1346
    assert resp.json['data']['number'] == 196544
1406 1347
    assert not resp.json['data']['childErrorList']
1407 1348

  
1408 1349

  
1409 1350
def test_update_family_not_linked_error(con, app):
1410 1351
    url = get_endpoint('update-family')
1411 1352
    params = {
......
1421 1362
        'rl1/adresse/zipcode': '75014',
1422 1363
    }
1423 1364

  
1424 1365
    resp = app.post_json(url + '?NameID=local', params=params)
1425 1366
    assert resp.json['err'] == 'not-linked'
1426 1367
    assert resp.json['err_desc'] == 'User not linked to family'
1427 1368

  
1428 1369

  
1429
@mock.patch('passerelle.utils.Request.get')
1430
@mock.patch('passerelle.utils.Request.post')
1431
def test_update_family_maelis_error(mocked_post, mocked_get, con, app):
1432
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1433
    mocked_post.return_value = UPDATE_FAMILY_ERR
1370
def test_update_family_maelis_error(family_service, con, app):
1371
    family_service.add_soap_response('updateFamily', get_xml_file('R_update_family_error.xml'))
1434 1372
    url = get_endpoint('update-family')
1435 1373
    params = {
1436 1374
        'category': 'ACCEUI',
1437 1375
        'situation': 'C',
1438 1376
        'childList/0/lastname': 'Zimmerman',
1439 1377
        'childList/0/firstname': 'Robert',
1440 1378
        'childList/0/sexe': 'M',
1441 1379
        'childList/0/birth/dateBirth': '1941-05-24',
......
1443 1381
    }
1444 1382

  
1445 1383
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1446 1384
    resp = app.post_json(url + '?NameID=local', params=params)
1447 1385
    assert resp.json['err'] == 'E65a'
1448 1386
    assert "E65a : Il existe déjà un enfant" in resp.json['err_desc']
1449 1387

  
1450 1388

  
1451
@mock.patch('passerelle.utils.Request.get')
1452
@mock.patch('passerelle.utils.Request.post')
1453
def test_update_family_soap_error(mocked_post, mocked_get, con, app):
1454
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1455
    mocked_post.return_value = UPDATE_FAMILY_500
1389
def test_update_family_soap_error(family_service, con, app):
1390
    family_service.add_soap_response(
1391
        'updateFamily', get_xml_file('R_update_family_soap_error.xml'), status=500
1392
    )
1456 1393
    url = get_endpoint('update-family')
1457 1394
    params = {
1458 1395
        'nbChild': '100',
1459 1396
        'category': 'BI',
1460 1397
        'situation': 'C',
1461 1398
        'rl1/civility': 'M.',
1462 1399
        'rl1/firstname': 'Jhon',
1463 1400
        'rl1/lastname': 'Doe',
......
1514 1451
    resp = app.post_json(url + '?NameID=local', params=params)
1515 1452
    assert resp.json['err'] == 'wrong-key'
1516 1453
    assert (
1517 1454
        resp.json['err_desc']
1518 1455
        == "childList/0/medicalRecord/vaccinList/0/code key value 'plop' do not belong to 'Vaccin' referential"
1519 1456
    )
1520 1457

  
1521 1458

  
1522
@mock.patch('passerelle.utils.Request.get')
1523
@mock.patch('passerelle.utils.Request.post')
1524
def test_create_rl1(mocked_post, mocked_get, con, app):
1525
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1526
    mocked_post.return_value = CREATE_FAMILY
1459
def test_create_rl1(family_service, con, app):
1460
    family_service.add_soap_response('createFamily', get_xml_file('R_create_family.xml'))
1527 1461
    url = get_endpoint('create-rl1')
1528 1462
    params = {
1529 1463
        'category': 'ACCEUI',
1530 1464
        'situation': 'C',
1531 1465
        'rl1/civility': 'M.',
1532 1466
        'rl1/firstname': 'Jhon',
1533 1467
        'rl1/lastname': 'Doe',
1534 1468
        'rl1/quality': 'AU',
1535 1469
        'rl1/birth/dateBirth': '1938-07-26',
1536 1470
        'rl1/adresse/street1': 'Chateau',
1537 1471
        'rl1/adresse/town': 'Paris',
1538 1472
        'rl1/adresse/zipcode': '75014',
1539 1473
    }
1540 1474

  
1541 1475
    resp = app.post_json(url + '?NameID=local', params=params)
1542
    assert_sent_payload(mocked_post, 'Q_create_rl1.xml')
1543 1476
    assert resp.json['err'] == 0
1544 1477
    assert resp.json['data'] == {'family_id': 196545}
1545 1478
    assert Link.objects.get(resource=con, family_id='196545', name_id='local')
1546 1479

  
1547 1480

  
1548 1481
def test_create_rl1_empty_referential_key_error(con, app):
1549 1482
    url = get_endpoint('create-rl1')
1550 1483
    params = {
......
1605 1538
    resp = app.post_json(url + '?NameID=local', params=params)
1606 1539
    assert resp.json['err'] == 'wrong-key'
1607 1540
    assert (
1608 1541
        resp.json['err_desc']
1609 1542
        == "rl1/adresse/numComp key value 'plop' do not belong to 'Complement' referential"
1610 1543
    )
1611 1544

  
1612 1545

  
1613
@mock.patch('passerelle.utils.Request.get')
1614
@mock.patch('passerelle.utils.Request.post')
1615
def test_create_rl1_maelis_error(mocked_post, mocked_get, con, app):
1616
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1617
    mocked_post.return_value = CREATE_FAMILY_ERR
1546
def test_create_rl1_maelis_error(family_service, con, app):
1547
    family_service.add_soap_response('createFamily', get_xml_file('R_create_family_error.xml'))
1618 1548
    url = get_endpoint('create-rl1')
1619 1549
    params = {
1620 1550
        'category': 'ACCEUI',
1621 1551
        'situation': 'C',
1622 1552
        'rl1/civility': 'M.',
1623 1553
        'rl1/firstname': 'Jhon',
1624 1554
        'rl1/lastname': 'Doe',
1625 1555
        'rl1/quality': 'AU',
......
1629 1559
        'rl1/adresse/zipcode': '75014',
1630 1560
    }
1631 1561

  
1632 1562
    resp = app.post_json(url + '?NameID=local', params=params)
1633 1563
    assert resp.json['err'] == 'already-rl1'
1634 1564
    assert 'Il existe déjà' in resp.json['err_desc']
1635 1565

  
1636 1566

  
1637
@mock.patch('passerelle.utils.Request.get')
1638
@mock.patch('passerelle.utils.Request.post')
1639
def test_update_rl1(mocked_post, mocked_get, con, app):
1640
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1641
    mocked_post.side_effect = [READ_RL1_FAMILY, UPDATE_FAMILY]
1567
def test_update_rl1(family_service, con, app):
1568
    def request_check(request):
1569
        assert request.dossierNumber == 1312
1570
        assert request.rl1['adresse']['street1'] == "Chateau d'eau"
1571

  
1572
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family_with_only_rl1.xml'))
1573
    family_service.add_soap_response(
1574
        'updateFamily', get_xml_file('R_update_family.xml'), request_check=request_check
1575
    )
1642 1576
    url = get_endpoint('update-rl1')
1643 1577
    params = {
1644 1578
        'civility': 'M.',
1645 1579
        'firstname': 'Jhonny',
1646 1580
        'lastname': 'Doe',
1647 1581
        'quality': 'PERE',
1648 1582
        'birth/dateBirth': '1943-06-15',
1649 1583
    }
1650 1584

  
1651 1585
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1652 1586
    resp = app.post_json(url + '?NameID=local', params=params)
1653
    assert_sent_payload(mocked_post, 'Q_update_rl1.xml')
1654 1587
    assert resp.json['err'] == 0
1655 1588

  
1656 1589

  
1657 1590
def test_update_rl1_not_linked_error(con, app):
1658 1591
    url = get_endpoint('update-rl1')
1659 1592
    params = {
1660 1593
        'civility': 'M.',
1661 1594
        'firstname': 'Jhonny',
......
1664 1597
        'birth/dateBirth': '1943-06-15',
1665 1598
    }
1666 1599

  
1667 1600
    resp = app.post_json(url + '?NameID=local', params=params)
1668 1601
    assert resp.json['err'] == 'not-linked'
1669 1602
    assert resp.json['err_desc'] == 'User not linked to family'
1670 1603

  
1671 1604

  
1672
@mock.patch('passerelle.utils.Request.get')
1673
@mock.patch('passerelle.utils.Request.post')
1674
def test_update_rl1_connection_error(mocked_post, mocked_get, con, app):
1675
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1676
    mocked_post.side_effect = CONNECTION_ERROR
1605
def test_update_rl1_connection_error(family_service, con, app):
1606
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family_with_only_rl1.xml'))
1607
    family_service.add_soap_response('updateFamily', ConnectionError('No address associated with hostname'))
1677 1608
    url = get_endpoint('update-rl1')
1678 1609
    params = {
1679 1610
        'civility': 'M.',
1680 1611
        'firstname': 'Jhonny',
1681 1612
        'lastname': 'Doe',
1682 1613
        'quality': 'PERE',
1683 1614
        'birth/dateBirth': '1943-06-15',
1684 1615
    }
......
1700 1631
    }
1701 1632

  
1702 1633
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1703 1634
    resp = app.post_json(url + '?NameID=local', params=params)
1704 1635
    assert resp.json['err'] == 'wrong-key'
1705 1636
    assert resp.json['err_desc'] == "quality key value 'plop' do not belong to 'Quality' required referential"
1706 1637

  
1707 1638

  
1708
@mock.patch('passerelle.utils.Request.get')
1709
@mock.patch('passerelle.utils.Request.post')
1710
def test_create_rl2(mocked_post, mocked_get, con, app):
1711
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1712
    mocked_post.side_effect = [READ_RL1_FAMILY, UPDATE_FAMILY]
1639
def test_create_rl2(family_service, con, app):
1640
    def request_check(request):
1641
        assert request.dossierNumber == 1312
1642

  
1643
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family_with_only_rl1.xml'))
1644
    family_service.add_soap_response(
1645
        'updateFamily', get_xml_file('R_update_family.xml'), request_check=request_check
1646
    )
1713 1647
    url = get_endpoint('create-rl2')
1714 1648
    params = {
1715 1649
        'civility': 'MME',
1716 1650
        'firstname': 'JANE',
1717 1651
        'lastname': 'DOE',
1718 1652
        'maidenName': 'Smith',
1719 1653
        'quality': 'MERE',
1720 1654
        'birth/dateBirth': '1940-06-22',
1721 1655
        'adresse/num': '170',
1722 1656
        'adresse/street1': "Chateau d'eau",
1723 1657
        'adresse/town': 'Paris',
1724 1658
        'adresse/zipcode': '75014',
1725 1659
    }
1726 1660

  
1727 1661
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1728 1662
    resp = app.post_json(url + '?NameID=local', params=params)
1729
    assert_sent_payload(mocked_post, 'Q_create_rl2.xml')
1730 1663
    assert resp.json['err'] == 0
1731 1664
    assert resp.json['data'] == {'id': '614062'}
1732 1665

  
1733 1666

  
1734 1667
def test_create_rl2_not_linked_error(con, app):
1735 1668
    url = get_endpoint('create-rl2')
1736 1669
    params = {
1737 1670
        'civility': 'MME',
......
1746 1679
        'adresse/zipcode': '75014',
1747 1680
    }
1748 1681

  
1749 1682
    resp = app.post_json(url + '?NameID=local', params=params)
1750 1683
    assert resp.json['err'] == 'not-linked'
1751 1684
    assert resp.json['err_desc'] == 'User not linked to family'
1752 1685

  
1753 1686

  
1754
@mock.patch('passerelle.utils.Request.get')
1755
@mock.patch('passerelle.utils.Request.post')
1756
def test_create_rl2_connection_error(mocked_post, mocked_get, con, app):
1757
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1758
    mocked_post.side_effect = CONNECTION_ERROR
1687
def test_create_rl2_connection_error(family_service, con, app):
1688
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family_with_only_rl1.xml'))
1689
    family_service.add_soap_response('updateFamily', ConnectionError('No address associated with hostname'))
1759 1690
    url = get_endpoint('create-rl2')
1760 1691
    params = {
1761 1692
        'civility': 'MME',
1762 1693
        'firstname': 'JANE',
1763 1694
        'lastname': 'DOE',
1764 1695
        'maidenName': 'Smith',
1765 1696
        'quality': 'MERE',
1766 1697
        'birth/dateBirth': '1940-06-22',
......
1771 1702
    }
1772 1703

  
1773 1704
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1774 1705
    resp = app.post_json(url + '?NameID=local', params=params, status=500)
1775 1706
    assert resp.json['err']
1776 1707
    assert resp.json['err_desc'] == 'No address associated with hostname'
1777 1708

  
1778 1709

  
1779
@mock.patch('passerelle.utils.Request.get')
1780
@mock.patch('passerelle.utils.Request.post')
1781
def test_create_rl2_already_exists_error(mocked_post, mocked_get, con, app):
1782
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1783
    mocked_post.side_effect = [READ_FAMILY, READ_FAMILY]
1710
def test_create_rl2_already_exists_error(family_service, con, app):
1711
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1784 1712
    url = get_endpoint('create-rl2')
1785 1713
    params = {
1786 1714
        'civility': 'MME',
1787 1715
        'firstname': 'JANE',
1788 1716
        'lastname': 'DOE',
1789 1717
        'maidenName': 'Smith',
1790 1718
        'quality': 'MERE',
1791 1719
        'birth/dateBirth': '1940-06-22',
......
1817 1745
    }
1818 1746

  
1819 1747
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1820 1748
    resp = app.post_json(url + '?NameID=local', params=params)
1821 1749
    assert resp.json['err'] == 'wrong-key'
1822 1750
    assert resp.json['err_desc'] == "quality key value 'plop' do not belong to 'Quality' required referential"
1823 1751

  
1824 1752

  
1825
@mock.patch('passerelle.utils.Request.get')
1826
@mock.patch('passerelle.utils.Request.post')
1827
def test_update_rl2(mocked_post, mocked_get, con, app):
1828
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1829
    mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
1753
def test_update_rl2(family_service, con, app):
1754
    def request_check(request):
1755
        assert request.dossierNumber == 1312
1756
        assert request.rl2['adresse']['street1'] == "Chateau d'eau"
1757

  
1758
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1759
    family_service.add_soap_response(
1760
        'updateFamily', get_xml_file('R_update_family.xml'), request_check=request_check
1761
    )
1830 1762
    url = get_endpoint('update-rl2')
1831 1763
    params = {
1832 1764
        'civility': 'MME',
1833 1765
        'firstname': 'JANE',
1834 1766
        'lastname': 'DOE',
1835 1767
        'maidenName': 'Smith',
1836 1768
        'quality': 'MERE',
1837 1769
        'birth/dateBirth': '1940-06-22',
1838 1770
    }
1839 1771

  
1840 1772
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1841 1773
    resp = app.post_json(url + '?NameID=local', params=params)
1842
    assert_sent_payload(mocked_post, 'Q_update_rl2.xml')
1843 1774
    assert resp.json['err'] == 0
1844 1775

  
1845 1776

  
1846 1777
def test_update_rl2_not_linked_error(con, app):
1847 1778
    url = get_endpoint('update-rl2')
1848 1779
    params = {
1849 1780
        'civility': 'MME',
1850 1781
        'firstname': 'JANE',
......
1854 1785
        'birth/dateBirth': '1940-06-22',
1855 1786
    }
1856 1787

  
1857 1788
    resp = app.post_json(url + '?NameID=local', params=params)
1858 1789
    assert resp.json['err'] == 'not-linked'
1859 1790
    assert resp.json['err_desc'] == 'User not linked to family'
1860 1791

  
1861 1792

  
1862
@mock.patch('passerelle.utils.Request.get')
1863
@mock.patch('passerelle.utils.Request.post')
1864
def test_update_rl2_connection_error(mocked_post, mocked_get, con, app):
1865
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1866
    mocked_post.side_effect = CONNECTION_ERROR
1793
def test_update_rl2_connection_error(family_service, con, app):
1794
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1795
    family_service.add_soap_response('updateFamily', ConnectionError('No address associated with hostname'))
1867 1796
    url = get_endpoint('update-rl2')
1868 1797
    params = {
1869 1798
        'civility': 'MME',
1870 1799
        'firstname': 'JANE',
1871 1800
        'lastname': 'DOE',
1872 1801
        'maidenName': 'Smith',
1873 1802
        'quality': 'MERE',
1874 1803
        'birth/dateBirth': '1940-06-22',
1875 1804
    }
1876 1805

  
1877 1806
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1878 1807
    resp = app.post_json(url + '?NameID=local', params=params, status=500)
1879 1808
    assert resp.json['err']
1880 1809
    assert resp.json['err_desc'] == 'No address associated with hostname'
1881 1810

  
1882 1811

  
1883
@mock.patch('passerelle.utils.Request.get')
1884
@mock.patch('passerelle.utils.Request.post')
1885
def test_update_rl2_not_exists_error(mocked_post, mocked_get, con, app):
1886
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1887
    mocked_post.return_value = READ_RL1_FAMILY
1812
def test_update_rl2_not_exists_error(family_service, con, app):
1813
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family_with_only_rl1.xml'))
1888 1814
    url = get_endpoint('update-rl2')
1889 1815
    params = {
1890 1816
        'civility': 'MME',
1891 1817
        'firstname': 'JANE',
1892 1818
        'lastname': 'DOE',
1893 1819
        'maidenName': 'Smith',
1894 1820
        'quality': 'MERE',
1895 1821
        'birth/dateBirth': '1940-06-22',
......
1913 1839
    }
1914 1840

  
1915 1841
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1916 1842
    resp = app.post_json(url + '?NameID=local', params=params)
1917 1843
    assert resp.json['err'] == 'wrong-key'
1918 1844
    assert resp.json['err_desc'] == "quality key value 'plop' do not belong to 'Quality' required referential"
1919 1845

  
1920 1846

  
1921
@mock.patch('passerelle.utils.Request.get')
1922
@mock.patch('passerelle.utils.Request.post')
1923
def test_create_child(mocked_post, mocked_get, con, app):
1924
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1925
    mocked_post.return_value = CREATE_CHILD
1847
def test_create_child(family_service, con, app):
1848
    family_service.add_soap_response('createChild', get_xml_file('R_create_child.xml'))
1926 1849
    url = get_endpoint('create-child')
1927 1850
    params = {
1928 1851
        'lastname': 'DOE',
1929 1852
        'firstname': 'JANNIS',
1930 1853
        'sexe': 'F',
1931 1854
        'birth/dateBirth': '1943-01-19',
1932 1855
        'birth/place': 'Port Arthur',
1933 1856
    }
1934 1857

  
1935 1858
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1936 1859
    resp = app.post_json(url + '?NameID=local', params=params)
1937
    assert_sent_payload(mocked_post, 'Q_create_child.xml')
1938 1860
    assert resp.json['err'] == 0
1939 1861
    assert resp.json['data'] == {'child_id': 613880}
1940 1862

  
1941 1863

  
1942 1864
def test_create_child_empty_referential_key_error(con, app):
1943 1865
    url = get_endpoint('create-child')
1944 1866
    params = {
1945 1867
        'lastname': 'DOE',
......
1980 1902
    }
1981 1903

  
1982 1904
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1983 1905
    resp = app.post_json(url + '?NameID=local', params=params)
1984 1906
    assert resp.json['err'] == 'wrong-key'
1985 1907
    assert resp.json['err_desc'] == "sexe key value 'plop' do not belong to 'Sex' required referential"
1986 1908

  
1987 1909

  
1988
@mock.patch('passerelle.utils.Request.get')
1989
@mock.patch('passerelle.utils.Request.post')
1990
def test_create_child_connection_error(mocked_post, mocked_get, con, app):
1991
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1992
    mocked_post.side_effect = CONNECTION_ERROR
1910
def test_create_child_connection_error(family_service, con, app):
1911
    family_service.add_soap_response('createChild', ConnectionError('No address associated with hostname'))
1993 1912
    url = get_endpoint('create-child')
1994 1913
    params = {
1995 1914
        'lastname': 'DOE',
1996 1915
        'firstname': 'JANNIS',
1997 1916
        'sexe': 'F',
1998 1917
        'birth/dateBirth': '1943-01-19',
1999 1918
        'birth/place': 'Port Arthur',
2000 1919
    }
2001 1920

  
2002 1921
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2003 1922
    resp = app.post_json(url + '?NameID=local', params=params, status=500)
2004 1923
    assert resp.json['err']
2005 1924
    assert resp.json['err_desc'] == 'No address associated with hostname'
2006 1925

  
2007 1926

  
2008
@mock.patch('passerelle.utils.Request.get')
2009
@mock.patch('passerelle.utils.Request.post')
2010
def test_create_child_maelis_error(mocked_post, mocked_get, con, app):
2011
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2012
    mocked_post.return_value = CREATE_CHILD_ERR
1927
def test_create_child_maelis_error(family_service, con, app):
1928
    family_service.add_soap_response('createChild', get_xml_file('R_create_child_error.xml'))
2013 1929
    url = get_endpoint('create-child')
2014 1930
    params = {
2015 1931
        'lastname': 'DOE',
2016 1932
        'firstname': 'JANNIS',
2017 1933
        'sexe': 'F',
2018 1934
        'birth/dateBirth': '1943-01-19',
2019 1935
        'birth/place': 'Port Arthur',
2020 1936
    }
2021 1937

  
2022 1938
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2023 1939
    resp = app.post_json(url + '?NameID=local', params=params)
2024 1940
    assert resp.json['err'] == 'already-child'
2025 1941
    assert 'Il existe déjà' in resp.json['err_desc']
2026 1942

  
2027 1943

  
2028
@mock.patch('passerelle.utils.Request.get')
2029
@mock.patch('passerelle.utils.Request.post')
2030
def test_update_child(mocked_post, mocked_get, con, app):
2031
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2032
    mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
1944
def test_update_child(family_service, con, app):
1945
    def request_check(request):
1946
        assert request.childList[0]['num'] == '613880'
1947
        assert request.childList[0]['authorizedPersonList'][0]['personInfo']['firstname'] == 'AMEL'
1948

  
1949
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
1950
    family_service.add_soap_response(
1951
        'updateFamily', get_xml_file('R_update_family.xml'), request_check=request_check
1952
    )
2033 1953
    url = get_endpoint('update-child')
2034 1954
    params = {
2035 1955
        'lastname': 'DOE',
2036 1956
        'firstname': 'JANNIS',
2037 1957
        'sexe': 'F',
2038 1958
        'birth/dateBirth': '1943-01-19',
2039 1959
        'birth/place': 'Port Arthur',
2040 1960
        'bPhoto': True,
2041 1961
        'bLeaveAlone': False,
2042 1962
    }
2043 1963

  
2044 1964
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2045 1965
    resp = app.post_json(url + '?NameID=local&child_id=613880', params=params)
2046
    assert_sent_payload(mocked_post, 'Q_update_child.xml')
2047 1966
    assert resp.json['err'] == 0
2048 1967

  
2049 1968

  
2050 1969
def test_update_child_not_linked_error(con, app):
2051 1970
    url = get_endpoint('update-child')
2052 1971
    params = {
2053 1972
        'lastname': 'DOE',
2054 1973
        'firstname': 'JANNIS',
......
2073 1992
    }
2074 1993

  
2075 1994
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2076 1995
    resp = app.post_json(url + '?NameID=local', params=params)
2077 1996
    assert resp.json['err'] == 'wrong-key'
2078 1997
    assert resp.json['err_desc'] == "sexe key value 'plop' do not belong to 'Sex' required referential"
2079 1998

  
2080 1999

  
2081
@mock.patch('passerelle.utils.Request.get')
2082
@mock.patch('passerelle.utils.Request.post')
2083
def test_update_child_connection_error(mocked_post, mocked_get, con, app):
2084
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2085
    mocked_post.side_effect = CONNECTION_ERROR
2000
def test_update_child_connection_error(family_service, con, app):
2001
    family_service.add_soap_response('readFamily', ConnectionError('No address associated with hostname'))
2086 2002
    url = get_endpoint('update-child')
2087 2003
    params = {
2088 2004
        'lastname': 'DOE',
2089 2005
        'firstname': 'JANNIS',
2090 2006
        'sexe': 'F',
2091 2007
        'birth/dateBirth': '1943-01-19',
2092 2008
        'birth/place': 'Port Arthur',
2093 2009
    }
2094 2010

  
2095 2011
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2096 2012
    resp = app.post_json(url + '?NameID=local&child_id=613880', params=params, status=500)
2097 2013
    assert resp.json['err']
2098 2014
    assert resp.json['err_desc'] == 'No address associated with hostname'
2099 2015

  
2100 2016

  
2101
@mock.patch('passerelle.utils.Request.get')
2102
@mock.patch('passerelle.utils.Request.post')
2103
def test_update_child_not_exists_error(mocked_post, mocked_get, con, app):
2104
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2105
    mocked_post.return_value = READ_RL1_FAMILY
2017
def test_update_child_not_exists_error(family_service, con, app):
2018
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family_with_only_rl1.xml'))
2106 2019
    url = get_endpoint('update-child')
2107 2020
    params = {
2108 2021
        'lastname': 'DOE',
2109 2022
        'firstname': 'JANNIS',
2110 2023
        'sexe': 'F',
2111 2024
        'birth/dateBirth': '1943-01-19',
2112 2025
        'birth/place': 'Port Arthur',
2113 2026
    }
2114 2027

  
2115 2028
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2116 2029
    resp = app.post_json(url + '?NameID=local&child_id=42', params=params)
2117 2030
    assert resp.json['err'] == 'no-child'
2118 2031
    assert resp.json['err_desc'] == 'No child 42 to update on family'
2119 2032

  
2120 2033

  
2121
@mock.patch('passerelle.utils.Request.get')
2122
@mock.patch('passerelle.utils.Request.post')
2123
def test_update_coordinate(mocked_post, mocked_get, con, app):
2124
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2125
    mocked_post.return_value = UPDATE_FAMILY
2034
def test_update_coordinate(family_service, con, app):
2035
    family_service.add_soap_response('updateCoordinate', get_xml_file('R_update_family.xml'))
2126 2036
    url = get_endpoint('update-coordinate')
2127 2037
    params = {
2128 2038
        'adresse/num': '169',
2129 2039
        'adresse/numComp': 'B',
2130 2040
        'adresse/idStreet': 'AM0330',
2131 2041
        'adresse/street1': 'Château',
2132 2042
        'adresse/street2': None,
2133 2043
        'adresse/town': 'Paris',
......
2138 2048
        'profession/phone': '0123456789',
2139 2049
        'profession/addressPro': {'num': None, 'street': None, 'zipcode': None, 'town': 'Orléans'},
2140 2050
        'CAFInfo/number': '789',
2141 2051
        'CAFInfo/organ': 'A10007752822',
2142 2052
    }
2143 2053

  
2144 2054
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2145 2055
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
2146
    assert_sent_payload(mocked_post, 'Q_update_coordinate.xml')
2147 2056
    assert resp.json['err'] == 0
2148 2057
    assert resp.json['data'] == 'ok'
2149 2058

  
2150 2059

  
2151 2060
def test_update_coordinate_schema_error(con, app):
2152 2061
    url = get_endpoint('update-coordinate')
2153 2062
    params = {
2154 2063
        'contact/isContactMail': 'true more text',
......
2164 2073
        'adresse/town': 'Paris',
2165 2074
        'adresse/zipcode': '75014',
2166 2075
    }
2167 2076
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params, status=400)
2168 2077
    assert resp.json['err'] == 1
2169 2078
    assert resp.json['err_desc'] == "'true more text' is not of type 'boolean'"
2170 2079

  
2171 2080

  
2172
@mock.patch('passerelle.utils.Request.get')
2173
@mock.patch('passerelle.utils.Request.post')
2174
def test_update_coordinate_wrong_referential_key_error(mocked_post, mocked_get, con, app):
2175
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2176
    mocked_post.return_value = UPDATE_FAMILY
2081
def test_update_coordinate_wrong_referential_key_error(con, app):
2177 2082
    url = get_endpoint('update-coordinate')
2178 2083
    params = {
2179 2084
        'adresse/num': '169',
2180 2085
        'adresse/numComp': 'plop',
2181 2086
        'adresse/street1': 'Château',
2182 2087
        'adresse/street2': None,
2183 2088
        'adresse/town': 'Paris',
2184 2089
        'adresse/zipcode': '75014',
......
2187 2092
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2188 2093
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
2189 2094
    assert resp.json['err'] == 'wrong-key'
2190 2095
    assert (
2191 2096
        resp.json['err_desc'] == "adresse/numComp key value 'plop' do not belong to 'Complement' referential"
2192 2097
    )
2193 2098

  
2194 2099

  
2195
@mock.patch('passerelle.utils.Request.get')
2196
@mock.patch('passerelle.utils.Request.post')
2197
def test_update_quotient(mocked_post, mocked_get, con, app):
2198
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2199
    mocked_post.return_value = UPDATE_QUOTIENT
2100
def test_update_quotient(family_service, con, app):
2101
    family_service.add_soap_response('createUpdateQuotient', get_xml_file('R_create_update_quotient.xml'))
2200 2102
    url = get_endpoint('update-quotient')
2201 2103
    params = {
2202 2104
        'yearRev': '2021',
2203 2105
        'dateStart': '2022-10-01',
2204 2106
        'dateEnd': '2023-01-31',
2205 2107
        'mtt': '1500.33',
2206 2108
        'cdquo': 'QS',
2207 2109
    }
2208 2110

  
2209 2111
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2210 2112
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
2211
    assert_sent_payload(mocked_post, 'Q_create_update_quotient.xml')
2212 2113
    assert resp.json['err'] == 0
2213 2114
    assert resp.json['data'] == 'ok'
2214 2115

  
2215 2116

  
2216 2117
def test_update_quotient_schema_error(con, app):
2217 2118
    url = get_endpoint('update-quotient')
2218 2119
    params = {
2219 2120
        'yearRev': '2021',
......
2224 2125
    }
2225 2126

  
2226 2127
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2227 2128
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params, status=400)
2228 2129
    assert resp.json['err'] == 1
2229 2130
    assert resp.json['err_desc'] == "mtt: '1500,33' does not match '^[0-9]+\\\\.?[0-9]*$'"
2230 2131

  
2231 2132

  
2232
@mock.patch('passerelle.utils.Request.get')
2233
@mock.patch('passerelle.utils.Request.post')
2234
def test_update_quotient_soap_error(mocked_post, mocked_get, con, app):
2235
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2236
    mocked_post.return_value = UPDATE_QUOTIENT_500
2133
def test_update_quotient_soap_error(family_service, con, app):
2134
    family_service.add_soap_response(
2135
        'createUpdateQuotient', get_xml_file('R_create_update_quotient_soap_error.xml'), status=500
2136
    )
2237 2137
    url = get_endpoint('update-quotient')
2238 2138
    params = {
2239 2139
        'yearRev': '2021',
2240 2140
        'dateStart': '2022-10-01',
2241 2141
        'dateEnd': '2023-01-31',
2242 2142
        'mtt': '1500.33',
2243 2143
        'cdquo': 'QS',
2244 2144
    }
......
2260 2160
    }
2261 2161

  
2262 2162
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2263 2163
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
2264 2164
    assert resp.json['err'] == 'wrong-key'
2265 2165
    assert resp.json['err_desc'] == "cdquo key value 'plop' do not belong to 'Quotient' required referential"
2266 2166

  
2267 2167

  
2268
@mock.patch('passerelle.utils.Request.get')
2269
@mock.patch('passerelle.utils.Request.post')
2270
def test_create_person(mocked_post, mocked_get, con, app):
2271
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2272
    mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
2168
def test_create_person(family_service, con, app):
2169
    def request_check(request):
2170
        assert request.dossierNumber == 1312
2171
        assert len(request.emergencyPersonList['personList']) == 2
2172
        assert request.emergencyPersonList['personList'][0]['numPerson'] == 614059
2173
        assert request.emergencyPersonList['personList'][0]['firstname'] == 'KENY'
2174
        assert request.emergencyPersonList['personList'][1]['numPerson'] is None
2175
        assert request.emergencyPersonList['personList'][1]['firstname'] == 'Mathias'
2176

  
2177
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2178
    family_service.add_soap_response(
2179
        'updateFamily', get_xml_file('R_update_family.xml'), request_check=request_check
2180
    )
2273 2181
    url = get_endpoint('create-person')
2274 2182
    params = {
2275 2183
        'civility': None,
2276 2184
        'firstname': 'Mathias',
2277 2185
        'lastname': 'Cassel',
2278 2186
        'quality': 'O',
2279 2187
        'sexe': 'M',
2280 2188
        'dateBirth': '1972-01-01',
2281 2189
        'contact/phone': None,
2282 2190
        'contact/mobile': '0623456789',
2283 2191
        'contact/mail': None,
2284 2192
    }
2285 2193

  
2286 2194
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2287 2195
    resp = app.post_json(url + '?NameID=local', params=params)
2288
    assert_sent_payload(mocked_post, 'Q_create_person.xml')
2289 2196
    assert resp.json['err'] == 0
2290 2197

  
2291 2198

  
2292 2199
def test_create_person_required_field_error(con, app):
2293 2200
    url = get_endpoint('create-person')
2294 2201
    params = {
2295 2202
        'civility': None,
2296 2203
        'firstname': 'Mathias',
......
2360 2267
    }
2361 2268

  
2362 2269
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2363 2270
    resp = app.post_json(url + '?NameID=local', params=params)
2364 2271
    assert resp.json['err'] == 'wrong-key'
2365 2272
    assert resp.json['err_desc'] == "sexe key value 'plop' do not belong to 'Sex' referential"
2366 2273

  
2367 2274

  
2368
@mock.patch('passerelle.utils.Request.get')
2369
@mock.patch('passerelle.utils.Request.post')
2370
def test_update_person(mocked_post, mocked_get, con, app):
2371
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2372
    mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
2275
def test_update_person(family_service, con, app):
2276
    def request_check(request):
2277
        assert request.dossierNumber == 1312
2278
        assert len(request.emergencyPersonList['personList']) == 1
2279
        assert request.emergencyPersonList['personList'][0]['numPerson'] == 614059
2280
        assert request.emergencyPersonList['personList'][0]['firstname'] == 'Mathias'
2281

  
2282
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2283
    family_service.add_soap_response(
2284
        'updateFamily', get_xml_file('R_update_family.xml'), request_check=request_check
2285
    )
2373 2286
    url = get_endpoint('update-person')
2374 2287
    params = {
2375 2288
        'civility': None,
2376 2289
        'firstname': 'Mathias',
2377 2290
        'lastname': 'Cassel',
2378 2291
        'quality': 'O',
2379 2292
        'sexe': 'M',
2380 2293
        'dateBirth': '1972-01-01',
2381 2294
        'contact/phone': None,
2382 2295
        'contact/mobile': '0623456789',
2383 2296
        'contact/mail': None,
2384 2297
    }
2385 2298

  
2386 2299
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2387 2300
    resp = app.post_json(url + '?NameID=local&person_id=614059', params=params)
2388
    assert_sent_payload(mocked_post, 'Q_update_person.xml')
2389 2301
    assert resp.json['err'] == 0
2390 2302

  
2391 2303

  
2392 2304
def test_update_person_not_linked_error(con, app):
2393 2305
    url = get_endpoint('update-person')
2394 2306
    params = {
2395 2307
        'civility': None,
2396 2308
        'firstname': 'Mathias',
......
2403 2315
        'contact/mail': None,
2404 2316
    }
2405 2317

  
2406 2318
    resp = app.post_json(url + '?NameID=local&person_id=614059', params=params)
2407 2319
    assert resp.json['err'] == 'not-linked'
2408 2320
    assert resp.json['err_desc'] == 'User not linked to family'
2409 2321

  
2410 2322

  
2411
@mock.patch('passerelle.utils.Request.get')
2412
@mock.patch('passerelle.utils.Request.post')
2413
def test_update_person_not_found(mocked_post, mocked_get, con, app):
2414
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2415
    mocked_post.return_value = READ_FAMILY
2323
def test_update_person_not_found(family_service, con, app):
2324
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2416 2325
    url = get_endpoint('update-person')
2417 2326
    params = {
2418 2327
        'civility': None,
2419 2328
        'firstname': 'Mathias',
2420 2329
        'lastname': 'Cassel',
2421 2330
        'quality': 'O',
2422 2331
        'sexe': 'M',
2423 2332
        'dateBirth': '1972-01-01',
......
2426 2335
        'contact/mail': None,
2427 2336
    }
2428 2337
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2429 2338
    resp = app.post_json(url + '?NameID=local&person_id=000000', params=params)
2430 2339
    assert resp.json['err'] == 'not-found'
2431 2340
    assert resp.json['err_desc'] == "no '000000' authorized person on '1312' family"
2432 2341

  
2433 2342

  
2434
@mock.patch('passerelle.utils.Request.get')
2435
@mock.patch('passerelle.utils.Request.post')
2436
def test_delete_person(mocked_post, mocked_get, con, app):
2437
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2438
    mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
2343
def test_delete_person(family_service, con, app):
2344
    def request_check(request):
2345
        assert request.dossierNumber == 1312
2346
        assert request.emergencyPersonList is None
2347

  
2348
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2349
    family_service.add_soap_response(
2350
        'updateFamily', get_xml_file('R_update_family.xml'), request_check=request_check
2351
    )
2439 2352
    url = get_endpoint('delete-person')
2440 2353

  
2441 2354
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2442 2355
    resp = app.post_json(url + '?NameID=local&person_id=614059')
2443
    assert_sent_payload(mocked_post, 'Q_delete_person.xml')
2444 2356
    assert resp.json['err'] == 0
2445 2357

  
2446 2358

  
2447 2359
def test_delete_person_not_linked_error(con, app):
2448 2360
    url = get_endpoint('delete-person')
2449 2361

  
2450 2362
    resp = app.post_json(url + '?NameID=local&person_id=614059')
2451 2363
    assert resp.json['err'] == 'not-linked'
2452 2364
    assert resp.json['err_desc'] == 'User not linked to family'
2453 2365

  
2454 2366

  
2455
@mock.patch('passerelle.utils.Request.get')
2456
@mock.patch('passerelle.utils.Request.post')
2457
def test_delete_person_not_found(mocked_post, mocked_get, con, app):
2458
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2459
    mocked_post.return_value = READ_FAMILY
2367
def test_delete_person_not_found(family_service, con, app):
2368
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2460 2369
    url = get_endpoint('delete-person')
2461 2370

  
2462 2371
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2463 2372
    resp = app.post_json(url + '?NameID=local&person_id=000000')
2464 2373
    assert resp.json['err'] == 'not-found'
2465 2374
    assert resp.json['err_desc'] == "no '000000' authorized person on '1312' family"
2466 2375

  
2467 2376

  
2468
@mock.patch('passerelle.utils.Request.get')
2469
@mock.patch('passerelle.utils.Request.post')
2470
def test_create_child_person(mocked_post, mocked_get, con, app):
2471
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2472
    mocked_post.side_effect = [READ_FAMILY, UPDATE_CHILD_AUTO]
2377
def test_create_child_person(family_service, con, app):
2378
    def request_check(request):
2379
        assert request.numFamily == '1312'
2380
        assert request.numPerson == 613880
2381
        assert len(request.personList) == 2
2382
        assert request.personList[0]['personInfo']['num'] == 614719
2383
        assert request.personList[0]['personInfo']['firstname'] == 'AMEL'
2384
        assert request.personList[1]['personInfo']['num'] is None
2385
        assert request.personList[1]['personInfo']['firstname'] == 'Diana'
2386

  
2387
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2388
    family_service.add_soap_response(
2389
        'updateChildAutorization',
2390
        get_xml_file('R_update_child_authorization.xml'),
2391
        request_check=request_check,
2392
    )
2473 2393
    url = get_endpoint('create-child-person')
2474 2394
    params = {
2475 2395
        'personInfo/civility': 'MME',
2476 2396
        'personInfo/firstname': 'Diana',
2477 2397
        'personInfo/lastname': 'Ross',
2478 2398
        'personInfo/sexe': 'F',
2479 2399
        'personInfo/dateBirth': '1944-03-26',
2480 2400
        'personInfo/contact/phone': '0199999999',
2481 2401
        'personInfo/contact/mobile': '0723456789',
2482 2402
        'personInfo/contact/mail': 'dross@example.org',
2483 2403
        'personQuality/code': 'TUTEUR',
2484 2404
    }
2485 2405

  
2486 2406
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2487 2407
    resp = app.post_json(url + '?NameID=local&child_id=613880', params=params)
2488
    assert_sent_payload(mocked_post, 'Q_create_child_person.xml')
2489 2408
    assert resp.json['err'] == 0
2490 2409

  
2491 2410

  
2492 2411
def test_create_child_person_empty_referential_key_error(con, app):
2493 2412
    url = get_endpoint('create-child-person')
2494 2413
    params = {
2495 2414
        'personInfo/civility': 'MME',
2496 2415
        'personInfo/firstname': 'Diana',
......
2542 2461
    }
2543 2462

  
2544 2463
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2545 2464
    resp = app.post_json(url + '?NameID=local&child_id=613880', params=params)
2546 2465
    assert resp.json['err'] == 'wrong-key'
2547 2466
    assert resp.json['err_desc'] == "personInfo/sexe key value 'plop' do not belong to 'Sex' referential"
2548 2467

  
2549 2468

  
2550
@mock.patch('passerelle.utils.Request.get')
2551
@mock.patch('passerelle.utils.Request.post')
2552
def test_create_child_person_no_child_error(mocked_post, mocked_get, con, app):
2553
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2554
    mocked_post.return_value = READ_FAMILY
2469
def test_create_child_person_no_child_error(family_service, con, app):
2470
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2555 2471
    url = get_endpoint('create-child-person')
2556 2472
    params = {
2557 2473
        'personInfo/civility': 'MME',
2558 2474
        'personInfo/firstname': 'Diana',
2559 2475
        'personInfo/lastname': 'Ross',
2560 2476
        'personInfo/sexe': 'F',
2561 2477
        'personInfo/dateBirth': '1944-03-26',
2562 2478
        'personInfo/contact/phone': '01999999999',
......
2566 2482
    }
2567 2483

  
2568 2484
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2569 2485
    resp = app.post_json(url + '?NameID=local&child_id=42', params=params)
2570 2486
    assert resp.json['err'] == 'not-found'
2571 2487
    assert resp.json['err_desc'] == "no '42' child on '1312' family"
2572 2488

  
2573 2489

  
2574
@mock.patch('passerelle.utils.Request.get')
2575
@mock.patch('passerelle.utils.Request.post')
2576
def test_update_child_person(mocked_post, mocked_get, con, app):
2577
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2578
    mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
2490
def test_update_child_person(family_service, con, app):
2491
    def request_check(request):
2492
        assert request.numFamily == '1312'
2493
        assert request.numPerson == 613880
2494
        assert len(request.personList) == 1
2495
        assert request.personList[0]['personInfo']['num'] == 614719
2496
        assert request.personList[0]['personInfo']['firstname'] == 'Angelo'
2497

  
2498
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2499
    family_service.add_soap_response(
2500
        'updateChildAutorization',
2501
        get_xml_file('R_update_child_authorization.xml'),
2502
        request_check=request_check,
2503
    )
2579 2504
    url = get_endpoint('update-child-person')
2580 2505
    params = {
2581 2506
        'personInfo/civility': 'M.',
2582 2507
        'personInfo/firstname': 'Angelo',
2583 2508
        'personInfo/lastname': 'Bent',
2584 2509
        'personInfo/sexe': 'M',
2585 2510
        'personInfo/dateBirth': '1985-06-22',
2586 2511
        'personInfo/contact/phone': '0102030405',
2587 2512
        'personInfo/contact/mobile': None,
2588 2513
        'personInfo/contact/mail': None,
2589 2514
        'personQuality/code': 'O',
2590 2515
    }
2591 2516

  
2592 2517
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2593 2518
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=614719', params=params)
2594
    assert_sent_payload(mocked_post, 'Q_update_child_person.xml')
2595 2519
    assert resp.json['err'] == 0
2596 2520

  
2597 2521

  
2598 2522
def test_update_child_person_not_linked_error(con, app):
2599 2523
    url = get_endpoint('update-child-person')
2600 2524
    params = {
2601 2525
        'personInfo/civility': 'M.',
2602 2526
        'personInfo/firstname': 'Angelo',
......
2628 2552
    }
2629 2553

  
2630 2554
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2631 2555
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=614719', params=params)
2632 2556
    assert resp.json['err'] == 'wrong-key'
2633 2557
    assert resp.json['err_desc'] == "personInfo/sexe key value 'plop' do not belong to 'Sex' referential"
2634 2558

  
2635 2559

  
2636
@mock.patch('passerelle.utils.Request.get')
2637
@mock.patch('passerelle.utils.Request.post')
2638
def test_update_child_person_no_child_error(mocked_post, mocked_get, con, app):
2639
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2640
    mocked_post.return_value = READ_FAMILY
2560
def test_update_child_person_no_child_error(family_service, con, app):
2561
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2641 2562
    url = get_endpoint('update-child-person')
2642 2563
    params = {
2643 2564
        'personInfo/civility': 'M.',
2644 2565
        'personInfo/firstname': 'Angelo',
2645 2566
        'personInfo/lastname': 'Bent',
2646 2567
        'personInfo/dateBirth': '1985-06-22',
2647 2568
        'personInfo/contact/phone': '0102030405',
2648 2569
        'personInfo/contact/mobile': None,
......
2651 2572
    }
2652 2573

  
2653 2574
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2654 2575
    resp = app.post_json(url + '?NameID=local&child_id=42&person_id=614719', params=params)
2655 2576
    assert resp.json['err'] == 'not-found'
2656 2577
    assert resp.json['err_desc'] == "no '42' child on '1312' family"
2657 2578

  
2658 2579

  
2659
@mock.patch('passerelle.utils.Request.get')
2660
@mock.patch('passerelle.utils.Request.post')
2661
def test_update_child_person_not_found(mocked_post, mocked_get, con, app):
2662
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2663
    mocked_post.return_value = READ_FAMILY
2580
def test_update_child_person_not_found(family_service, con, app):
2581
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2664 2582
    url = get_endpoint('update-child-person')
2665 2583
    params = {
2666 2584
        'personInfo/civility': 'M.',
2667 2585
        'personInfo/firstname': 'Angelo',
2668 2586
        'personInfo/lastname': 'Bent',
2669 2587
        'personInfo/dateBirth': '1985-06-22',
2670 2588
        'personInfo/contact/phone': '0102030405',
2671 2589
        'personInfo/contact/mobile': None,
......
2674 2592
    }
2675 2593

  
2676 2594
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2677 2595
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=000000', params=params)
2678 2596
    assert resp.json['err'] == 'not-found'
2679 2597
    assert resp.json['err_desc'] == "No '000000' authorized person on '613880' child"
2680 2598

  
2681 2599

  
2682
@mock.patch('passerelle.utils.Request.get')
2683
@mock.patch('passerelle.utils.Request.post')
2684
def test_delete_child_person(mocked_post, mocked_get, con, app):
2685
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2686
    mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
2600
def test_delete_child_person(family_service, con, app):
2601
    def request_check(request):
2602
        assert request.numFamily == '1312'
2603
        assert request.numPerson == 613880
2604
        assert len(request.personList) == 0
2605

  
2606
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2607
    family_service.add_soap_response(
2608
        'updateChildAutorization',
2609
        get_xml_file('R_update_child_authorization.xml'),
2610
        request_check=request_check,
2611
    )
2687 2612
    url = get_endpoint('delete-child-person')
2688 2613

  
2689 2614
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2690 2615
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=614719')
2691
    assert_sent_payload(mocked_post, 'Q_delete_child_person.xml')
2692 2616
    assert resp.json['err'] == 0
2693 2617

  
2694 2618

  
2695 2619
def test_delete_child_person_not_linked_error(con, app):
2696 2620
    url = get_endpoint('delete-child-person')
2697 2621

  
2698 2622
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=614719')
2699 2623
    assert resp.json['err'] == 'not-linked'
2700 2624
    assert resp.json['err_desc'] == 'User not linked to family'
2701 2625

  
2702 2626

  
2703
@mock.patch('passerelle.utils.Request.get')
2704
@mock.patch('passerelle.utils.Request.post')
2705
def test_delete_child_person_no_child_error(mocked_post, mocked_get, con, app):
2706
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2707
    mocked_post.return_value = READ_FAMILY
2627
def test_delete_child_person_no_child_error(family_service, con, app):
2628
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2708 2629
    url = get_endpoint('delete-child-person')
2709 2630

  
2710 2631
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2711 2632
    resp = app.post_json(url + '?NameID=local&child_id=42&person_id=614719')
2712 2633
    assert resp.json['err'] == 'not-found'
2713 2634
    assert resp.json['err_desc'] == "no '42' child on '1312' family"
2714 2635

  
2715 2636

  
2716
@mock.patch('passerelle.utils.Request.get')
2717
@mock.patch('passerelle.utils.Request.post')
2718
def test_delete_child_person_no_person_error(mocked_post, mocked_get, con, app):
2719
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2720
    mocked_post.return_value = READ_FAMILY
2637
def test_delete_child_person_no_person_error(family_service, con, app):
2638
    family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
2721 2639
    url = get_endpoint('delete-child-person')
2722 2640

  
2723 2641
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2724 2642
    resp = app.post_json(url + '?NameID=local&child_id=613880&person_id=000000')
2725 2643
    assert resp.json['err'] == 'not-found'
2726 2644
    assert resp.json['err_desc'] == "No '000000' authorized person on '613880' child"
2727 2645

  
2728 2646

  
2729
@mock.patch('passerelle.utils.Request.get')
2730
@mock.patch('passerelle.utils.Request.post')
2731
def test_update_child_dietcode(mocked_post, mocked_get, con, app):
2732
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2733
    mocked_post.return_value = UPDATE_DIETCODE
2647
def test_update_child_dietcode(family_service, con, app):
2648
    family_service.add_soap_response('createOrUpdateChildDiet', get_xml_file('R_update_child_dietcode.xml'))
2734 2649
    url = get_endpoint('update-child-dietcode')
2735 2650

  
2736 2651
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2737 2652
    resp = app.post_json(url + '?NameID=local&child_id=613878&dietcode=RSV')
2738
    assert_sent_payload(mocked_post, 'Q_update_child_dietcode.xml')
2739 2653
    assert resp.json['err'] == 0
2740 2654
    assert resp.json['data'] == 'ok'
2741 2655

  
2742 2656

  
2743 2657
def test_update_child_dietcode_not_linked_error(con, app):
2744 2658
    url = get_endpoint('update-child-dietcode')
2745 2659

  
2746 2660
    resp = app.post_json(url + '?NameID=local&child_id=613878&dietcode=RVS')
......
2754 2668
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2755 2669
    resp = app.post_json(url + '?NameID=local&child_id=613878&dietcode=plop')
2756 2670
    assert resp.json['err'] == 'wrong-key'
2757 2671
    assert (
2758 2672
        resp.json['err_desc'] == "dietcode parameter key value 'plop' do not belong to 'DietCode' referential"
2759 2673
    )
2760 2674

  
2761 2675

  
2762
@mock.patch('passerelle.utils.Request.get')
2763
@mock.patch('passerelle.utils.Request.post')
2764
def test_update_child_pai(mocked_post, mocked_get, con, app):
2765
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2766
    mocked_post.return_value = UPDATE_PAI
2676
def test_update_child_pai(family_service, con, app):
2677
    family_service.add_soap_response('updateChildPAI', get_xml_file('R_update_child_pai.xml'))
2767 2678
    url = get_endpoint('update-child-pai')
2768 2679
    params = {
2769 2680
        'code': 'PAIALI',
2770 2681
        'dateDeb': '2022-01-01',
2771 2682
        'dateFin': '',
2772 2683
        'description': 'some text',
2773 2684
    }
2774 2685

  
......
2822 2733
        'description': 'some text',
2823 2734
    }
2824 2735

  
2825 2736
    resp = app.post_json(url + '?NameID=local&child_id=613878', params=params)
2826 2737
    assert resp.json['err'] == 'not-linked'
2827 2738
    assert resp.json['err_desc'] == 'User not linked to family'
2828 2739

  
2829 2740

  
2830
@mock.patch('passerelle.utils.Request.get')
2831
@mock.patch('passerelle.utils.Request.post')
2832
def test_update_child_pai_soap_error(mocked_post, mocked_get, con, app):
2833
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2834
    mocked_post.return_value = UPDATE_PAI_500
2741
def test_update_child_pai_soap_error(family_service, con, app):
2742
    family_service.add_soap_response(
2743
        'updateChildPAI', get_xml_file('R_update_child_pai_soap_error.xml'), status=500
2744
    )
2835 2745
    url = get_endpoint('update-child-pai')
2836 2746
    params = {
2837 2747
        'code': 'PAIALI',
2838 2748
        'dateDeb': '2022-01-01',
2839 2749
        'dateFin': '',
2840 2750
        'description': 'a' * 501,
2841 2751
    }
2842 2752

  
2843 2753
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2844 2754
    resp = app.post_json(url + '?NameID=local&child_id=613878', params=params)
2845 2755
    assert resp.json['err'] == 'Family-updateChildPAI-soap:Server'
2846 2756
    assert 'Une erreur est survenue' in resp.json['err_desc']
2847 2757
    assert 'valeur trop grande' in resp.json['err_desc']
2848 2758
    assert 'maximum : 500' in resp.json['err_desc']
2849 2759

  
2850 2760

  
2851
@mock.patch('passerelle.utils.Request.get')
2852
@mock.patch('passerelle.utils.Request.post')
2853
def test_update_child_medical_record(mocked_post, mocked_get, con, app):
2854
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2855
    mocked_post.return_value = UPDATE_MEDICAL
2761
def test_update_child_medical_record(family_service, con, app):
2762
    family_service.add_soap_response(
2763
        'updateChildMedicalRecord', get_xml_file('R_update_child_medical_record.xml')
2764
    )
2856 2765
    url = get_endpoint('update-child-medical-record')
2857 2766
    params = {
2858 2767
        'familyDoctor/name': 'Dre',
2859 2768
        'familyDoctor/phone': '0612341234',
2860 2769
        'familyDoctor/address/street1': 'Alameda',
2861 2770
        'familyDoctor/address/zipcode': '90220',
2862 2771
        'familyDoctor/address/town': 'Compton',
2863 2772
        'allergy1': 'butterscotch, imitation butterscotch, glow-in-the-dark monster make-up, and shrimp',
......
2871 2780
        'vaccinList/0/code': 'DTC',
2872 2781
        'vaccinList/0/vaccinationDate': '2011-01-11',
2873 2782
        'vaccinList/1/code': 'ROR',
2874 2783
        'vaccinList/1/vaccinationDate': '2022-02-22',
2875 2784
    }
2876 2785

  
2877 2786
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2878 2787
    resp = app.post_json(url + '?NameID=local&child_id=613878', params=params)
2879
    assert_sent_payload(mocked_post, 'Q_update_child_medical_record.xml')
2880 2788
    assert resp.json['err'] == 0
2881 2789
    assert resp.json['data'] == 'ok'
2882 2790

  
2883 2791

  
2884
@mock.patch('passerelle.utils.Request.get')
2885
@mock.patch('passerelle.utils.Request.post')
2886
def test_update_child_medical_record_with_empty_vaccin_list(mocked_post, mocked_get, con, app):
2887
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2888
    mocked_post.return_value = UPDATE_MEDICAL
2792
def test_update_child_medical_record_with_empty_vaccin_list(family_service, con, app):
2793
    family_service.add_soap_response(
2794
        'updateChildMedicalRecord', get_xml_file('R_update_child_medical_record.xml')
2795
    )
2889 2796
    url = get_endpoint('update-child-medical-record')
2890 2797
    params = {
2891 2798
        'familyDoctor/name': 'Dre',
2892 2799
        'familyDoctor/phone': '0612341234',
2893 2800
        'familyDoctor/address/street1': 'Alameda',
2894 2801
        'familyDoctor/address/zipcode': '90220',
2895 2802
        'familyDoctor/address/town': 'Compton',
2896 2803
        'allergy1': 'butterscotch, imitation butterscotch, glow-in-the-dark monster make-up, and shrimp',
......
2912 2819
def test_update_child_medical_record_not_linked_error(con, app):
2913 2820
    url = get_endpoint('update-child-medical-record')
2914 2821

  
2915 2822
    resp = app.post_json(url + '?NameID=local&child_id=613878', params={})
2916 2823
    assert resp.json['err'] == 'not-linked'
2917 2824
    assert resp.json['err_desc'] == 'User not linked to family'
2918 2825

  
2919 2826

  
2920
@mock.patch('passerelle.utils.Request.get')
2921
@mock.patch('passerelle.utils.Request.post')
2922
def test_update_child_medical_record_soap_error(mocked_post, mocked_get, con, app):
2923
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2924
    mocked_post.return_value = UPDATE_MEDICAL_500
2827
def test_update_child_medical_record_soap_error(family_service, con, app):
2828
    family_service.add_soap_response(
2829
        'updateChildMedicalRecord', get_xml_file('R_update_child_medical_record_soap_error.xml'), status=500
2830
    )
2925 2831
    url = get_endpoint('update-child-medical-record')
2926 2832
    params = {
2927 2833
        'vaccinList/0/code': 'DTC',
2928 2834
        'vaccinList/0/vaccinationDate': '2022-02-31',
2929 2835
    }
2930 2836

  
2931 2837
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2932 2838
    resp = app.post_json(url + '?NameID=local&child_id=613878', params=params)
......
2950 2856
    }
2951 2857

  
2952 2858
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2953 2859
    resp = app.post_json(url + '?NameID=local&child_id=613878', params=params)
2954 2860
    assert resp.json['err'] == 'wrong-key'
2955 2861
    assert resp.json['err_desc'] == "vaccinList/1/code key value 'plop' do not belong to 'Vaccin' referential"
2956 2862

  
2957 2863

  
2958
@mock.patch('passerelle.utils.Request.get')
2959
@mock.patch('passerelle.utils.Request.post')
2960
def test_update_rl_indicator(mocked_post, mocked_get, con, app):
2961
    mocked_get.return_value = FAMILY_SERVICE_WSDL
2962
    mocked_post.return_value = UPDATE_INDICATOR
2864
def test_update_rl_indicator(family_service, con, app):
2865
    family_service.add_soap_response('updatePersonIndicatorList', get_xml_file('R_update_indicator.xml'))
2963 2866
    url = get_endpoint('update-rl-indicator')
2964 2867
    params = {
2965 2868
        'indicatorList': [
2966 2869
            {
2967 2870
                'code': 'AVL',
2968 2871
                'isActive': True,
2969 2872
            },
2970 2873
            {
......
2972 2875
                'note': 'SNPP',
2973 2876
                'isActive': True,
2974 2877
            },
2975 2878
        ],
2976 2879
    }
2977 2880

  
2978 2881
    Link.objects.create(resource=con, family_id='1312', name_id='local')
2979 2882
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
2980
    assert_sent_payload(mocked_post, 'Q_update_rl_indicator.xml')
2981 2883
    assert resp.json['err'] == 0
2982 2884
    assert resp.json['data'] == 'ok'
2983 2885

  
2984 2886

  
2985 2887
def test_update_rl_indicator_not_linked_error(con, app):
2986 2888
    url = get_endpoint('update-rl-indicator')
2987 2889
    params = {
2988 2890
        'indicatorList': [
......
3040 2942
    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
3041 2943
    assert resp.json['err'] == 'wrong-key'
3042 2944
    assert (
3043 2945
        resp.json['err_desc']
3044 2946
        == "indicatorList/0/code key value 'plop' do not belong to 'RLIndicator' required referential"
3045 2947
    )
3046 2948

  
3047 2949

  
3048
@mock.patch('passerelle.utils.Request.get')
3049
@mock.patch('passerelle.utils.Request.post')
3050
def test_update_child_indicator(mocked_post, mocked_get, con, app):
3051
    mocked_get.return_value = FAMILY_SERVICE_WSDL
3052
    mocked_post.return_value = UPDATE_INDICATOR
2950
def test_update_child_indicator(family_service, con, app):
2951
    family_service.add_soap_response('updatePersonIndicatorList', get_xml_file('R_update_indicator.xml'))
3053 2952
    url = get_endpoint('update-child-indicator')
3054 2953
    params = {
3055 2954
        'indicatorList': [
3056 2955
            {
3057 2956
                'code': 'LUNETTE',
3058 2957
                'isActive': True,
3059 2958
            },
3060 2959
            {
......
3062 2961
                'note': 'rebellious',
3063 2962
                'isActive': True,
3064 2963
            },
3065 2964
        ],
3066 2965
    }
3067 2966

  
3068 2967
    Link.objects.create(resource=con, family_id='1312', name_id='local')
3069 2968
    resp = app.post_json(url + '?NameID=local&child_id=613880', params=params)
3070
    assert_sent_payload(mocked_post, 'Q_update_child_indicator.xml')
3071 2969
    assert resp.json['err'] == 0
3072 2970
    assert resp.json['data'] == 'ok'
3073 2971

  
3074 2972

  
3075 2973
def test_update_child_indicator_not_linked_error(con, app):
3076 2974
    url = get_endpoint('update-child-indicator')
3077 2975
    params = {
3078 2976
        'indicatorList': [
tests/utils.py
102 102
                finally:
103 103
                    if request_check:
104 104
                        request = operation.input.deserialize(doc.getroot())
105 105
                        request_check(request)
106 106
            return False, None
107 107

  
108 108
        return matcher
109 109

  
110
    def add_soap_response(self, mock, operation_name, response_content, request_check=None):
110
    def add_soap_response(self, mock, operation_name, response_content, status=200, request_check=None):
111 111
        operation = self.binding.get(operation_name)
112
        doc = ET.parse(io.BytesIO(response_content))
113
        try:
114
            operation.output.deserialize(doc.getroot())
115
        except Exception as e:
116
            raise AssertionError(f'response_content did not match operation "{operation_name}" schema') from e
112
        if not isinstance(response_content, Exception):
113
            doc = ET.parse(io.BytesIO(response_content))
114
            try:
115
                operation.output.deserialize(doc.getroot())
116
            except Exception as e:
117
                raise AssertionError(
118
                    f'response_content did not match operation "{operation_name}" schema'
119
                ) from e
117 120
        mock.add(
118 121
            responses.POST,
119 122
            self.address,
120 123
            body=response_content,
121
            status=200,
124
            status=status,
122 125
            match=(self.soap_matcher(operation_name, request_check),),
123 126
        )
124 127

  
125 128
    @contextlib.contextmanager
126 129
    def __call__(self):
127 130
        with responses.RequestsMock() as mock:
128 131
            mock.add(responses.GET, self.wsdl_url, body=self.wsdl_content, status=200)
129 132
            mock.add_soap_response = (
130
                lambda operation, response_content, request_check=None: self.add_soap_response(
133
                lambda operation, response_content, status=200, request_check=None: self.add_soap_response(
131 134
                    mock,
132 135
                    operation,
133 136
                    response_content,
137
                    status=status,
134 138
                    request_check=request_check,
135 139
                )
136 140
            )
137 141
            yield mock
138
-