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
7 changes: 4 additions & 3 deletions app/services/file_manager/file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
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.4.0a0"
version = "2.4.0"
description = "This service is designed to support pilot platform"
authors = ["Indoc Research"]

Expand Down
43 changes: 43 additions & 0 deletions tests/app/commands/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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] == ' '