Skip to content

Commit

Permalink
updated file large tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adal-chiriliuc-reef committed Apr 30, 2024
1 parent e675d85 commit 8568d63
Showing 1 changed file with 91 additions and 6 deletions.
97 changes: 91 additions & 6 deletions test/unit/test_console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,11 @@ def test_get_download_auth_url_with_encoding(self):
def test_list_unfinished_large_files_with_none(self):
self._authorize_account()
self._create_my_bucket()
self._run_command(['list-unfinished-large-files', 'my-bucket'], '', '', 0)
self._run_command(
['list-unfinished-large-files', 'my-bucket'], '',
'WARNING: `list-unfinished-large-files` command is deprecated. Use `file large unfinished list` instead.\n',
0
)

def test_upload_large_file(self):
self._authorize_account()
Expand Down Expand Up @@ -2992,7 +2996,18 @@ def setUp(self):

def test_cancel_large_file(self):
file = self.v1_bucket.start_large_file('file1', 'text/plain', {})
self._run_command(['cancel-large-file', file.file_id], '9999 canceled\n', '', 0)
self._run_command(
['file', 'large', 'unfinished', 'cancel', f'b2id://{file.file_id}'], '9999 canceled\n',
'', 0
)

def test_cancel_large_file_deprecated(self):
file = self.v1_bucket.start_large_file('file1', 'text/plain', {})
self._run_command(
['cancel-large-file', file.file_id], '9999 canceled\n',
'WARNING: `cancel-large-file` command is deprecated. Use `file large unfinished cancel` instead.\n',
0
)

def test_cancel_all_large_file(self):
self.v1_bucket.start_large_file('file1', 'text/plain', {})
Expand All @@ -3003,15 +3018,58 @@ def test_cancel_all_large_file(self):
'''

self._run_command(
['cancel-all-unfinished-large-files', 'my-v1-bucket'], expected_stdout, '', 0
['file', 'large', 'unfinished', 'cancel', 'b2://my-v1-bucket'], expected_stdout, '', 0
)

def test_cancel_all_large_file_deprecated(self):
self.v1_bucket.start_large_file('file1', 'text/plain', {})
self.v1_bucket.start_large_file('file2', 'text/plain', {})
expected_stdout = '''
9999 canceled
9998 canceled
'''

self._run_command(
['cancel-all-unfinished-large-files', 'my-v1-bucket'], expected_stdout,
'WARNING: `cancel-all-unfinished-large-files` command is deprecated. Use `file large unfinished cancel` instead.\n',
0
)

def test_list_parts_with_none(self):
file = self.v1_bucket.start_large_file('file', 'text/plain', {})
self._run_command(['list-parts', file.file_id], '', '', 0)
self._run_command(['file', 'large', 'parts', f'b2id://{file.file_id}'], '', '', 0)

def test_list_parts_with_none_deprecated(self):
file = self.v1_bucket.start_large_file('file', 'text/plain', {})
self._run_command(
['list-parts', file.file_id], '',
'WARNING: `list-parts` command is deprecated. Use `file large parts` instead.\n', 0
)

def test_list_parts_with_parts(self):
bucket = self.b2_api.get_bucket_by_name('my-bucket')
file = self.v1_bucket.start_large_file('file', 'text/plain', {})
content = b'hello world'
large_file_upload_state = mock.MagicMock()
large_file_upload_state.has_error.return_value = False
bucket.api.services.upload_manager._upload_part(
bucket.id_, file.file_id, UploadSourceBytes(content), 1, large_file_upload_state, None,
None
)
bucket.api.services.upload_manager._upload_part(
bucket.id_, file.file_id, UploadSourceBytes(content), 3, large_file_upload_state, None,
None
)
expected_stdout = '''
1 11 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
3 11 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
'''

self._run_command(
['file', 'large', 'parts', f'b2id://{file.file_id}'], expected_stdout, '', 0
)

def test_list_parts_with_parts_deprecated(self):
bucket = self.b2_api.get_bucket_by_name('my-bucket')
file = self.v1_bucket.start_large_file('file', 'text/plain', {})
content = b'hello world'
Expand All @@ -3030,7 +3088,10 @@ def test_list_parts_with_parts(self):
3 11 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
'''

self._run_command(['list-parts', file.file_id], expected_stdout, '', 0)
self._run_command(
['list-parts', file.file_id], expected_stdout,
'WARNING: `list-parts` command is deprecated. Use `file large parts` instead.\n', 0
)

def test_list_unfinished_large_files_with_some(self):
api_url = self.account_info.get_api_url()
Expand All @@ -3048,7 +3109,31 @@ def test_list_unfinished_large_files_with_some(self):
9997 file3 application/json
'''

self._run_command(['list-unfinished-large-files', 'my-bucket'], expected_stdout, '', 0)
self._run_command(
['file', 'large', 'unfinished', 'list', 'b2://my-bucket'], expected_stdout, '', 0
)

def test_list_unfinished_large_files_with_some_deprecated(self):
api_url = self.account_info.get_api_url()
auth_token = self.account_info.get_account_auth_token()
self.raw_api.start_large_file(api_url, auth_token, 'bucket_0', 'file1', 'text/plain', {})
self.raw_api.start_large_file(
api_url, auth_token, 'bucket_0', 'file2', 'text/plain', {'color': 'blue'}
)
self.raw_api.start_large_file(
api_url, auth_token, 'bucket_0', 'file3', 'application/json', {}
)
expected_stdout = '''
9999 file1 text/plain
9998 file2 text/plain color=blue
9997 file3 application/json
'''

self._run_command(
['list-unfinished-large-files', 'my-bucket'], expected_stdout,
'WARNING: `list-unfinished-large-files` command is deprecated. Use `file large unfinished list` instead.\n',
0
)


class TestRmConsoleTool(BaseConsoleToolTest):
Expand Down

0 comments on commit 8568d63

Please sign in to comment.