Skip to content

Commit 9205666

Browse files
committed
Add basic retention scenario to test_raw_api
1 parent 61ff868 commit 9205666

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

b2sdk/raw_api.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from .b2http import B2Http
2525
from .exception import FileOrBucketNotFound, ResourceNotFound, UnusableFileName, InvalidMetadataDirective, WrongEncryptionModeForBucketDefault
2626
from .encryption.setting import EncryptionAlgorithm, EncryptionMode, EncryptionSetting
27-
from .file_lock import BucketRetentionSetting, FileRetentionSetting, RetentionMode, RetentionPeriod
27+
from .file_lock import BucketRetentionSetting, FileRetentionSetting, NO_RETENTION_FILE_SETTING, RetentionMode, RetentionPeriod
2828
from .utils import b2_url_encode, hex_sha1_of_stream
2929

3030
# All possible capabilities
@@ -1027,7 +1027,12 @@ def test_raw_api_helper(raw_api):
10271027
account_id, int(time.time()), random.randint(1000, 9999)
10281028
)
10291029
bucket_dict = raw_api.create_bucket(
1030-
api_url, account_auth_token, account_id, bucket_name, 'allPublic'
1030+
api_url,
1031+
account_auth_token,
1032+
account_id,
1033+
bucket_name,
1034+
'allPublic',
1035+
is_file_lock_enabled=True,
10311036
)
10321037
bucket_id = bucket_dict['bucketId']
10331038
first_bucket_revision = bucket_dict['revision']
@@ -1039,9 +1044,13 @@ def test_raw_api_helper(raw_api):
10391044
algorithm=EncryptionAlgorithm.AES256,
10401045
)
10411046
sse_none = EncryptionSetting(mode=EncryptionMode.NONE)
1042-
for encryption_setting in [
1043-
sse_none,
1044-
sse_b2_aes,
1047+
for encryption_setting, default_retention in [
1048+
(
1049+
sse_none,
1050+
BucketRetentionSetting(mode=RetentionMode.GOVERNANCE, period=RetentionPeriod(days=1))
1051+
),
1052+
(sse_b2_aes, None),
1053+
(sse_b2_aes, BucketRetentionSetting(RetentionMode.NONE)),
10451054
]:
10461055
bucket_dict = raw_api.update_bucket(
10471056
api_url,
@@ -1050,6 +1059,7 @@ def test_raw_api_helper(raw_api):
10501059
bucket_id,
10511060
'allPublic',
10521061
default_server_side_encryption=encryption_setting,
1062+
default_retention=default_retention,
10531063
)
10541064

10551065
# b2_list_buckets
@@ -1233,7 +1243,10 @@ def test_raw_api_helper(raw_api):
12331243
account_id,
12341244
bucket_id,
12351245
'allPrivate',
1236-
bucket_info={'color': 'blue'}
1246+
bucket_info={'color': 'blue'},
1247+
default_retention=BucketRetentionSetting(
1248+
mode=RetentionMode.GOVERNANCE, period=RetentionPeriod(days=1)
1249+
),
12371250
)
12381251
assert first_bucket_revision < updated_bucket['revision']
12391252

@@ -1259,6 +1272,16 @@ def _clean_and_delete_bucket(raw_api, api_url, account_auth_token, account_id, b
12591272
action = version_dict['action']
12601273
if action in ['hide', 'upload']:
12611274
print('b2_delete_file', file_name, action)
1275+
if action == 'upload' and version_dict[
1276+
'fileRetention'] and version_dict['fileRetention']['value']['mode'] is not None:
1277+
raw_api.update_file_retention(
1278+
api_url,
1279+
account_auth_token,
1280+
file_id,
1281+
file_name,
1282+
NO_RETENTION_FILE_SETTING,
1283+
bypass_governance=True
1284+
)
12621285
raw_api.delete_file_version(api_url, account_auth_token, file_id, file_name)
12631286
else:
12641287
print('b2_cancel_large_file', file_name)

0 commit comments

Comments
 (0)