Skip to content

Commit 0635c77

Browse files
Add licences, changelog and fixes
1 parent f061a37 commit 0635c77

File tree

15 files changed

+94
-58
lines changed

15 files changed

+94
-58
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
######################################################################
2+
#
3+
# File: b2sdk/_internal/testing/__init__.py
4+
#
5+
# Copyright 2021 Backblaze Inc. All Rights Reserved.
6+
#
7+
# License https://www.backblaze.com/using_b2_code.html
8+
#
9+
######################################################################
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
######################################################################
2+
#
3+
# File: b2sdk/_internal/testing/fixtures/__init__.py
4+
#
5+
# Copyright 2021 Backblaze Inc. All Rights Reserved.
6+
#
7+
# License https://www.backblaze.com/using_b2_code.html
8+
#
9+
######################################################################

b2sdk/_internal/testing/fixtures/api.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
######################################################################
32
#
4-
# File: test/integration/conftest.py
3+
# File: b2sdk/_internal/testing/fixtures/api.py
54
#
65
# Copyright 2021 Backblaze Inc. All Rights Reserved.
76
#
@@ -16,7 +15,12 @@
1615

1716
import pytest
1817

19-
from b2sdk._internal.testing.helpers.api import get_b2_auth_data, authorize
18+
from b2sdk._internal.testing.helpers.api import authorize, get_b2_auth_data, get_realm
19+
20+
21+
@pytest.fixture(scope='session')
22+
def realm():
23+
yield get_realm()
2024

2125

2226
@pytest.fixture(autouse=True, scope='session')
@@ -34,8 +38,8 @@ def b2_auth_data():
3438

3539

3640
@pytest.fixture(scope='session')
37-
def _b2_api(b2_auth_data):
38-
b2_api, _ = authorize(b2_auth_data)
41+
def _b2_api(b2_auth_data, realm):
42+
b2_api, _ = authorize(b2_auth_data, realm)
3943
return b2_api
4044

4145

b2sdk/_internal/testing/fixtures/buckets.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
######################################################################
22
#
3-
# File: test/integration/conftest.py
3+
# File: b2sdk/_internal/testing/fixtures/buckets.py
44
#
55
# Copyright 2021 Backblaze Inc. All Rights Reserved.
66
#
77
# License https://www.backblaze.com/using_b2_code.html
88
#
99
######################################################################
1010
from __future__ import annotations
11+
1112
import secrets
1213

1314
import pytest
1415

15-
from b2sdk._internal.utils import current_time_millis
1616
from b2sdk._internal.testing.helpers.bucket_manager import BucketManager
1717
from b2sdk._internal.testing.helpers.buckets import (
1818
BUCKET_CREATED_AT_MILLIS,
19+
GENERAL_BUCKET_NAME_PREFIX,
1920
get_bucket_name_prefix,
2021
random_bucket_name,
21-
GENERAL_BUCKET_NAME_PREFIX,
2222
)
23+
from b2sdk._internal.utils import current_time_millis
2324

2425

2526
def pytest_addoption(parser):
@@ -47,15 +48,17 @@ def general_bucket_name_prefix():
4748

4849

4950
@pytest.fixture(scope='session')
50-
def bucket_manager(bucket_name_prefix, general_bucket_name_prefix, dont_cleanup_old_buckets, _b2_api):
51-
cleaner = BucketManager(
51+
def bucket_manager(
52+
bucket_name_prefix, general_bucket_name_prefix, dont_cleanup_old_buckets, _b2_api
53+
):
54+
manager = BucketManager(
5255
dont_cleanup_old_buckets,
5356
_b2_api,
5457
current_run_prefix=bucket_name_prefix,
55-
general_prefix=general_bucket_name_prefix
58+
general_prefix=general_bucket_name_prefix,
5659
)
57-
yield cleaner
58-
cleaner.clean_buckets()
60+
yield manager
61+
manager.clean_buckets()
5962

6063

6164
@pytest.fixture
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
######################################################################
2+
#
3+
# File: b2sdk/_internal/testing/helpers/__init__.py
4+
#
5+
# Copyright 2021 Backblaze Inc. All Rights Reserved.
6+
#
7+
# License https://www.backblaze.com/using_b2_code.html
8+
#
9+
######################################################################

b2sdk/_internal/testing/helpers/api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
######################################################################
22
#
3-
# File: test/integration/helpers.py
3+
# File: b2sdk/_internal/testing/helpers/api.py
44
#
55
# Copyright 2022 Backblaze Inc. All Rights Reserved.
66
#
@@ -18,6 +18,10 @@
1818
)
1919

2020

21+
def get_realm() -> str:
22+
return os.environ.get('B2_TEST_ENVIRONMENT', 'production')
23+
24+
2125
def get_b2_auth_data():
2226
application_key_id = os.environ.get('B2_TEST_APPLICATION_KEY_ID')
2327
if application_key_id is None:
@@ -29,10 +33,8 @@ def get_b2_auth_data():
2933
return application_key_id, application_key
3034

3135

32-
def authorize(b2_auth_data, api_config=DEFAULT_HTTP_API_CONFIG):
36+
def authorize(b2_auth_data, realm, api_config=DEFAULT_HTTP_API_CONFIG):
3337
info = InMemoryAccountInfo()
34-
# TODO ME: Cache?
3538
b2_api = B2Api(info, api_config=api_config)
36-
realm = os.environ.get('B2_TEST_ENVIRONMENT', 'production')
3739
b2_api.authorize_account(*b2_auth_data, realm=realm)
38-
return b2_api, info
40+
return b2_api, info

b2sdk/_internal/testing/helpers/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
######################################################################
22
#
3-
# File: test/integration/base.py
3+
# File: b2sdk/_internal/testing/helpers/base.py
44
#
55
# Copyright 2022 Backblaze Inc. All Rights Reserved.
66
#
@@ -11,13 +11,13 @@
1111

1212
import pytest
1313

14-
from b2sdk.v2 import B2Api, current_time_millis
15-
from b2sdk.v2.exception import DuplicateBucketName
1614
from b2sdk._internal.testing.helpers.bucket_manager import BucketManager
1715
from b2sdk._internal.testing.helpers.buckets import (
1816
BUCKET_CREATED_AT_MILLIS,
1917
random_bucket_name,
2018
)
19+
from b2sdk.v2 import B2Api, current_time_millis
20+
from b2sdk.v2.exception import DuplicateBucketName
2121

2222

2323
@pytest.mark.usefixtures('cls_setup')

b2sdk/_internal/testing/helpers/bucket_manager.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
######################################################################
22
#
3-
# File: test/integration/bucket_manager.py
3+
# File: b2sdk/_internal/testing/helpers/bucket_manager.py
44
#
55
# Copyright 2022 Backblaze Inc. All Rights Reserved.
66
#
@@ -13,13 +13,18 @@
1313
import platform
1414
from collections.abc import Iterable
1515
from datetime import datetime, timedelta
16-
1716
from itertools import chain
1817
from typing import Any
1918

2019
import tenacity
2120

22-
from b2sdk._internal.exception import BucketIdNotFound, TooManyRequests, FileNotPresent
21+
from b2sdk._internal.exception import BucketIdNotFound, FileNotPresent, TooManyRequests
22+
from b2sdk._internal.testing.helpers.buckets import (
23+
BUCKET_CREATED_AT_MILLIS,
24+
BUCKET_NAME_LENGTH,
25+
GENERAL_BUCKET_NAME_PREFIX,
26+
random_token,
27+
)
2328
from b2sdk.v3 import (
2429
NO_RETENTION_FILE_SETTING,
2530
B2Api,
@@ -29,9 +34,6 @@
2934
current_time_millis,
3035
)
3136
from b2sdk.v3.exception import BadRequest
32-
from b2sdk._internal.testing.helpers.buckets import BUCKET_CREATED_AT_MILLIS, GENERAL_BUCKET_NAME_PREFIX, random_token, \
33-
BUCKET_NAME_LENGTH
34-
3537

3638
NODE_DESCRIPTION = f'{platform.node()}: {platform.platform()}'
3739
ONE_HOUR_MILLIS = 60 * 60 * 1000
@@ -45,8 +47,8 @@ def __init__(
4547
self,
4648
dont_cleanup_old_buckets: bool,
4749
b2_api: B2Api,
48-
current_run_prefix: str,
49-
general_prefix: str = GENERAL_BUCKET_NAME_PREFIX
50+
current_run_prefix: str = '',
51+
general_prefix: str = GENERAL_BUCKET_NAME_PREFIX,
5052
):
5153
self.current_run_prefix = current_run_prefix
5254
self.general_prefix = general_prefix
@@ -77,7 +79,7 @@ def create_bucket(self, bucket_type: str = 'allPublic', **kwargs) -> Bucket:
7779
)
7880

7981
def _should_remove_bucket(self, bucket: Bucket) -> tuple[bool, str]:
80-
if bucket.name.startswith(self.current_run_prefix):
82+
if self.current_run_prefix and bucket.name.startswith(self.current_run_prefix):
8183
return True, 'it is a bucket for this very run'
8284
if self.dont_cleanup_old_buckets:
8385
return False, 'old buckets ought not to be cleaned'

b2sdk/_internal/testing/helpers/buckets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
######################################################################
22
#
3-
# File: test/integration/helpers.py
3+
# File: b2sdk/_internal/testing/helpers/buckets.py
44
#
55
# Copyright 2022 Backblaze Inc. All Rights Reserved.
66
#
@@ -32,4 +32,4 @@ def get_bucket_name_prefix(rnd_len: int = 8) -> str:
3232

3333

3434
def random_bucket_name(prefix: str = GENERAL_BUCKET_NAME_PREFIX) -> str:
35-
return prefix + random_token(BUCKET_NAME_LENGTH - len(prefix))
35+
return prefix + random_token(BUCKET_NAME_LENGTH - len(prefix))

b2sdk/v3/testing/__init__.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111

1212
# testing - it is not imported in v3.__init__ as it depends on pytest and other test dependencies.
1313

14-
from b2sdk._internal.testing.helpers.api import (
15-
get_b2_auth_data,
16-
authorize
17-
)
14+
from b2sdk._internal.testing.helpers.api import get_b2_auth_data, authorize, get_realm
1815
from b2sdk._internal.testing.helpers.base import IntegrationTestBase
1916
from b2sdk._internal.testing.helpers.buckets import (
2017
GENERAL_BUCKET_NAME_PREFIX,
@@ -23,19 +20,20 @@
2320
RNG,
2421
random_token,
2522
get_bucket_name_prefix,
26-
random_bucket_name
23+
random_bucket_name,
2724
)
2825
from b2sdk._internal.testing.helpers.bucket_manager import (
2926
NODE_DESCRIPTION,
3027
ONE_HOUR_MILLIS,
3128
BUCKET_CLEANUP_PERIOD_MILLIS,
32-
BucketManager
29+
BucketManager,
3330
)
3431
from b2sdk._internal.testing.fixtures.api import (
3532
set_http_debug,
3633
b2_auth_data,
3734
_b2_api,
38-
b2_api
35+
b2_api,
36+
realm,
3937
)
4038
from b2sdk._internal.testing.fixtures.buckets import (
4139
pytest_addoption,
@@ -44,5 +42,5 @@
4442
general_bucket_name_prefix,
4543
bucket_manager,
4644
bucket,
47-
b2_subfolder
45+
b2_subfolder,
4846
)

0 commit comments

Comments
 (0)