From 6342cc483f06de66fbbfe4d9eb6321dde666b5cd Mon Sep 17 00:00:00 2001 From: Harsha Kethineni Date: Mon, 19 Mar 2018 13:38:21 -0500 Subject: [PATCH] One to one matching of metadata to file form --- api/files.py | 5 ++++- api/placer.py | 3 +-- tests/integration_tests/python/test_uploads.py | 14 +++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/api/files.py b/api/files.py index 5b2bfaeee..b438e7613 100644 --- a/api/files.py +++ b/api/files.py @@ -122,10 +122,13 @@ class SingleFileFieldStorage(cgi.FieldStorage): def make_file(self, binary=None): # Sanitize form's filename (read: prevent malicious escapes, bad characters, etc) - self.filename = fs.path.basename(self.filename) self.hasher = hashlib.new(DEFAULT_HASH_ALG) if not isinstance(self.filename, unicode): self.filename = six.u(self.filename) + + # If the filepath doesn't exist, make it + if not file_system.exists(fs.path.dirname(self.filename)) and self.filename: + file_system.makedirs(fs.path.dirname(self.filename)) self.open_file = file_system.open(self.filename, 'wb') return self.open_file diff --git a/api/placer.py b/api/placer.py index 5f2068f4e..2e1215092 100644 --- a/api/placer.py +++ b/api/placer.py @@ -2,7 +2,6 @@ import copy import datetime import dateutil -import os import pymongo import uuid import zipfile @@ -290,7 +289,7 @@ def process_file_field(self, field, file_attrs): file_mds = self.metadata.get(self.container_type, {}).get('files', []) for file_md in file_mds: - if os.path.basename(file_md['name']) == file_attrs['name']: + if file_md['name'] == file_attrs['name']: file_attrs.update(file_md) break diff --git a/tests/integration_tests/python/test_uploads.py b/tests/integration_tests/python/test_uploads.py index 3acaf0ac1..ad001f17a 100644 --- a/tests/integration_tests/python/test_uploads.py +++ b/tests/integration_tests/python/test_uploads.py @@ -708,7 +708,12 @@ def test_acquisition_engine_upload(data_builder, file_form, as_root): 'info': {'test': 'f0'} }, { - 'name': 'folder/two.csv', + 'name': 'folderA/two.csv', + 'type': 'engine type 1', + 'info': {'test': 'f1'} + }, + { + 'name': 'folderB/two.csv', 'type': 'engine type 1', 'info': {'test': 'f1'} } @@ -717,7 +722,7 @@ def test_acquisition_engine_upload(data_builder, file_form, as_root): # engine upload r = as_root.post('/engine', params={'level': 'acquisition', 'id': acquisition, 'job': job}, - files=file_form('one.csv', 'two.csv', meta=metadata) + files=file_form('one.csv', 'folderA/two.csv', 'folderB/two.csv', meta=metadata) ) assert r.ok @@ -752,7 +757,6 @@ def test_acquisition_engine_upload(data_builder, file_form, as_root): assert f['type'] == mf['type'] assert f['info'] == mf['info'] - def test_session_engine_upload(data_builder, file_form, as_root): project = data_builder.create_project() session = data_builder.create_session() @@ -789,7 +793,7 @@ def test_session_engine_upload(data_builder, file_form, as_root): r = as_root.post('/engine', params={'level': 'session', 'id': session}, - files=file_form('one.csv', 'two.csv', 'three.csv', meta=metadata) + files=file_form('one.csv', 'two.csv', 'folder/three.csv', meta=metadata) ) assert r.ok @@ -846,7 +850,7 @@ def test_project_engine_upload(data_builder, file_form, as_root): r = as_root.post('/engine', params={'level': 'project', 'id': project}, - files=file_form('one.csv', 'two.csv', 'three.csv', meta=metadata) + files=file_form('one.csv', 'two.csv', 'folder/three.csv', meta=metadata) ) assert r.ok