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
17 changes: 8 additions & 9 deletions app/services/dataset_manager/dataset_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ def pre_dataset_version_download(self):
'Session-ID': self.session_id,
}
payload = {'version': self.version}
try:
response = requests.get(url, headers=headers, params=payload)
res = response.json()
code = res.get('code')
if code == 404:
SrvErrorHandler.customized_handle(ECustomizedError.VERSION_NOT_EXIST, True, self.version)
else:
return res
except Exception:
response = requests.get(url, headers=headers, params=payload)
res = response.json()
code = response.status_code
if code == 200:
return res
elif code == 404:
SrvErrorHandler.customized_handle(ECustomizedError.VERSION_NOT_EXIST, True, self.version)
else:
SrvErrorHandler.default_handle(response.content, True)

@require_valid_token()
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.2.3"
version = "2.2.4"
description = "This service is designed to support pilot platform"
authors = ["Indoc Research"]

Expand Down
51 changes: 51 additions & 0 deletions tests/app/commands/test_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (C) 2022-2023 Indoc Research
#
# Contact Indoc Research for any questions regarding the use of this source code.

from app.commands.dataset import dataset_download
from app.configs.app_config import AppConfig


def test_download_not_exited_dataset_version(requests_mock, mocker, cli_runner, capsys):
mocker.patch('app.services.user_authentication.token_manager.SrvTokenManager.check_valid', return_value=0)
requests_mock.get(
'http://bff_cli' + '/v1/dataset/testdataset',
json={
'code': 200,
'error_msg': '',
'result': {
'general_info': {
'id': 'fake-id',
'source': '',
'authors': ['test-admin', 'test-user'],
'code': 'testdataset',
'type': 'GENERAL',
'modality': [],
'collection_method': [],
'license': '',
'tags': ['cdsa'],
'description': 'Description example.',
'size': 25,
'total_files': 1,
'title': 'test dataset',
'creator': 'test-admin',
'project_id': 'project-id',
'created_at': '2022-02-03T19:49:35',
'updated_at': '2022-03-18T18:08:33',
},
'version_detail': [],
'version_no': 0,
},
},
)

requests_mock.get(
AppConfig.Connections.url_dataset + '/fake-id/download/pre',
json={'error': 'version does not exist'},
status_code=404,
)

result = cli_runner.invoke(dataset_download, ['testdataset', '.', '-v', '1.0'])
outputs = result.output.split('\n')
assert outputs[0] == 'Current dataset version: 1.0'
assert outputs[1] == 'Version not available: 1.0'
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def reset_singletons():
def mock_settings(monkeypatch):
monkeypatch.setattr(AppConfig.Connections, 'url_authn', 'http://service_auth')
monkeypatch.setattr(AppConfig.Connections, 'url_bff', 'http://bff_cli')
monkeypatch.setattr(AppConfig.Connections, 'url_dataset', 'http://url_dataset')
monkeypatch.setattr(AppConfig.Connections, 'url_upload_greenroom', 'http://upload_gr')
monkeypatch.setattr(AppConfig.Connections, 'url_upload_core', 'http://upload_core')
monkeypatch.setattr(UserConfig, 'username', 'test-user')
Expand Down