Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions app/services/file_manager/file_upload/file_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,24 @@ def simple_upload( # noqa: C901
# if the input request zip folder then process the path as single file
# otherwise read throught the folder to get path underneath
if os.path.isdir(input_path):
job_type = UploadType.AS_FILE if compress_zip else UploadType.AS_FOLDER
if job_type == UploadType.AS_FILE:
upload_file_path = [input_path.rstrip('/').lstrip() + '.zip']
compress_folder_to_zip(input_path)
if compress_zip:
zip_file_path = compress_folder_to_zip(input_path)
upload_file_path = [zip_file_path]
job_type = UploadType.AS_FILE
# since now this is a file upload, we need to strip the folder name
current_folder_node = os.path.dirname(current_folder_node)
else:
job_type = UploadType.AS_FOLDER
upload_file_path = get_file_in_folder(input_path)

# currently not support tag and attribute for a folder upload
elif tags or attribute:
if tags or attribute:
SrvErrorHandler.customized_handle(ECustomizedError.UNSUPPORT_TAG_MANIFEST, True)
# currently not support n-to-n relationship in lineage, meaning
# can ONLY specify one source id for a folder upload
elif len(source_id) > 1 and job_type == UploadType.AS_FOLDER:
SrvErrorHandler.customized_handle(ECustomizedError.UNSUPPORT_SOURCE_MANIFEST, True)
else:
upload_file_path = get_file_in_folder(input_path)

else:
upload_file_path = [input_path]
job_type = UploadType.AS_FILE
Expand Down Expand Up @@ -255,7 +260,6 @@ def simple_upload( # noqa: C901
upload_client.output_manifest(
pre_upload_infos, non_duplicate_file_objects[len(pre_upload_infos) + 1 :], output_path
)

# now loop over each file under the folder and start
# the chunk upload
pool = ThreadPool(num_of_thread)
Expand Down
27 changes: 27 additions & 0 deletions tests/app/services/file_manager/file_upload/test_file_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,33 @@ def test_folder_merge_skip_with_all_duplication(mocker, mock_upload_client, capf
raise AssertionError('SystemExit not raised')


def test_upload_folder_as_zip(mocker, mock_upload_client):
test_folder = 'test'
upload_event = {
'file': test_folder,
'project_code': 'test_project',
'zone': 'greenroom',
'create_folder_flag': False,
'compress_zip': True,
}

mocker.patch('os.path.isdir', return_value=True)
mocker.patch('app.services.file_manager.file_upload.models.FileObject.generate_meta', return_value=(1, 1))
compress_mock = mocker.patch(
'app.services.file_manager.file_upload.file_upload.compress_folder_to_zip', return_value='test.zip'
)

non_dup_list = [FileObject('object/path', 'local_path', 'resumable_id', 'job_id', 'item_id')]
mocker.patch(
'app.services.file_manager.file_upload.file_upload.UploadClient.check_upload_duplication',
return_value=(non_dup_list, []),
)
item_ids = simple_upload(upload_event)
assert len(item_ids) == 1
assert item_ids[0] == non_dup_list[0].item_id
assert compress_mock.call_count == 1


def test_resume_upload(mocker):
mocker.patch('app.services.file_manager.file_upload.models.FileObject.generate_meta', return_value=(1, 1))
test_obj = FileObject('object/path', 'local_path', 'resumable_id', 'job_id', 'item_id')
Expand Down
Loading