Project

General

Profile

0001-tests-refactor-mdel-tests-36471.patch

Benjamin Dauvergne, 26 Sep 2019 10:41 PM

Download (38.1 KB)

View differences:

Subject: [PATCH 1/2] tests: refactor mdel tests (#36471)

- simplify loading of file fixtures
- explode parametrized tests into many test functions
 .../mdel/{ActeEtatCivil-V1.A.xsd => aec.xsd}  |   0
 ...formdata_aec_deces.json => aec_deces.json} |   0
 ...data_aec_mariage.json => aec_mariage.json} |   0
 ...data_aec_naiss.json => aec_naissance.json} |   0
 tests/data/mdel/aec_naissance_etranger.json   | 131 +++++
 tests/data/mdel/{formdata.json => ile.json}   |   0
 tests/data/mdel/{ILE_v1.1.xsd => ile.xsd}     |   0
 tests/test_mdel.py                            | 469 +++++++++---------
 8 files changed, 376 insertions(+), 224 deletions(-)
 rename tests/data/mdel/{ActeEtatCivil-V1.A.xsd => aec.xsd} (100%)
 rename tests/data/mdel/{formdata_aec_deces.json => aec_deces.json} (100%)
 rename tests/data/mdel/{formdata_aec_mariage.json => aec_mariage.json} (100%)
 rename tests/data/mdel/{formdata_aec_naiss.json => aec_naissance.json} (100%)
 create mode 100644 tests/data/mdel/aec_naissance_etranger.json
 rename tests/data/mdel/{formdata.json => ile.json} (100%)
 rename tests/data/mdel/{ILE_v1.1.xsd => ile.xsd} (100%)
tests/data/mdel/aec_naissance_etranger.json
1
{
2
    "criticality_level": 0,
3
    "display_id": "1-4",
4
    "display_name": "Demande d'un acte de naissance #15-4",
5
    "evolution": [
6
        {
7
            "status": "2",
8
            "time": "2016-10-19T14:00:19Z",
9
            "who": {
10
                "email": "chelsea@whatever.com",
11
                "id": "2",
12
                "name": "chelsea"
13
            }
14
        }
15
    ],
16
    "extra": {
17
        "aec_type": "Acte de naissance",
18
        "aec_type_raw": "NAISSANCE",
19
        "code_insee": "54395",
20
        "code_postal": "54000",
21
        "demand_type": "aec-la",
22
        "ville": "Nancy",
23
        "date_acte": "1958-05-19"
24
    },
25
    "fields": {
26
        "aec_nature": "Copie int\u00e9grale",
27
        "aec_nature_raw": "COPIE-INTEGRALE",
28
        "demandeur_adresse_etrangere_pays_raw": "Suisse",
29
        "demandeur_adresse_etrangere": "4 rue des coquelicots, 3800 Bern",
30
        "demandeur_civilite": "Madame",
31
        "demandeur_civilite_raw": "Madame",
32
        "demandeur_email": "chelsea@whatever.com",
33
        "demandeur_nom": "Whatever",
34
        "demandeur_prenom": "Chelsea",
35
        "demandeur_telephone": "0122334455",
36
        "motif_demande": "Certificat de nationalit\u00e9 fran\u00e7aise",
37
        "motif_demande_raw": "CertificatDeNationaliteFrancaise",
38
        "nombre_exemplaires": "2",
39
        "qualite_demandeur": "Son fils ou sa fille",
40
        "qualite_demandeur_autre": null,
41
        "qualite_demandeur_raw": "Fils",
42
        "titulaire_civilite": "Madame",
43
        "titulaire_civilite_raw": "Madame",
44
        "titulaire_mere_nom": "Song",
45
        "titulaire_mere_prenoms": "Eloise",
46
        "titulaire_naiss_date": "1958-05-19",
47
        "titulaire_naiss_departement": "Meurthe et Moselle",
48
        "titulaire_naiss_departement_raw": "54",
49
        "titulaire_naiss_pays": "France",
50
        "titulaire_naiss_pays_raw": "FRA",
51
        "titulaire_naiss_ville": "Nancy",
52
        "titulaire_naiss_ville_raw": "Nancy",
53
        "titulaire_nationalite": "France",
54
        "titulaire_nationalite_raw": "FRA",
55
        "titulaire_nom": "Whatever",
56
        "titulaire_pere_nom": "Whatever",
57
        "titulaire_pere_prenoms": "Fritz",
58
        "titulaire_prenoms": "Kim"
59
    },
60
    "id": "demande-d-un-acte-de-naissance/4",
61
    "last_update_time": "2016-10-19T14:00:19Z",
62
    "receipt_time": "2016-10-19T14:00:19Z",
63
    "roles": {
64
        "_receiver": [
65
            {
66
                "allows_backoffice_access": true,
67
                "details": "",
68
                "emails": [],
69
                "emails_to_members": false,
70
                "id": "22",
71
                "name": "Etat civil Acte",
72
                "slug": "etat-civil-acte",
73
                "text": "Etat civil Acte"
74
            }
75
        ],
76
        "actions": [
77
            {
78
                "allows_backoffice_access": true,
79
                "details": "",
80
                "emails": [],
81
                "emails_to_members": false,
82
                "id": "3",
83
                "name": "agent",
84
                "slug": "agent",
85
                "text": "agent"
86
            }
87
        ],
88
        "concerned": [
89
            {
90
                "allows_backoffice_access": true,
91
                "details": "",
92
                "emails": [],
93
                "emails_to_members": false,
94
                "id": "3",
95
                "name": "agent",
96
                "slug": "agent",
97
                "text": "agent"
98
            },
99
            {
100
                "allows_backoffice_access": true,
101
                "details": "",
102
                "emails": [],
103
                "emails_to_members": false,
104
                "id": "22",
105
                "name": "Etat civil Acte",
106
                "slug": "etat-civil-acte",
107
                "text": "Etat civil Acte"
108
            }
109
        ]
110
    },
111
    "submission": {
112
        "backoffice": false,
113
        "channel": "web"
114
    },
115
    "url": "http://wcs.debian.local/demande-d-un-acte-de-naissance/4/",
116
    "user": {
117
        "email": "chelsea@whatever.com",
118
        "id": "2",
119
        "name": "chelsea"
120
    },
121
    "workflow": {
122
        "fields": {
123
            "aec_type": "Acte de naissance",
124
            "aec_type_raw": "NAISSANCE"
125
        },
126
        "status": {
127
            "id": "2",
128
            "name": "new"
129
        }
130
    }
131
}
tests/test_mdel.py
1
# -*- coding: utf-8 -*-
2
# Passerelle - uniform access to data and services
3
# Copyright (C) 2015  Entr'ouvert
1
# coding: utf-8
2
# passerelle - uniform access to data and services
3
# Copyright (C) 2019  Entr'ouvert
4 4
#
5 5
# This program is free software: you can redistribute it and/or modify it
6 6
# under the terms of the GNU Affero General Public License as published
......
14 14
#
15 15
# You should have received a.deepcopy of the GNU Affero General Public License
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17

  
17 18
from __future__ import unicode_literals
18 19

  
19 20
import shutil
......
33 34

  
34 35
import utils
35 36

  
36
AEC_XSD = 'ActeEtatCivil-V1.A.xsd'
37
ILE_XSD = 'ILE_v1.1.xsd'
38

  
37
data_dir = os.path.join(os.path.dirname(__file__), 'data', 'mdel')
39 38

  
40
def get_mdel_base_dir():
41
    return os.path.join(os.path.dirname(__file__), 'data', 'mdel')
42 39

  
40
def generate_json_fixture(path):
41
    @pytest.fixture
42
    def fixture():
43
        with open(path) as fd:
44
            return json.load(fd)
45
    return fixture
43 46

  
44
def get_file_from_test_base_dir(filename):
45
    path = os.path.join(get_mdel_base_dir(), filename)
46
    with open(path, 'rb') as fd:
47
        return fd.read()
48 47

  
48
def generate_xsd_fixture(path):
49
    @pytest.fixture
50
    def fixture():
51
        def validate_schema(doc):
52
            xsd = letree.parse(path).getroot()
53
            schema = letree.XMLSchema(xsd)
54
            parser = letree.XMLParser(schema=schema)
55
            letree.parse(doc, parser=parser)  # Will raise an exception if schema not respected
56
        return validate_schema
57
    return fixture
49 58

  
50
def validate_schema(doc, xsd):
51
    xsd_path = os.path.join(get_mdel_base_dir(), xsd)
52
    xsd = letree.parse(xsd_path).getroot()
53
    schema = letree.XMLSchema(xsd)
54
    parser = letree.XMLParser(schema=schema)
55
    letree.parse(doc, parser=parser)  # Will raise an exception if schema not respected
56 59

  
60
for filename in os.listdir(data_dir):
61
    path = os.path.join(data_dir, filename)
62
    name, ext = os.path.splitext(filename)
63
    if ext == '.json':
64
        globals()[name + '_payload'] = generate_json_fixture(path)
65
    elif ext == '.xsd':
66
        globals()[name + '_schema'] = generate_xsd_fixture(path)
57 67

  
58 68

  
59
@pytest.fixture
60
def setup(db):
69
@pytest.fixture(autouse=True)
70
def mdel(db):
61 71
    return utils.setup_access_rights(MDEL.objects.create(slug='test'))
62 72

  
63 73

  
64
@pytest.fixture(params=[
65
                json.loads(get_file_from_test_base_dir('formdata_aec_naiss.json')),
66
                json.loads(get_file_from_test_base_dir('formdata_aec_mariage.json')),
67
                json.loads(get_file_from_test_base_dir('formdata_aec_deces.json')),
68
                ], ids=['naissance', 'mariage', 'deces'])
69
def aec_payload(request):
70
    return request.param
71

  
72

  
73
ILE_PAYLOAD = json.loads(get_file_from_test_base_dir('formdata.json'))
74

  
75

  
76 74
def test_message():
77 75
    ns = {'mdel': 'http://finances.gouv.fr/dgme/pec/message/v1'}
78 76
    xmlns = 'http://finances.gouv.fr/dgme/gf/composants/teledemarchexml/donnee/metier'
......
93 91

  
94 92

  
95 93
def test_description():
96

  
97 94
    attached_files = [
98 95
        AttachedFile('JI', 'passport', base64.b64encode('this is passport')),
99 96
        AttachedFile('JD', 'energy_bill', base64.b64encode('this is edf_mai_2016')),
100 97
    ]
101

  
102 98
    description = Description(
103 99
        'ILE-LA', '77', '94600', attached_files=attached_files)
104 100
    xml = description.xml
......
109 105
    assert xml.find('Teledemarche/IdentifiantPlateforme').text == '1'
110 106

  
111 107

  
112
def test_invalid_demand_type(app, setup):
113
    ILE_PAYLOAD_INVALID = copy.deepcopy(ILE_PAYLOAD)
108
def test_invalid_demand_type(app, ile_payload):
109
    ILE_PAYLOAD_INVALID = copy.deepcopy(ile_payload)
114 110
    ILE_PAYLOAD_INVALID['extra']['demand_type'] = 'whatever'
115 111
    resp = app.post_json('/mdel/test/create', params=ILE_PAYLOAD_INVALID, status=200)
116 112
    assert resp.json['err_desc'] == "demand_type must be : ['ILE-LA', 'RCO-LA', 'AEC-LA']"
117 113

  
118 114

  
119
def test_invalid_demand_no_form_number(app, setup):
120
    ILE_PAYLOAD_INVALID_NO = copy.deepcopy(ILE_PAYLOAD)
115
def test_invalid_demand_no_form_number(app, ile_payload):
116
    ILE_PAYLOAD_INVALID_NO = copy.deepcopy(ile_payload)
121 117
    ILE_PAYLOAD_INVALID_NO.pop('display_id')
122 118
    resp = app.post_json('/mdel/test/create', params=ILE_PAYLOAD_INVALID_NO, status=200)
123 119
    assert resp.json['err_desc'] == "display_id is required"
124 120

  
125 121

  
126
def test_create_rco_demand_type(app, setup):
127
    RCO_PAYLOAD = copy.deepcopy(ILE_PAYLOAD)
122
def test_unsupported_demand_type(app, ile_payload):
123
    RCO_PAYLOAD = copy.deepcopy(ile_payload)
128 124
    RCO_PAYLOAD['extra']['demand_type'] = 'rco-la'
129 125
    resp = app.post_json('/mdel/test/create', params=RCO_PAYLOAD, status=200)
130 126
    assert resp.json['err_desc'] == "RCO-LA processing not implemented"
131 127

  
132 128

  
133
def test_create_aec_demand_type(app, setup, aec_payload):
134
    resp = app.post_json('/mdel/test/create', params=aec_payload, status=200)
135

  
136
    if aec_payload['display_id'] == '15-4':
137
        assert resp.json['data']['demand_id'] == '15-4-AEC-LA'
138

  
139
        doc = os.path.join(get_resource_base_dir(), 'test', 'inputs', '15-4-AEC-LA--0', '15-4-AEC-LA-doc-.xml')
140
        validate_schema(doc, AEC_XSD)
141

  
142
        root = etree.parse(doc).getroot()
143

  
144
        assert root.tag == 'EnveloppeMetierType'
145

  
146
        # Generic tags
147
        assert root.find('DemandeActe/TypeActe/Code').text == 'NAISSANCE'
148
        assert root.find('DemandeActe/NatureActe/Code').text == 'COPIE-INTEGRALE'
149
        assert root.find('DemandeActe/MotifDemande/Commentaire').text == 'CertificatDeNationaliteFrancaise'
150
        assert root.find('DemandeActe/LieuActe/CodePostal').text == '54000'
151
        assert root.find('DemandeActe/LieuActe/CodeINSEE').text == '54395'
152
        assert root.find('DemandeActe/LieuActe/Ville').text == 'Nancy'
153
        assert root.find('DemandeActe/DateActe').text == '1958-05-19'
154
        assert root.find('DemandeActe/NombreExemplaires').text == '2'
155

  
156
        # Requester
157
        assert root.find('DemandeActe/Demandeur/Courriel').text == 'chelsea@whatever.com'
158
        assert root.find('DemandeActe/Demandeur/Civilite').text == 'MADAME'
159
        assert root.find('DemandeActe/Demandeur/Nom').text == 'Whatever'
160
        assert root.find('DemandeActe/Demandeur/Prenom').text == 'Chelsea'
161
        assert root.find('DemandeActe/Demandeur/Telephone').text == '0122334455'
162
        assert root.find('DemandeActe/Demandeur/QualiteDemandeur/Code').text == 'Fils'
163
        assert root.find('DemandeActe/Demandeur/AdresseEtrangere/Pays').text == 'Suisse'
164
        assert root.find('DemandeActe/Demandeur/AdresseEtrangere/Adresse').text == '3ème, Bâtiment B, 37 rue de Paris, 3800 Bern'
165

  
166
        assert not root.find('DemandeActe/Demandeur/AdresseFrancaise/CodePostal')
167
        assert not root.find('DemandeActe/Demandeur/AdresseFrancaise/Ville')
168
        assert not root.find('DemandeActe/Demandeur/AdresseFrancaise/Voie')
169

  
170
        # Concerned
171
        assert root.find('DemandeActe/Titulaire/Civilite').text == 'MADAME'
172
        assert root.find('DemandeActe/Titulaire/Nationalite').text == 'FRA'
173
        assert root.find('DemandeActe/Titulaire/DateDeNaissance').text == '1958-05-19'
174
        assert root.find('DemandeActe/Titulaire/PaysDeNaissance').text == 'FRA'
175
        assert root.find('DemandeActe/Titulaire/DepartementDeNaissance').text == '54'
176
        assert root.find('DemandeActe/Titulaire/NomNaissance').text == 'Whatever'
177
        assert root.find('DemandeActe/Titulaire/Prenoms').text == 'Kim'
178
        assert root.find('DemandeActe/Titulaire/Filiation/Mere/Nom').text == 'Song'
179
        assert root.find('DemandeActe/Titulaire/Filiation/Mere/Prenoms').text == 'Eloise'
180
        assert root.find('DemandeActe/Titulaire/Filiation/Pere/Nom').text == 'Whatever'
181
        assert root.find('DemandeActe/Titulaire/Filiation/Pere/Prenoms').text == 'Fritz'
182

  
183
    elif aec_payload['display_id'] == '16-1':
184

  
185
        assert resp.json['data']['demand_id'] == '16-1-AEC-LA'
186

  
187
        doc = os.path.join(get_resource_base_dir(), 'test', 'inputs', '16-1-AEC-LA--0', '16-1-AEC-LA-doc-.xml')
188
        validate_schema(doc, AEC_XSD)
189

  
190
        root = etree.parse(doc).getroot()
191

  
192
        assert root.tag == 'EnveloppeMetierType'
193

  
194
        # Generic tags
195
        assert root.find('DemandeActe/TypeActe/Code').text == 'MARIAGE'
196
        assert root.find('DemandeActe/NatureActe/Code').text == 'EXTRAIT-AVEC-FILIATION'
197
        assert root.find('DemandeActe/MotifDemande/Commentaire').text == 'Autre'
198
        assert root.find('DemandeActe/LieuActe/CodePostal').text == '54000'
199
        assert root.find('DemandeActe/LieuActe/CodeINSEE').text == '54395'
200
        assert root.find('DemandeActe/LieuActe/Ville').text == 'Nancy'
201
        assert root.find('DemandeActe/DateActe').text == '2008-08-18'
202
        assert root.find('DemandeActe/NombreExemplaires').text == '3'
203

  
204
        # Requester
205
        assert root.find('DemandeActe/Demandeur/Courriel').text == 'chelsea@whatever.com'
206
        assert root.find('DemandeActe/Demandeur/Civilite').text == 'MADAME'
207
        assert root.find('DemandeActe/Demandeur/Nom').text == 'Whatever'
208
        assert root.find('DemandeActe/Demandeur/Prenom').text == 'Chelsea'
209
        assert root.find('DemandeActe/Demandeur/Telephone').text == '0122334455'
210
        assert root.find('DemandeActe/Demandeur/QualiteDemandeur/Code').text == 'Autre'
211
        assert root.find('DemandeActe/Demandeur/QualiteDemandeur/Libelle').text == 'Sa soeur'
212
        assert root.find('DemandeActe/Demandeur/AdresseFrancaise/Voie').text == '22 rue Danton'
213
        assert root.find('DemandeActe/Demandeur/AdresseFrancaise/CodePostal').text == '94270'
214
        assert root.find('DemandeActe/Demandeur/AdresseFrancaise/Ville').text == 'Kremlin Bicetre'
215

  
216
        # Concerned
217
        assert root.find('DemandeActe/Titulaire/Civilite').text == 'MONSIEUR'
218
        assert root.find('DemandeActe/Titulaire/NomNaissance').text == 'Whatever'
219
        assert root.find('DemandeActe/Titulaire/PaysDeNaissance').text == 'PRK'
220
        assert root.find('DemandeActe/Titulaire/DateDeNaissance').text == '1978-05-19'
221
        assert root.find('DemandeActe/Titulaire/Prenoms').text == 'Josh'
222
        assert root.find('DemandeActe/Titulaire/Filiation/Mere/Nom').text == 'Song'
223
        assert root.find('DemandeActe/Titulaire/Filiation/Mere/Prenoms').text == 'Eloise'
224
        assert root.find('DemandeActe/Titulaire/Filiation/Pere/Nom').text == 'Whatever'
225
        assert root.find('DemandeActe/Titulaire/Filiation/Pere/Prenoms').text == 'Fritz'
226

  
227
        # Concerned2
228
        assert root.find('DemandeActe/Titulaire2/Civilite').text == 'MADAME'
229
        assert root.find('DemandeActe/Titulaire2/NomNaissance').text == 'Kokey'
230
        assert root.find('DemandeActe/Titulaire2/PaysDeNaissance').text == 'SEN'
231
        assert root.find('DemandeActe/Titulaire2/DateDeNaissance').text == '1980-03-12'
232
        assert root.find('DemandeActe/Titulaire2/Prenoms').text == 'Sarah'
233
        assert root.find('DemandeActe/Titulaire2/Filiation/Mere/Nom').text == 'De'
234
        assert root.find('DemandeActe/Titulaire2/Filiation/Mere/Prenoms').text == 'Coudy'
235
        assert root.find('DemandeActe/Titulaire2/Filiation/Pere/Nom').text == 'Kokey'
236
        assert root.find('DemandeActe/Titulaire2/Filiation/Pere/Prenoms').text == 'Pascal'
237

  
238
    else:
239
        assert resp.json['data']['demand_id'] == '17-1-AEC-LA'
240

  
241
        doc = os.path.join(get_resource_base_dir(), 'test', 'inputs', '17-1-AEC-LA--0', '17-1-AEC-LA-doc-.xml')
242
        validate_schema(doc, AEC_XSD)
243

  
244
        root = etree.parse(doc).getroot()
245

  
246
        assert root.tag == 'EnveloppeMetierType'
247

  
248
        # Generic tags
249
        assert root.find('DemandeActe/TypeActe/Code').text == 'DECES'
250
        assert root.find('DemandeActe/NatureActe/Code').text == 'COPIE-INTEGRALE'
251
        assert root.find('DemandeActe/MotifDemande/Commentaire').text == 'Autre'
252
        assert root.find('DemandeActe/LieuActe/CodePostal').text == '54000'
253
        assert root.find('DemandeActe/LieuActe/CodeINSEE').text == '54395'
254
        assert root.find('DemandeActe/LieuActe/Ville').text == 'Nancy'
255
        assert root.find('DemandeActe/DateActe').text == '2014-04-26'
256
        assert root.find('DemandeActe/NombreExemplaires').text == '4'
257

  
258
        # Requester
259
        assert root.find('DemandeActe/Demandeur/Courriel').text == 'chelsea@whatever.com'
260
        assert root.find('DemandeActe/Demandeur/Civilite').text == 'MADAME'
261
        assert root.find('DemandeActe/Demandeur/Nom').text == 'Whatever'
262
        assert root.find('DemandeActe/Demandeur/Prenom').text == 'Chelsea'
263
        assert root.find('DemandeActe/Demandeur/Telephone').text == '0122334455'
264
        assert root.find('DemandeActe/Demandeur/QualiteDemandeur/Code').text == 'Autre'
265
        assert root.find('DemandeActe/Demandeur/AdresseFrancaise/CodePostal').text == '54000'
266
        assert root.find('DemandeActe/Demandeur/AdresseFrancaise/Ville').text == 'Nancy'
267
        assert root.find('DemandeActe/Demandeur/AdresseFrancaise/Voie').text == "37 Rue de l'Aigle Blanc"
268

  
269
        assert not root.find('DemandeActe/Demandeur/AdresseEtrangere/Pays')
270
        assert not root.find('DemandeActe/Demandeur/AdresseEtrangere/Adresse')
271

  
272
        # Concerned
273
        assert root.find('DemandeActe/Titulaire/Civilite').text == 'MONSIEUR'
274
        assert root.find('DemandeActe/Titulaire/NomNaissance').text == 'Yamamoto'
275
        assert root.find('DemandeActe/Titulaire/PaysDeNaissance').text == 'FRA'
276
        assert root.find('DemandeActe/Titulaire/DateDeNaissance').text == '1978-05-19'
277
        assert root.find('DemandeActe/Titulaire/Prenoms').text == 'Yosuke'
278
        assert root.find('DemandeActe/Titulaire/Filiation/Mere/Nom').text == 'Ino'
279
        assert root.find('DemandeActe/Titulaire/Filiation/Mere/Prenoms').text == 'Haruka'
280
        assert root.find('DemandeActe/Titulaire/Filiation/Pere/Nom').text == 'Yamamoto'
281
        assert root.find('DemandeActe/Titulaire/Filiation/Pere/Prenoms').text == 'Ryu'
282

  
283

  
284
def test_create_aec_demand_type_without_date_acte(app, setup):
285
    payload = json.loads(get_file_from_test_base_dir('formdata_aec_deces.json'))
286
    payload['fields'].pop('date_acte')
287
    resp = app.post_json('/mdel/test/create', params=payload, status=200)
129
def test_aec_naissance(app, aec_schema, aec_naissance_payload):
130
    resp = app.post_json('/mdel/test/create', params=aec_naissance_payload, status=200)
131

  
132
    assert resp.json['data']['demand_id'] == '15-4-AEC-LA'
133

  
134
    doc = os.path.join(get_resource_base_dir(), 'test', 'inputs', '15-4-AEC-LA--0', '15-4-AEC-LA-doc-.xml')
135
    aec_schema(doc)
136

  
137
    root = etree.parse(doc).getroot()
138

  
139
    assert root.tag == 'EnveloppeMetierType'
140

  
141
    # Generic tags
142
    assert root.find('DemandeActe/TypeActe/Code').text == 'NAISSANCE'
143
    assert root.find('DemandeActe/NatureActe/Code').text == 'COPIE-INTEGRALE'
144
    assert root.find('DemandeActe/MotifDemande/Commentaire').text == 'CertificatDeNationaliteFrancaise'
145
    assert root.find('DemandeActe/LieuActe/CodePostal').text == '54000'
146
    assert root.find('DemandeActe/LieuActe/CodeINSEE').text == '54395'
147
    assert root.find('DemandeActe/LieuActe/Ville').text == 'Nancy'
148
    assert root.find('DemandeActe/DateActe').text == '1958-05-19'
149
    assert root.find('DemandeActe/NombreExemplaires').text == '2'
150

  
151
    # Requester
152
    assert root.find('DemandeActe/Demandeur/Courriel').text == 'chelsea@whatever.com'
153
    assert root.find('DemandeActe/Demandeur/Civilite').text == 'MADAME'
154
    assert root.find('DemandeActe/Demandeur/Nom').text == 'Whatever'
155
    assert root.find('DemandeActe/Demandeur/Prenom').text == 'Chelsea'
156
    assert root.find('DemandeActe/Demandeur/Telephone').text == '0122334455'
157
    assert root.find('DemandeActe/Demandeur/QualiteDemandeur/Code').text == 'Fils'
158
    assert root.find('DemandeActe/Demandeur/AdresseFrancaise') is None
159
    assert root.find('DemandeActe/Demandeur/AdresseEtrangere/Pays').text == 'Suisse'
160
    assert (root.find('DemandeActe/Demandeur/AdresseEtrangere/Adresse').text
161
            == '3ème, Bâtiment B, 37 rue de Paris, 3800 Bern')
162

  
163
    assert not root.find('DemandeActe/Demandeur/AdresseFrancaise/CodePostal')
164
    assert not root.find('DemandeActe/Demandeur/AdresseFrancaise/Ville')
165
    assert not root.find('DemandeActe/Demandeur/AdresseFrancaise/Voie')
166

  
167
    # Concerned
168
    assert root.find('DemandeActe/Titulaire/Civilite').text == 'MADAME'
169
    assert root.find('DemandeActe/Titulaire/Nationalite').text == 'FRA'
170
    assert root.find('DemandeActe/Titulaire/DateDeNaissance').text == '1958-05-19'
171
    assert root.find('DemandeActe/Titulaire/PaysDeNaissance').text == 'FRA'
172
    assert root.find('DemandeActe/Titulaire/DepartementDeNaissance').text == '54'
173
    assert root.find('DemandeActe/Titulaire/NomNaissance').text == 'Whatever'
174
    assert root.find('DemandeActe/Titulaire/Prenoms').text == 'Kim'
175
    assert root.find('DemandeActe/Titulaire/Filiation/Mere/Nom').text == 'Song'
176
    assert root.find('DemandeActe/Titulaire/Filiation/Mere/Prenoms').text == 'Eloise'
177
    assert root.find('DemandeActe/Titulaire/Filiation/Pere/Nom').text == 'Whatever'
178
    assert root.find('DemandeActe/Titulaire/Filiation/Pere/Prenoms').text == 'Fritz'
179

  
180

  
181
def test_aec_naissance_etranger(app, aec_schema, aec_naissance_etranger_payload):
182
    resp = app.post_json('/mdel/test/create', params=aec_naissance_etranger_payload, status=200)
183

  
184
    assert resp.json['data']['demand_id'] == '1-4-AEC-LA'
185

  
186
    doc = os.path.join(get_resource_base_dir(), 'test', 'inputs', '1-4-AEC-LA--0', '1-4-AEC-LA-doc-.xml')
187
    aec_schema(doc)
188

  
189
    root = etree.parse(doc).getroot()
190

  
191
    assert root.tag == 'EnveloppeMetierType'
192

  
193
    # Requester
194
    assert root.find('DemandeActe/Demandeur/AdresseFrancaise') is None
195
    assert root.find('DemandeActe/Demandeur/AdresseEtrangere/Pays').text == 'Suisse'
196
    assert (root.find('DemandeActe/Demandeur/AdresseEtrangere/Adresse').text
197
            == '4 rue des coquelicots, 3800 Bern')
198

  
199

  
200
def test_aec_mariage(app, aec_schema, aec_mariage_payload):
201
    resp = app.post_json('/mdel/test/create', params=aec_mariage_payload, status=200)
202

  
203
    assert resp.json['data']['demand_id'] == '16-1-AEC-LA'
204

  
205
    doc = os.path.join(get_resource_base_dir(), 'test', 'inputs', '16-1-AEC-LA--0', '16-1-AEC-LA-doc-.xml')
206

  
207
    aec_schema(doc)
208

  
209
    root = etree.parse(doc).getroot()
210

  
211
    assert root.tag == 'EnveloppeMetierType'
212

  
213
    # Generic tags
214
    assert root.find('DemandeActe/TypeActe/Code').text == 'MARIAGE'
215
    assert root.find('DemandeActe/NatureActe/Code').text == 'EXTRAIT-AVEC-FILIATION'
216
    assert root.find('DemandeActe/MotifDemande/Commentaire').text == 'Autre'
217
    assert root.find('DemandeActe/LieuActe/CodePostal').text == '54000'
218
    assert root.find('DemandeActe/LieuActe/CodeINSEE').text == '54395'
219
    assert root.find('DemandeActe/LieuActe/Ville').text == 'Nancy'
220
    assert root.find('DemandeActe/DateActe').text == '2008-08-18'
221
    assert root.find('DemandeActe/NombreExemplaires').text == '3'
222

  
223
    # Requester
224
    assert root.find('DemandeActe/Demandeur/Courriel').text == 'chelsea@whatever.com'
225
    assert root.find('DemandeActe/Demandeur/Civilite').text == 'MADAME'
226
    assert root.find('DemandeActe/Demandeur/Nom').text == 'Whatever'
227
    assert root.find('DemandeActe/Demandeur/Prenom').text == 'Chelsea'
228
    assert root.find('DemandeActe/Demandeur/Telephone').text == '0122334455'
229
    assert root.find('DemandeActe/Demandeur/QualiteDemandeur/Code').text == 'Autre'
230
    assert root.find('DemandeActe/Demandeur/QualiteDemandeur/Libelle').text == 'Sa soeur'
231
    assert root.find('DemandeActe/Demandeur/AdresseFrancaise/Voie').text == '22 rue Danton'
232
    assert root.find('DemandeActe/Demandeur/AdresseFrancaise/CodePostal').text == '94270'
233
    assert root.find('DemandeActe/Demandeur/AdresseFrancaise/Ville').text == 'Kremlin Bicetre'
234

  
235
    # Concerned
236
    assert root.find('DemandeActe/Titulaire/Civilite').text == 'MONSIEUR'
237
    assert root.find('DemandeActe/Titulaire/NomNaissance').text == 'Whatever'
238
    assert root.find('DemandeActe/Titulaire/PaysDeNaissance').text == 'PRK'
239
    assert root.find('DemandeActe/Titulaire/DateDeNaissance').text == '1978-05-19'
240
    assert root.find('DemandeActe/Titulaire/Prenoms').text == 'Josh'
241
    assert root.find('DemandeActe/Titulaire/Filiation/Mere/Nom').text == 'Song'
242
    assert root.find('DemandeActe/Titulaire/Filiation/Mere/Prenoms').text == 'Eloise'
243
    assert root.find('DemandeActe/Titulaire/Filiation/Pere/Nom').text == 'Whatever'
244
    assert root.find('DemandeActe/Titulaire/Filiation/Pere/Prenoms').text == 'Fritz'
245

  
246
    # Concerned2
247
    assert root.find('DemandeActe/Titulaire2/Civilite').text == 'MADAME'
248
    assert root.find('DemandeActe/Titulaire2/NomNaissance').text == 'Kokey'
249
    assert root.find('DemandeActe/Titulaire2/PaysDeNaissance').text == 'SEN'
250
    assert root.find('DemandeActe/Titulaire2/DateDeNaissance').text == '1980-03-12'
251
    assert root.find('DemandeActe/Titulaire2/Prenoms').text == 'Sarah'
252
    assert root.find('DemandeActe/Titulaire2/Filiation/Mere/Nom').text == 'De'
253
    assert root.find('DemandeActe/Titulaire2/Filiation/Mere/Prenoms').text == 'Coudy'
254
    assert root.find('DemandeActe/Titulaire2/Filiation/Pere/Nom').text == 'Kokey'
255
    assert root.find('DemandeActe/Titulaire2/Filiation/Pere/Prenoms').text == 'Pascal'
256

  
257

  
258
def test_aec_deces(app, aec_schema, aec_deces_payload):
259
    resp = app.post_json('/mdel/test/create', params=aec_deces_payload, status=200)
260

  
261
    assert resp.json['data']['demand_id'] == '17-1-AEC-LA'
262

  
263
    doc = os.path.join(get_resource_base_dir(), 'test', 'inputs', '17-1-AEC-LA--0', '17-1-AEC-LA-doc-.xml')
264
    aec_schema(doc)
265

  
266
    root = etree.parse(doc).getroot()
267

  
268
    assert root.tag == 'EnveloppeMetierType'
269

  
270
    # Generic tags
271
    assert root.find('DemandeActe/TypeActe/Code').text == 'DECES'
272
    assert root.find('DemandeActe/NatureActe/Code').text == 'COPIE-INTEGRALE'
273
    assert root.find('DemandeActe/MotifDemande/Commentaire').text == 'Autre'
274
    assert root.find('DemandeActe/LieuActe/CodePostal').text == '54000'
275
    assert root.find('DemandeActe/LieuActe/CodeINSEE').text == '54395'
276
    assert root.find('DemandeActe/LieuActe/Ville').text == 'Nancy'
277
    assert root.find('DemandeActe/DateActe').text == '2014-04-26'
278
    assert root.find('DemandeActe/NombreExemplaires').text == '4'
279

  
280
    # Requester
281
    assert root.find('DemandeActe/Demandeur/Courriel').text == 'chelsea@whatever.com'
282
    assert root.find('DemandeActe/Demandeur/Civilite').text == 'MADAME'
283
    assert root.find('DemandeActe/Demandeur/Nom').text == 'Whatever'
284
    assert root.find('DemandeActe/Demandeur/Prenom').text == 'Chelsea'
285
    assert root.find('DemandeActe/Demandeur/Telephone').text == '0122334455'
286
    assert root.find('DemandeActe/Demandeur/QualiteDemandeur/Code').text == 'Autre'
287
    assert root.find('DemandeActe/Demandeur/AdresseFrancaise/CodePostal').text == '54000'
288
    assert root.find('DemandeActe/Demandeur/AdresseFrancaise/Ville').text == 'Nancy'
289
    assert root.find('DemandeActe/Demandeur/AdresseFrancaise/Voie').text == "37 Rue de l'Aigle Blanc"
290

  
291
    assert not root.find('DemandeActe/Demandeur/AdresseEtrangere/Pays')
292
    assert not root.find('DemandeActe/Demandeur/AdresseEtrangere/Adresse')
293

  
294
    # Concerned
295
    assert root.find('DemandeActe/Titulaire/Civilite').text == 'MONSIEUR'
296
    assert root.find('DemandeActe/Titulaire/NomNaissance').text == 'Yamamoto'
297
    assert root.find('DemandeActe/Titulaire/PaysDeNaissance').text == 'FRA'
298
    assert root.find('DemandeActe/Titulaire/DateDeNaissance').text == '1978-05-19'
299
    assert root.find('DemandeActe/Titulaire/Prenoms').text == 'Yosuke'
300
    assert root.find('DemandeActe/Titulaire/Filiation/Mere/Nom').text == 'Ino'
301
    assert root.find('DemandeActe/Titulaire/Filiation/Mere/Prenoms').text == 'Haruka'
302
    assert root.find('DemandeActe/Titulaire/Filiation/Pere/Nom').text == 'Yamamoto'
303
    assert root.find('DemandeActe/Titulaire/Filiation/Pere/Prenoms').text == 'Ryu'
304

  
305

  
306
def test_aec_without_date_acte(app, aec_deces_payload):
307
    aec_deces_payload['fields'].pop('date_acte')
308
    resp = app.post_json('/mdel/test/create', params=aec_deces_payload, status=200)
288 309
    assert resp.json['err_desc'] == '<date_acte> is required'
289 310

  
290 311

  
291
def test_create_ile_demand_type(app, setup):
292
    resp = app.post_json('/mdel/test/create', params=ILE_PAYLOAD, status=200)
312
def test_ile(app, ile_schema, ile_payload):
313
    resp = app.post_json('/mdel/test/create', params=ile_payload, status=200)
293 314
    assert resp.json['data']['demand_id'] == '1-14-ILE-LA'
294 315

  
295 316
    base_doc = os.path.join(get_resource_base_dir(), 'test', 'inputs', '1-14-ILE-LA--0')
296 317
    doc = os.path.join(base_doc, '1-14-ILE-LA-doc-.xml')
297 318

  
298
    validate_schema(doc, ILE_XSD)
319
    ile_schema(doc)
299 320

  
300 321
    root = etree.parse(doc).getroot()
301 322

  
......
334 355
    assert root.find('ns2:Routage/ns2:Donnee/ns2:Valeur', namespaces=ns).text == '54395'
335 356
    assert root.find('ns2:Document/ns2:Code', namespaces=ns).text == '1-14-ILE-LA'
336 357
    assert root.find('ns2:Document/ns2:Nom', namespaces=ns).text == '1-14-ILE-LA'
337
    assert root.find('ns2:Document/ns2:FichierFormulaire/ns2:FichierDonnees', namespaces=ns).text == '1-14-ILE-LA-doc-.xml'
358
    assert (root.find('ns2:Document/ns2:FichierFormulaire/ns2:FichierDonnees', namespaces=ns).text
359
            == '1-14-ILE-LA-doc-.xml')
338 360

  
339 361
    attached_files = root.findall('ns2:PieceJointe', namespaces=ns)
340 362
    assert len(attached_files) == 3
......
359 381
        assert fname in expected_files
360 382

  
361 383
    # Without anterieur_situation_raw
362
    payload = copy.deepcopy(ILE_PAYLOAD)
384
    payload = copy.deepcopy(ile_payload)
363 385
    payload['fields'].pop('anterieur_situation_raw')
364 386
    resp = app.post_json('/mdel/test/create', params=payload, status=200)
365 387
    assert resp.json['err_desc'] == 'anterieur_situation_raw is required'
366 388

  
367 389

  
368
def test_create_ile_demand_type_invalid_document_proof(app, setup):
390
def test_ile_missing_key(app, ile_payload):
369 391
    # test with missing key
370
    payload = json.loads(get_file_from_test_base_dir('formdata.json'))
371
    payload['fields'].pop('justificatif_domicile_hebergeur')
372
    resp = app.post_json('/mdel/test/create', params=payload, status=200)
392
    ile_payload['fields'].pop('justificatif_domicile_hebergeur')
393
    resp = app.post_json('/mdel/test/create', params=ile_payload, status=200)
373 394
    assert resp.json['err_desc'] == 'justificatif_domicile and all its attributes are required'
374 395

  
375
    # test with invalid content
376
    payload = json.loads(get_file_from_test_base_dir('formdata.json'))
377
    payload['fields']['justificatif_identite'] = None
378
    payload['fields']['justificatif_identite_verso'] = None
379
    resp = app.post_json('/mdel/test/create', params=payload, status=200)
396

  
397
def test_ile_invalid_value(app, ile_payload):
398
    ile_payload['fields']['justificatif_identite'] = None
399
    ile_payload['fields']['justificatif_identite_verso'] = None
400
    resp = app.post_json('/mdel/test/create', params=ile_payload, status=200)
380 401
    assert resp.json['err_desc'] == 'justificatif_identite and all its attributes are required'
381 402

  
382 403

  
383
def test_get_status(app, setup):
404
def test_ile_get_status(app, mdel, ile_payload):
384 405
    shutil.copytree(
385
        os.path.join(get_mdel_base_dir(), 'test', 'outputs'),
406
        os.path.join(data_dir, 'test', 'outputs'),
386 407
        os.path.join(get_resource_base_dir(), 'test', 'outputs'))
387
    resp = app.post_json('/mdel/test/create', params=ILE_PAYLOAD, status=200)
408
    resp = app.post_json('/mdel/test/create', params=ile_payload, status=200)
388 409
    demand_id = resp.json['data']['demand_id']
389 410
    assert demand_id == '1-14-ILE-LA'
390 411
    resp = app.get('/mdel/test/status', params={'demand_id': demand_id})
......
395 416
    assert data['comment'] == 'Dossier traité.'
396 417
    assert Demand.objects.get(demand_id='1-14-ILE-LA').status == 'accepted'
397 418

  
398
    Demand.objects.create(resource=setup, num='97-5', flow_type='AEC-LA', demand_id='97-5-AEC-LA')
419
    Demand.objects.create(resource=mdel, num='97-5', flow_type='AEC-LA', demand_id='97-5-AEC-LA')
399 420

  
400 421
    resp = app.get('/mdel/test/status', params={'demand_id': '97-5-AEC-LA'}, status=200)
401 422
    data = resp.json['data']
......
405 426
    assert data['comment'] == 'Le dossier a été reçu et sera traité prochainement.'
406 427
    assert Demand.objects.get(demand_id='97-5-AEC-LA').status == 'imported'
407 428

  
408
    Demand.objects.create(resource=setup, num='102-2', flow_type='AEC-LA', demand_id='102-2-AEC-LA')
429
    Demand.objects.create(resource=mdel, num='102-2', flow_type='AEC-LA', demand_id='102-2-AEC-LA')
409 430

  
410 431
    resp = app.get('/mdel/test/status', params={'demand_id': '102-2-AEC-LA'}, status=200)
411 432
    data = resp.json['data']
......
416 437
    assert Demand.objects.get(demand_id='102-2-AEC-LA').status == 'accepted'
417 438

  
418 439

  
419
def test_get_status_unknown_demand(app, setup):
440
def test_get_status_unknown_demand(app):
420 441
    resp = app.get('/mdel/test/status', params={'demand_id': '1-14-ILE-LA'}, status=404)
421 442
    assert resp.json['err_desc'] == 'Demand matching query does not exist.'
422 443

  
423 444

  
424
def test_get_status_no_response(app, setup):
445
def test_get_status_no_response(app, mdel):
425 446
    shutil.copytree(
426
        os.path.join(get_mdel_base_dir(), 'test', 'outputs'),
447
        os.path.join(data_dir, 'test', 'outputs'),
427 448
        os.path.join(get_resource_base_dir(), 'test', 'outputs'))
428
    Demand.objects.create(resource=setup, num='1-15', flow_type='ILE-LA', demand_id='1-15-ILE-LA')
449
    Demand.objects.create(resource=mdel, num='1-15', flow_type='ILE-LA', demand_id='1-15-ILE-LA')
429 450

  
430 451
    resp = app.get('/mdel/test/status', params={'demand_id': '1-15-ILE-LA'}, status=200)
431 452
    data = resp.json['data']
......
436 457
    assert Demand.objects.get(demand_id='1-15-ILE-LA').status is None
437 458

  
438 459

  
439
def test_get_not_closed_status(app, setup):
460
def test_get_not_closed_status(app, mdel):
440 461
    shutil.copytree(
441
        os.path.join(get_mdel_base_dir(), 'test', 'outputs'),
462
        os.path.join(data_dir, 'test', 'outputs'),
442 463
        os.path.join(get_resource_base_dir(), 'test', 'outputs'))
443
    Demand.objects.create(resource=setup, num='15-9', flow_type='AEC-LA', demand_id='15-9-AEC-LA')
464
    Demand.objects.create(resource=mdel, num='15-9', flow_type='AEC-LA', demand_id='15-9-AEC-LA')
444 465

  
445 466
    resp = app.get('/mdel/test/status', params={'demand_id': '15-9-AEC-LA'}, status=200)
446 467
    data = resp.json['data']
......
452 473
    assert Demand.objects.get(demand_id='15-9-AEC-LA').status == 'in progress'
453 474

  
454 475

  
455
def test_data_source_applicants(app, setup):
476
def test_data_source_applicants(app):
456 477
    resp = app.get('/mdel/test/applicants', status=200)
457 478
    data = resp.json['data']
458 479
    assert len(data) == 9
......
464 485
    assert len(data) == 7
465 486

  
466 487

  
467
def test_data_source_certificates(app, setup):
488
def test_data_source_certificates(app):
468 489
    resp = app.get('/mdel/test/certificates', status=200)
469 490
    data = resp.json['data']
470 491
    for datum in data:
......
476 497
            assert datum['text'] == 'Acte de décès'
477 498

  
478 499

  
479
def test_data_source_certificate_types(app, setup):
500
def test_data_source_certificate_types(app):
480 501
    resp = app.get('/mdel/test/certificate-types', status=200)
481 502
    data = resp.json['data']
482 503
    assert len(data) == 4
483
-