Skip to content

Commit

Permalink
[Storage][Blob][Batch]Support batch delete empty blob list (#13029)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiafu-msft authored Aug 12, 2020
1 parent a1039c8 commit 0996619
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,9 @@ def delete_blobs(self, *blobs, **kwargs):
:dedent: 8
:caption: Deleting multiple blobs.
"""
if len(blobs) == 0:
return iter(list())

reqs, options = self._generate_delete_blobs_options(*blobs, **kwargs)

return self._batch_send(*reqs, **options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,9 @@ async def delete_blobs( # pylint: disable=arguments-differ
:dedent: 12
:caption: Deleting multiple blobs.
"""
if len(blobs) == 0:
return iter(list())

reqs, options = self._generate_delete_blobs_options(*blobs, **kwargs)

return await self._batch_send(*reqs, **options)
Expand Down
7 changes: 6 additions & 1 deletion sdk/storage/azure-storage-blob/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
PremiumPageBlobTier,
generate_container_sas,
PartialBatchErrorException,
generate_account_sas, ResourceTypes, AccountSasPermissions)
generate_account_sas, ResourceTypes, AccountSasPermissions, ContainerClient)

#------------------------------------------------------------------------------
TEST_CONTAINER_PREFIX = 'container'
Expand Down Expand Up @@ -1073,6 +1073,11 @@ def test_list_blobs_with_delimiter(self, resource_group, location, storage_accou
self.assertNamedItemInContainer(resp, 'b/')
self.assertNamedItemInContainer(resp, 'blob4')

def test_batch_delete_empty_blob_list(self):
container_client = ContainerClient("https://mystorageaccount.blob.core.windows.net", "container")
blob_list = list()
container_client.delete_blobs(*blob_list)

@pytest.mark.skipif(sys.version_info < (3, 0), reason="Batch not supported on Python 2.7")
@GlobalStorageAccountPreparer()
def test_delete_blobs_simple(self, resource_group, location, storage_account, storage_account_key):
Expand Down
5 changes: 5 additions & 0 deletions sdk/storage/azure-storage-blob/tests/test_container_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,11 @@ async def test_list_blobs_with_delimiter(self, resource_group, location, storage
self.assertNamedItemInContainer(resp, 'b/')
self.assertNamedItemInContainer(resp, 'blob4')

def test_batch_delete_empty_blob_list(self):
container_client = ContainerClient("https://mystorageaccount.blob.core.windows.net", "container")
blob_list = list()
container_client.delete_blobs(*blob_list)

@GlobalStorageAccountPreparer()
@AsyncStorageTestCase.await_prepared_test
async def test_delete_blobs_simple(self, resource_group, location, storage_account, storage_account_key):
Expand Down

0 comments on commit 0996619

Please sign in to comment.