From 11a2bbdf06fdee5ade9fad82ec1c65b370981350 Mon Sep 17 00:00:00 2001 From: Josue Kouka Date: Mon, 12 Mar 2018 16:41:30 +0100 Subject: [PATCH 2/2] ciyweb: use civil status interface (#16768) --- passerelle/apps/cityweb/models.py | 35 ++++++++++++++++++++++----------- tests/data/cityweb/payload_birth.json | 4 ++-- tests/data/cityweb/payload_death.json | 6 +++--- tests/data/cityweb/payload_mariage.json | 16 +++++++-------- tests/test_cityweb.py | 9 ++++++++- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/passerelle/apps/cityweb/models.py b/passerelle/apps/cityweb/models.py index 4b2c2aa..d2996f0 100644 --- a/passerelle/apps/cityweb/models.py +++ b/passerelle/apps/cityweb/models.py @@ -15,20 +15,38 @@ # along with this program. If not, see . import os -import json from django.utils.translation import ugettext_lazy as _ from django.core.files.storage import default_storage +from passerelle.civilstatus import CivilStatusMixin from passerelle.base.models import BaseResource from passerelle.utils.api import endpoint -from passerelle.utils.jsonresponse import APIError from .cityweb import (CivilStatusApplication, TITLES, SEXES, DOCUMENT_TYPES, CERTIFICATE_TYPES, CONCERNED, ORIGINS) -class CityWeb(BaseResource): +MATCH = { + 'birth': 'NAI', + 'death': 'DEC', + 'full': 'CPI', + 'mariage': 'MAR', + 'multilingual': 'EXTPL', + 'other': 'REC', + 'with-filiation': 'EXTAF', + 'without-filiation': 'EXTSF' +} + + +def transform(data): + for key, value in data.iteritems(): + if value in MATCH: + data[key] = MATCH[value] + return data + + +class CityWeb(CivilStatusMixin, BaseResource): category = _('Business Process Connectors') class Meta: @@ -38,15 +56,8 @@ class CityWeb(BaseResource): def get_verbose_name(cls): return cls._meta.verbose_name - @endpoint(perm='can_access', methods=['post'], description=_('Create a demand')) - def create(self, request, *args, **kwargs): - payload = json.loads(request.body) - # check mandatory keys - for key in ('application_id', 'application_time', 'certificate_type'): - if key not in payload: - raise APIError('<%s> is required' % key) - - application = CivilStatusApplication(payload) + def create_demand(self, request, payload, *args, **kwargs): + application = CivilStatusApplication(transform(payload)) application.save(self.basepath) return {'data': {'demand_id': application.identifiant}} diff --git a/tests/data/cityweb/payload_birth.json b/tests/data/cityweb/payload_birth.json index 455745a..c00b89f 100644 --- a/tests/data/cityweb/payload_birth.json +++ b/tests/data/cityweb/payload_birth.json @@ -18,7 +18,7 @@ "application_origin": "internet", "application_reason": "They are just messy", "application_time": "2016-10-20T14:41:20Z", - "certificate_type": "NAI", + "certificate_type": "birth", "certificate_type_label": "Acte de naissance", "concerned_birth_city": "Harare", "concerned_birth_country": "Zimbabwe", @@ -42,7 +42,7 @@ "concerned_title": "M", "concerned_usual_name": "Whatever", "document_copies": "1", - "document_type": "CPI", + "document_type": "full", "document_type_label": "Copie Integrale", "event_city": "Nancy", "event_date_end": "", diff --git a/tests/data/cityweb/payload_death.json b/tests/data/cityweb/payload_death.json index 7e034fc..c78c845 100644 --- a/tests/data/cityweb/payload_death.json +++ b/tests/data/cityweb/payload_death.json @@ -14,11 +14,11 @@ "applicant_title": "Mme", "applicant_title_label": "Madame", "applicant_usual_name": "Whatever", - "application_origin": "internet", "application_id": "D201610171", + "application_origin": "internet", "application_reason": "", "application_time": "2016-10-20T14:41:20Z", - "certificate_type": "DEC", + "certificate_type": "death", "certificate_type_label": "Acte de d\u00e9c\u00e8s", "concerned_birth_city": "Harare", "concerned_birth_country": "Zimbabwe", @@ -30,7 +30,7 @@ "concerned_title": "M", "concerned_usual_name": "Whatever", "document_copies": "1", - "document_type": "EXTSF", + "document_type": "without-filiation", "document_type_label": "Extrait sans filiation", "event_city": "Nancy", "event_date_start": "2012-07-14" diff --git a/tests/data/cityweb/payload_mariage.json b/tests/data/cityweb/payload_mariage.json index 8717815..aec33a0 100644 --- a/tests/data/cityweb/payload_mariage.json +++ b/tests/data/cityweb/payload_mariage.json @@ -18,30 +18,30 @@ "application_origin": "internet", "application_reason": "Happy mariage", "application_time": "2016-10-20T14:41:20Z", - "certificate_type": "MAR", + "certificate_type": "mariage", "certificate_type_label": "Acte de naissance", "concerned_birth_city": "Harare", "concerned_birth_country": "Zimbabwe", "concerned_birth_county": "", "concerned_birth_date": "1980-02-29", + "concerned_firstnames": "Kevin", + "concerned_lastname": "Whatever", + "concerned_name_usage": "", "concerned_parent1_firstnames": "John Oliver", "concerned_parent1_lastname": "Smith", "concerned_parent1_name_usage": "Smith", "concerned_parent1_title": "M", "concerned_parent1_title_label": "Monsieur", "concerned_parent1_usual_name": "Smith", - "concerned_firstnames": "Kevin", - "concerned_lastname": "Whatever", "concerned_parent2_firstnames": "Kim", "concerned_parent2_lastname": "Smith", "concerned_parent2_name_usage": "nom d'\u00e9pouse", "concerned_parent2_title": "Mme", "concerned_parent2_usual_name": "Smith", - "concerned_name_usage": "", "concerned_sex": "M", "concerned_title": "M", "document_copies": "1", - "document_type": "CPI", + "document_type": "full", "document_type_label": "Copie Integrale", "event_city": "Nancy", "event_date_end": "", @@ -50,18 +50,18 @@ "partner_birth_country": "Zimbabwe", "partner_birth_county": "", "partner_birth_date": "1984-02-29", + "partner_firstnames": "Chelsea", + "partner_lastname": "Contrao", + "partner_name_usage": "", "partner_parent1_firstnames": "Antonio", "partner_parent1_lastname": "Scaramucci", "partner_parent1_title": "M", "partner_parent1_title_label": "Monsieur", - "partner_firstnames": "Chelsea", - "partner_lastname": "Contrao", "partner_parent2_firstnames": "Marguerite", "partner_parent2_lastname": "Scaramucci", "partner_parent2_name_usage": "nom d'\u00e9pouse", "partner_parent2_title": "Mme", "partner_parent2_usual_name": "Gaye", - "partner_name_usage": "", "partner_sex": "F", "partner_title": "Mme", "partner_usual_name": "Scaramucci" diff --git a/tests/test_cityweb.py b/tests/test_cityweb.py index c54e82f..3471ee0 100644 --- a/tests/test_cityweb.py +++ b/tests/test_cityweb.py @@ -22,7 +22,7 @@ import shutil import pytest import mock -from lxml import etree, objectify as xobject +from lxml import etree import zipfile import utils @@ -92,6 +92,13 @@ def test_demand_creation(app, setup, payload): assert_xml_doc(archive) +def test_demand_status(app, setup): + response = app.get('/cityweb/test/status/N20161015-4/', status=400) + assert response.json['err'] == 1 + assert response.json['err_desc'] == ' endpoint is not available' + assert response.json['data'] is None + + def test_datasource_titles(app, setup): response = app.get('/cityweb/test/titles/') data = response.json['data'] -- 2.11.0