From f12e0fdebbc77ee13c840e69a8fcef05e027c26d Mon Sep 17 00:00:00 2001 From: Josue Kouka Date: Fri, 14 Sep 2018 12:04:31 +0200 Subject: [PATCH] dpark: pass file's raw content to zeep (#26417) --- passerelle/contrib/dpark/models.py | 6 +++++- tests/test_dpark.py | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/passerelle/contrib/dpark/models.py b/passerelle/contrib/dpark/models.py index 909627e..b584b3e 100644 --- a/passerelle/contrib/dpark/models.py +++ b/passerelle/contrib/dpark/models.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import base64 import json from django.conf import settings @@ -399,8 +400,11 @@ class DPark(BaseResource): errors.extend(value_errors) continue + # use raw content because to prevent zeep + # from encoding the content into base64 a second time. + file_raw_content = base64.b64decode(value['content']) attached_files.append({ - 'TypeDocument': doc_id, 'NomFichier': value['filename'], 'Fichier': value['content']}) + 'TypeDocument': doc_id, 'NomFichier': value['filename'], 'Fichier': file_raw_content}) # deduce the number of files if errors: raise APIError(errors) diff --git a/tests/test_dpark.py b/tests/test_dpark.py index dcb7aac..e8b5eac 100644 --- a/tests/test_dpark.py +++ b/tests/test_dpark.py @@ -487,7 +487,7 @@ def test_send_files(dpark, app, settings): 'content': base64.b64encode('this is my proof of address')} params['cartegrise,1'] = { 'filename': 'cartegrise.pdf', 'content_type': 'application/pdf', - 'content': base64.b64encode('whatever') + 'content': base64.b64encode('carte grise 1') } params['toto,6'] = { 'filename': 'cartegrisetoto.pdf', 'content_type': 'application/pdf', @@ -495,7 +495,7 @@ def test_send_files(dpark, app, settings): } params['cartegrise,6'] = { 'filename': 'cartegrise2.pdf', 'content_type': 'application/pdf', - 'content': base64.b64encode('whatever') + 'content': base64.b64encode('carte grise 2') } params['taxe_habitat'] = { 'filename': 'cartegrise2.pdf', 'content_type': 'application/pdf', @@ -529,5 +529,7 @@ def test_send_files(dpark, app, settings): assert len(soap_call.call_args[0][4]) == 4 assert soap_call.call_args[0][4][0]['NomFichier'] == 'cartegrise.pdf' assert soap_call.call_args[0][4][0]['TypeDocument'] == '6' + assert soap_call.call_args[0][4][0]['Fichier'] == 'carte grise 1' assert soap_call.call_args[0][4][1]['NomFichier'] == 'cartegrise2.pdf' assert soap_call.call_args[0][4][1]['TypeDocument'] == '6' + assert soap_call.call_args[0][4][1]['Fichier'] == 'carte grise 2' -- 2.18.0