Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1702,11 +1702,18 @@ def test_rewrite_rotate_csek_to_cmek(self):
class TestRetentionPolicy(unittest.TestCase):
def setUp(self):
self.case_buckets_to_delete = []
self.case_blobs_to_delete = []

def tearDown(self):
# discard test blobs retention policy settings
for blob in self.case_blobs_to_delete:
blob.event_based_hold = False
blob.temporary_hold = False
blob.patch()

for bucket_name in self.case_buckets_to_delete:
bucket = Config.CLIENT.bucket(bucket_name)
retry_429_harder(bucket.delete)()
retry_429_harder(bucket.delete)(force=True)

def test_bucket_w_retention_period(self):
import datetime
Expand All @@ -1732,6 +1739,8 @@ def test_bucket_w_retention_period(self):
blob = bucket.blob(blob_name)
blob.upload_from_string(payload)

self.case_blobs_to_delete.append(blob)

other = bucket.get_blob(blob_name)

self.assertFalse(other.event_based_hold)
Expand All @@ -1756,6 +1765,7 @@ def test_bucket_w_retention_period(self):
self.assertIsNone(other.retention_expiration_time)

other.delete()
self.case_blobs_to_delete.pop()

def test_bucket_w_default_event_based_hold(self):
from google.api_core import exceptions
Expand All @@ -1780,6 +1790,8 @@ def test_bucket_w_default_event_based_hold(self):
blob = bucket.blob(blob_name)
blob.upload_from_string(payload)

self.case_blobs_to_delete.append(blob)

other = bucket.get_blob(blob_name)

self.assertTrue(other.event_based_hold)
Expand All @@ -1791,7 +1803,6 @@ def test_bucket_w_default_event_based_hold(self):

other.event_based_hold = False
other.patch()

other.delete()

bucket.default_event_based_hold = False
Expand All @@ -1803,11 +1814,12 @@ def test_bucket_w_default_event_based_hold(self):
self.assertFalse(bucket.retention_policy_locked)

blob.upload_from_string(payload)
self.assertFalse(other.event_based_hold)
self.assertFalse(other.temporary_hold)
self.assertIsNone(other.retention_expiration_time)
self.assertFalse(blob.event_based_hold)
self.assertFalse(blob.temporary_hold)
self.assertIsNone(blob.retention_expiration_time)
Copy link
Author

@IlyaFaer IlyaFaer Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, there is an error here: other blob is already deleted (line 1806). Most likely, blob was going to be here, as it's just has been uploaded and there is no asserts for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch


blob.delete()
self.case_blobs_to_delete.pop()

def test_blob_w_temporary_hold(self):
from google.api_core import exceptions
Expand All @@ -1824,6 +1836,8 @@ def test_blob_w_temporary_hold(self):
blob = bucket.blob(blob_name)
blob.upload_from_string(payload)

self.case_blobs_to_delete.append(blob)

other = bucket.get_blob(blob_name)
other.temporary_hold = True
other.patch()
Expand All @@ -1839,6 +1853,7 @@ def test_blob_w_temporary_hold(self):
other.patch()

other.delete()
self.case_blobs_to_delete.pop()

def test_bucket_lock_retention_policy(self):
import datetime
Expand Down