From db844751436803bab3a14d52abfa1ada97a2541e Mon Sep 17 00:00:00 2001 From: zhiren Date: Tue, 26 Sep 2023 16:52:59 -0400 Subject: [PATCH 1/4] update the error message when folder merging --- app/resources/custom_error.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/resources/custom_error.py b/app/resources/custom_error.py index e708703e..a8eff967 100644 --- a/app/resources/custom_error.py +++ b/app/resources/custom_error.py @@ -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.' From 1be237f968dd0c81029e99dd16c025902a0b1825 Mon Sep 17 00:00:00 2001 From: zhiren Date: Tue, 26 Sep 2023 16:53:15 -0400 Subject: [PATCH 2/4] bumpup version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6234d349..f2b2b44d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] From 0af981481681dca3d1c6d3ebb169083fa54f1b95 Mon Sep 17 00:00:00 2001 From: zhiren Date: Wed, 27 Sep 2023 09:12:56 -0400 Subject: [PATCH 3/4] update the warning message when all files are all duplicated --- app/services/file_manager/file_upload/file_upload.py | 1 + app/services/output_manager/message_handler.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/services/file_manager/file_upload/file_upload.py b/app/services/file_manager/file_upload/file_upload.py index aa8ae001..93224751 100644 --- a/app/services/file_manager/file_upload/file_upload.py +++ b/app/services/file_manager/file_upload/file_upload.py @@ -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) diff --git a/app/services/output_manager/message_handler.py b/app/services/output_manager/message_handler.py index d5b179ac..a6aab665 100644 --- a/app/services/output_manager/message_handler.py +++ b/app/services/output_manager/message_handler.py @@ -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(): From 2b858c22ec904d56fd79eb92016ce7a1a4790c35 Mon Sep 17 00:00:00 2001 From: zhiren Date: Wed, 27 Sep 2023 09:39:22 -0400 Subject: [PATCH 4/4] fixup the test cases --- .../file_upload/test_file_upload.py | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/tests/app/services/file_manager/file_upload/test_file_upload.py b/tests/app/services/file_manager/file_upload/test_file_upload.py index fcc1c726..c8eddaa4 100644 --- a/tests/app/services/file_manager/file_upload/test_file_upload.py +++ b/tests/app/services/file_manager/file_upload/test_file_upload.py @@ -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, @@ -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): @@ -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):