From 758b36a4f932ddedb2876828165d39444aaf4127 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Thu, 22 Nov 2018 22:18:46 +0100 Subject: [PATCH] actesweb: fix unicode content writing into file (#28272) --- passerelle/apps/actesweb/models.py | 2 +- tests/data/actesweb/payload_mariage.json | 4 ++-- tests/test_actesweb.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/passerelle/apps/actesweb/models.py b/passerelle/apps/actesweb/models.py index ae08f1d0..2b2d1a7d 100644 --- a/passerelle/apps/actesweb/models.py +++ b/passerelle/apps/actesweb/models.py @@ -71,7 +71,7 @@ class ActesWeb(BaseResource): filename = '%s.DEM' % now().strftime('%Y-%m-%d_%H-%M-%S_%f') filepath = os.path.join(self.basepath, filename) with tempfile.NamedTemporaryFile(dir=tmp_dir, suffix='.DEM', delete=False) as tpf: - tpf.write(demand_content) + tpf.write(demand_content.encode('utf-8')) tpf.flush() os.fsync(tpf.file.fileno()) os.rename(tpf.name, filepath) diff --git a/tests/data/actesweb/payload_mariage.json b/tests/data/actesweb/payload_mariage.json index 5ca1c3be..35dc5edb 100644 --- a/tests/data/actesweb/payload_mariage.json +++ b/tests/data/actesweb/payload_mariage.json @@ -5,9 +5,9 @@ "applicant_address_county": "Meurthe-et-Moselle", "applicant_email": "chelsea@whatever.com", "applicant_phone": "+33 6 55 44 22 11", - "applicant_address_street": "37 Rue du Cheval Blanc", + "applicant_address_street": "169, rue du Château", "applicant_address_zipcode": "54000", - "applicant_firstnames": "Kim Chelsea", + "applicant_firstnames": "Zoé", "applicant_lastname": "Bar", "applicant_name_usage": "nom d'epouse", "applicant_status": "concerne", diff --git a/tests/test_actesweb.py b/tests/test_actesweb.py index 5bf69d53..b5fea5ba 100644 --- a/tests/test_actesweb.py +++ b/tests/test_actesweb.py @@ -76,7 +76,7 @@ def get_demand_filepath(con, demand_id): def assert_file_content_values(filename, expectations): with io.open(filename, 'rb') as fp: for line in fp.readlines(): - field, value = line.split('=') + field, value = line.decode('utf-8').split('=') if field in expectations: assert value.strip() == expectations[field] @@ -120,8 +120,8 @@ def test_demand_creation(app, payload, actesweb): DEMANDEUR_CIVILITE="Madame", DEMANDEUR_NOM_USAGE="Whatever", DEMANDEUR_NOM="Bar", - DEMANDEUR_PRENOMS="Kim Chelsea", - DEMANDEUR_ADRESSE1="37 Rue du Cheval Blanc", + DEMANDEUR_PRENOMS="Zoé", + DEMANDEUR_ADRESSE1="169, rue du Château", DEMANDEUR_VILLE="Nancy", DEMANDEUR_PAYS="France", DEMANDEUR_TEL="+33 6 55 44 22 11", -- 2.19.2