Skip to content

Commit cc191b0

Browse files
authored
fix: split retention period tests due to caching change (#1068)
1 parent 051513f commit cc191b0

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

tests/system/test_bucket.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,9 @@ def test_bucket_list_blobs_w_match_glob(
653653
assert [blob.name for blob in blobs] == expected_names
654654

655655

656-
def test_bucket_w_retention_period(
656+
def test_bucket_update_retention_period(
657657
storage_client,
658658
buckets_to_delete,
659-
blobs_to_delete,
660659
):
661660
period_secs = 3
662661
bucket_name = _helpers.unique_name("w-retention-period")
@@ -676,23 +675,6 @@ def test_bucket_w_retention_period(
676675
assert not bucket.default_event_based_hold
677676
assert not bucket.retention_policy_locked
678677

679-
blob_name = "test-blob"
680-
payload = b"DEADBEEF"
681-
blob = bucket.blob(blob_name)
682-
blob.upload_from_string(payload)
683-
684-
blobs_to_delete.append(blob)
685-
686-
other = bucket.get_blob(blob_name)
687-
_helpers.retry_has_retention_expiration(other.reload)()
688-
689-
assert not other.event_based_hold
690-
assert not other.temporary_hold
691-
assert isinstance(other.retention_expiration_time, datetime.datetime)
692-
693-
with pytest.raises(exceptions.Forbidden):
694-
other.delete()
695-
696678
bucket.retention_period = None
697679
bucket.patch()
698680

@@ -705,15 +687,41 @@ def test_bucket_w_retention_period(
705687
assert not bucket.default_event_based_hold
706688
assert not bucket.retention_policy_locked
707689

708-
_helpers.retry_no_retention_expiration(other.reload)()
709690

710-
assert not other.event_based_hold
711-
assert not other.temporary_hold
712-
assert other.retention_expiration_time is None
691+
def test_delete_object_bucket_w_retention_period(
692+
storage_client,
693+
buckets_to_delete,
694+
blobs_to_delete,
695+
):
696+
# Create a bucket with retention period.
697+
period_secs = 12
698+
bucket = storage_client.bucket(_helpers.unique_name("w-retention-period"))
699+
bucket.retention_period = period_secs
700+
bucket.default_event_based_hold = False
701+
bucket = _helpers.retry_429_503(storage_client.create_bucket)(bucket)
702+
buckets_to_delete.append(bucket)
703+
704+
_helpers.retry_has_retention_period(bucket.reload)()
705+
assert bucket.retention_period == period_secs
706+
assert isinstance(bucket.retention_policy_effective_time, datetime.datetime)
707+
708+
payload = b"DEADBEEF"
709+
blob = bucket.blob(_helpers.unique_name("w-retention"))
710+
blob.upload_from_string(payload)
711+
blobs_to_delete.append(blob)
712+
713+
_helpers.retry_has_retention_expiration(blob.reload)()
714+
assert isinstance(blob.retention_expiration_time, datetime.datetime)
715+
assert not blob.event_based_hold
716+
assert not blob.temporary_hold
717+
718+
# Attempts to delete objects whose age is less than the retention period should fail.
719+
with pytest.raises(exceptions.Forbidden):
720+
blob.delete()
713721

714722
# Object can be deleted once it reaches the age defined in the retention policy.
715723
_helpers.await_config_changes_propagate(sec=period_secs)
716-
other.delete()
724+
blob.delete()
717725
blobs_to_delete.pop()
718726

719727

0 commit comments

Comments
 (0)