| 1 |
###################################################################### |
| 2 |
# |
| 3 |
# File: test/unit/console_tool/test_ls.py |
| 4 |
# |
| 5 |
# Copyright 2024 Backblaze Inc. All Rights Reserved. |
| 6 |
# |
| 7 |
# License https://www.backblaze.com/using_b2_code.html |
| 8 |
# |
| 9 |
###################################################################### |
| 10 |
###################################################################### |
| 11 |
# |
| 12 |
# File: test/unit/console_tool/test_download_file.py |
| 13 |
# |
| 14 |
# Copyright 2023 Backblaze Inc. All Rights Reserved. |
| 15 |
# |
| 16 |
# License https://www.backblaze.com/using_b2_code.html |
| 17 |
# |
| 18 |
###################################################################### |
| 19 |
|
| 20 |
import pytest |
| 21 |
|
| 22 |
|
| 23 |
def test_ls__without_bucket_name(b2_cli, bucket_info): |
| 24 |
expected_output = "bucket_0 allPublic my-bucket\n" |
| 25 |
|
| 26 |
b2_cli.run(["ls"], expected_stdout=expected_output) |
| 27 |
b2_cli.run(["ls", "b2://"], expected_stdout=expected_output) |
| 28 |
|
| 29 |
|
| 30 |
def test_ls__without_bucket_name__json(b2_cli, bucket_info): |
| 31 |
expected_output = [ |
| 32 |
{ |
| 33 |
"accountId": "account-0", |
| 34 |
"bucketId": "bucket_0", |
| 35 |
"bucketInfo": {}, |
| 36 |
"bucketName": "my-bucket", |
| 37 |
"bucketType": "allPublic", |
| 38 |
"corsRules": [], |
| 39 |
"defaultRetention": { |
| 40 |
"mode": None |
| 41 |
}, |
| 42 |
"defaultServerSideEncryption": { |
| 43 |
"mode": "none" |
| 44 |
}, |
| 45 |
"isFileLockEnabled": False, |
| 46 |
"lifecycleRules": [], |
| 47 |
"options": [], |
| 48 |
"replication": { |
| 49 |
"asReplicationDestination": None, |
| 50 |
"asReplicationSource": None, |
| 51 |
}, |
| 52 |
"revision": 1, |
| 53 |
} |
| 54 |
] |
| 55 |
|
| 56 |
b2_cli.run(["ls", "--json"], expected_json_in_stdout=expected_output) |
| 57 |
b2_cli.run(["ls", "--json", "b2://"], expected_json_in_stdout=expected_output) |
| 58 |
|
| 59 |
|
| 60 |
@pytest.mark.parametrize("flag", ["--long", "--recursive", "--replication"]) |
| 61 |
def test_ls__without_bucket_name__option_not_supported(b2_cli, bucket_info, flag): |
| 62 |
b2_cli.run( |
| 63 |
["ls", flag], |
| 64 |
expected_stderr=f"ERROR: Cannot use {flag} option without specifying a bucket name\n", |
| 65 |
expected_status=1, |
| 66 |
) |