0001-actesweb-fix-unicode-content-writing-into-file-28272.patch
passerelle/apps/actesweb/models.py | ||
---|---|---|
18 | 18 |
import json |
19 | 19 |
import os |
20 | 20 |
import tempfile |
21 |
import six |
|
22 |
import contextlib |
|
21 | 23 | |
22 | 24 |
from django.core.files.storage import default_storage |
23 | 25 |
from django.template.loader import get_template |
... | ... | |
30 | 32 |
from passerelle.utils.jsonresponse import APIError |
31 | 33 | |
32 | 34 | |
35 |
@contextlib.contextmanager |
|
36 |
def named_tempfile(*args, **kwargs): |
|
37 |
with tempfile.NamedTemporaryFile(*args, **kwargs) as fp: |
|
38 |
if six.PY2: |
|
39 |
import codecs |
|
40 |
fp = codecs.getwriter('utf-8')(fp) |
|
41 |
yield fp |
|
42 | ||
43 | ||
33 | 44 |
class ActesWeb(BaseResource): |
34 | 45 |
category = _('Civil Status Connectors') |
35 | 46 | |
... | ... | |
70 | 81 | |
71 | 82 |
filename = '%s.DEM' % now().strftime('%Y-%m-%d_%H-%M-%S_%f') |
72 | 83 |
filepath = os.path.join(self.basepath, filename) |
73 |
with tempfile.NamedTemporaryFile(dir=tmp_dir, suffix='.DEM', delete=False) as tpf:
|
|
84 |
with named_tempfile(dir=tmp_dir, suffix='.DEM', delete=False) as tpf:
|
|
74 | 85 |
tpf.write(demand_content) |
75 | 86 |
tpf.flush() |
76 | 87 |
os.fsync(tpf.file.fileno()) |
tests/data/actesweb/payload_mariage.json | ||
---|---|---|
5 | 5 |
"applicant_address_county": "Meurthe-et-Moselle", |
6 | 6 |
"applicant_email": "chelsea@whatever.com", |
7 | 7 |
"applicant_phone": "+33 6 55 44 22 11", |
8 |
"applicant_address_street": "37 Rue du Cheval Blanc",
|
|
8 |
"applicant_address_street": "169, rue du Château",
|
|
9 | 9 |
"applicant_address_zipcode": "54000", |
10 |
"applicant_firstnames": "Kim Chelsea",
|
|
10 |
"applicant_firstnames": "Zoé",
|
|
11 | 11 |
"applicant_lastname": "Bar", |
12 | 12 |
"applicant_name_usage": "nom d'epouse", |
13 | 13 |
"applicant_status": "concerne", |
tests/test_actesweb.py | ||
---|---|---|
20 | 20 |
import io |
21 | 21 |
import os |
22 | 22 |
import shutil |
23 |
import six |
|
23 | 24 | |
24 | 25 |
import pytest |
25 | 26 | |
... | ... | |
76 | 77 |
def assert_file_content_values(filename, expectations): |
77 | 78 |
with io.open(filename, 'rb') as fp: |
78 | 79 |
for line in fp.readlines(): |
79 |
field, value = line.split('=') |
|
80 |
if six.PY2: |
|
81 |
field, value = line.decode('utf-8').split('=') |
|
82 |
else: |
|
83 |
field, value = line.split('=') |
|
80 | 84 |
if field in expectations: |
81 | 85 |
assert value.strip() == expectations[field] |
82 | 86 | |
... | ... | |
120 | 124 |
DEMANDEUR_CIVILITE="Madame", |
121 | 125 |
DEMANDEUR_NOM_USAGE="Whatever", |
122 | 126 |
DEMANDEUR_NOM="Bar", |
123 |
DEMANDEUR_PRENOMS="Kim Chelsea",
|
|
124 |
DEMANDEUR_ADRESSE1="37 Rue du Cheval Blanc",
|
|
127 |
DEMANDEUR_PRENOMS="Zoé",
|
|
128 |
DEMANDEUR_ADRESSE1="169, rue du Château",
|
|
125 | 129 |
DEMANDEUR_VILLE="Nancy", |
126 | 130 |
DEMANDEUR_PAYS="France", |
127 |
DEMANDEUR_TEL="+33 6 55 44 22 11",
|
|
131 |
DEMANDEUR_TEL="+33 6 55 44 22 11", |
|
128 | 132 |
DEMANDEUR_ADR="chelsea@whatever.com", |
129 | 133 |
DEMANDE_NOM="Whatever", |
130 | 134 |
DEMANDE_PRENOMS="Kevin", |
131 |
- |