0002-make-MDEL-CivilStatusMixin-compliant-16768.patch
passerelle/contrib/mdel/models.py | ||
---|---|---|
17 | 17 | |
18 | 18 |
import os |
19 | 19 |
import json |
20 |
import logging |
|
21 |
import warnings |
|
20 | 22 | |
21 | 23 |
from dateutil.parser import parse as dateutil_parse |
22 | 24 | |
... | ... | |
30 | 32 | |
31 | 33 |
from . import mdel |
32 | 34 | |
33 |
from .utils import zipdir, get_file_content_from_zip |
|
35 |
from .utils import (zipdir, get_file_content_from_zip, |
|
36 |
format_to_leagcy) |
|
34 | 37 | |
35 | 38 | |
36 | 39 |
DEMAND_TYPES = ['ILE-LA', 'RCO-LA', 'AEC-LA'] |
... | ... | |
90 | 93 |
"""Create a demand |
91 | 94 |
""" |
92 | 95 |
formdata = json.loads(request.body) |
96 | ||
97 |
# check if payload is CivilStatusMixin compliant |
|
98 |
if 'application_id' in formdata: |
|
99 |
return super(MDEL, self).create(request, formdata) |
|
100 | ||
101 |
logging.captureWarnings(True) |
|
102 |
warnings.warn("MDEL payload's format deprecated.") |
|
103 | ||
93 | 104 |
extra = formdata.pop('extra', {}) |
94 | 105 |
fields = formdata.pop('fields', {}) |
95 | 106 | |
... | ... | |
124 | 135 | |
125 | 136 |
return {'data': {'demand_id': demand.demand_id}} |
126 | 137 | |
127 |
@endpoint(perm='can_access') |
|
128 |
def status(self, request, *args, **kwargs): |
|
129 |
"""Return demand's statutes
|
|
138 |
@endpoint(perm='can_access', pattern='(?P<demand_id>[\w-]*)')
|
|
139 |
def status(self, request, demand_id=None, *args, **kwargs):
|
|
140 |
"""Return demand's status |
|
130 | 141 |
""" |
131 |
demand_id = request.GET.get('demand_id', None) |
|
132 |
if not demand_id: |
|
142 |
if not demand_id and 'demand_id' not in request.GET: |
|
133 | 143 |
raise APIError('demand_id is required') |
134 | 144 | |
135 | 145 |
demand = Demand.objects.get(demand_id=demand_id, resource=self) |
... | ... | |
139 | 149 |
demand.save() |
140 | 150 |
return {'data': status} |
141 | 151 | |
152 |
def create_demand(self, request, payload, *args, **kwargs): |
|
153 |
if payload['certificate_type'] in ('birth', 'mariage', 'death'): |
|
154 |
demand_type = 'AEC-LA' |
|
155 |
if 'application_city_inseecode' not in payload: |
|
156 |
raise APIError('code_insee is required') |
|
157 | ||
158 |
demand, created = Demand.objects.get_or_create( |
|
159 |
num=payload['application_id'], flow_type=demand_type, resource=self) |
|
160 |
if not created: |
|
161 |
demand.step += 1 |
|
162 | ||
163 |
payload = format_to_leagcy(payload) |
|
164 |
demand.create_zip(payload) |
|
165 |
return {'data': {'demand_id': demand.demand_id}} |
|
166 | ||
142 | 167 |
@endpoint(perm='can_access') |
143 | 168 |
def applicants(self, request, without=''): |
144 | 169 |
return {'data': [item for item in APPLICANTS |
passerelle/contrib/mdel/utils.py | ||
---|---|---|
68 | 68 |
""" |
69 | 69 |
with zipfile.ZipFile(path, 'r') as zipf: |
70 | 70 |
return zipf.read(filename) |
71 | ||
72 | ||
73 |
# key mapping of civil status api keys and legacy keys |
|
74 | ||
75 |
LEGACY_KEYS_MAP = { |
|
76 |
'application_id': 'display_id', |
|
77 |
'application_date': 'receipt_time', |
|
78 |
'certificate_type': 'aec_nature_raw', |
|
79 |
'certificate_type_label': 'aec_nature', |
|
80 |
'document_type': 'aec_type_raw', |
|
81 |
'document_type_label': 'aec_type', |
|
82 |
'document_copies': 'nombre_exemplaires', |
|
83 |
'application_reason': 'motif_demande_raw', |
|
84 |
'application_reason_label': 'motif_demande', |
|
85 |
'application_city': 'ville', |
|
86 |
'application_city_inseecode': 'code_insee', |
|
87 |
'application_city_zipcode': 'code_postal', |
|
88 |
'event_date': 'date_acte', |
|
89 |
'applicant_title': 'demandeur_civilite', |
|
90 |
'applicant_lastname': 'demandeur_nom', |
|
91 |
'applicant_firstnames': 'demandeur_prenom', |
|
92 |
'applicant_status': 'qualite_demandeur_raw', |
|
93 |
'applicant_status_label': 'qualite_demandeur', |
|
94 |
'applicant_status': 'qualite_demandeur_raw', |
|
95 |
'applicant_address_complement': 'demandeur_adresse_batiment', |
|
96 |
'applicant_address_city': 'demandeur_adresse_ville', |
|
97 |
'applicant_address_street': 'demandeur_adresse_voie', |
|
98 |
'applicant_address_country': 'demandeur_adresse_pays_raw', |
|
99 |
'applicant_phone': 'demandeur_telephone', |
|
100 |
'applicant_email': 'demandeur_email', |
|
101 |
'concerned_title': 'titulaire_civilite', |
|
102 |
'concerned_lastname': 'titulaire_nom', |
|
103 |
'concerned_firstnames': 'titulaire_prenoms', |
|
104 |
'concerned_birthdate': 'titulaire_naiss_date', |
|
105 |
'concerned_birthcity': 'titulaire_naiss_ville', |
|
106 |
'concerned_birthcounty': 'titulaire_naiss_departement_raw', |
|
107 |
'concerned_birthcountry': 'titulaire_naiss_pays_raw', |
|
108 |
'concerned_citizenship': 'titulaire_nationalite_raw', |
|
109 |
'concerned_parent1_lastname': 'titulaire_pere_nom', |
|
110 |
'concerned_parent1_firstnames': 'titulaire_pere_prenoms', |
|
111 |
'concerned_parent2_lastname': 'titulaire_mere_nom', |
|
112 |
'concerned_parent2_firstnames': 'titulaire_mere_prenoms', |
|
113 |
'partner_title': 'titulaire2_civilite', |
|
114 |
'partner_lastname': 'titulaire2_nom', |
|
115 |
'partner_firstnames': 'titulaire2_prenoms', |
|
116 |
'partner_birthdate': 'titulaire2_naiss_date', |
|
117 |
'partner_birthcity': 'titulaire2_naiss_ville', |
|
118 |
'partner_birthcounty': 'titulaire2_naiss_departement_raw', |
|
119 |
'partner_birthcountry': 'titulaire2_naiss_pays_raw', |
|
120 |
'partner_citizenship': 'titulaire2_nationalite_raw', |
|
121 |
'partner_parent1_lastname': 'titulaire2_pere_nom', |
|
122 |
'partner_parent1_firstnames': 'titulaire2_pere_prenoms', |
|
123 |
'partner_parent2_lastname': 'titulaire2_mere_nom', |
|
124 |
'partner_parent2_firstnames': 'titulaire2_mere_prenoms', |
|
125 |
} |
|
126 | ||
127 | ||
128 |
def format_to_leagcy(data): |
|
129 |
""" |
|
130 |
""" |
|
131 |
legacy_data = {} |
|
132 | ||
133 |
for key, legacy_key in LEGACY_KEYS_MAP.iteritems(): |
|
134 |
if key in data: |
|
135 |
legacy_data[legacy_key] = data[key] |
|
136 | ||
137 |
return legacy_data |
tests/data/mdel/payload_mariage.json | ||
---|---|---|
1 |
{ |
|
2 |
"applicant_address_city": "Vancouver", |
|
3 |
"applicant_address_country": "CAN", |
|
4 |
"applicant_address_street": "West 12th Avenue", |
|
5 |
"applicant_address_street_number": "274", |
|
6 |
"applicant_address_zipcode": "BC V5Y 1V4", |
|
7 |
"applicant_firstnames": "Chelsea", |
|
8 |
"applicant_lastname": "Whatever", |
|
9 |
"applicant_email": "chelsea@whatever.com", |
|
10 |
"applicant_phone": "0122334455", |
|
11 |
"applicant_status": "Autre", |
|
12 |
"applicant_status_label": "Sa soeur", |
|
13 |
"applicant_title": "Madame", |
|
14 |
"applicant_title_raw": "Madame", |
|
15 |
"application_city": "Nancy", |
|
16 |
"application_city_inseecode": "54395", |
|
17 |
"application_city_zipcode": "54000", |
|
18 |
"application_id": "16-1", |
|
19 |
"application_time": "2016-10-20T15:17:05Z", |
|
20 |
"application_zipcode": "54000", |
|
21 |
"certificate_type": "mariage", |
|
22 |
"certificate_type_label": "Acte de mariage", |
|
23 |
"concerned_firstnames": "Josh", |
|
24 |
"concerned_lastname": "Whatever", |
|
25 |
"concerned_naiss_date": "1978-05-19", |
|
26 |
"concerned_naiss_pays": "Coree", |
|
27 |
"concerned_naiss_pays_raw": "PRK", |
|
28 |
"concerned_nationalite_raw": "FRA", |
|
29 |
"concerned_parent1_firstnames": "Fritz", |
|
30 |
"concerned_parent1_lastname": "Whatever", |
|
31 |
"concerned_parent2_firstnames": "Eloise", |
|
32 |
"concerned_parent2_lastname": "Song", |
|
33 |
"concerned_title": "Monsieur", |
|
34 |
"concerned_title_raw": "Monsieur", |
|
35 |
"document_copies": "3", |
|
36 |
"document_type": "with-filiation", |
|
37 |
"document_type_label": "Extrait avec filiation", |
|
38 |
"event_date": "18/08/2008", |
|
39 |
"partner_firstnames": "Sarah", |
|
40 |
"partner_lastname": "Kokey", |
|
41 |
"partner_naiss_date": "1980-03-12", |
|
42 |
"partner_naiss_pays": "Senegal", |
|
43 |
"partner_naiss_pays_raw": "SEN", |
|
44 |
"partner_nationalite_raw": "FRA", |
|
45 |
"partner_parent1_firstnames": "Pascal", |
|
46 |
"partner_parent1_lastname": "Kokey", |
|
47 |
"partner_parent2_firstnames": "Coudy", |
|
48 |
"partner_parent2_lastname": "De", |
|
49 |
"partner_title": "Madame", |
|
50 |
"partner_title_raw": "MADAME" |
|
51 |
} |
tests/test_mdel.py | ||
---|---|---|
51 | 51 |
json.loads(get_file_from_test_base_dir('formdata_aec_naiss.json')), |
52 | 52 |
json.loads(get_file_from_test_base_dir('formdata_aec_mariage.json')), |
53 | 53 |
json.loads(get_file_from_test_base_dir('formdata_aec_deces.json')), |
54 |
], ids=['naissance', 'mariage', 'deces']) |
|
54 |
json.loads(get_file_from_test_base_dir('payload_mariage.json')), |
|
55 |
], ids=['naissance', 'mariage', 'deces', 'mariage_cvm']) |
|
55 | 56 |
def aec_payload(request): |
56 | 57 |
return request.param |
57 | 58 | |
... | ... | |
120 | 121 |
def test_create_aec_demand_type(app, setup, aec_payload): |
121 | 122 |
resp = app.post_json('/mdel/test/create', params=aec_payload, status=200) |
122 | 123 | |
123 |
if aec_payload['display_id'] == '15-4': |
|
124 |
display_id = aec_payload['display_id'] if 'display_id' in aec_payload else aec_payload['application_id'] |
|
125 | ||
126 |
if display_id == '15-4': |
|
124 | 127 |
assert resp.json['data']['demand_id'] == '15-4-AEC-LA' |
125 | 128 | |
126 | 129 |
doc = os.path.join(get_mdel_base_dir(), 'test', 'inputs', '15-4-AEC-LA--0', '15-4-AEC-LA-doc-.xml') |
... | ... | |
162 | 165 |
assert root.find('DemandeActe/Titulaire/Filiation/Pere/Nom').text == 'Whatever' |
163 | 166 |
assert root.find('DemandeActe/Titulaire/Filiation/Pere/Prenoms').text == 'Fritz' |
164 | 167 | |
165 |
elif aec_payload['display_id'] == '16-1':
|
|
168 |
elif display_id == '16-1':
|
|
166 | 169 | |
167 | 170 |
assert resp.json['data']['demand_id'] == '16-1-AEC-LA' |
168 | 171 | |
... | ... | |
387 | 390 |
assert data['comment'] == 'Dossier accepté' |
388 | 391 |
assert Demand.objects.get(demand_id='102-2-AEC-LA').status == 'accepted' |
389 | 392 | |
393 |
# test status endpoint compliance with CivilStatusMixin |
|
394 |
resp = app.get('/mdel/test/status/102-2-AEC-LA/', status=200) |
|
395 |
data = resp.json['data'] |
|
396 | ||
397 |
assert data['closed'] is True |
|
398 |
assert data['status'] == 'accepted' |
|
399 |
assert data['comment'] == 'Dossier accepté' |
|
400 |
assert Demand.objects.get(demand_id='102-2-AEC-LA').status == 'accepted' |
|
401 | ||
390 | 402 | |
391 | 403 |
def test_get_status_unknown_demand(app, setup): |
392 | 404 |
resp = app.get('/mdel/test/status', params={'demand_id': '1-14-ILE-LA'}, status=404) |
393 |
- |