Skip to content
Merged
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
2 changes: 1 addition & 1 deletion app/resources/custom_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
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
8 changes: 7 additions & 1 deletion app/services/file_manager/file_upload/upload_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.0"
version = "2.8.0a0"
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