@@ -1702,11 +1702,18 @@ def test_rewrite_rotate_csek_to_cmek(self):
1702
1702
class TestRetentionPolicy (unittest .TestCase ):
1703
1703
def setUp (self ):
1704
1704
self .case_buckets_to_delete = []
1705
+ self .case_blobs_to_delete = []
1705
1706
1706
1707
def tearDown (self ):
1708
+ # discard test blobs retention policy settings
1709
+ for blob in self .case_blobs_to_delete :
1710
+ blob .event_based_hold = False
1711
+ blob .temporary_hold = False
1712
+ blob .patch ()
1713
+
1707
1714
for bucket_name in self .case_buckets_to_delete :
1708
1715
bucket = Config .CLIENT .bucket (bucket_name )
1709
- retry_429_harder (bucket .delete )()
1716
+ retry_429_harder (bucket .delete )(force = True )
1710
1717
1711
1718
def test_bucket_w_retention_period (self ):
1712
1719
import datetime
@@ -1732,6 +1739,8 @@ def test_bucket_w_retention_period(self):
1732
1739
blob = bucket .blob (blob_name )
1733
1740
blob .upload_from_string (payload )
1734
1741
1742
+ self .case_blobs_to_delete .append (blob )
1743
+
1735
1744
other = bucket .get_blob (blob_name )
1736
1745
1737
1746
self .assertFalse (other .event_based_hold )
@@ -1756,6 +1765,7 @@ def test_bucket_w_retention_period(self):
1756
1765
self .assertIsNone (other .retention_expiration_time )
1757
1766
1758
1767
other .delete ()
1768
+ self .case_blobs_to_delete .pop ()
1759
1769
1760
1770
def test_bucket_w_default_event_based_hold (self ):
1761
1771
from google .api_core import exceptions
@@ -1780,6 +1790,8 @@ def test_bucket_w_default_event_based_hold(self):
1780
1790
blob = bucket .blob (blob_name )
1781
1791
blob .upload_from_string (payload )
1782
1792
1793
+ self .case_blobs_to_delete .append (blob )
1794
+
1783
1795
other = bucket .get_blob (blob_name )
1784
1796
1785
1797
self .assertTrue (other .event_based_hold )
@@ -1791,7 +1803,6 @@ def test_bucket_w_default_event_based_hold(self):
1791
1803
1792
1804
other .event_based_hold = False
1793
1805
other .patch ()
1794
-
1795
1806
other .delete ()
1796
1807
1797
1808
bucket .default_event_based_hold = False
@@ -1803,11 +1814,12 @@ def test_bucket_w_default_event_based_hold(self):
1803
1814
self .assertFalse (bucket .retention_policy_locked )
1804
1815
1805
1816
blob .upload_from_string (payload )
1806
- self .assertFalse (other .event_based_hold )
1807
- self .assertFalse (other .temporary_hold )
1808
- self .assertIsNone (other .retention_expiration_time )
1817
+ self .assertFalse (blob .event_based_hold )
1818
+ self .assertFalse (blob .temporary_hold )
1819
+ self .assertIsNone (blob .retention_expiration_time )
1809
1820
1810
1821
blob .delete ()
1822
+ self .case_blobs_to_delete .pop ()
1811
1823
1812
1824
def test_blob_w_temporary_hold (self ):
1813
1825
from google .api_core import exceptions
@@ -1824,6 +1836,8 @@ def test_blob_w_temporary_hold(self):
1824
1836
blob = bucket .blob (blob_name )
1825
1837
blob .upload_from_string (payload )
1826
1838
1839
+ self .case_blobs_to_delete .append (blob )
1840
+
1827
1841
other = bucket .get_blob (blob_name )
1828
1842
other .temporary_hold = True
1829
1843
other .patch ()
@@ -1839,6 +1853,7 @@ def test_blob_w_temporary_hold(self):
1839
1853
other .patch ()
1840
1854
1841
1855
other .delete ()
1856
+ self .case_blobs_to_delete .pop ()
1842
1857
1843
1858
def test_bucket_lock_retention_policy (self ):
1844
1859
import datetime
0 commit comments