@@ -331,16 +331,18 @@ def test_delete_default_miss(self):
331331 connection = _Connection ()
332332 bucket = self ._makeOne (connection , NAME )
333333 self .assertRaises (NotFound , bucket .delete )
334- self .assertEqual (connection ._deleted , [NAME ])
334+ expected_cw = [{'method' : 'DELETE' , 'path' : bucket .path }]
335+ self .assertEqual (connection ._deleted_buckets , expected_cw )
335336
336337 def test_delete_explicit_hit (self ):
337338 NAME = 'name'
338339 GET_BLOBS_RESP = {'items' : []}
339340 connection = _Connection (GET_BLOBS_RESP )
340- connection ._delete_ok = True
341+ connection ._delete_bucket = True
341342 bucket = self ._makeOne (connection , NAME )
342343 self .assertEqual (bucket .delete (force = True ), None )
343- self .assertEqual (connection ._deleted , [NAME ])
344+ expected_cw = [{'method' : 'DELETE' , 'path' : bucket .path }]
345+ self .assertEqual (connection ._deleted_buckets , expected_cw )
344346
345347 def test_delete_explicit_force_delete_blobs (self ):
346348 NAME = 'name'
@@ -355,21 +357,23 @@ def test_delete_explicit_force_delete_blobs(self):
355357 DELETE_BLOB1_RESP = DELETE_BLOB2_RESP = {}
356358 connection = _Connection (GET_BLOBS_RESP , DELETE_BLOB1_RESP ,
357359 DELETE_BLOB2_RESP )
358- connection ._delete_ok = True
360+ connection ._delete_bucket = True
359361 bucket = self ._makeOne (connection , NAME )
360362 self .assertEqual (bucket .delete (force = True ), None )
361- self .assertEqual (connection ._deleted , [NAME ])
363+ expected_cw = [{'method' : 'DELETE' , 'path' : bucket .path }]
364+ self .assertEqual (connection ._deleted_buckets , expected_cw )
362365
363366 def test_delete_explicit_force_miss_blobs (self ):
364367 NAME = 'name'
365368 BLOB_NAME = 'blob-name1'
366369 GET_BLOBS_RESP = {'items' : [{'name' : BLOB_NAME }]}
367370 # Note the connection does not have a response for the blob.
368371 connection = _Connection (GET_BLOBS_RESP )
369- connection ._delete_ok = True
372+ connection ._delete_bucket = True
370373 bucket = self ._makeOne (connection , NAME )
371374 self .assertEqual (bucket .delete (force = True ), None )
372- self .assertEqual (connection ._deleted , [NAME ])
375+ expected_cw = [{'method' : 'DELETE' , 'path' : bucket .path }]
376+ self .assertEqual (connection ._deleted_buckets , expected_cw )
373377
374378 def test_delete_explicit_too_many (self ):
375379 NAME = 'name'
@@ -382,12 +386,13 @@ def test_delete_explicit_too_many(self):
382386 ],
383387 }
384388 connection = _Connection (GET_BLOBS_RESP )
385- connection ._delete_ok = True
389+ connection ._delete_bucket = True
386390 bucket = self ._makeOne (connection , NAME )
387391
388392 # Make the Bucket refuse to delete with 2 objects.
389393 bucket ._MAX_OBJECTS_FOR_BUCKET_DELETE = 1
390394 self .assertRaises (ValueError , bucket .delete , force = True )
395+ self .assertEqual (connection ._deleted_buckets , [])
391396
392397 def test_delete_blob_miss (self ):
393398 from gcloud .exceptions import NotFound
@@ -1079,31 +1084,40 @@ def get_items_from_response(self, response):
10791084
10801085
10811086class _Connection (object ):
1082- _delete_ok = False
1087+ _delete_bucket = False
10831088
10841089 def __init__ (self , * responses ):
10851090 self ._responses = responses
10861091 self ._requested = []
1087- self ._deleted = []
1092+ self ._deleted_buckets = []
1093+
1094+ @staticmethod
1095+ def _is_bucket_path (path ):
1096+ if not path .startswith ('/b/' ): # pragma: NO COVER
1097+ return False
1098+ # Now just ensure the path only has /b/ and one more segment.
1099+ return path .count ('/' ) == 2
10881100
10891101 def api_request (self , ** kw ):
10901102 from gcloud .exceptions import NotFound
10911103 self ._requested .append (kw )
10921104
1105+ method = kw .get ('method' )
1106+ path = kw .get ('path' , '' )
1107+ if method == 'DELETE' and self ._is_bucket_path (path ):
1108+ self ._deleted_buckets .append (kw )
1109+ if self ._delete_bucket :
1110+ return
1111+ else :
1112+ raise NotFound ('miss' )
1113+
10931114 try :
10941115 response , self ._responses = self ._responses [0 ], self ._responses [1 :]
10951116 except :
10961117 raise NotFound ('miss' )
10971118 else :
10981119 return response
10991120
1100- def delete_bucket (self , bucket ):
1101- from gcloud .exceptions import NotFound
1102- self ._deleted .append (bucket )
1103- if not self ._delete_ok :
1104- raise NotFound ('miss' )
1105- return True
1106-
11071121
11081122class _Bucket (object ):
11091123 path = '/b/name'
0 commit comments