From 5c04eefe2599f13cf37b91cf60bd242e64b97bd7 Mon Sep 17 00:00:00 2001 From: Gurov Ilya Date: Fri, 3 Apr 2020 20:39:23 +0300 Subject: [PATCH] =?UTF-8?q?tests:=20add=20blobs=20retention=20policy=20dis?= =?UTF-8?q?carding=20into=20TestRetentionPolicy=E2=80=A6=20(#99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * tests: add blobs retention policy discarding into TestRetentionPolicy() teardown * merging error fix --- tests/system/test_system.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 2cb3dc0ab..ef4bc051b 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -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 @@ -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) @@ -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 @@ -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) @@ -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 @@ -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 @@ -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() @@ -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