From 4262d4fe0f8c377d9d6c65afa259c385ead6d871 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 23 Aug 2023 12:57:38 +0000 Subject: [PATCH] fix(tests): fixed mock test_upload; - Fixed issues with `test_upload` mock action for tests. --- ckanapi/tests/mock/mock_ckan.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ckanapi/tests/mock/mock_ckan.py b/ckanapi/tests/mock/mock_ckan.py index 6c7db54..2f717b3 100644 --- a/ckanapi/tests/mock/mock_ckan.py +++ b/ckanapi/tests/mock/mock_ckan.py @@ -3,6 +3,11 @@ import csv from wsgiref.util import setup_testing_defaults from wsgiref.simple_server import make_server +try: + from cStringIO import StringIO +except ImportError: + from io import StringIO + def mock_ckan(environ, start_response): status = '200 OK' @@ -39,7 +44,14 @@ def mock_ckan(environ, start_response): environ=environ, keep_blank_values=True, ) - records = list(csv.reader(fs['upload'].file)) + upload_data = fs.getvalue('upload').decode('utf-8').splitlines() + csv_file = StringIO() + writer = csv.writer(csv_file) + for line_data in upload_data: + row_data = line_data.split(',') + writer.writerow(row_data) + csv_file.seek(0) + records = list(csv.reader(csv_file)) start_response(status, headers) return [json.dumps({ "help": "none",