Skip to content

Commit

Permalink
deprecated commands unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adal-chiriliuc-reef committed Apr 26, 2024
1 parent b10f3fb commit 2895c67
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/unit/console_tool/test_download_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def test_download_file_by_uri__flag_support(b2_cli, uploaded_file, tmp_path, fla
)
assert output_path.read_text() == uploaded_file['content']

b2_cli.run(
['download-file', flag, 'b2id://9999',
str(output_path)],
expected_stderr=
'WARNING: `download-file` command is deprecated. Use `file download` instead.\n',
expected_stdout=expected_stdout.format(output_path=pathlib.Path(output_path).resolve())
)
assert output_path.read_text() == uploaded_file['content']


@pytest.mark.parametrize('b2_uri', [
'b2://my-bucket/file1.txt',
Expand Down Expand Up @@ -191,6 +200,12 @@ def test_cat__b2id_uri(b2_cli, bucket, uploaded_stdout_txt, tmp_path, capfd):
b2_cli.run(['file', 'cat', '--no-progress', "b2id://9999"],)
assert capfd.readouterr().out == uploaded_stdout_txt['content']

b2_cli.run(
['cat', '--no-progress', "b2id://9999"],
expected_stderr='WARNING: `cat` command is deprecated. Use `file cat` instead.\n'
)
assert capfd.readouterr().out == uploaded_stdout_txt['content']


def test__download_file__threads(b2_cli, local_file, uploaded_file, tmp_path):
num_threads = 13
Expand Down
8 changes: 8 additions & 0 deletions test/unit/console_tool/test_get_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def uploaded_file_url_by_id(uploaded_file):
return f"http://download.example.com/b2api/v2/b2_download_file_by_id?fileId={uploaded_file['fileId']}"


def test_get_url(b2_cli, uploaded_file, uploaded_file_url_by_id):
b2_cli.run(
["get-url", f"b2id://{uploaded_file['fileId']}"],
expected_stdout=f"{uploaded_file_url_by_id}\n",
expected_stderr='WARNING: `get-url` command is deprecated. Use `file url` instead.\n',
)


def test_make_url(b2_cli, uploaded_file, uploaded_file_url_by_id):
b2_cli.run(
["make-url", uploaded_file["fileId"]],
Expand Down
24 changes: 24 additions & 0 deletions test/unit/console_tool/test_upload_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ def test_upload_file__stdin(b2_cli, bucket, tmpdir, mock_stdin):
)


def test_upload_file_deprecated__stdin(b2_cli, bucket, tmpdir, mock_stdin):
"""Test `upload-file` stdin alias support"""
content = "stdin input deprecated"
filename = 'stdin-deprecated.txt'

expected_stdout = f'URL by file name: http://download.example.com/file/my-bucket/{filename}'
expected_json = {
"action": "upload",
"contentSha1": "fcaa935e050efe0b5d7b26e65162b32b5e40aa81",
"fileName": filename,
"size": len(content),
}
mock_stdin.write(content)
mock_stdin.close()

b2_cli.run(
['upload-file', '--no-progress', 'my-bucket', '-', filename],
expected_stderr='WARNING: `upload-file` command is deprecated. Use `file upload` instead.\n',
expected_json_in_stdout=expected_json,
remove_version=True,
expected_part_of_stdout=expected_stdout,
)


def test_upload_file__threads_setting(b2_cli, bucket, tmp_path):
"""Test `file upload` supports setting number of threads"""
num_threads = 66
Expand Down
40 changes: 39 additions & 1 deletion test/unit/test_console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,20 @@ def test_files_encrypted(self):
expected_json_in_stdout=expected_json,
)

self._run_command(
['file-info', 'b2id://9999'],
expected_stderr=
'WARNING: `file-info` command is deprecated. Use `file info` instead.\n',
expected_json_in_stdout=expected_json,
)

self._run_command(
['get-file-info', '9999'],
expected_stderr=
'WARNING: `get-file-info` command is deprecated. Use `file info` instead.\n',
expected_json_in_stdout=expected_json,
)

# Download by name
local_download1 = os.path.join(temp_dir, 'download1.txt')
expected_stdout_template = '''
Expand Down Expand Up @@ -1576,6 +1590,30 @@ def test_copy_file_by_id(self):
expected_json_in_stdout=expected_json,
)

expected_json = {
"accountId": self.account_id,
"action": "copy",
"bucketId": "bucket_1",
"size": 11,
"contentSha1": "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
"contentType": "b2/x-auto",
"fileId": "9993",
"fileInfo": {
"src_last_modified_millis": "1500111222000"
},
"fileName": "file1_copy_2.txt",
"serverSideEncryption": {
"mode": "none"
},
"uploadTimestamp": 5005
}
self._run_command(
['copy-file-by-id', '9999', 'my-bucket1', 'file1_copy_2.txt'],
expected_stderr=
'WARNING: `copy-file-by-id` command is deprecated. Use `file copy-by-id` instead.\n',
expected_json_in_stdout=expected_json,
)

def test_get_download_auth_defaults(self):
self._authorize_account()
self._create_my_bucket()
Expand Down Expand Up @@ -1985,7 +2023,7 @@ def test_get_bucket_with_hidden(self):
console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', 'hidden1'])
console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', 'hidden2'])
console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', 'hidden3'])
console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', 'hidden4'])
console_tool.run_command(['b2', 'hide-file', 'my-bucket', 'hidden4'])

# Now check the output of `bucket get` against the canon.
expected_json = {
Expand Down

0 comments on commit 2895c67

Please sign in to comment.