diff --git a/app/services/file_manager/file_upload/upload_client.py b/app/services/file_manager/file_upload/upload_client.py index 86dc08e3..77421ac0 100644 --- a/app/services/file_manager/file_upload/upload_client.py +++ b/app/services/file_manager/file_upload/upload_client.py @@ -167,7 +167,7 @@ def check_upload_duplication(self, file_objects: List[FileObject]) -> Tuple[List # 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} + object_path_file_object_map = {x.object_path.lower(): x for x in file_objects} payload = { 'locations': locations, @@ -182,10 +182,16 @@ def check_upload_duplication(self, file_objects: List[FileObject]) -> Tuple[List if response.status_code == 200: exist_files = response.json().get('result', []) for exist_file_path in exist_files: - object_path_file_object_map.pop(exist_file_path) + object_path_file_object_map.pop(exist_file_path.lower()) else: SrvErrorHandler.default_handle('Error when checking file duplication', if_exit=True) + # reconstruct non exist file objects which will be uploaded + # without lower() function. + return_list = {} + for _, item in object_path_file_object_map.items(): + return_list.update({item.object_path: item}) + return list(object_path_file_object_map.values()), exist_files @require_valid_token() diff --git a/pyproject.toml b/pyproject.toml index db648cfe..e177743c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "app" -version = "3.0.3" +version = "3.0.4" description = "This service is designed to support pilot platform" authors = ["Indoc Systems"] diff --git a/tests/app/services/file_manager/file_upload/test_upload_client.py b/tests/app/services/file_manager/file_upload/test_upload_client.py index 21454ee3..a8a386be 100644 --- a/tests/app/services/file_manager/file_upload/test_upload_client.py +++ b/tests/app/services/file_manager/file_upload/test_upload_client.py @@ -8,6 +8,8 @@ from multiprocessing.pool import ThreadPool from time import sleep +import pytest + from app.configs.app_config import AppConfig from app.services.file_manager.file_upload.models import FileObject from app.services.file_manager.file_upload.upload_client import UploadClient @@ -153,7 +155,8 @@ def test_resumable_pre_upload_failed_with_404(httpx_mock, mocker): AssertionError('SystemExit not raised') -def test_check_upload_duplication_success(httpx_mock, mocker): +@pytest.mark.parametrize('case_insensitive', [True, False]) +def test_check_upload_duplication_success(httpx_mock, mocker, case_insensitive): mocker.patch( 'app.services.user_authentication.token_manager.SrvTokenManager.decode_access_token', return_value=decoded_token(), @@ -167,12 +170,12 @@ def test_check_upload_duplication_success(httpx_mock, mocker): httpx_mock.add_response( method='POST', url=url, - json={'result': [dup_obj.object_path]}, + json={'result': [dup_obj.object_path.upper() if case_insensitive else dup_obj.object_path]}, ) not_dup_list, dup_list = upload_client.check_upload_duplication([dup_obj, not_dup_object]) assert not_dup_list == [not_dup_object] - assert dup_list == [dup_obj.object_path] + assert dup_list == [dup_obj.object_path.upper() if case_insensitive else dup_obj.object_path] def test_check_upload_duplication_fail_with_500(httpx_mock, mocker, capfd):