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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
######################################################################
#
# File: test/unit/account_info/fixtures.py
#
# Copyright 2021 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from __future__ import annotations
import pytest
from apiver_deps import InMemoryAccountInfo, SqliteAccountInfo
from pytest_lazy_fixtures import lf
from b2sdk.v2 import SqliteAccountInfo as V2SqliteAccountInfo
from b2sdk.v3 import SqliteAccountInfo as V3SqliteAccountInfo
@pytest.fixture
def account_info_default_data_schema_0():
return dict(
account_id='account_id',
auth_token='account_auth',
api_url='https://api000.backblazeb2.xyz:8180',
download_url='https://f000.backblazeb2.xyz:8180',
minimum_part_size=100,
application_key='app_key',
realm='dev',
)
@pytest.fixture
def account_info_default_data(account_info_default_data_schema_0, apiver):
if apiver in ['v0', 'v1']:
return dict(
allowed=None,
application_key_id='application_key_id',
s3_api_url='https://s3.us-west-000.backblazeb2.xyz:8180',
**account_info_default_data_schema_0,
)
return dict(
allowed=None,
application_key_id='application_key_id',
s3_api_url='https://s3.us-west-000.backblazeb2.xyz:8180',
account_id='account_id',
auth_token='account_auth',
api_url='https://api000.backblazeb2.xyz:8180',
download_url='https://f000.backblazeb2.xyz:8180',
recommended_part_size=100,
absolute_minimum_part_size=50,
application_key='app_key',
realm='dev',
)
@pytest.fixture(scope='session')
def in_memory_account_info_factory():
def get_account_info():
return InMemoryAccountInfo()
return get_account_info
@pytest.fixture
def in_memory_account_info(in_memory_account_info_factory):
return in_memory_account_info_factory()
@pytest.fixture
def sqlite_account_info_factory(tmpdir):
def get_account_info(file_name=None, schema_0=False):
if file_name is None:
file_name = str(tmpdir.join('b2_account_info'))
if schema_0:
last_upgrade_to_run = 0
else:
last_upgrade_to_run = None
return SqliteAccountInfo(file_name, last_upgrade_to_run)
return get_account_info
@pytest.fixture
def v2_sqlite_account_info_factory(tmpdir):
def get_account_info(file_name=None):
if file_name is None:
file_name = str(tmpdir.join('b2_account_info'))
return V2SqliteAccountInfo(file_name, last_upgrade_to_run=4)
return get_account_info
@pytest.fixture
def v3_sqlite_account_info_factory(tmpdir):
def get_account_info(file_name=None):
if file_name is None:
file_name = str(tmpdir.join('b2_account_info'))
return V3SqliteAccountInfo(file_name)
return get_account_info
@pytest.fixture
def sqlite_account_info(sqlite_account_info_factory):
return sqlite_account_info_factory()
@pytest.fixture(
params=[
lf('in_memory_account_info_factory'),
lf('sqlite_account_info_factory'),
]
)
def account_info_factory(request):
return request.param
@pytest.fixture(
params=[
lf('in_memory_account_info'),
lf('sqlite_account_info'),
]
)
def account_info(request):
return request.param
@pytest.fixture
def fake_account_info(mocker):
account_info = mocker.MagicMock(name='FakeAccountInfo', spec=InMemoryAccountInfo)
account_info.REALM_URLS = {
'dev': 'http://api.backblazeb2.xyz:8180',
}
account_info.is_same_account.return_value = True
account_info.is_same_key.return_value = True
return account_info
|