Skip to content

Commit

Permalink
tests: add blobs retention policy discarding into TestRetentionPolicy… (
Browse files Browse the repository at this point in the history
#99)

* tests: add blobs retention policy discarding into TestRetentionPolicy() teardown

* merging error fix
  • Loading branch information
Gurov Ilya committed Apr 3, 2020
1 parent 44060de commit 5c04eef
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions tests/system/test_system.py
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)

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

0 comments on commit 5c04eef

Please sign in to comment.