0002-ciyweb-use-civil-status-interface-16768.patch
passerelle/apps/cityweb/models.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import os |
18 |
import json |
|
19 | 18 | |
20 | 19 |
from django.utils.translation import ugettext_lazy as _ |
21 | 20 |
from django.core.files.storage import default_storage |
22 | 21 | |
22 |
from passerelle.civilstatus import CivilStatusMixin |
|
23 | 23 |
from passerelle.base.models import BaseResource |
24 | 24 |
from passerelle.utils.api import endpoint |
25 |
from passerelle.utils.jsonresponse import APIError |
|
26 | 25 | |
27 | 26 |
from .cityweb import (CivilStatusApplication, TITLES, SEXES, DOCUMENT_TYPES, |
28 | 27 |
CERTIFICATE_TYPES, CONCERNED, ORIGINS) |
29 | 28 | |
30 | 29 | |
31 |
class CityWeb(BaseResource): |
|
30 |
MATCH = { |
|
31 |
'birth': 'NAI', |
|
32 |
'death': 'DEC', |
|
33 |
'full': 'CPI', |
|
34 |
'mariage': 'MAR', |
|
35 |
'multilingual': 'EXTPL', |
|
36 |
'other': 'REC', |
|
37 |
'with-filiation': 'EXTAF', |
|
38 |
'without-filiation': 'EXTSF' |
|
39 |
} |
|
40 | ||
41 | ||
42 |
def transform(data): |
|
43 |
for key, value in data.iteritems(): |
|
44 |
if value in MATCH: |
|
45 |
data[key] = MATCH[value] |
|
46 |
return data |
|
47 | ||
48 | ||
49 |
class CityWeb(CivilStatusMixin, BaseResource): |
|
32 | 50 |
category = _('Business Process Connectors') |
33 | 51 | |
34 | 52 |
class Meta: |
... | ... | |
38 | 56 |
def get_verbose_name(cls): |
39 | 57 |
return cls._meta.verbose_name |
40 | 58 | |
41 |
@endpoint(perm='can_access', methods=['post'], description=_('Create a demand')) |
|
42 |
def create(self, request, *args, **kwargs): |
|
43 |
payload = json.loads(request.body) |
|
44 |
# check mandatory keys |
|
45 |
for key in ('application_id', 'application_time', 'certificate_type'): |
|
46 |
if key not in payload: |
|
47 |
raise APIError('<%s> is required' % key) |
|
48 | ||
49 |
application = CivilStatusApplication(payload) |
|
59 |
def create_demand(self, request, payload, *args, **kwargs): |
|
60 |
application = CivilStatusApplication(transform(payload)) |
|
50 | 61 |
application.save(self.basepath) |
51 | 62 |
return {'data': {'demand_id': application.identifiant}} |
52 | 63 |
tests/data/cityweb/payload_birth.json | ||
---|---|---|
18 | 18 |
"application_origin": "internet", |
19 | 19 |
"application_reason": "They are just messy", |
20 | 20 |
"application_time": "2016-10-20T14:41:20Z", |
21 |
"certificate_type": "NAI",
|
|
21 |
"certificate_type": "birth",
|
|
22 | 22 |
"certificate_type_label": "Acte de naissance", |
23 | 23 |
"concerned_birth_city": "Harare", |
24 | 24 |
"concerned_birth_country": "Zimbabwe", |
... | ... | |
42 | 42 |
"concerned_title": "M", |
43 | 43 |
"concerned_usual_name": "Whatever", |
44 | 44 |
"document_copies": "1", |
45 |
"document_type": "CPI",
|
|
45 |
"document_type": "full",
|
|
46 | 46 |
"document_type_label": "Copie Integrale", |
47 | 47 |
"event_city": "Nancy", |
48 | 48 |
"event_date_end": "", |
tests/data/cityweb/payload_death.json | ||
---|---|---|
14 | 14 |
"applicant_title": "Mme", |
15 | 15 |
"applicant_title_label": "Madame", |
16 | 16 |
"applicant_usual_name": "Whatever", |
17 |
"application_origin": "internet", |
|
18 | 17 |
"application_id": "D201610171", |
18 |
"application_origin": "internet", |
|
19 | 19 |
"application_reason": "", |
20 | 20 |
"application_time": "2016-10-20T14:41:20Z", |
21 |
"certificate_type": "DEC",
|
|
21 |
"certificate_type": "death",
|
|
22 | 22 |
"certificate_type_label": "Acte de d\u00e9c\u00e8s", |
23 | 23 |
"concerned_birth_city": "Harare", |
24 | 24 |
"concerned_birth_country": "Zimbabwe", |
... | ... | |
30 | 30 |
"concerned_title": "M", |
31 | 31 |
"concerned_usual_name": "Whatever", |
32 | 32 |
"document_copies": "1", |
33 |
"document_type": "EXTSF",
|
|
33 |
"document_type": "without-filiation",
|
|
34 | 34 |
"document_type_label": "Extrait sans filiation", |
35 | 35 |
"event_city": "Nancy", |
36 | 36 |
"event_date_start": "2012-07-14" |
tests/data/cityweb/payload_mariage.json | ||
---|---|---|
18 | 18 |
"application_origin": "internet", |
19 | 19 |
"application_reason": "Happy mariage", |
20 | 20 |
"application_time": "2016-10-20T14:41:20Z", |
21 |
"certificate_type": "MAR",
|
|
21 |
"certificate_type": "mariage",
|
|
22 | 22 |
"certificate_type_label": "Acte de naissance", |
23 | 23 |
"concerned_birth_city": "Harare", |
24 | 24 |
"concerned_birth_country": "Zimbabwe", |
25 | 25 |
"concerned_birth_county": "", |
26 | 26 |
"concerned_birth_date": "1980-02-29", |
27 |
"concerned_firstnames": "Kevin", |
|
28 |
"concerned_lastname": "Whatever", |
|
29 |
"concerned_name_usage": "", |
|
27 | 30 |
"concerned_parent1_firstnames": "John Oliver", |
28 | 31 |
"concerned_parent1_lastname": "Smith", |
29 | 32 |
"concerned_parent1_name_usage": "Smith", |
30 | 33 |
"concerned_parent1_title": "M", |
31 | 34 |
"concerned_parent1_title_label": "Monsieur", |
32 | 35 |
"concerned_parent1_usual_name": "Smith", |
33 |
"concerned_firstnames": "Kevin", |
|
34 |
"concerned_lastname": "Whatever", |
|
35 | 36 |
"concerned_parent2_firstnames": "Kim", |
36 | 37 |
"concerned_parent2_lastname": "Smith", |
37 | 38 |
"concerned_parent2_name_usage": "nom d'\u00e9pouse", |
38 | 39 |
"concerned_parent2_title": "Mme", |
39 | 40 |
"concerned_parent2_usual_name": "Smith", |
40 |
"concerned_name_usage": "", |
|
41 | 41 |
"concerned_sex": "M", |
42 | 42 |
"concerned_title": "M", |
43 | 43 |
"document_copies": "1", |
44 |
"document_type": "CPI",
|
|
44 |
"document_type": "full",
|
|
45 | 45 |
"document_type_label": "Copie Integrale", |
46 | 46 |
"event_city": "Nancy", |
47 | 47 |
"event_date_end": "", |
... | ... | |
50 | 50 |
"partner_birth_country": "Zimbabwe", |
51 | 51 |
"partner_birth_county": "", |
52 | 52 |
"partner_birth_date": "1984-02-29", |
53 |
"partner_firstnames": "Chelsea", |
|
54 |
"partner_lastname": "Contrao", |
|
55 |
"partner_name_usage": "", |
|
53 | 56 |
"partner_parent1_firstnames": "Antonio", |
54 | 57 |
"partner_parent1_lastname": "Scaramucci", |
55 | 58 |
"partner_parent1_title": "M", |
56 | 59 |
"partner_parent1_title_label": "Monsieur", |
57 |
"partner_firstnames": "Chelsea", |
|
58 |
"partner_lastname": "Contrao", |
|
59 | 60 |
"partner_parent2_firstnames": "Marguerite", |
60 | 61 |
"partner_parent2_lastname": "Scaramucci", |
61 | 62 |
"partner_parent2_name_usage": "nom d'\u00e9pouse", |
62 | 63 |
"partner_parent2_title": "Mme", |
63 | 64 |
"partner_parent2_usual_name": "Gaye", |
64 |
"partner_name_usage": "", |
|
65 | 65 |
"partner_sex": "F", |
66 | 66 |
"partner_title": "Mme", |
67 | 67 |
"partner_usual_name": "Scaramucci" |
tests/test_cityweb.py | ||
---|---|---|
22 | 22 | |
23 | 23 |
import pytest |
24 | 24 |
import mock |
25 |
from lxml import etree, objectify as xobject
|
|
25 |
from lxml import etree |
|
26 | 26 |
import zipfile |
27 | 27 | |
28 | 28 |
import utils |
... | ... | |
92 | 92 |
assert_xml_doc(archive) |
93 | 93 | |
94 | 94 | |
95 |
def test_demand_status(app, setup): |
|
96 |
response = app.get('/cityweb/test/status/N20161015-4/', status=400) |
|
97 |
assert response.json['err'] == 1 |
|
98 |
assert response.json['err_desc'] == '<status> endpoint is not available' |
|
99 |
assert response.json['data'] is None |
|
100 | ||
101 | ||
95 | 102 |
def test_datasource_titles(app, setup): |
96 | 103 |
response = app.get('/cityweb/test/titles/') |
97 | 104 |
data = response.json['data'] |
98 |
- |