File: test_get_url.py

package info (click to toggle)
backblaze-b2 3.19.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,372 kB
  • sloc: python: 12,571; makefile: 21; sh: 12
file content (53 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
######################################################################
#
# File: test/unit/console_tool/test_get_url.py
#
# Copyright 2023 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
import pytest


@pytest.fixture
def uploaded_file_url(bucket_info, uploaded_file):
    return f"http://download.example.com/file/{bucket_info['bucketName']}/{uploaded_file['fileName']}"


@pytest.fixture
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_make_url(b2_cli, uploaded_file, uploaded_file_url_by_id):
    b2_cli.run(
        ["make-url", uploaded_file["fileId"]],
        expected_stdout=f"{uploaded_file_url_by_id}\n",
        expected_stderr='WARNING: make-url command is deprecated. Use get-url instead.\n',
    )


def test_make_friendly_url(b2_cli, bucket, uploaded_file, uploaded_file_url):
    b2_cli.run(
        ["make-friendly-url", bucket, uploaded_file["fileName"]],
        expected_stdout=f"{uploaded_file_url}\n",
        expected_stderr='WARNING: make-friendly-url command is deprecated. Use get-url instead.\n',
    )


def test_get_url__b2_uri(b2_cli, bucket, uploaded_file, uploaded_file_url):
    b2_cli.run(
        [
            "get-url",
            f'b2://{bucket}/{uploaded_file["fileName"]}',
        ],
        expected_stdout=f"{uploaded_file_url}\n",
    )


def test_get_url__b2id_uri(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",
    )