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
7 changes: 5 additions & 2 deletions app/resources/custom_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ class Error:
),
'UPLOAD_CANCEL': 'Upload task was cancelled.',
'UPLOAD_FAIL': 'Upload task was failed. Please check the console output.',
'UPLOAD_SKIP_DUPLICATION': 'Following files with the same '
'name already exist in the Project: \n%s.\nDo you want to skip uploading',
'UPLOAD_SKIP_DUPLICATION': (
'\nSome of the selected files cannot be uploaded.\n\n'
'The following files already exist in the upload destination: \n%s\n'
'Do you want to cancel the upload [N] or skip duplicates and continue uploading [y]?'
),
'UPLOAD_ID_NOT_EXIST': (
'The specified multipart upload does not exist. '
'The upload ID may be invalid, or the upload may have been aborted or completed.'
Expand Down
1 change: 1 addition & 0 deletions app/services/file_manager/file_upload/file_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def simple_upload( # noqa: C901

if len(non_duplicate_file_objects) == 0:
mhandler.SrvOutPutHandler.file_duplication_check_warning_with_all_same()
SrvErrorHandler.customized_handle(ECustomizedError.UPLOAD_CANCEL, if_exit=True)
elif len(duplicated_file) > 0:
mhandler.SrvOutPutHandler.file_duplication_check_success()
duplicate_warning_format = '\n'.join(duplicated_file)
Expand Down
2 changes: 1 addition & 1 deletion app/services/output_manager/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def file_duplication_check_success():
@staticmethod
def file_duplication_check_warning_with_all_same():
"""e.g. file duplication check warning with all same."""
return logger.warning('All files are the same, no need to upload.')
return logger.warning('\nAll files already exist in the upload destination.\n')

@staticmethod
def resume_check_success():
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "app"
version = "2.7.2"
version = "2.7.3"
description = "This service is designed to support pilot platform"
authors = ["Indoc Systems"]

Expand Down
49 changes: 35 additions & 14 deletions tests/app/services/file_manager/file_upload/test_file_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_assemble_path_at_non_existing_folder(mocker):
assert create_folder_flag is True


def test_file_upload_skip_empty_file(mocker, tmp_path):
def test_file_upload_skip_empty_file(mocker, tmp_path, capfd):
file_name = 'test'
upload_event = {
'file': file_name,
Expand All @@ -120,8 +120,23 @@ def test_file_upload_skip_empty_file(mocker, tmp_path):
mocker.patch('os.path.isdir', return_value=False)
mocker.patch('app.services.file_manager.file_upload.models.FileObject.generate_meta', return_value=(0, 0))

item_ids = simple_upload(upload_event, output_path=str(tmp_path / 'test'))
assert len(item_ids) == 0
try:
simple_upload(upload_event, output_path=str(tmp_path / 'test'))
except SystemExit:
out, _ = capfd.readouterr()

expect = (
f'Starting upload of: {file_name}\n'
+ 'Skip the file with 0 size: test\n'
+ 'Checking for file duplication...\n'
+ '\nAll files already exist in the upload destination.\n\n'
+ customized_error_msg(ECustomizedError.UPLOAD_CANCEL)
+ '\n'
)

assert out == expect
else:
AssertionError('SystemExit not raised')


def test_dont_allow_tagging_when_folder_upload(mocker, capfd):
Expand Down Expand Up @@ -242,17 +257,23 @@ def test_folder_merge_skip_with_all_duplication(mocker, mock_upload_client, capf
return_value=([], dup_list),
)

item_ids = simple_upload(upload_event)
assert len(item_ids) == 0
assert click_yes_mock.call_count == 0

out, _ = capfd.readouterr()
expect = (
f'Starting upload of: {file_name}\n'
+ 'Checking for file duplication...\n'
+ 'All files are the same, no need to upload.\n'
)
assert expect in out
try:
simple_upload(upload_event)

except SystemExit:
assert click_yes_mock.call_count == 0

out, _ = capfd.readouterr()
expect = (
f'Starting upload of: {file_name}\n'
+ 'Checking for file duplication...\n'
+ '\nAll files already exist in the upload destination.\n\n'
+ customized_error_msg(ECustomizedError.UPLOAD_CANCEL)
+ '\n'
)
assert expect in out
else:
AssertionError('SystemExit not raised')


def test_resume_upload(mocker):
Expand Down