@GlobalStorageAccountPreparer()
@AsyncStorageTestCase.await_prepared_test
async def test_soft_delete_with_leased_blob(self, resource_group, location, storage_account, storage_account_key):
    try:
        (await self._setup(storage_account.name, storage_account_key))
        (await self._enable_soft_delete())
        blob_name = (await self._create_block_blob())
        blob = self.bsc.get_blob_client(self.container_name, blob_name)
        lease = (await blob.acquire_lease())
        with self.assertRaises(HttpResponseError):
            (await blob.delete_blob())
        (await blob.delete_blob(lease=lease))
        container = self.bsc.get_container_client(self.container_name)
        blob_list = []
        async for b in container.list_blobs(include='deleted'):
            blob_list.append(b)
        self.assertEqual(len(blob_list), 1)
        self._assert_blob_is_soft_deleted(blob_list[0])
        blob_list = []
        async for b in container.list_blobs():
            blob_list.append(b)
        self.assertEqual(len(blob_list), 0)
        (await blob.undelete_blob())
        blob_list = []
        async for b in container.list_blobs(include='deleted'):
            blob_list.append(b)
        self.assertEqual(len(blob_list), 1)
        self._assert_blob_not_soft_deleted(blob_list[0])
    finally:
        (await self._disable_soft_delete())
@GlobalStorageAccountPreparer()
@AsyncStorageTestCase.await_prepared_test
async def test_soft_delete_with_leased_blob(self, resource_group, location, storage_account, storage_account_key):
    try:
        (await self._setup(storage_account.name, storage_account_key))
        (await self._enable_soft_delete())
        blob_name = (await self._create_block_blob())
        blob = self.bsc.get_blob_client(self.container_name, blob_name)
        lease = (await blob.acquire_lease())
        with self.assertRaises(HttpResponseError):
            (await blob.delete_blob())
        (await blob.delete_blob(lease=lease))
        container = self.bsc.get_container_client(self.container_name)
        blob_list = []
        async for b in container.list_blobs(include='deleted'):
            blob_list.append(b)
        self.assertEqual(len(blob_list), 1)
        self._assert_blob_is_soft_deleted(blob_list[0])
        blob_list = []
        async for b in container.list_blobs():
            blob_list.append(b)
        self.assertEqual(len(blob_list), 0)
        (await blob.undelete_blob())
        blob_list = []
        async for b in container.list_blobs(include='deleted'):
            blob_list.append(b)
        self.assertEqual(len(blob_list), 1)
        self._assert_blob_not_soft_deleted(blob_list[0])
    finally:
        (await self._disable_soft_delete())