| 1 |
###################################################################### |
| 2 |
# |
| 3 |
# File: test/unit/console_tool/test_get_url.py |
| 4 |
# |
| 5 |
# Copyright 2023 Backblaze Inc. All Rights Reserved. |
| 6 |
# |
| 7 |
# License https://www.backblaze.com/using_b2_code.html |
| 8 |
# |
| 9 |
###################################################################### |
| 10 |
import pytest |
| 11 |
|
| 12 |
|
| 13 |
@pytest.fixture |
| 14 |
def uploaded_file_url(bucket_info, uploaded_file): |
| 15 |
return f"http://download.example.com/file/{bucket_info['bucketName']}/{uploaded_file['fileName']}" |
| 16 |
|
| 17 |
|
| 18 |
@pytest.fixture |
| 19 |
def uploaded_file_url_by_id(uploaded_file): |
| 20 |
return f"http://download.example.com/b2api/v2/b2_download_file_by_id?fileId={uploaded_file['fileId']}" |
| 21 |
|
| 22 |
|
| 23 |
def test_make_url(b2_cli, uploaded_file, uploaded_file_url_by_id): |
| 24 |
b2_cli.run( |
| 25 |
["make-url", uploaded_file["fileId"]], |
| 26 |
expected_stdout=f"{uploaded_file_url_by_id}\n", |
| 27 |
expected_stderr='WARNING: make-url command is deprecated. Use get-url instead.\n', |
| 28 |
) |
| 29 |
|
| 30 |
|
| 31 |
def test_make_friendly_url(b2_cli, bucket, uploaded_file, uploaded_file_url): |
| 32 |
b2_cli.run( |
| 33 |
["make-friendly-url", bucket, uploaded_file["fileName"]], |
| 34 |
expected_stdout=f"{uploaded_file_url}\n", |
| 35 |
expected_stderr='WARNING: make-friendly-url command is deprecated. Use get-url instead.\n', |
| 36 |
) |
| 37 |
|
| 38 |
|
| 39 |
def test_get_url__b2_uri(b2_cli, bucket, uploaded_file, uploaded_file_url): |
| 40 |
b2_cli.run( |
| 41 |
[ |
| 42 |
"get-url", |
| 43 |
f'b2://{bucket}/{uploaded_file["fileName"]}', |
| 44 |
], |
| 45 |
expected_stdout=f"{uploaded_file_url}\n", |
| 46 |
) |
| 47 |
|
| 48 |
|
| 49 |
def test_get_url__b2id_uri(b2_cli, uploaded_file, uploaded_file_url_by_id): |
| 50 |
b2_cli.run( |
| 51 |
["get-url", f'b2id://{uploaded_file["fileId"]}'], |
| 52 |
expected_stdout=f"{uploaded_file_url_by_id}\n", |
| 53 |
) |