Skip to content

Commit 762321a

Browse files
Clean up imports and use bucket manager in base test case.
1 parent 0635c77 commit 762321a

File tree

8 files changed

+19
-67
lines changed

8 files changed

+19
-67
lines changed

b2sdk/_internal/testing/fixtures/buckets.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515

1616
from b2sdk._internal.testing.helpers.bucket_manager import BucketManager
1717
from b2sdk._internal.testing.helpers.buckets import (
18-
BUCKET_CREATED_AT_MILLIS,
1918
GENERAL_BUCKET_NAME_PREFIX,
2019
get_bucket_name_prefix,
21-
random_bucket_name,
2220
)
23-
from b2sdk._internal.utils import current_time_millis
2421

2522

2623
def pytest_addoption(parser):
@@ -62,15 +59,8 @@ def bucket_manager(
6259

6360

6461
@pytest.fixture
65-
def bucket(b2_api, bucket_name_prefix, bucket_manager):
66-
bucket = b2_api.create_bucket(
67-
random_bucket_name(bucket_name_prefix),
68-
'allPrivate',
69-
bucket_info={
70-
'created_by': 'b2-sdk integration test',
71-
BUCKET_CREATED_AT_MILLIS: str(current_time_millis()),
72-
},
73-
)
62+
def bucket(bucket_name_prefix, bucket_manager):
63+
bucket = bucket_manager.create_bucket()
7464
yield bucket
7565
bucket_manager.clean_bucket(bucket)
7666

b2sdk/_internal/testing/helpers/api.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111

1212
import os
1313

14-
from b2sdk.v3 import (
15-
DEFAULT_HTTP_API_CONFIG,
16-
B2Api,
17-
InMemoryAccountInfo,
18-
)
14+
from b2sdk._internal.account_info.in_memory import InMemoryAccountInfo
15+
from b2sdk._internal.api import B2Api
16+
from b2sdk._internal.api_config import DEFAULT_HTTP_API_CONFIG
1917

2018

2119
def get_realm() -> str:

b2sdk/_internal/testing/helpers/base.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
import pytest
1313

1414
from b2sdk._internal.testing.helpers.bucket_manager import BucketManager
15-
from b2sdk._internal.testing.helpers.buckets import (
16-
BUCKET_CREATED_AT_MILLIS,
17-
random_bucket_name,
18-
)
19-
from b2sdk.v2 import B2Api, current_time_millis
15+
from b2sdk.v2 import B2Api
2016
from b2sdk.v2.exception import DuplicateBucketName
2117

2218

@@ -42,9 +38,6 @@ def setup_method(self):
4238
for bucket in self.buckets_created:
4339
self.bucket_manager.clean_bucket(bucket)
4440

45-
def generate_bucket_name(self):
46-
return random_bucket_name(self.this_run_bucket_name_prefix)
47-
4841
def write_zeros(self, file, number):
4942
line = b'0' * 1000 + b'\n'
5043
line_len = len(line)
@@ -54,13 +47,9 @@ def write_zeros(self, file, number):
5447
written += line_len
5548

5649
def create_bucket(self):
57-
bucket_name = self.generate_bucket_name()
50+
bucket_name = self.bucket_manager.new_bucket_name()
5851
try:
59-
bucket = self.b2_api.create_bucket(
60-
bucket_name,
61-
'allPrivate',
62-
bucket_info={BUCKET_CREATED_AT_MILLIS: str(current_time_millis())},
63-
)
52+
bucket = self.bucket_manager.create_bucket(name=bucket_name)
6453
except DuplicateBucketName:
6554
self._duplicated_bucket_name_debug_info(bucket_name)
6655
raise

b2sdk/_internal/testing/helpers/bucket_manager.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@
1818

1919
import tenacity
2020

21-
from b2sdk._internal.exception import BucketIdNotFound, FileNotPresent, TooManyRequests
21+
from b2sdk._internal.api import B2Api
22+
from b2sdk._internal.bucket import Bucket
23+
from b2sdk._internal.exception import BadRequest, BucketIdNotFound, FileNotPresent, TooManyRequests
24+
from b2sdk._internal.file_lock import NO_RETENTION_FILE_SETTING, LegalHold, RetentionMode
2225
from b2sdk._internal.testing.helpers.buckets import (
2326
BUCKET_CREATED_AT_MILLIS,
2427
BUCKET_NAME_LENGTH,
2528
GENERAL_BUCKET_NAME_PREFIX,
2629
random_token,
2730
)
28-
from b2sdk.v3 import (
29-
NO_RETENTION_FILE_SETTING,
30-
B2Api,
31-
Bucket,
32-
LegalHold,
33-
RetentionMode,
34-
current_time_millis,
35-
)
36-
from b2sdk.v3.exception import BadRequest
31+
from b2sdk._internal.utils import current_time_millis
3732

3833
NODE_DESCRIPTION = f'{platform.node()}: {platform.platform()}'
3934
ONE_HOUR_MILLIS = 60 * 60 * 1000
@@ -70,7 +65,7 @@ def new_bucket_info(self) -> dict:
7065
}
7166

7267
def create_bucket(self, bucket_type: str = 'allPublic', **kwargs) -> Bucket:
73-
bucket_name = self.new_bucket_name()
68+
bucket_name = kwargs.pop('name', self.new_bucket_name())
7469
return self.b2_api.create_bucket(
7570
bucket_name,
7671
bucket_type=bucket_type,

b2sdk/_internal/testing/helpers/buckets.py

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

1212
import secrets
1313

14-
from b2sdk.v3 import (
15-
BUCKET_NAME_CHARS_UNIQ,
16-
BUCKET_NAME_LENGTH_RANGE,
17-
)
14+
from b2sdk._internal.http_constants import BUCKET_NAME_CHARS_UNIQ, BUCKET_NAME_LENGTH_RANGE
1815

1916
GENERAL_BUCKET_NAME_PREFIX = 'sdktst'
2017
BUCKET_NAME_LENGTH = BUCKET_NAME_LENGTH_RANGE[1]
@@ -29,7 +26,3 @@ def random_token(length: int, chars: str = BUCKET_NAME_CHARS_UNIQ) -> str:
2926

3027
def get_bucket_name_prefix(rnd_len: int = 8) -> str:
3128
return GENERAL_BUCKET_NAME_PREFIX + random_token(rnd_len)
32-
33-
34-
def random_bucket_name(prefix: str = GENERAL_BUCKET_NAME_PREFIX) -> str:
35-
return prefix + random_token(BUCKET_NAME_LENGTH - len(prefix))

b2sdk/v3/testing/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
RNG,
2121
random_token,
2222
get_bucket_name_prefix,
23-
random_bucket_name,
2423
)
2524
from b2sdk._internal.testing.helpers.bucket_manager import (
2625
NODE_DESCRIPTION,

test/integration/conftest.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,5 @@
88
#
99
######################################################################
1010

11-
from b2sdk.v3.testing import ( # noqa: F401
12-
_b2_api,
13-
b2_api,
14-
b2_auth_data,
15-
b2_subfolder,
16-
bucket,
17-
bucket_manager,
18-
bucket_name_prefix,
19-
dont_cleanup_old_buckets,
20-
general_bucket_name_prefix,
21-
pytest_addoption,
22-
realm,
23-
set_http_debug,
24-
)
11+
12+
pytest_plugins = ["b2sdk.v3.testing"]

test/integration/test_raw_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def raw_api_test_helper(raw_api, should_cleanup_old_buckets):
168168
account_auth_token,
169169
account_id,
170170
bucket_name,
171-
'allPrivate',
171+
'allPublic',
172172
is_file_lock_enabled=True,
173173
)
174174
bucket_id = bucket_dict['bucketId']
@@ -208,7 +208,7 @@ def raw_api_test_helper(raw_api, should_cleanup_old_buckets):
208208
account_auth_token,
209209
account_id,
210210
replication_source_bucket_name,
211-
'allPrivate',
211+
'allPublic',
212212
is_file_lock_enabled=True,
213213
replication=ReplicationConfiguration(
214214
rules=[

0 commit comments

Comments
 (0)