From 194bbb31a74adfea76127d3ff83f2ca102612fd7 Mon Sep 17 00:00:00 2001 From: Simon Drabble Date: Mon, 15 Jul 2019 13:24:18 -0600 Subject: [PATCH] Fixes #510 in upstream: multiple file uploads via POST now work correctly. --- connexion/operations/abstract.py | 2 +- tests/api/test_parameters.py | 11 +++++++++++ tests/fakeapi/hello.py | 7 ++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/connexion/operations/abstract.py b/connexion/operations/abstract.py index a56da2e52..c96841f2e 100644 --- a/connexion/operations/abstract.py +++ b/connexion/operations/abstract.py @@ -176,7 +176,7 @@ def validate_responses(self): @staticmethod def _get_file_arguments(files, arguments, has_kwargs=False): - return {k: v for k, v in files.items() if k in arguments or has_kwargs} + return {k: files.getlist(k) for k in files.keys() if k in arguments or has_kwargs} @abc.abstractmethod def _get_val_from_param(self, value, query_defn): diff --git a/tests/api/test_parameters.py b/tests/api/test_parameters.py index acbc157a8..32ecf7ed1 100644 --- a/tests/api/test_parameters.py +++ b/tests/api/test_parameters.py @@ -211,6 +211,17 @@ def test_formdata_file_upload(simple_app): response = json.loads(resp.data.decode('utf-8', 'replace')) assert response == {'filename.txt': 'file contents'} +def test_formdata_multiple_file_upload(simple_app): + app_client = simple_app.app.test_client() + resp = app_client.post('/v1.0/test-formData-file-upload', + data={'formData': [(BytesIO(b'file contents'), 'filename.txt'), + (BytesIO(b'file contents 2'), 'filename2.txt')] + }) + assert resp.status_code == 200 + response = json.loads(resp.data.decode('utf-8', 'replace')) + assert response == [{'filename.txt': 'file contents'}, + {'filename2.txt': 'file contents 2'}] + def test_formdata_file_upload_bad_request(simple_app): app_client = simple_app.app.test_client() diff --git a/tests/fakeapi/hello.py b/tests/fakeapi/hello.py index daf2cbca4..70076a148 100755 --- a/tests/fakeapi/hello.py +++ b/tests/fakeapi/hello.py @@ -295,9 +295,10 @@ def test_formdata_missing_param(): def test_formdata_file_upload(formData, **kwargs): - filename = formData.filename - contents = formData.read().decode('utf-8', 'replace') - return {filename: contents} + if len(formData) == 1: + return {x.filename: x.read().decode('utf-8', 'replace') for x in formData} + + return [{x.filename: x.read().decode('utf-8', 'replace')} for x in formData] def test_formdata_file_upload_missing_param():