diff --git a/api/upload.py b/api/upload.py index 35db758b50b1f8d7031561b93dd43574faebb8ab..75569e16e5ac4b8b3c16f06e5960ca17cc3404c4 100644 --- a/api/upload.py +++ b/api/upload.py @@ -84,8 +84,6 @@ def process_upload(request, strategy, container_type=None, id_=None, origin=None placer_class = strategy.value placer = placer_class(container_type, container, id_, metadata, timestamp, origin, context) - placer.check() - # Browsers, when sending a multipart upload, will send files with field name "file" (if sinuglar) # or "file1", "file2", etc (if multiple). Following this convention is probably a good idea. # Here, we accept any @@ -96,6 +94,10 @@ def process_upload(request, strategy, container_type=None, id_=None, origin=None # Ref docs from placer.TargetedPlacer for details. if strategy == Strategy.targeted and len(file_fields) > 1: raise Exception("Targeted uploads can only send one file") + elif strategy in [Strategy.reaper, Strategy.uidupload, Strategy.labelupload, Strategy.uidmatch] and len(file_fields) < 1: + raise Exception("No files selected for uploading") + placer.check() + for field in file_fields: diff --git a/tests/integration_tests/python/test_uploads.py b/tests/integration_tests/python/test_uploads.py index bef994a96ebddaad6ecab75cc2d0269c68716b22..5b5e366d68d43b0770391c49c3ad2d447988f42c 100644 --- a/tests/integration_tests/python/test_uploads.py +++ b/tests/integration_tests/python/test_uploads.py @@ -55,6 +55,20 @@ def test_reaper_upload(data_builder, randstr, upload_file_form, as_admin): )) assert r.ok + # reaper-upload files to group_1/project_label_1 using session_uid + file_form = upload_file_form( + group={'_id': group_1}, + project={'label': project_label_1, "files":[]}, + session={'uid': session_uid+"1", "files":[], 'subject': { + 'code': prefix + '-subject-code', + 'files': [] + }} + ) + print file_form + r = as_admin.post('/upload/reaper', files={"metadata": file_form.get("metadata")}) + print r.json() + assert r.status_code == 500 + # get session created by the upload project_1 = as_admin.get('/groups/' + group_1 + '/projects').json()[0]['_id'] session = as_admin.get('/projects/' + project_1 + '/sessions').json()[0]['_id'] @@ -173,6 +187,25 @@ def test_reaper_upload_unknown_group_project(data_builder, file_form, as_root, a ) assert r.ok + # Try uploading 0 files + r = as_root.post('/upload/label', files={"metadata":file_form( + 'acquisition.csv', + meta={ + 'group': {'_id': 'not_a_real_group'}, + 'project': { + 'label': 'new_project', + }, + 'session': { + 'label': 'test_session_label', + }, + 'acquisition': { + 'label': 'test_acquisition_label', + 'files': [{'name': 'acquisition.csv'}] + } + }).get("metadata")} + ) + assert r.status_code == 500 + # get session created by the upload r = as_root.get('/groups/unknown/projects') @@ -266,6 +299,10 @@ def test_uid_upload(data_builder, file_form, as_admin, as_user, as_public): r = as_user.post('/upload/uid', files=file_form(*uid_files, meta=uid_meta)) assert r.status_code == 403 + # try to uid-upload no files + r = as_admin.post('/upload/uid', files={"metadata": file_form(*uid_files, meta=uid_meta).get("metadata")}) + assert r.status_code == 500 + # uid-upload files r = as_admin.post('/upload/uid', files=file_form(*uid_files, meta=uid_meta)) assert r.ok