diff --git a/app/services/file_manager/file_list.py b/app/services/file_manager/file_list.py index f2193b05..5abf963c 100644 --- a/app/services/file_manager/file_list.py +++ b/app/services/file_manager/file_list.py @@ -67,9 +67,10 @@ def list_files_without_pagination(self, paths, zone, page, page_size): def list_files_with_pagination(self, paths, zone, page, page_size): while True: files = self.list_files(paths, zone, page, page_size) - if len(files) < page_size and page == 0: - break - elif len(files) < page_size and page != 0: + file_list = files.split('...')[:-1] if files != '' else [] + if len(file_list) < page_size and page == 0: + choice = ['exit'] + elif len(file_list) < page_size and page != 0: choice = ['previous page', 'exit'] elif page == 0: choice = ['next page', 'exit'] diff --git a/pyproject.toml b/pyproject.toml index 773ed5a9..9f1aaf98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "app" -version = "2.4.0a0" +version = "2.4.0" description = "This service is designed to support pilot platform" authors = ["Indoc Research"] diff --git a/tests/app/commands/test_file.py b/tests/app/commands/test_file.py index a82fd154..f9939b79 100644 --- a/tests/app/commands/test_file.py +++ b/tests/app/commands/test_file.py @@ -3,12 +3,15 @@ # Contact Indoc Research for any questions regarding the use of this source code. import click +import questionary +from app.commands.file import file_list from app.commands.file import file_put from app.commands.file import file_resume from app.services.file_manager.file_upload.models import FileObject from app.services.output_manager.error_handler import ECustomizedError from app.services.output_manager.error_handler import customized_error_msg +from tests.conftest import decoded_token def test_file_upload_command_success_with_attribute(mocker, cli_runner): @@ -59,3 +62,43 @@ def test_resumable_upload_command_failed_with_file_not_exists(mocker, cli_runner result = cli_runner.invoke(file_resume, ['--resumable-manifest', 'test.json', '--thread', 1]) assert result.exit_code == 0 assert result.output == customized_error_msg(ECustomizedError.INVALID_RESUMABLE) + '\n' + + +def test_file_list_with_pagination(requests_mock, mocker, cli_runner): + mocker.patch( + 'app.services.user_authentication.token_manager.SrvTokenManager.decode_access_token', + return_value=decoded_token(), + ) + + mocker.patch('app.services.file_manager.file_list.search_item', return_value=None) + requests_mock.get( + 'http://bff_cli' + '/v1/testproject/files/query', + json={ + 'code': 200, + 'error_msg': '', + 'result': [{'type': 'file', 'name': 'file1'}, {'type': 'file', 'name': 'file2'}], + }, + ) + mocker.patch.object(questionary, 'select') + questionary.select.return_value.ask.return_value = 'exit' + result = cli_runner.invoke(file_list, ['testproject/admin', '-z', 'greenroom']) + outputs = result.output.split('\n') + assert outputs[0] == 'file1 file2 ' + + +def test_empty_file_list_with_pagination(requests_mock, mocker, cli_runner): + mocker.patch( + 'app.services.user_authentication.token_manager.SrvTokenManager.decode_access_token', + return_value=decoded_token(), + ) + + mocker.patch('app.services.file_manager.file_list.search_item', return_value=None) + requests_mock.get( + 'http://bff_cli' + '/v1/testproject/files/query', + json={'code': 200, 'error_msg': '', 'result': []}, + ) + mocker.patch.object(questionary, 'select') + questionary.select.return_value.ask.return_value = 'exit' + result = cli_runner.invoke(file_list, ['testproject/admin', '-z', 'greenroom']) + outputs = result.output.split('\n') + assert outputs[0] == ' '