@@ -63,9 +63,9 @@ def _bad_copy(bad_request):
6363retry_bad_copy = RetryErrors (exceptions .BadRequest , error_predicate = _bad_copy )
6464
6565
66- def _empty_bucket (bucket ):
66+ def _empty_bucket (client , bucket ):
6767 """Empty a bucket of all existing blobs (including multiple versions)."""
68- for blob in list (bucket .list_blobs (versions = True )):
68+ for blob in list (client .list_blobs (bucket , versions = True )):
6969 try :
7070 blob .delete ()
7171 except exceptions .NotFound :
@@ -96,7 +96,7 @@ def setUpModule():
9696def tearDownModule ():
9797 errors = (exceptions .Conflict , exceptions .TooManyRequests )
9898 retry = RetryErrors (errors , max_tries = 15 )
99- retry (_empty_bucket )(Config .TEST_BUCKET )
99+ retry (_empty_bucket )(Config .CLIENT , Config . TEST_BUCKET )
100100 retry (Config .TEST_BUCKET .delete )(force = True )
101101
102102
@@ -622,7 +622,7 @@ def test_large_encrypted_file_write_from_stream(self):
622622
623623 with tempfile .NamedTemporaryFile () as temp_f :
624624 with open (temp_f .name , "wb" ) as file_obj :
625- blob . download_to_file ( file_obj )
625+ Config . CLIENT . download_blob_to_file ( blob , file_obj )
626626
627627 with open (temp_f .name , "rb" ) as file_obj :
628628 md5_temp_hash = _base64_md5hash (file_obj )
@@ -718,11 +718,15 @@ def test_crud_blob_w_user_project(self):
718718 self .assertIsNone (blob1 .metadata )
719719 finally :
720720 # Exercise 'objects.delete' (metadata) w/ userProject.
721- blobs = with_user_project .list_blobs (prefix = blob .name , versions = True )
721+ blobs = Config .CLIENT .list_blobs (
722+ with_user_project , prefix = blob .name , versions = True
723+ )
722724 self .assertEqual ([each .generation for each in blobs ], [gen0 , gen1 ])
723725
724726 blob0 .delete ()
725- blobs = with_user_project .list_blobs (prefix = blob .name , versions = True )
727+ blobs = Config .CLIENT .list_blobs (
728+ with_user_project , prefix = blob .name , versions = True
729+ )
726730 self .assertEqual ([each .generation for each in blobs ], [gen1 ])
727731
728732 blob1 .delete ()
@@ -859,7 +863,7 @@ def test_direct_write_and_read_into_file(self):
859863 with tempfile .NamedTemporaryFile () as temp_f :
860864
861865 with open (temp_f .name , "wb" ) as file_obj :
862- same_blob . download_to_file ( file_obj )
866+ Config . CLIENT . download_blob_to_file ( same_blob , file_obj )
863867
864868 with open (temp_f .name , "rb" ) as file_obj :
865869 stored_contents = file_obj .read ()
@@ -881,11 +885,12 @@ def test_download_w_generation_match(self):
881885
882886 with open (temp_f .name , "wb" ) as file_obj :
883887 with self .assertRaises (google .api_core .exceptions .PreconditionFailed ):
884- same_blob . download_to_file (
885- file_obj , if_generation_match = WRONG_GENERATION_NUMBER
888+ Config . CLIENT . download_blob_to_file (
889+ same_blob , file_obj , if_generation_match = WRONG_GENERATION_NUMBER
886890 )
887891
888- same_blob .download_to_file (
892+ Config .CLIENT .download_blob_to_file (
893+ same_blob ,
889894 file_obj ,
890895 if_generation_match = blob .generation ,
891896 if_metageneration_match = blob .metageneration ,
@@ -1068,7 +1073,7 @@ class TestStorageListFiles(TestStorageFiles):
10681073 def setUpClass (cls ):
10691074 super (TestStorageListFiles , cls ).setUpClass ()
10701075 # Make sure bucket empty before beginning.
1071- _empty_bucket (cls .bucket )
1076+ _empty_bucket (Config . CLIENT , cls .bucket )
10721077
10731078 logo_path = cls .FILES ["logo" ]["path" ]
10741079 blob = storage .Blob (cls .FILENAMES [0 ], bucket = cls .bucket )
@@ -1089,7 +1094,7 @@ def tearDownClass(cls):
10891094
10901095 @RetryErrors (unittest .TestCase .failureException )
10911096 def test_list_files (self ):
1092- all_blobs = list (self . bucket .list_blobs ())
1097+ all_blobs = list (Config . CLIENT .list_blobs (self . bucket ))
10931098 self .assertEqual (
10941099 sorted (blob .name for blob in all_blobs ), sorted (self .FILENAMES )
10951100 )
@@ -1100,7 +1105,7 @@ def test_list_files_with_user_project(self):
11001105 with_user_project = Config .CLIENT .bucket (
11011106 self .bucket .name , user_project = USER_PROJECT
11021107 )
1103- all_blobs = list (with_user_project . list_blobs ())
1108+ all_blobs = list (Config . CLIENT . list_blobs (with_user_project ))
11041109 self .assertEqual (
11051110 sorted (blob .name for blob in all_blobs ), sorted (self .FILENAMES )
11061111 )
@@ -1109,7 +1114,7 @@ def test_list_files_with_user_project(self):
11091114 def test_paginate_files (self ):
11101115 truncation_size = 1
11111116 count = len (self .FILENAMES ) - truncation_size
1112- iterator = self . bucket .list_blobs (max_results = count )
1117+ iterator = Config . CLIENT .list_blobs (self . bucket , max_results = count )
11131118 page_iter = iterator .pages
11141119
11151120 page1 = six .next (page_iter )
@@ -1133,7 +1138,8 @@ def test_paginate_files_with_offset(self):
11331138 exclusive_end_offset = self .FILENAMES [- 1 ]
11341139 desired_files = self .FILENAMES [1 :- 1 ]
11351140 count = len (desired_files ) - truncation_size
1136- iterator = self .bucket .list_blobs (
1141+ iterator = Config .CLIENT .list_blobs (
1142+ self .bucket ,
11371143 max_results = count ,
11381144 start_offset = inclusive_start_offset ,
11391145 end_offset = exclusive_end_offset ,
@@ -1173,7 +1179,7 @@ class TestStoragePseudoHierarchy(TestStorageFiles):
11731179 def setUpClass (cls ):
11741180 super (TestStoragePseudoHierarchy , cls ).setUpClass ()
11751181 # Make sure bucket empty before beginning.
1176- _empty_bucket (cls .bucket )
1182+ _empty_bucket (Config . CLIENT , cls .bucket )
11771183
11781184 cls .suite_blobs_to_delete = []
11791185 simple_path = cls .FILES ["simple" ]["path" ]
@@ -1197,7 +1203,7 @@ def test_blob_get_w_delimiter(self):
11971203
11981204 @RetryErrors (unittest .TestCase .failureException )
11991205 def test_root_level_w_delimiter (self ):
1200- iterator = self . bucket .list_blobs (delimiter = "/" )
1206+ iterator = Config . CLIENT .list_blobs (self . bucket , delimiter = "/" )
12011207 page = six .next (iterator .pages )
12021208 blobs = list (page )
12031209 self .assertEqual ([blob .name for blob in blobs ], ["file01.txt" ])
@@ -1206,7 +1212,9 @@ def test_root_level_w_delimiter(self):
12061212
12071213 @RetryErrors (unittest .TestCase .failureException )
12081214 def test_first_level (self ):
1209- iterator = self .bucket .list_blobs (delimiter = "/" , prefix = "parent/" )
1215+ iterator = Config .CLIENT .list_blobs (
1216+ self .bucket , delimiter = "/" , prefix = "parent/"
1217+ )
12101218 page = six .next (iterator .pages )
12111219 blobs = list (page )
12121220 self .assertEqual (
@@ -1219,7 +1227,9 @@ def test_first_level(self):
12191227 def test_second_level (self ):
12201228 expected_names = ["parent/child/file21.txt" , "parent/child/file22.txt" ]
12211229
1222- iterator = self .bucket .list_blobs (delimiter = "/" , prefix = "parent/child/" )
1230+ iterator = Config .CLIENT .list_blobs (
1231+ self .bucket , delimiter = "/" , prefix = "parent/child/"
1232+ )
12231233 page = six .next (iterator .pages )
12241234 blobs = list (page )
12251235 self .assertEqual ([blob .name for blob in blobs ], expected_names )
@@ -1234,7 +1244,9 @@ def test_third_level(self):
12341244 # of 1024 characters in the UTF-8 encoded name:
12351245 # https://cloud.google.com/storage/docs/bucketnaming#objectnames
12361246 # Exercise a layer deeper to illustrate this.
1237- iterator = self .bucket .list_blobs (delimiter = "/" , prefix = "parent/child/grand/" )
1247+ iterator = Config .CLIENT .list_blobs (
1248+ self .bucket , delimiter = "/" , prefix = "parent/child/grand/"
1249+ )
12381250 page = six .next (iterator .pages )
12391251 blobs = list (page )
12401252 self .assertEqual (
@@ -1245,8 +1257,8 @@ def test_third_level(self):
12451257
12461258 @RetryErrors (unittest .TestCase .failureException )
12471259 def test_include_trailing_delimiter (self ):
1248- iterator = self . bucket .list_blobs (
1249- delimiter = "/" , include_trailing_delimiter = True
1260+ iterator = Config . CLIENT .list_blobs (
1261+ self . bucket , delimiter = "/" , include_trailing_delimiter = True
12501262 )
12511263 page = six .next (iterator .pages )
12521264 blobs = list (page )
@@ -1273,7 +1285,7 @@ def setUpClass(cls):
12731285
12741286 @classmethod
12751287 def tearDownClass (cls ):
1276- _empty_bucket (cls .bucket )
1288+ _empty_bucket (Config . CLIENT , cls .bucket )
12771289 errors = (exceptions .Conflict , exceptions .TooManyRequests )
12781290 retry = RetryErrors (errors , max_tries = 6 )
12791291 retry (cls .bucket .delete )(force = True )
@@ -1961,7 +1973,7 @@ class TestAnonymousClient(unittest.TestCase):
19611973 def test_access_to_public_bucket (self ):
19621974 anonymous = storage .Client .create_anonymous_client ()
19631975 bucket = anonymous .bucket (self .PUBLIC_BUCKET )
1964- (blob ,) = retry_429_503 (bucket .list_blobs )(max_results = 1 )
1976+ (blob ,) = retry_429_503 (anonymous .list_blobs )(bucket , max_results = 1 )
19651977 with tempfile .TemporaryFile () as stream :
19661978 retry_429_503 (blob .download_to_file )(stream )
19671979
@@ -1988,7 +2000,7 @@ def _kms_key_name(self, key_name=None):
19882000 @classmethod
19892001 def setUpClass (cls ):
19902002 super (TestKMSIntegration , cls ).setUpClass ()
1991- _empty_bucket (cls .bucket )
2003+ _empty_bucket (Config . CLIENT , cls .bucket )
19922004
19932005 def setUp (self ):
19942006 super (TestKMSIntegration , self ).setUp ()
@@ -2048,7 +2060,7 @@ def test_blob_w_explicit_kms_key_name(self):
20482060 # We don't know the current version of the key.
20492061 self .assertTrue (blob .kms_key_name .startswith (kms_key_name ))
20502062
2051- (listed ,) = list (self . bucket .list_blobs ())
2063+ (listed ,) = list (Config . CLIENT .list_blobs (self . bucket ))
20522064 self .assertTrue (listed .kms_key_name .startswith (kms_key_name ))
20532065
20542066 @RetryErrors (unittest .TestCase .failureException )
0 commit comments