Skip to content

Commit

Permalink
One to one matching of metadata to file form
Browse files Browse the repository at this point in the history
  • Loading branch information
hkethi002 committed Mar 19, 2018
1 parent 9f3ad43 commit 6342cc4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion api/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions api/placer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import copy
import datetime
import dateutil
import os
import pymongo
import uuid
import zipfile
Expand Down Expand Up @@ -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

Expand Down
14 changes: 9 additions & 5 deletions tests/integration_tests/python/test_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
}
Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6342cc4

Please sign in to comment.