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
9 changes: 8 additions & 1 deletion app/commands/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,16 @@ def file_resume(**kwargs): # noqa: C901
# are rather similar with the input
validate_upload_event(resumable_manifest)

# print(resumable_manifest)
resume_upload(resumable_manifest, thread)

# since only file upload can attach manifest, take the first file object
srv_manifest = SrvFileManifests()
item_id = next(iter(resumable_manifest.get('file_objects')))
attribute = resumable_manifest.get('attributes')
zone = resumable_manifest.get('zone')
srv_manifest.attach_manifest(attribute, item_id, zone) if attribute else None
message_handler.SrvOutPutHandler.all_file_uploaded()


def validate_upload_event(event):
"""validate upload request, raise error when filed."""
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 @@ -156,6 +156,7 @@ def simple_upload( # noqa: C901
tags=tags,
source_id=source_id,
upload_message=upload_message,
attributes=attribute,
)

# format the local path into object storage path for preupload
Expand Down
3 changes: 3 additions & 0 deletions app/services/file_manager/file_upload/upload_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(
regular_file: str = True,
tags: list = None,
source_id: str = '',
attributes: dict = None,
):
self.user = UserConfig()
self.operator = self.user.username
Expand All @@ -80,6 +81,7 @@ def __init__(
# tags and souce_id are only allowed in file uplaod
self.tags = tags
self.source_id = source_id
self.attributes = attributes

# the flag to indicate if all upload process finished
# then the token refresh loop will end
Expand Down Expand Up @@ -226,6 +228,7 @@ def output_manifest(self, file_objects: List[FileObject], output_path: str) -> D
'tags': self.tags,
'upload_message': self.upload_message,
'file_objects': {file_object.item_id: file_object.to_dict() for file_object in file_objects},
'attributes': self.attributes if self.attributes else {},
}

with open(output_path, 'w') as f:
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.5.2a0"
version = "2.5.2"
Comment thread
erikdvlp marked this conversation as resolved.
description = "This service is designed to support pilot platform"
authors = ["Indoc Research"]

Expand Down
25 changes: 24 additions & 1 deletion tests/app/commands/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,34 @@ def test_resumable_upload_command_success(mocker, cli_runner):
# mock the open function
mocked_open_data = mocker.mock_open(read_data='test')
mocker.patch('builtins.open', mocked_open_data)
mocker.patch('json.load', return_value={'resumable_manifest': 'test.json', 'thread': 1})
mocker.patch('json.load', return_value={'file_objects': {'test_item_id': {'file_name': 'test.json'}}, 'zone': 1})
mocker.patch('app.commands.file.resume_upload', return_value=None)
result = cli_runner.invoke(file_resume, ['--resumable-manifest', 'test.json', '--thread', 1])
assert result.exit_code == 0


def test_resumable_upload_command_with_file_attribute_success(mocker, cli_runner):
mocker.patch('os.path.exists', return_value=True)
# mock the open function
mocked_open_data = mocker.mock_open(read_data='test')
mocker.patch('builtins.open', mocked_open_data)
mocker.patch(
'json.load',
return_value={
'file_objects': {'test_item_id': {'file_name': 'test.json'}},
'zone': 1,
'attributes': {'M1': {'attr1': '1'}},
},
)
mocker.patch('app.commands.file.resume_upload', return_value=None)

attribute_fun_mock = mocker.patch(
'app.services.file_manager.file_manifests.SrvFileManifests.attach_manifest', return_value=None
)

result = cli_runner.invoke(file_resume, ['--resumable-manifest', 'test.json', '--thread', 1])
assert result.exit_code == 0
attribute_fun_mock.assert_called_once()


def test_resumable_upload_command_failed_with_file_not_exists(mocker, cli_runner):
Expand Down