From 21d7adeebc6ce348594f8020be5d7b0b7317a453 Mon Sep 17 00:00:00 2001 From: xiafu Date: Mon, 4 Jan 2021 17:42:11 -0800 Subject: [PATCH] [Blob]fix parse url for blob emulator --- .../azure-storage-blob/azure/storage/blob/_blob_client.py | 2 +- sdk/storage/azure-storage-blob/tests/test_blob_client.py | 1 + sdk/storage/azure-storage-blob/tests/test_blob_client_async.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py index ffe7d5dd1d95..0c32d37a52ed 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py @@ -227,7 +227,7 @@ def from_blob_url(cls, blob_url, credential=None, snapshot=None, **kwargs): path_blob = parsed_url.path.lstrip('/').split('/', 1) elif "localhost" in parsed_url.netloc or "127.0.0.1" in parsed_url.netloc: path_blob = parsed_url.path.lstrip('/').split('/', 2) - account_path += path_blob[0] + account_path += '/' + path_blob[0] else: # for customized url. blob name that has directory info cannot be parsed. path_blob = parsed_url.path.lstrip('/').split('/') diff --git a/sdk/storage/azure-storage-blob/tests/test_blob_client.py b/sdk/storage/azure-storage-blob/tests/test_blob_client.py index c82ba195c256..b585b41c1e3a 100644 --- a/sdk/storage/azure-storage-blob/tests/test_blob_client.py +++ b/sdk/storage/azure-storage-blob/tests/test_blob_client.py @@ -449,6 +449,7 @@ def test_create_blob_client_with_sub_directory_path_in_blob_name(self): blob_client = BlobClient.from_blob_url(blob_emulator_url) self.assertEqual(blob_client.container_name, "containername") self.assertEqual(blob_client.blob_name, "dir1/sub000/2010_Unit150_Ivan097_img0003.jpg") + self.assertEqual(blob_client.url, blob_emulator_url) def test_create_client_for_emulator(self): container_client = ContainerClient( diff --git a/sdk/storage/azure-storage-blob/tests/test_blob_client_async.py b/sdk/storage/azure-storage-blob/tests/test_blob_client_async.py index 0de666766538..df3afff39f1b 100644 --- a/sdk/storage/azure-storage-blob/tests/test_blob_client_async.py +++ b/sdk/storage/azure-storage-blob/tests/test_blob_client_async.py @@ -459,6 +459,7 @@ def test_create_blob_client_with_sub_directory_path_in_blob_name(self): blob_client = BlobClient.from_blob_url(blob_emulator_url) self.assertEqual(blob_client.container_name, "containername") self.assertEqual(blob_client.blob_name, "dir1/sub000/2010_Unit150_Ivan097_img0003.jpg") + self.assertEqual(blob_client.url, blob_emulator_url) @GlobalStorageAccountPreparer() @AsyncStorageTestCase.await_prepared_test