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.' diff --git a/app/resources/custom_help.py b/app/resources/custom_help.py index 7f6a27f5..a90ff648 100644 --- a/app/resources/custom_help.py +++ b/app/resources/custom_help.py @@ -6,7 +6,7 @@ class HelpPage: page = { 'update': { - 'version': '2.7.0', + 'version': '2.8.0a0', '1': 'Add new feature for folder merging', '2': 'Secure the config file', '3': 'Optimize logic, input and error message', 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/file_manager/file_upload/upload_client.py b/app/services/file_manager/file_upload/upload_client.py index cf3fb7a7..52ed7933 100644 --- a/app/services/file_manager/file_upload/upload_client.py +++ b/app/services/file_manager/file_upload/upload_client.py @@ -161,13 +161,19 @@ def check_upload_duplication(self, file_objects: List[FileObject]) -> Tuple[List """ headers = {'Authorization': 'Bearer ' + self.user.access_token, 'Session-ID': self.user.session_id} url = AppConfig.Connections.url_base + '/portal/v1/files/exists' + zone_int = 0 if self.zone == 'greenroom' else 1 # generate a list of locations for uploaded files to check duplication # at same time, generate a dict of mapping with object_path: FileObject locations = [x.object_path for x in file_objects] object_path_file_object_map = {x.object_path: x for x in file_objects} - payload = {'locations': locations, 'container_code': self.project_code, 'container_type': 'project', 'zone': 0} + payload = { + 'locations': locations, + 'container_code': self.project_code, + 'container_type': 'project', + 'zone': zone_int, + } response = resilient_session().post(url, json=payload, headers=headers) # pop the file object if the file has been uploaded 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(): diff --git a/pyproject.toml b/pyproject.toml index 1ac9ae0c..a59ef366 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "app" -version = "2.7.0" +version = "2.8.0a0" description = "This service is designed to support pilot platform" authors = ["Indoc Systems"] 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):