Skip to content

Commit

Permalink
use file copy-by-id subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
adal-chiriliuc-reef committed Apr 25, 2024
1 parent 66685c2 commit 2d31d7e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
53 changes: 33 additions & 20 deletions test/integration/test_b2_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def test_basic(b2_tool, bucket_name, sample_file, tmp_path, b2_uri_args):
)
should_equal([], [f['fileName'] for f in list_of_files])

b2_tool.should_succeed(['copy-file-by-id', first_a_version['fileId'], bucket_name, 'x'])
b2_tool.should_succeed(['file', 'copy-by-id', first_a_version['fileId'], bucket_name, 'x'])

b2_tool.should_succeed(['ls', *b2_uri_args(bucket_name)], '^a{0}b/{0}d{0}'.format(os.linesep))
# file_id, action, date, time, size(, replication), name
Expand Down Expand Up @@ -1493,12 +1493,15 @@ def test_sse_b2(b2_tool, bucket_name, sample_file, tmp_path, b2_uri_args):

b2_tool.should_succeed(
[
'copy-file-by-id', '--destination-server-side-encryption=SSE-B2',
'file', 'copy-by-id', '--destination-server-side-encryption=SSE-B2',
encrypted_version['fileId'], bucket_name, 'copied_encrypted'
]
)
b2_tool.should_succeed(
['copy-file-by-id', not_encrypted_version['fileId'], bucket_name, 'copied_not_encrypted']
[
'file', 'copy-by-id', not_encrypted_version['fileId'], bucket_name,
'copied_not_encrypted'
]
)

list_of_files = b2_tool.should_succeed_json(
Expand Down Expand Up @@ -1617,22 +1620,22 @@ def test_sse_c(b2_tool, bucket_name, is_running_on_docker, sample_file, tmp_path
assert read_file(dir_path / 'b') == read_file(sample_file)

b2_tool.should_fail(
['copy-file-by-id', file_version_info['fileId'], bucket_name, 'gonna-fail-anyway'],
['file', 'copy-by-id', file_version_info['fileId'], bucket_name, 'gonna-fail-anyway'],
expected_pattern=
'ERROR: The object was stored using a form of Server Side Encryption. The correct '
r'parameters must be provided to retrieve the object. \(bad_request\)'
)
b2_tool.should_fail(
[
'copy-file-by-id', '--source-server-side-encryption=SSE-C', file_version_info['fileId'],
bucket_name, 'gonna-fail-anyway'
'file', 'copy-by-id', '--source-server-side-encryption=SSE-C',
file_version_info['fileId'], bucket_name, 'gonna-fail-anyway'
],
expected_pattern='ValueError: Using SSE-C requires providing an encryption key via '
'B2_SOURCE_SSE_C_KEY_B64 env var'
)
b2_tool.should_fail(
[
'copy-file-by-id', '--source-server-side-encryption=SSE-C',
'file', 'copy-by-id', '--source-server-side-encryption=SSE-C',
'--destination-server-side-encryption=SSE-C', file_version_info['fileId'], bucket_name,
'gonna-fail-anyway'
],
Expand All @@ -1642,8 +1645,8 @@ def test_sse_c(b2_tool, bucket_name, is_running_on_docker, sample_file, tmp_path
)
b2_tool.should_fail(
[
'copy-file-by-id', '--source-server-side-encryption=SSE-C', file_version_info['fileId'],
bucket_name, 'gonna-fail-anyway'
'file', 'copy-by-id', '--source-server-side-encryption=SSE-C',
file_version_info['fileId'], bucket_name, 'gonna-fail-anyway'
],
additional_env={'B2_SOURCE_SSE_C_KEY_B64': base64.b64encode(secret).decode()},
expected_pattern=
Expand All @@ -1652,7 +1655,8 @@ def test_sse_c(b2_tool, bucket_name, is_running_on_docker, sample_file, tmp_path
)
b2_tool.should_succeed(
[
'copy-file-by-id',
'file',
'copy-by-id',
'--source-server-side-encryption=SSE-C',
file_version_info['fileId'],
bucket_name,
Expand All @@ -1666,7 +1670,8 @@ def test_sse_c(b2_tool, bucket_name, is_running_on_docker, sample_file, tmp_path
)
b2_tool.should_succeed(
[
'copy-file-by-id',
'file',
'copy-by-id',
'--source-server-side-encryption=SSE-C',
file_version_info['fileId'],
bucket_name,
Expand All @@ -1679,7 +1684,8 @@ def test_sse_c(b2_tool, bucket_name, is_running_on_docker, sample_file, tmp_path
)
b2_tool.should_succeed(
[
'copy-file-by-id',
'file',
'copy-by-id',
'--source-server-side-encryption=SSE-C',
file_version_info['fileId'],
bucket_name,
Expand All @@ -1690,7 +1696,8 @@ def test_sse_c(b2_tool, bucket_name, is_running_on_docker, sample_file, tmp_path
)
b2_tool.should_succeed(
[
'copy-file-by-id',
'file',
'copy-by-id',
'--source-server-side-encryption=SSE-C',
'--destination-server-side-encryption=SSE-C',
file_version_info['fileId'],
Expand All @@ -1705,7 +1712,8 @@ def test_sse_c(b2_tool, bucket_name, is_running_on_docker, sample_file, tmp_path
)
b2_tool.should_succeed(
[
'copy-file-by-id',
'file',
'copy-by-id',
'--source-server-side-encryption=SSE-C',
'--destination-server-side-encryption=SSE-C',
file_version_info['fileId'],
Expand All @@ -1723,7 +1731,8 @@ def test_sse_c(b2_tool, bucket_name, is_running_on_docker, sample_file, tmp_path
)
b2_tool.should_succeed(
[
'copy-file-by-id',
'file',
'copy-by-id',
'--source-server-side-encryption=SSE-C',
'--destination-server-side-encryption=SSE-C',
file_version_info['fileId'],
Expand Down Expand Up @@ -2133,7 +2142,8 @@ def test_file_lock(

b2_tool.should_fail(
[
'copy-file-by-id',
'file',
'copy-by-id',
lockable_file['fileId'],
lock_disabled_bucket_name,
'copied',
Expand All @@ -2148,7 +2158,8 @@ def test_file_lock(

copied_file = b2_tool.should_succeed_json(
[
'copy-file-by-id',
'file',
'copy-by-id',
lockable_file['fileId'],
lock_enabled_bucket_name,
'copied',
Expand Down Expand Up @@ -2302,7 +2313,8 @@ def file_lock_without_perms_test(

b2_tool.should_fail(
[
'copy-file-by-id',
'file',
'copy-by-id',
lockable_file_id,
lock_enabled_bucket_name,
'copied',
Expand All @@ -2318,7 +2330,8 @@ def file_lock_without_perms_test(

b2_tool.should_fail(
[
'copy-file-by-id',
'file',
'copy-by-id',
lockable_file_id,
lock_disabled_bucket_name,
'copied',
Expand Down Expand Up @@ -3174,7 +3187,7 @@ def assert_expected(file_info, expected=expected_file_info):

copied_version = b2_tool.should_succeed_json(
[
'copy-file-by-id', '--quiet', *args, '--content-type', 'text/plain',
'file', 'copy-by-id', '--quiet', *args, '--content-type', 'text/plain',
file_version['fileId'], bucket_name, 'copied_file'
]
)
Expand Down
17 changes: 10 additions & 7 deletions test/unit/test_console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ def test_copy_file_by_id(self):
"uploadTimestamp": 5001
}
self._run_command(
['copy-file-by-id', '9999', 'my-bucket', 'file1_copy.txt'],
['file', 'copy-by-id', '9999', 'my-bucket', 'file1_copy.txt'],
expected_json_in_stdout=expected_json,
)

Expand All @@ -1466,7 +1466,7 @@ def test_copy_file_by_id(self):
"uploadTimestamp": 5002
}
self._run_command(
['copy-file-by-id', '--range', '3,7', '9999', 'my-bucket', 'file1_copy.txt'],
['file', 'copy-by-id', '--range', '3,7', '9999', 'my-bucket', 'file1_copy.txt'],
expected_json_in_stdout=expected_json,
)

Expand All @@ -1480,7 +1480,8 @@ def test_copy_file_by_id(self):
expected_stderr = "ERROR: File info can be set only when content type is set\n"
self._run_command(
[
'copy-file-by-id',
'file',
'copy-by-id',
'--info',
'a=b',
'9999',
Expand All @@ -1496,7 +1497,8 @@ def test_copy_file_by_id(self):
expected_stderr = "ERROR: File info can be not set only when content type is not set\n"
self._run_command(
[
'copy-file-by-id',
'file',
'copy-by-id',
'--content-type',
'text/plain',
'9999',
Expand Down Expand Up @@ -1528,7 +1530,8 @@ def test_copy_file_by_id(self):
}
self._run_command(
[
'copy-file-by-id',
'file',
'copy-by-id',
'--content-type',
'text/plain',
'--info',
Expand All @@ -1543,7 +1546,7 @@ def test_copy_file_by_id(self):
# UnsatisfiableRange
expected_stderr = "ERROR: The range in the request is outside the size of the file\n"
self._run_command(
['copy-file-by-id', '--range', '12,20', '9999', 'my-bucket', 'file1_copy.txt'],
['file', 'copy-by-id', '--range', '12,20', '9999', 'my-bucket', 'file1_copy.txt'],
'',
expected_stderr,
1,
Expand All @@ -1569,7 +1572,7 @@ def test_copy_file_by_id(self):
"uploadTimestamp": 5004
}
self._run_command(
['copy-file-by-id', '9999', 'my-bucket1', 'file1_copy.txt'],
['file', 'copy-by-id', '9999', 'my-bucket1', 'file1_copy.txt'],
expected_json_in_stdout=expected_json,
)

Expand Down

0 comments on commit 2d31d7e

Please sign in to comment.