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
10 changes: 8 additions & 2 deletions app/services/file_manager/file_upload/upload_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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):
Expand Down