From 117fbacf9474eace7e5fa5daf64022c317f84b58 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 29 Apr 2026 01:55:18 -0400 Subject: [PATCH 1/8] samples/ --- .../samples/file_samples_authentication.py | 1 - .../azure-storage-file-share/samples/file_samples_client.py | 2 -- .../azure-storage-file-share/samples/file_samples_service.py | 1 - 3 files changed, 4 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_authentication.py b/sdk/storage/azure-storage-file-share/samples/file_samples_authentication.py index a4eeb424e463..b7207e0608da 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_authentication.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_authentication.py @@ -147,4 +147,3 @@ def authentication_default_azure_credential(self): sample.authentication_shared_access_key() sample.authentication_shared_access_signature() sample.authentication_default_azure_credential() - diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_client.py b/sdk/storage/azure-storage-file-share/samples/file_samples_client.py index 98cc9db0a6f3..0e0f967c8db3 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_client.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_client.py @@ -152,5 +152,3 @@ def acquire_file_lease(self): sample.simple_file_operations() sample.copy_file_from_url() sample.acquire_file_lease() - - diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_service.py b/sdk/storage/azure-storage-file-share/samples/file_samples_service.py index 2fbc65c80774..0bb0e5c95961 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_service.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_service.py @@ -124,4 +124,3 @@ def get_share_client(self): sample.file_service_properties() sample.list_shares_in_service() sample.get_share_client() - From 35c5bacdd0602bad7707fd1c80e740b362785e8f Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 29 Apr 2026 18:15:57 -0400 Subject: [PATCH 2/8] halfway done --- .../tests/encryption_test_helper.py | 4 + .../T1_legacy_tests/_test_base.py | 41 +++- .../T1_legacy_tests/upload.py | 2 +- .../tests/perfstress_tests/_test_base.py | 45 +++- .../tests/perfstress_tests/upload.py | 6 +- .../tests/settings/testcase.py | 34 ++- .../tests/test_directory_async.py | 26 ++- .../tests/test_file.py | 133 ++++++------ .../tests/test_file_api_version.py | 8 +- .../tests/test_file_async.py | 199 +++++++++++------- .../tests/test_file_client.py | 130 ++++++++---- .../tests/test_handle.py | 9 +- .../tests/test_helpers.py | 7 +- .../tests/test_nfs.py | 24 +-- .../tests/test_share.py | 55 +++-- .../tests/test_share_async.py | 46 ++-- 16 files changed, 472 insertions(+), 297 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/tests/encryption_test_helper.py b/sdk/storage/azure-storage-file-share/tests/encryption_test_helper.py index a452a1071c87..3c25756940cb 100644 --- a/sdk/storage/azure-storage-file-share/tests/encryption_test_helper.py +++ b/sdk/storage/azure-storage-file-share/tests/encryption_test_helper.py @@ -3,6 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- + from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric.padding import ( OAEP, @@ -16,6 +17,9 @@ ) +_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM = "Unknown keywrap algorithm specified. Supported algorithm: A256KW." + + class KeyWrapper: def __init__(self, kid='local:key1'): # Must have constant key value for recorded tests, otherwise we could use a random generator. diff --git a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/_test_base.py b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/_test_base.py index 8b37a0d5f83b..0b248d5801ef 100644 --- a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/_test_base.py +++ b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/_test_base.py @@ -3,19 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import uuid from devtools_testutils.perfstress_tests import PerfStressTest -from azure.storage.file import FileService +from azure.storage.file import FileService # pylint: disable=no-name-in-module class _LegacyServiceTest(PerfStressTest): service_client = None async_service_client = None def __init__(self, arguments): - super().__init__(arguments) + super().__init__(arguments) # pylint: disable=useless-parent-delegation connection_string = self.get_from_env("AZURE_STORAGE_CONNECTION_STRING") if not _LegacyServiceTest.service_client or self.args.no_client_share: _LegacyServiceTest.service_client = FileService(connection_string=connection_string) @@ -27,16 +26,42 @@ def __init__(self, arguments): @staticmethod def add_arguments(parser): super(_LegacyServiceTest, _LegacyServiceTest).add_arguments(parser) - parser.add_argument('-r', '--max-range-size', nargs='?', type=int, help='Maximum size of data uploading in single HTTP PUT. Defaults to 4*1024*1024', default=4*1024*1024) - parser.add_argument('-c', '--max-concurrency', nargs='?', type=int, help='Maximum number of concurrent threads used for data transfer. Defaults to 1', default=1) - parser.add_argument('-s', '--size', nargs='?', type=int, help='Size of data to transfer. Default is 10240.', default=10240) - parser.add_argument('--no-client-share', action='store_true', help='Create one ServiceClient per test instance. Default is to share a single ServiceClient.', default=False) + parser.add_argument( + '-r', + '--max-range-size', + nargs='?', + type=int, + help='Maximum size of data uploading in single HTTP PUT. Defaults to 4*1024*1024', + default=4*1024*1024 + ) + parser.add_argument( + '-c', + '--max-concurrency', + nargs='?', + type=int, + help='Maximum number of concurrent threads used for data transfer. Defaults to 1', + default=1 + ) + parser.add_argument( + '-s', + '--size', + nargs='?', + type=int, + help='Size of data to transfer. Default is 10240.', + default=10240 + ) + parser.add_argument( + '--no-client-share', + action='store_true', + help='Create one ServiceClient per test instance. Default is to share a single ServiceClient.', + default=False + ) class _LegacyShareTest(_LegacyServiceTest): share_name = "perfstress-legacy-" + str(uuid.uuid4()) - def __init__(self, arguments): + def __init__(self, arguments): # pylint: disable=useless-parent-delegation super().__init__(arguments) async def global_setup(self): diff --git a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/upload.py b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/upload.py index 24ed6988f36e..077f2fb7abf0 100644 --- a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/upload.py +++ b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/upload.py @@ -5,7 +5,7 @@ import uuid -from devtools_testutils.perfstress_tests import RandomStream, get_random_bytes +from devtools_testutils.perfstress_tests import RandomStream from ._test_base import _LegacyShareTest diff --git a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/_test_base.py b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/_test_base.py index 8b612b0ef096..a19693235876 100644 --- a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/_test_base.py +++ b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/_test_base.py @@ -3,7 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import uuid from devtools_testutils.perfstress_tests import PerfStressTest @@ -23,8 +22,14 @@ def __init__(self, arguments): if self.args.max_range_size is not None: kwargs['max_range_size'] = self.args.max_range_size if not _ServiceTest.service_client or self.args.no_client_share: - _ServiceTest.service_client = SyncShareServiceClient.from_connection_string(conn_str=connection_string, **kwargs) - _ServiceTest.async_service_client = AsyncShareServiceClient.from_connection_string(conn_str=connection_string, **kwargs) + _ServiceTest.service_client = SyncShareServiceClient.from_connection_string( + conn_str=connection_string, + **kwargs + ) + _ServiceTest.async_service_client = AsyncShareServiceClient.from_connection_string( + conn_str=connection_string, + **kwargs + ) self.service_client = _ServiceTest.service_client self.async_service_client =_ServiceTest.async_service_client @@ -35,10 +40,36 @@ async def close(self): @staticmethod def add_arguments(parser): super(_ServiceTest, _ServiceTest).add_arguments(parser) - parser.add_argument('-r', '--max-range-size', nargs='?', type=int, help='Maximum size of data uploading in single HTTP PUT. Defaults to SDK default.', default=None) - parser.add_argument('-c', '--max-concurrency', nargs='?', type=int, help='Maximum number of concurrent threads used for data transfer. Defaults to 1', default=1) - parser.add_argument('-s', '--size', nargs='?', type=int, help='Size of data to transfer. Default is 10240.', default=10240) - parser.add_argument('--no-client-share', action='store_true', help='Create one ServiceClient per test instance. Default is to share a single ServiceClient.', default=False) + parser.add_argument( + '-r', + '--max-range-size', + nargs='?', + type=int, + help='Maximum size of data uploading in single HTTP PUT. Defaults to SDK default.', + default=None + ) + parser.add_argument( + '-c', + '--max-concurrency', + nargs='?', + type=int, + help='Maximum number of concurrent threads used for data transfer. Defaults to 1', + default=1 + ) + parser.add_argument( + '-s', + '--size', + nargs='?', + type=int, + help='Size of data to transfer. Default is 10240.', + default=10240 + ) + parser.add_argument( + '--no-client-share', + action='store_true', + help='Create one ServiceClient per test instance. Default is to share a single ServiceClient.', + default=False + ) class _ShareTest(_ServiceTest): diff --git a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/upload.py b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/upload.py index 116cb4498d73..7380b321a064 100644 --- a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/upload.py +++ b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/upload.py @@ -3,11 +3,11 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from ._test_base import _FileTest - -from devtools_testutils.perfstress_tests import RandomStream, get_random_bytes +from devtools_testutils.perfstress_tests import RandomStream from devtools_testutils.perfstress_tests import AsyncRandomStream +from ._test_base import _FileTest + class UploadTest(_FileTest): def __init__(self, arguments): diff --git a/sdk/storage/azure-storage-file-share/tests/settings/testcase.py b/sdk/storage/azure-storage-file-share/tests/settings/testcase.py index 7e5a94151067..c0465c4a67ed 100644 --- a/sdk/storage/azure-storage-file-share/tests/settings/testcase.py +++ b/sdk/storage/azure-storage-file-share/tests/settings/testcase.py @@ -4,23 +4,15 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +# pylint: disable=unused-wildcard-import, wildcard-import + from __future__ import division import functools import os.path -try: - import unittest.mock as mock -except ImportError: - import mock - -import logging from devtools_testutils import EnvironmentVariableLoader, EnvironmentVariableOptions from devtools_testutils.fake_credentials import STORAGE_ACCOUNT_FAKE_KEY -try: - from cStringIO import StringIO # Python 2 -except ImportError: - from io import StringIO try: # Running locally - use configuration in settings_real.py @@ -29,20 +21,18 @@ # Running on the pipeline - use fake values in order to create rg, etc. from .settings_fake import * -try: - from devtools_testutils import mgmt_settings_real as settings -except ImportError: - from devtools_testutils import mgmt_settings_fake as settings - - LOGGING_FORMAT = '%(asctime)s %(name)-20s %(levelname)-5s %(message)s' os.environ['STORAGE_ACCOUNT_NAME'] = os.environ.get('STORAGE_ACCOUNT_NAME', None) or STORAGE_ACCOUNT_NAME os.environ['STORAGE_ACCOUNT_KEY'] = os.environ.get('STORAGE_ACCOUNT_KEY', None) or STORAGE_ACCOUNT_KEY -os.environ['PREMIUM_STORAGE_FILE_ACCOUNT_NAME'] = os.environ.get('PREMIUM_STORAGE_FILE_ACCOUNT_NAME', None) or PREMIUM_STORAGE_FILE_ACCOUNT_NAME -os.environ['PREMIUM_STORAGE_FILE_ACCOUNT_KEY'] = os.environ.get('PREMIUM_STORAGE_FILE_ACCOUNT_KEY', None) or PREMIUM_STORAGE_FILE_ACCOUNT_KEY -os.environ['SECONDARY_STORAGE_ACCOUNT_NAME'] = os.environ.get('SECONDARY_STORAGE_ACCOUNT_NAME', None) or SECONDARY_STORAGE_ACCOUNT_NAME -os.environ['SECONDARY_STORAGE_ACCOUNT_KEY'] = os.environ.get('SECONDARY_STORAGE_ACCOUNT_KEY', None) or SECONDARY_STORAGE_ACCOUNT_KEY +os.environ['PREMIUM_STORAGE_FILE_ACCOUNT_NAME'] = os.environ.get( + 'PREMIUM_STORAGE_FILE_ACCOUNT_NAME', None) or PREMIUM_STORAGE_FILE_ACCOUNT_NAME +os.environ['PREMIUM_STORAGE_FILE_ACCOUNT_KEY'] = os.environ.get( + 'PREMIUM_STORAGE_FILE_ACCOUNT_KEY', None) or PREMIUM_STORAGE_FILE_ACCOUNT_KEY +os.environ['SECONDARY_STORAGE_ACCOUNT_NAME'] = os.environ.get( + 'SECONDARY_STORAGE_ACCOUNT_NAME', None) or SECONDARY_STORAGE_ACCOUNT_NAME +os.environ['SECONDARY_STORAGE_ACCOUNT_KEY'] = os.environ.get( + 'SECONDARY_STORAGE_ACCOUNT_KEY', None) or SECONDARY_STORAGE_ACCOUNT_KEY os.environ['AZURE_TEST_RUN_LIVE'] = os.environ.get('AZURE_TEST_RUN_LIVE', None) or RUN_IN_LIVE os.environ['AZURE_SKIP_LIVE_RECORDING'] = os.environ.get('AZURE_SKIP_LIVE_RECORDING', None) or SKIP_LIVE_RECORDING @@ -58,7 +48,9 @@ premium_storage_file_account_key=STORAGE_ACCOUNT_FAKE_KEY, secondary_storage_account_name="pyrmtstoragestorname", secondary_storage_account_key=STORAGE_ACCOUNT_FAKE_KEY, - options=EnvironmentVariableOptions(hide_secrets=["storage_account_key", "secondary_storage_account_key", "premium_storage_file_account_key"]), + options=EnvironmentVariableOptions( + hide_secrets=["storage_account_key", "secondary_storage_account_key", "premium_storage_file_account_key"] + ), ) diff --git a/sdk/storage/azure-storage-file-share/tests/test_directory_async.py b/sdk/storage/azure-storage-file-share/tests/test_directory_async.py index 23a0f3845df2..fde85260ceae 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_directory_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_directory_async.py @@ -7,22 +7,23 @@ # -------------------------------------------------------------------------- import asyncio import os -import unittest from datetime import datetime, timedelta, timezone import pytest -from azure.core.exceptions import ClientAuthenticationError, ResourceExistsError, ResourceNotFoundError + +from devtools_testutils.aio import recorded_by_proxy_async +from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase +from settings.testcase import FileSharePreparer + +from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError from azure.storage.fileshare import ( generate_share_sas, NTFSAttributes, ShareSasPermissions, - StorageErrorCode + StorageErrorCode, ) from azure.storage.fileshare.aio import ShareDirectoryClient, ShareServiceClient -from devtools_testutils.aio import recorded_by_proxy_async -from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase -from settings.testcase import FileSharePreparer # ------------------------------------------------------------------------------ TEST_FILE_PERMISSIONS = 'O:S-1-5-21-2127521184-1604012920-1887927527-21560751G:S-1-5-21-2127521184-' \ @@ -116,7 +117,8 @@ async def test_create_directory_set_smb_properties(self, **kwargs): directory_client = share_client.get_directory_client('dir1') file_attributes = NTFSAttributes(read_only=True, directory=True) - file_creation_time = file_last_write_time = file_change_time = datetime(2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc) + file_creation_time = file_last_write_time = file_change_time = ( + datetime(2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc)) # Act await directory_client.create_directory( @@ -938,7 +940,9 @@ async def test_list_subdirectories_and_files_include_other_data_async(self, **kw # Act list_dir = [] - async for d in directory.list_directories_and_files(include=["timestamps", "Etag", "Attributes", "PermissionKey"]): + async for d in directory.list_directories_and_files( + include=["timestamps", "Etag", "Attributes", "PermissionKey"] + ): list_dir.append(d) assert len(list_dir) == 6 @@ -1024,7 +1028,7 @@ async def test_list_subdirectories_and_files_with_snapshot(self, **kwargs): directory.create_subdirectory("subdir1"), directory.create_subdirectory("subdir2"), directory.upload_file("file1", "data1")) - + snapshot = await share_client.create_snapshot() await asyncio.gather( directory.create_subdirectory("subdir3"), @@ -1379,7 +1383,7 @@ async def test_rename_directory_smb_properties(self, **kwargs): props = await new_directory.get_directory_properties() assert props is not None assert props.is_directory - assert str(file_attributes), props.file_attributes.replace(' ' == '') + assert str(file_attributes), props.file_attributes.replace(' ', '') assert file_creation_time == props.creation_time assert file_last_write_time == props.last_write_time assert file_change_time == props.change_time @@ -1518,7 +1522,7 @@ async def test_bad_audience_directory_client(self, **kwargs): share_client.share_name, 'dir1.', credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://badaudience.file.core.windows.net' + audience='https://badaudience.file.core.windows.net' ) # Assert diff --git a/sdk/storage/azure-storage-file-share/tests/test_file.py b/sdk/storage/azure-storage-file-share/tests/test_file.py index 0c03d1fccc29..02c3eb27d437 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file.py @@ -9,9 +9,15 @@ import pytest import requests + +from devtools_testutils import recorded_by_proxy +from devtools_testutils.storage import StorageRecordedTestCase +from settings.testcase import FileSharePreparer +from test_helpers import MockStorageTransport, ProgressTracker + from azure.core import MatchConditions from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError +from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError from azure.storage.blob import BlobServiceClient from azure.storage.fileshare import ( AccessPolicy, @@ -26,13 +32,9 @@ ShareFileClient, ShareSasPermissions, ShareServiceClient, - StorageErrorCode + StorageErrorCode, ) -from devtools_testutils import recorded_by_proxy -from devtools_testutils.storage import StorageRecordedTestCase -from settings.testcase import FileSharePreparer -from test_helpers import MockStorageTransport, ProgressTracker # ------------------------------------------------------------------------------ TEST_SHARE_PREFIX = 'share' @@ -215,7 +217,8 @@ def test_make_file_url_with_sas(self, **kwargs): self._setup(storage_account_name, storage_account_key) # cspell:disable-next-line - sas = '?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D' + sas = ('?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&' + 'sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D') file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name="vhds", @@ -472,45 +475,6 @@ def test_create_file_with_invalid_file_permission(self, **kwargs): with pytest.raises(HttpResponseError): file_name.create_file(1024, file_permission="abcde") - @FileSharePreparer() - @recorded_by_proxy - def test_create_file_semantics(self, **kwargs): - storage_account_name = kwargs.pop("storage_account_name") - storage_account_key = kwargs.pop("storage_account_key") - - self._setup(storage_account_name, storage_account_key) - file_name = self._get_file_reference() - - file1 = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name + "file1", - credential=storage_account_key.secret - ) - file1.create_file(1024, file_property_semantics=None) - props = file1.get_file_properties() - assert props is not None - - file2 = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name + "file2", - credential=storage_account_key.secret - ) - file2.create_file(1024, file_property_semantics="New") - props = file2.get_file_properties() - assert props is not None - - file3 = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name + "file2", - credential=storage_account_key.secret - ) - file3.create_file(1024, file_property_semantics="Restore", file_permission=TEST_FILE_PERMISSIONS) - props = file3.get_file_properties() - assert props is not None - @FileSharePreparer() @recorded_by_proxy def test_create_file_with_lease(self, **kwargs): @@ -681,7 +645,8 @@ def test_create_file_set_smb_properties(self, **kwargs): file_client = self._get_file_client() file_attributes = NTFSAttributes(read_only=True, archive=True) - file_creation_time = file_last_write_time = file_change_time = datetime(2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc) + file_creation_time = file_last_write_time = file_change_time = datetime( + 2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc) # Act file_client.create_file( @@ -1595,7 +1560,8 @@ def test_update_range_from_file_url_with_oauth(self, **kwargs): self._setup(storage_account_name, storage_account_key) source_blob_client = self._create_source_blob() - token = "Bearer {}".format(self.get_credential(ShareServiceClient).get_token("https://storage.azure.com/.default").token) + token = "Bearer {}".format(self.get_credential(ShareServiceClient).get_token( + "https://storage.azure.com/.default").token) destination_file_name = 'filetoupdate' destination_file_client = self._create_empty_file(file_name=destination_file_name) @@ -1814,7 +1780,7 @@ def test_update_file_unicode(self, **kwargs): file_client = self._create_file() # Act - data = u'abcdefghijklmnop' * 32 + data = 'abcdefghijklmnop' * 32 file_client.upload_range(data, offset=0, length=512) encoded = data.encode('utf-8') @@ -2463,7 +2429,12 @@ def test_copy_file_async_private_file(self, **kwargs): secondary_storage_account_name = kwargs.pop("secondary_storage_account_name") secondary_storage_account_key = kwargs.pop("secondary_storage_account_key") - self._setup(storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key.secret) + self._setup( + storage_account_name, + storage_account_key, + secondary_storage_account_name, + secondary_storage_account_key.secret + ) self._create_remote_share() source_file = self._create_remote_file() @@ -2487,7 +2458,12 @@ def test_copy_file_async_private_file_with_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") secondary_storage_account_name = kwargs.pop("secondary_storage_account_name") secondary_storage_account_key = kwargs.pop("secondary_storage_account_key") - self._setup(storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key.secret) + self._setup( + storage_account_name, + storage_account_key, + secondary_storage_account_name, + secondary_storage_account_key.secret + ) data = b'12345678' * 1024 self._create_remote_share() source_file = self._create_remote_file(file_data=data) @@ -2526,7 +2502,12 @@ def test_abort_copy_file(self, **kwargs): secondary_storage_account_name = kwargs.pop("secondary_storage_account_name") secondary_storage_account_key = kwargs.pop("secondary_storage_account_key") - self._setup(storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key.secret) + self._setup( + storage_account_name, + storage_account_key, + secondary_storage_account_name, + secondary_storage_account_key.secret + ) data = b'12345678' * 1024 * 1024 self._create_remote_share() source_file = self._create_remote_file(file_data=data) @@ -2689,7 +2670,7 @@ def test_file_unicode_data(self, **kwargs): credential=storage_account_key.secret) # Act - data = u'hello world啊齄丂狛狜'.encode('utf-8') + data = 'hello world啊齄丂狛狜'.encode('utf-8') file_client.upload_file(data) # Assert @@ -2706,7 +2687,7 @@ def test_file_unicode_data_and_file_attributes(self, **kwargs): file_client = self._get_file_client() # Act - data = u'hello world啊齄丂狛狜'.encode('utf-8') + data = 'hello world啊齄丂狛狜'.encode('utf-8') file_client.upload_file(data, file_attributes=NTFSAttributes(temporary=True)) # Assert @@ -2722,7 +2703,22 @@ def test_unicode_get_file_binary_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - base64_data = 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==' + base64_data = ( + 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0' + 'xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYm' + 'ZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm' + '5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM' + '0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gI' + 'GCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNz' + 's/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRob' + 'HB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2h' + 'pamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tb' + 'a3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECA' + 'wQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9Q' + 'UVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2' + 'en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6' + 'uvs7e7v8PHy8/T19vf4+fr7/P3+/w==' + ) binary_data = base64.b64decode(base64_data) file_name = self._get_file_reference() @@ -3046,7 +3042,7 @@ def test_create_file_from_text(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_name = self._get_file_reference() - text = u'hello 啊齄丂狛狜 world' + text = 'hello 啊齄丂狛狜 world' data = text.encode('utf-8') file_client = ShareFileClient( self.account_url(storage_account_name, "file"), @@ -3069,7 +3065,7 @@ def test_create_file_from_text_with_encoding(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_name = self._get_file_reference() - text = u'hello 啊齄丂狛狜 world' + text = 'hello 啊齄丂狛狜 world' data = text.encode('utf-16') file_client = ShareFileClient( self.account_url(storage_account_name, "file"), @@ -3294,7 +3290,7 @@ def test_account_sas(self, **kwargs): file_path=file_client.file_name, credential=token) - response = requests.get(file_client.url) + response = requests.get(file_client.url, timeout=15) # Assert assert response.ok @@ -3387,7 +3383,7 @@ def test_shared_read_access_file(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, credential=token) - response = requests.get(file_client.url) + response = requests.get(file_client.url, timeout=15) # Assert assert response.ok @@ -3422,7 +3418,7 @@ def test_shared_read_access_file_with_content_query_params(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, credential=token) - response = requests.get(file_client.url) + response = requests.get(file_client.url, timeout=15) # Assert assert self.short_byte_data == response.content @@ -3458,7 +3454,7 @@ def test_shared_write_access_file(self, **kwargs): # Act headers = {'x-ms-range': 'bytes=0-16', 'x-ms-write': 'update'} - response = requests.put(file_client.url + '&comp=range', headers=headers, data=updated_data) + response = requests.put(file_client.url + '&comp=range', headers=headers, data=updated_data, timeout=15) # Assert assert response.ok @@ -3489,7 +3485,7 @@ def test_shared_delete_access_file(self, **kwargs): credential=token) # Act - response = requests.delete(file_client.url) + response = requests.delete(file_client.url, timeout=15) # Assert assert response.ok @@ -3647,12 +3643,13 @@ def test_rename_file_smb_properties(self, **kwargs): file_attributes=file_attributes, file_creation_time=file_creation_time, file_last_write_time=file_last_write_time, - file_change_time=file_change_time) + file_change_time=file_change_time + ) # Assert props = new_file.get_file_properties() assert props is not None - assert str(file_attributes), props.file_attributes.replace(' ' == '') + assert str(file_attributes), props.file_attributes.replace(' ', '') assert file_creation_time == props.creation_time assert file_last_write_time == props.last_write_time assert file_change_time == props.change_time @@ -3796,7 +3793,7 @@ def test_bad_audience_file_client(self, **kwargs): file_path=file_name, credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://badaudience.file.core.windows.net' + audience='https://badaudience.file.core.windows.net' ) # Assert @@ -3981,7 +3978,8 @@ def test_download_file_decompress(self, **kwargs): credential=storage_account_key.secret, max_range_size=4 * 1024 ) - compressed_data = b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcaH\xcd\xc9\xc9WH+\xca\xcfUH\xaf\xca,\x00\x00\x00\x00\xff\xff\x03\x00d\xaa\x8e\xb5\x0f\x00\x00\x00' + compressed_data = (b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcaH\xcd\xc9\xc9WH+\xca\xcfUH' + b'\xaf\xca,\x00\x00\x00\x00\xff\xff\x03\x00d\xaa\x8e\xb5\x0f\x00\x00\x00') decompressed_data = b"hello from gzip" content_settings = ContentSettings(content_encoding='gzip') @@ -4006,7 +4004,8 @@ def test_download_file_no_decompress_chunks(self, **kwargs): max_chunk_get_size=4, max_single_get_size=4, ) - compressed_data = b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcaH\xcd\xc9\xc9WH+\xca\xcfUH\xaf\xca,\x00\x00\x00\x00\xff\xff\x03\x00d\xaa\x8e\xb5\x0f\x00\x00\x00' + compressed_data = (b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcaH\xcd\xc9\xc9WH+\xca\xcfUH' + b'\xaf\xca,\x00\x00\x00\x00\xff\xff\x03\x00d\xaa\x8e\xb5\x0f\x00\x00\x00') content_settings = ContentSettings(content_encoding='gzip') # Act / Assert diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_api_version.py b/sdk/storage/azure-storage-file-share/tests/test_file_api_version.py index 0f05f1543337..6d450be22723 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_api_version.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_api_version.py @@ -5,14 +5,16 @@ # -------------------------------------------------------------------------- import pytest -from azure.core.exceptions import ResourceExistsError -from azure.storage.fileshare import ShareClient, ShareDirectoryClient, ShareFileClient, ShareServiceClient -from azure.storage.fileshare._shared.constants import X_MS_VERSION from devtools_testutils import recorded_by_proxy from devtools_testutils.storage import StorageRecordedTestCase from settings.testcase import FileSharePreparer +from azure.core.exceptions import ResourceExistsError +from azure.storage.fileshare import ShareClient, ShareDirectoryClient, ShareFileClient, ShareServiceClient +from azure.storage.fileshare._shared.constants import X_MS_VERSION + + # ------------------------------------------------------------------------------ TEST_FILE_PREFIX = 'file' diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_async.py b/sdk/storage/azure-storage-file-share/tests/test_file_async.py index 73d9780c8f56..2e1f0ea3df3a 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_async.py @@ -11,8 +11,14 @@ import pytest import requests + +from devtools_testutils.aio import recorded_by_proxy_async +from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase +from settings.testcase import FileSharePreparer +from test_helpers_async import AsyncStream, MockStorageTransport, ProgressTracker + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError +from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError from azure.storage.blob.aio import BlobServiceClient from azure.storage.fileshare import ( AccessPolicy, @@ -25,14 +31,10 @@ NTFSAttributes, ResourceTypes, ShareSasPermissions, - StorageErrorCode + StorageErrorCode, ) from azure.storage.fileshare.aio import ShareFileClient, ShareServiceClient -from devtools_testutils.aio import recorded_by_proxy_async -from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase -from settings.testcase import FileSharePreparer -from test_helpers_async import AsyncStream, MockStorageTransport, ProgressTracker # ------------------------------------------------------------------------------ TEST_SHARE_PREFIX = 'share' @@ -230,7 +232,8 @@ async def test_make_file_url_with_sas(self, **kwargs): self._setup(storage_account_name, storage_account_key) # cspell:disable-next-line - sas = '?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D' + sas = ('?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&' + 'sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D') file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name="vhds", @@ -483,46 +486,6 @@ async def test_create_file_with_invalid_file_permission(self, **kwargs): with pytest.raises(HttpResponseError): await file_name.create_file(1024, file_permission="abcde") - @FileSharePreparer() - @recorded_by_proxy_async - async def test_create_file_semantics(self, **kwargs): - storage_account_name = kwargs.pop("storage_account_name") - storage_account_key = kwargs.pop("storage_account_key") - - self._setup(storage_account_name, storage_account_key) - await self._setup_share(storage_account_name, storage_account_key) - file_name = self._get_file_reference() - - file1 = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name + "file1", - credential=storage_account_key.secret - ) - await file1.create_file(1024, file_property_semantics=None) - props = await file1.get_file_properties() - assert props is not None - - file2 = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name + "file2", - credential=storage_account_key.secret - ) - await file2.create_file(1024, file_property_semantics="New") - props = await file2.get_file_properties() - assert props is not None - - file3 = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name + "file2", - credential=storage_account_key.secret - ) - await file3.create_file(1024, file_property_semantics="Restore", file_permission=TEST_FILE_PERMISSIONS) - props = await file3.get_file_properties() - assert props is not None - @FileSharePreparer() @recorded_by_proxy_async async def test_create_file_with_lease(self, **kwargs): @@ -696,7 +659,8 @@ async def test_create_file_set_smb_properties(self, **kwargs): file_client = await self._get_file_client(storage_account_name, storage_account_key) file_attributes = NTFSAttributes(read_only=True, archive=True) - file_creation_time = file_last_write_time = file_change_time = datetime(2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc) + file_creation_time = file_last_write_time = file_change_time = datetime( + 2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc) # Act await file_client.create_file( @@ -1553,10 +1517,18 @@ async def test_update_range_from_file_url_when_source_file_does_not_have_enough_ self._setup(storage_account_name, storage_account_key) source_file_name = 'testfile1' - source_file_client = await self._create_file(storage_account_name, storage_account_key, file_name=source_file_name) + source_file_client = await self._create_file( + storage_account_name, + storage_account_key, + file_name=source_file_name + ) destination_file_name = 'filetoupdate' - destination_file_client = await self._create_file(storage_account_name, storage_account_key, file_name=destination_file_name) + destination_file_client = await self._create_file( + storage_account_name, + storage_account_key, + file_name=destination_file_name + ) # generate SAS for the source file sas_token_for_source_file = self.generate_sas( @@ -1584,12 +1556,20 @@ async def test_update_range_from_file_url(self, **kwargs): self._setup(storage_account_name, storage_account_key) source_file_name = 'testfile' - source_file_client = await self._create_file(storage_account_name, storage_account_key, file_name=source_file_name) + source_file_client = await self._create_file( + storage_account_name, + storage_account_key, + file_name=source_file_name + ) data = b'abcdefghijklmnop' * 32 await source_file_client.upload_range(data, offset=0, length=512) destination_file_name = 'filetoupdate' - destination_file_client = await self._create_empty_file(storage_account_name, storage_account_key, file_name=destination_file_name) + destination_file_client = await self._create_empty_file( + storage_account_name, + storage_account_key, + file_name=destination_file_name + ) # generate SAS for the source file sas_token_for_source_file = self.generate_sas( @@ -1623,7 +1603,8 @@ async def test_update_range_from_file_url_with_oauth(self, **kwargs): self._setup(storage_account_name, storage_account_key) source_blob_client = await self._create_source_blob() - access_token = await self.get_credential(ShareServiceClient, is_async=True).get_token("https://storage.azure.com/.default") + access_token = await self.get_credential(ShareServiceClient, is_async=True).get_token( + "https://storage.azure.com/.default") token = "Bearer {}".format(access_token.token) destination_file_name = 'filetoupdate' @@ -1644,12 +1625,20 @@ async def test_update_range_from_file_url_with_lease(self, **kwargs): self._setup(storage_account_name, storage_account_key) source_file_name = 'testfile' - source_file_client = await self._create_file(storage_account_name, storage_account_key, file_name=source_file_name) + source_file_client = await self._create_file( + storage_account_name, + storage_account_key, + file_name=source_file_name + ) data = b'abcdefghijklmnop' * 32 await source_file_client.upload_range(data, offset=0, length=512) destination_file_name = 'filetoupdate' - destination_file_client = await self._create_empty_file(storage_account_name, storage_account_key, file_name=destination_file_name) + destination_file_client = await self._create_empty_file( + storage_account_name, + storage_account_key, + file_name=destination_file_name + ) lease = await destination_file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') # generate SAS for the source file @@ -1689,12 +1678,22 @@ async def test_update_big_range_from_file_url(self, **kwargs): source_file_name = 'testfile1' end = 1048575 - source_file_client = await self._create_empty_file(storage_account_name, storage_account_key, file_name=source_file_name, file_size=1024 * 1024) + source_file_client = await self._create_empty_file( + storage_account_name, + storage_account_key, + file_name=source_file_name, + file_size=1024 * 1024 + ) data = b'abcdefghijklmnop' * 65536 await source_file_client.upload_range(data, offset=0, length=end+1) destination_file_name = 'filetoupdate1' - destination_file_client = await self._create_empty_file(storage_account_name, storage_account_key, file_name=destination_file_name, file_size=1024 * 1024) + destination_file_client = await self._create_empty_file( + storage_account_name, + storage_account_key, + file_name=destination_file_name, + file_size=1024 * 1024 + ) # generate SAS for the source file sas_token_for_source_file = self.generate_sas( @@ -1851,7 +1850,7 @@ async def test_update_file_unicode(self, **kwargs): file_client = await self._create_file(storage_account_name, storage_account_key) # Act - data = u'abcdefghijklmnop' * 32 + data = 'abcdefghijklmnop' * 32 await file_client.upload_range(data, offset=0, length=512) encoded = data.encode('utf-8') @@ -2122,7 +2121,10 @@ async def test_list_ranges_diff_support_rename(self, **kwargs): await file_client.get_ranges_diff(previous_sharesnapshot=previous_snapshot) with pytest.raises(ResourceExistsError): await file_client.get_ranges_diff(previous_sharesnapshot=previous_snapshot, include_renames=False) - ranges, cleared = await file_client.get_ranges_diff(previous_sharesnapshot=previous_snapshot, include_renames=True) + ranges, cleared = await file_client.get_ranges_diff( + previous_sharesnapshot=previous_snapshot, + include_renames=True + ) assert ranges is not None assert isinstance(ranges, list) assert len(ranges) == 1 @@ -2177,7 +2179,7 @@ async def test_list_ranges_none_from_snapshot(self, **kwargs): file_path=file_name, credential=storage_account_key.secret) await file_client.create_file(1024) - + share_client = self.fsc.get_share_client(self.share_name) snapshot = await share_client.create_snapshot() snapshot_client = ShareFileClient( @@ -2251,7 +2253,7 @@ async def test_list_ranges_2_from_snapshot(self, **kwargs): data = b'abcdefghijklmnop' * 32 resp1 = await file_client.upload_range(data, offset=0, length=512) resp2 = await file_client.upload_range(data, offset=1024, length=512) - + share_client = self.fsc.get_share_client(self.share_name) snapshot = await share_client.create_snapshot() snapshot_client = ShareFileClient( @@ -2507,7 +2509,12 @@ async def test_copy_file_async_private_file_async(self, **kwargs): secondary_storage_account_name = kwargs.pop("secondary_storage_account_name") secondary_storage_account_key = kwargs.pop("secondary_storage_account_key") - self._setup(storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key.secret) + self._setup( + storage_account_name, + storage_account_key, + secondary_storage_account_name, + secondary_storage_account_key.secret + ) await self._setup_share(storage_account_name, storage_account_key) await self._create_remote_share() source_file = await self._create_remote_file() @@ -2534,7 +2541,12 @@ async def test_copy_file_async_private_file_with_sas_async(self, **kwargs): secondary_storage_account_name = kwargs.pop("secondary_storage_account_name") secondary_storage_account_key = kwargs.pop("secondary_storage_account_key") - self._setup(storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key.secret) + self._setup( + storage_account_name, + storage_account_key, + secondary_storage_account_name, + secondary_storage_account_key.secret + ) data = b'12345678' * 1024 await self._create_remote_share() source_file = await self._create_remote_file(file_data=data) @@ -2561,7 +2573,7 @@ async def test_copy_file_async_private_file_with_sas_async(self, **kwargs): # Assert assert copy_resp['copy_status'] in ['success', 'pending'] - await self._wait_for_async_copy(self.share_name, target_file_name) + await self._wait_for_async_copy(self.share_name, target_file_name) content = await file_client.download_file() actual_data = await content.readall() @@ -2575,7 +2587,12 @@ async def test_abort_copy_file_async(self, **kwargs): secondary_storage_account_name = kwargs.pop("secondary_storage_account_name") secondary_storage_account_key = kwargs.pop("secondary_storage_account_key") - self._setup(storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key.secret) + self._setup( + storage_account_name, + storage_account_key, + secondary_storage_account_name, + secondary_storage_account_key.secret + ) data = b'12345678' * 1024 * 1024 await self._setup_share(storage_account_name, storage_account_key) await self._create_remote_share() @@ -2617,7 +2634,12 @@ async def test_abort_copy_file_async_with_oauth(self, **kwargs): secondary_storage_account_key = kwargs.pop("secondary_storage_account_key") token_credential = self.get_credential(ShareServiceClient, is_async=True) - self._setup(storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key.secret) + self._setup( + storage_account_name, + storage_account_key, + secondary_storage_account_name, + secondary_storage_account_key.secret + ) data = b'12345678' * 1024 * 1024 await self._setup_share(storage_account_name, storage_account_key) await self._create_remote_share() @@ -2747,7 +2769,7 @@ async def test_file_unicode_data(self, **kwargs): credential=storage_account_key.secret) # Act - data = u'hello world啊齄丂狛狜'.encode('utf-8') + data = 'hello world啊齄丂狛狜'.encode('utf-8') await file_client.upload_file(data) # Assert @@ -2765,7 +2787,7 @@ async def test_file_unicode_data_and_file_attributes(self, **kwargs): file_client = await self._get_file_client(storage_account_name, storage_account_key) # Act - data = u'hello world啊齄丂狛狜'.encode('utf-8') + data = 'hello world啊齄丂狛狜'.encode('utf-8') await file_client.upload_file(data, file_attributes=NTFSAttributes(temporary=True)) # Assert @@ -2782,7 +2804,22 @@ async def test_unicode_get_file_binary_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - base64_data = 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==' + base64_data = ( + 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0' + 'xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYm' + 'ZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm' + '5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM' + '0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gI' + 'GCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNz' + 's/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRob' + 'HB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2h' + 'pamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tb' + 'a3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECA' + 'wQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9Q' + 'UVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2' + 'en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6' + 'uvs7e7v8PHy8/T19vf4+fr7/P3+/w==' + ) binary_data = base64.b64decode(base64_data) await self._setup_share(storage_account_name, storage_account_key) @@ -3145,7 +3182,7 @@ async def test_create_file_from_text(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_name = self._get_file_reference() await self._setup_share(storage_account_name, storage_account_key) - text = u'hello 啊齄丂狛狜 world' + text = 'hello 啊齄丂狛狜 world' data = text.encode('utf-8') file_client = ShareFileClient( self.account_url(storage_account_name, "file"), @@ -3169,7 +3206,7 @@ async def test_create_file_from_text_with_encoding(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_name = self._get_file_reference() await self._setup_share(storage_account_name, storage_account_key) - text = u'hello 啊齄丂狛狜 world' + text = 'hello 啊齄丂狛狜 world' data = text.encode('utf-16') file_client = ShareFileClient( self.account_url(storage_account_name, "file"), @@ -3403,7 +3440,7 @@ async def test_account_sas(self, **kwargs): file_path=file_client.file_name, credential=token) - response = requests.get(file_client.url) + response = requests.get(file_client.url, timeout=15) # Assert assert response.ok @@ -3496,7 +3533,7 @@ async def test_shared_read_access_file(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, credential=token) - response = requests.get(file_client.url) + response = requests.get(file_client.url, timeout=15) # Assert assert response.ok @@ -3531,7 +3568,7 @@ async def test_shared_read_access_file_with_content_query_params(self, **kwargs) share_name=self.share_name, file_path=file_client.file_name, credential=token) - response = requests.get(file_client.url) + response = requests.get(file_client.url, timeout=15) # Assert assert self.short_byte_data == response.content @@ -3567,7 +3604,7 @@ async def test_shared_write_access_file(self, **kwargs): # Act headers = {'x-ms-range': 'bytes=0-16', 'x-ms-write': 'update'} - response = requests.put(file_client.url + '&comp=range', headers=headers, data=updated_data) + response = requests.put(file_client.url + '&comp=range', headers=headers, data=updated_data, timeout=15) # Assert assert response.ok @@ -3599,7 +3636,7 @@ async def test_shared_delete_access_file(self, **kwargs): credential=token) # Act - response = requests.delete(file_client.url) + response = requests.delete(file_client.url, timeout=15) # Assert assert response.ok @@ -3765,7 +3802,7 @@ async def test_rename_file_smb_properties(self, **kwargs): # Assert props = await new_file.get_file_properties() assert props is not None - assert str(file_attributes), props.file_attributes.replace(' ' == '') + assert str(file_attributes), props.file_attributes.replace(' ', '') assert file_creation_time == props.creation_time assert file_last_write_time == props.last_write_time assert file_change_time == props.change_time @@ -3912,7 +3949,7 @@ async def test_bad_audience_file_client(self, **kwargs): file_path=file_name, credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://badaudience.file.core.windows.net' + audience='https://badaudience.file.core.windows.net' ) # Assert @@ -4106,7 +4143,8 @@ async def test_download_file_decompress(self, **kwargs): credential=storage_account_key.secret, max_range_size=4 * 1024 ) - compressed_data = b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcaH\xcd\xc9\xc9WH+\xca\xcfUH\xaf\xca,\x00\x00\x00\x00\xff\xff\x03\x00d\xaa\x8e\xb5\x0f\x00\x00\x00' + compressed_data = (b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcaH\xcd\xc9\xc9WH+\xca\xcfUH' + b'\xaf\xca,\x00\x00\x00\x00\xff\xff\x03\x00d\xaa\x8e\xb5\x0f\x00\x00\x00') decompressed_data = b"hello from gzip" content_settings = ContentSettings(content_encoding='gzip') @@ -4132,7 +4170,8 @@ async def test_download_file_no_decompress_chunks(self, **kwargs): max_chunk_get_size=4, max_single_get_size=4, ) - compressed_data = b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcaH\xcd\xc9\xc9WH+\xca\xcfUH\xaf\xca,\x00\x00\x00\x00\xff\xff\x03\x00d\xaa\x8e\xb5\x0f\x00\x00\x00' + compressed_data = (b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcaH\xcd\xc9\xc9WH+\xca\xcfUH' + b'\xaf\xca,\x00\x00\x00\x00\xff\xff\x03\x00d\xaa\x8e\xb5\x0f\x00\x00\x00') content_settings = ContentSettings(content_encoding='gzip') # Act / Assert diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_client.py b/sdk/storage/azure-storage-file-share/tests/test_file_client.py index 101a96270c96..cefdd9cbea35 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_client.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_client.py @@ -7,6 +7,12 @@ import platform import pytest + +from devtools_testutils import recorded_by_proxy +from devtools_testutils.storage import StorageRecordedTestCase +from devtools_testutils.storage.testcase import generate_sas_token +from settings.testcase import FileSharePreparer + from azure.core.exceptions import AzureError from azure.storage.fileshare import ( LocationMode, @@ -14,14 +20,9 @@ ShareDirectoryClient, ShareFileClient, ShareServiceClient, - VERSION + VERSION, ) -from devtools_testutils import recorded_by_proxy -from devtools_testutils.storage import StorageRecordedTestCase -from devtools_testutils.storage.testcase import generate_sas_token -from settings.testcase import FileSharePreparer - # ------------------------------------------------------------------------------ SERVICES = { @@ -54,8 +55,10 @@ def validate_standard_account_endpoints(self, service, service_type, protocol='h assert service.account_name == self.account_name assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key.secret - assert service.primary_endpoint.startswith('{}://{}.{}.core.windows.net/'.format(protocol, self.account_name, service_type)) is True - assert service.secondary_endpoint.startswith('{}://{}-secondary.{}.core.windows.net/'.format(protocol, self.account_name, service_type)) is True + assert service.primary_endpoint.startswith( + '{}://{}.{}.core.windows.net/'.format(protocol, self.account_name, service_type)) is True + assert service.secondary_endpoint.startswith( + '{}://{}-secondary.{}.core.windows.net/'.format(protocol, self.account_name, service_type)) is True def validate_ipv6_account_endpoints(self, service, account_name, account_key, primary_endpoint, secondary_endpoint): assert service is not None @@ -137,8 +140,10 @@ def test_create_service_china(self, **kwargs): assert service.account_name == self.account_name assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key.secret - assert service.primary_hostname == '{}.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1]) - assert service.secondary_hostname == '{}-secondary.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1]) + assert service.primary_hostname == '{}.{}.core.chinacloudapi.cn'.format( + self.account_name, service_type[1]) + assert service.secondary_hostname == '{}-secondary.{}.core.chinacloudapi.cn'.format( + self.account_name, service_type[1]) @FileSharePreparer() def test_create_service_protocol(self, **kwargs): @@ -167,9 +172,14 @@ def test_create_service_empty_key(self, **kwargs): # Passing an empty key to create account should fail. with pytest.raises(ValueError) as e: service_type( - self.account_url(storage_account_name, "file"), share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + share_name='foo', + directory_path='bar', + file_path='baz' + ) - assert str(e.value.args[0]) == 'You need to provide either an account shared key or SAS token when creating a storage service.' + assert (str(e.value.args[0]) == + 'You need to provide either an account shared key or SAS token when creating a storage service.') @FileSharePreparer() def test_create_service_with_socket_timeout(self, **kwargs): @@ -181,11 +191,20 @@ def test_create_service_with_socket_timeout(self, **kwargs): for service_type in SERVICES.items(): # Act default_service = service_type[0]( - self.account_url(storage_account_name, "file"), credential=self.account_key.secret, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret, + share_name='foo', + directory_path='bar', + file_path='baz' + ) service = service_type[0]( - self.account_url(storage_account_name, "file"), credential=self.account_key.secret, connection_timeout=22, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret, + connection_timeout=22, + share_name='foo', + directory_path='bar', + file_path='baz' + ) # Assert self.validate_standard_account_endpoints(service, service_type[1]) @@ -233,7 +252,7 @@ def test_create_service_ipv6(self, account_url, expected_primary, expected_secon share_name, directory_path, file_path = "foo", "bar", "baz" - for service_type in SERVICES.keys(): + for service_type in SERVICES: service = service_type( account_url, credential=storage_account_key.secret, @@ -276,7 +295,7 @@ def test_create_service_ipv6_custom_domain(self): hostname= "github.com" account_url = f"https://{hostname}" - for service_type in SERVICES.keys(): + for service_type in SERVICES: service = service_type( account_url, credential=token_credential, @@ -336,8 +355,12 @@ def test_create_service_with_connection_string_endpoint_protocol(self, **kwargs) storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};AccountKey={};DefaultEndpointsProtocol=http;EndpointSuffix=core.chinacloudapi.cn;'.format( - self.account_name, self.account_key.secret) + conn_string = ( + 'AccountName={};AccountKey={};DefaultEndpointsProtocol=http;EndpointSuffix=core.chinacloudapi.cn;'.format( + self.account_name, + self.account_key.secret + ) + ) for service_type in SERVICES.items(): # Act @@ -349,8 +372,11 @@ def test_create_service_with_connection_string_endpoint_protocol(self, **kwargs) assert service.account_name == self.account_name assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key.secret - assert service.primary_hostname, '{}.{}.core.chinacloudapi.cn'.format(self.account_name == service_type[1]) - assert service.secondary_hostname == '{}-secondary.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1]) + assert service.primary_hostname, '{}.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1]) + assert service.secondary_hostname == '{}-secondary.{}.core.chinacloudapi.cn'.format( + self.account_name, + service_type[1] + ) assert service.scheme == 'http' @FileSharePreparer() @@ -409,7 +435,7 @@ def test_create_service_with_connection_string_succeeds_if_secondary_with_primar assert service.secondary_hostname == 'www-sec.mydomain.com' @FileSharePreparer() - def test_create_service_with_custom_account_endpoint_path(self, **kwargs): + def test_create_service_with_custom_account_endpoint_path(self, **kwargs): # pylint: disable=too-many-statements storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") @@ -428,7 +454,7 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key.secret assert service.primary_hostname == 'local-machine:11002/custom/account/path' - + service = ShareServiceClient(account_url=custom_account_url) assert service.account_name == None assert service.credential == None @@ -443,14 +469,20 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith('http://local-machine:11002/custom/account/path/foo?sharesnapshot=snap&') - service = ShareDirectoryClient(account_url=custom_account_url, share_name='foo', directory_path="bar/baz", snapshot="snap") + service = ShareDirectoryClient( + account_url=custom_account_url, + share_name='foo', + directory_path="bar/baz", snapshot="snap" + ) assert service.account_name == None assert service.share_name == "foo" assert service.directory_path == "bar/baz" assert service.snapshot == "snap" assert service.credential == None assert service.primary_hostname == 'local-machine:11002/custom/account/path' - assert service.url.startswith('http://local-machine:11002/custom/account/path/foo/bar%2Fbaz?sharesnapshot=snap&') + assert service.url.startswith( + 'http://local-machine:11002/custom/account/path/foo/bar%2Fbaz?sharesnapshot=snap&' + ) service = ShareDirectoryClient(account_url=custom_account_url, share_name='foo', directory_path="") assert service.account_name == None @@ -461,16 +493,23 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith('http://local-machine:11002/custom/account/path/foo?') - service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="bar/baz/file", snapshot="snap") + service = ShareFileClient( + account_url=custom_account_url, + share_name="foo", + file_path="bar/baz/file", + snapshot="snap" + ) assert service.account_name == None assert service.share_name == "foo" assert service.directory_path == "bar/baz" - assert service.file_path, ["bar", "baz" == "file"] + assert service.file_path, ["bar", "baz", "file"] assert service.file_name == "file" assert service.snapshot == "snap" assert service.credential == None assert service.primary_hostname == 'local-machine:11002/custom/account/path' - assert service.url.startswith('http://local-machine:11002/custom/account/path/foo/bar/baz/file?sharesnapshot=snap&') + assert service.url.startswith( + 'http://local-machine:11002/custom/account/path/foo/bar/baz/file?sharesnapshot=snap&' + ) service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="file") assert service.account_name == None @@ -483,7 +522,7 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith('http://local-machine:11002/custom/account/path/foo/file?') - @pytest.mark.skip(reason="Client Request ID is different for every request, needs further investigation: https://github.com/Azure/azure-sdk-for-python/issues/8098") + @pytest.mark.skip(reason="Client Request ID is different for every request, needs further investigation: https://github.com/Azure/azure-sdk-for-python/issues/8098") # pylint: disable=line-too-long @FileSharePreparer() def test_client_request_id_echo(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") @@ -494,21 +533,21 @@ def test_client_request_id_echo(self, **kwargs): service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key.secret) # Act make the client request ID slightly different - def callback(response): + def first_callback(response): response.http_response.status_code = 200 response.http_response.headers[request_id_header_name] += '1' # Assert the client request ID validation is working with pytest.raises(AzureError): - service.get_service_properties(raw_response_hook=callback) + service.get_service_properties(raw_response_hook=first_callback) # Act remove the echoed client request ID - def callback(response): + def second_callback(response): response.status_code = 200 del response.http_response.headers[request_id_header_name] # Assert the client request ID validation is not throwing when the ID is not echoed - service.get_service_properties(raw_response_hook=callback) + service.get_service_properties(raw_response_hook=second_callback) @FileSharePreparer() @recorded_by_proxy @@ -583,8 +622,13 @@ def test_error_with_malformed_conn_str(self, **kwargs): for service_type in SERVICES.items(): # Act with pytest.raises(ValueError) as e: - service = service_type[0].from_connection_string(conn_str, share_name="test", directory_path="foo/bar", file_path="temp/dat") - + service_type[0].from_connection_string( + conn_str, + share_name="test", + directory_path="foo/bar", + file_path="temp/dat" + ) + if conn_str in("", "foobar", "foo;bar;baz", ";"): assert e.value.args[0] == "Connection string is either blank or malformed." elif conn_str in ("foobar=baz=foo" , "foo=;bar=;", "=", "=;=="): @@ -600,7 +644,12 @@ def test_closing_pipeline_client(self, **kwargs): for client, url in SERVICES.items(): # Act service = client( - self.account_url(storage_account_name, "file"), credential=self.account_key.secret, share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret, + share_name='foo', + directory_path='bar', + file_path='baz' + ) # Assert with service: @@ -617,5 +666,10 @@ def test_closing_pipeline_client_simple(self, **kwargs): for client, url in SERVICES.items(): # Act service = client( - self.account_url(storage_account_name, "file"), credential=self.account_key.secret, share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret, + share_name='foo', + directory_path='bar', + file_path='baz' + ) service.close() diff --git a/sdk/storage/azure-storage-file-share/tests/test_handle.py b/sdk/storage/azure-storage-file-share/tests/test_handle.py index 20f957a55390..39b80c88c07c 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_handle.py +++ b/sdk/storage/azure-storage-file-share/tests/test_handle.py @@ -3,15 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- + import unittest import pytest -from azure.storage.fileshare import ShareServiceClient from devtools_testutils import recorded_by_proxy from devtools_testutils.storage import StorageRecordedTestCase from settings.testcase import FileSharePreparer +from azure.storage.fileshare import ShareServiceClient + + # ------------------------------------------------------------------------------ TEST_SHARE_NAME = 'test-share' # ------------------------------------------------------------------------------ @@ -50,7 +53,7 @@ def test_list_handles_on_share(self, **kwargs): # don't run live, since the test set up was highly manual # only run when recording, or playing back in CI - + self._setup(storage_account_name, storage_account_key) share = self.fsc.get_share_client(TEST_SHARE_NAME) root = share.get_directory_client() @@ -115,7 +118,7 @@ def test_list_handles_with_marker(self, **kwargs): # Make sure the old handle did not appear # In other words, the marker worked - old_handle_not_present = all([old_handle.id != handle.id for handle in remaining_handles]) + old_handle_not_present = all(old_handle.id != handle.id for handle in remaining_handles) assert old_handle_not_present @pytest.mark.playback_test_only diff --git a/sdk/storage/azure-storage-file-share/tests/test_helpers.py b/sdk/storage/azure-storage-file-share/tests/test_helpers.py index 6f36069ec952..1514a04858af 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_helpers.py +++ b/sdk/storage/azure-storage-file-share/tests/test_helpers.py @@ -5,13 +5,14 @@ # -------------------------------------------------------------------------- from typing import Any, Dict, Optional -from typing_extensions import Self -from azure.core.pipeline.transport import HttpTransport, RequestsTransportResponse -from azure.core.rest import HttpRequest from requests import Response +from typing_extensions import Self from urllib3 import HTTPResponse +from azure.core.pipeline.transport import HttpTransport, RequestsTransportResponse # pylint: disable=no-name-in-module +from azure.core.rest import HttpRequest + class ProgressTracker: def __init__(self, total: int, step: int): diff --git a/sdk/storage/azure-storage-file-share/tests/test_nfs.py b/sdk/storage/azure-storage-file-share/tests/test_nfs.py index 3b714c7d465d..33b8a16159bf 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_nfs.py +++ b/sdk/storage/azure-storage-file-share/tests/test_nfs.py @@ -3,27 +3,25 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import pytest + from typing import Any, Dict, Optional, Union from urllib.parse import unquote -from azure.core.exceptions import ( - ClientAuthenticationError, - HttpResponseError, - ResourceExistsError, - ResourceNotFoundError -) +import pytest + +from devtools_testutils import recorded_by_proxy +from devtools_testutils.storage import StorageRecordedTestCase +from settings.testcase import FileSharePreparer + +from azure.core.exceptions import ResourceNotFoundError from azure.storage.fileshare import ( ContentSettings, - FileProperties, DirectoryProperties, - ShareFileClient, + FileProperties, ShareDirectoryClient, - ShareServiceClient + ShareFileClient, + ShareServiceClient, ) -from devtools_testutils import recorded_by_proxy -from devtools_testutils.storage import StorageRecordedTestCase -from settings.testcase import FileSharePreparer TEST_INTENT = 'backup' diff --git a/sdk/storage/azure-storage-file-share/tests/test_share.py b/sdk/storage/azure-storage-file-share/tests/test_share.py index 3b6572837a68..71d3a94eacc7 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_share.py +++ b/sdk/storage/azure-storage-file-share/tests/test_share.py @@ -3,21 +3,27 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import jwt + import os import time import unittest from datetime import datetime, timedelta +import jwt import pytest import requests + +from devtools_testutils import recorded_by_proxy +from devtools_testutils.storage import LogCaptured, StorageRecordedTestCase +from settings.testcase import FileSharePreparer + from azure.core.exceptions import ( ClientAuthenticationError, HttpResponseError, ResourceExistsError, - ResourceNotFoundError + ResourceNotFoundError, ) -from azure.core.pipeline.transport import RequestsTransport +from azure.core.pipeline.transport import RequestsTransport # pylint: disable=no-name-in-module from azure.storage.fileshare import ( AccessPolicy, AccountSasPermissions, @@ -25,9 +31,7 @@ generate_account_sas, generate_file_sas, generate_share_sas, - Metrics, ResourceTypes, - RetentionPolicy, ShareAccessTier, ShareClient, ShareFileClient, @@ -35,12 +39,9 @@ ShareRootSquash, ShareSasPermissions, ShareServiceClient, - StorageErrorCode + StorageErrorCode, ) -from devtools_testutils import recorded_by_proxy -from devtools_testutils.storage import LogCaptured, StorageRecordedTestCase -from settings.testcase import FileSharePreparer # ------------------------------------------------------------------------------ TEST_SHARE_PREFIX = 'share' @@ -77,9 +78,9 @@ def _create_share(self, prefix=TEST_SHARE_PREFIX, **kwargs): def _create_share_if_not_exists(self, prefix=TEST_SHARE_PREFIX, **kwargs): share_client = self._get_share_reference(prefix) - return share_client.create_share_if_not_exists(**kwargs) - - def _delete_shares(self, prefix=TEST_SHARE_PREFIX): + return share_client.create_share_if_not_exists(**kwargs) # pylint: disable=no-member + + def _delete_shares(self, prefix=TEST_SHARE_PREFIX): # pylint: disable=unused-argument for l in self.fsc.list_shares(include_snapshots=True): try: self.fsc.delete_share(l.name, delete_snapshots=True) @@ -88,11 +89,20 @@ def _delete_shares(self, prefix=TEST_SHARE_PREFIX): # --Test cases for shares ----------------------------------------- def test_create_share_client(self): - share_client = ShareClient.from_share_url("http://127.0.0.1:11002/account/customized/path/share?snapshot=baz&", credential={"account_name": "myaccount", "account_key": "key"}) + share_client = ShareClient.from_share_url( + "http://127.0.0.1:11002/account/customized/path/share?snapshot=baz&", + credential={ + "account_name": "myaccount", + "account_key": "key" + } + ) assert share_client.share_name == "share" assert share_client.snapshot == "baz" - share_client = ShareClient.from_share_url("http://127.0.0.1:11002/account/share?snapshot=baz&", credential="credential") + share_client = ShareClient.from_share_url( + "http://127.0.0.1:11002/account/share?snapshot=baz&", + credential="credential" + ) assert share_client.share_name == "share" assert share_client.snapshot == "baz" @@ -728,7 +738,7 @@ def test_unicode_create_share_unicode_name(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_name = u'啊齄丂狛狜' + share_name = '啊齄丂狛狜' # Act with pytest.raises(HttpResponseError): @@ -1285,7 +1295,7 @@ def test_set_share_acl(self, **kwargs): share.create_share() # Act - resp = share.set_share_access_policy(signed_identifiers=dict()) + resp = share.set_share_access_policy(signed_identifiers={}) # Assert acl = share.get_share_access_policy() @@ -1303,7 +1313,7 @@ def test_set_share_acl_with_empty_signed_identifiers(self, **kwargs): share.create_share() # Act - resp = share.set_share_access_policy(dict()) + resp = share.set_share_access_policy({}) # Assert acl = share.get_share_access_policy() @@ -1361,7 +1371,10 @@ def test_set_share_acl_too_many_ids(self, **kwargs): # Assert with pytest.raises(ValueError) as e: share.set_share_access_policy(identifiers) - assert str(e.value.exception) == 'Too many access policies provided. The server does not support setting more than 5 access policies on a single resource.' + assert str(e.value.exception) == ( + 'Too many access policies provided. ' + 'The server does not support setting more than 5 access policies on a single resource.' + ) self._delete_shares() @FileSharePreparer() @@ -1543,7 +1556,7 @@ def test_shared_access_share(self, **kwargs): # Act print(sas_client.url) - response = requests.get(sas_client.url) + response = requests.get(sas_client.url, timeout=15) # Assert assert response.ok @@ -1904,7 +1917,7 @@ def test_get_user_delegation_sas(self, **kwargs): @pytest.mark.live_test_only @FileSharePreparer() - def test_share_cross_tenant_sas(self, **kwargs): + def test_share_cross_tenant_sas(self, **kwargs): # pylint: disable=too-many-locals storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") @@ -1918,7 +1931,7 @@ def test_share_cross_tenant_sas(self, **kwargs): start = datetime.utcnow() expiry = datetime.utcnow() + timedelta(hours=1) token = token_credential.get_token("https://storage.azure.com/.default") - decoded = jwt.decode(token.token, options={"verify_signature": False}) + decoded = jwt.decode(token.token, options={"verify_signature": False}) # pylint: disable=no-member user_delegation_oid = decoded.get("oid") delegated_user_tid = decoded.get("tid") user_delegation_key = service.get_user_delegation_key( diff --git a/sdk/storage/azure-storage-file-share/tests/test_share_async.py b/sdk/storage/azure-storage-file-share/tests/test_share_async.py index 5face0374f45..0c1c248cec0c 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_share_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_share_async.py @@ -3,20 +3,27 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import jwt + import os import time from datetime import datetime, timedelta +import jwt import pytest import requests + +from devtools_testutils.aio import recorded_by_proxy_async +from devtools_testutils.storage import LogCaptured +from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase +from settings.testcase import FileSharePreparer + from azure.core.exceptions import ( ClientAuthenticationError, HttpResponseError, ResourceExistsError, - ResourceNotFoundError + ResourceNotFoundError, ) -from azure.core.pipeline.transport import AioHttpTransport +from azure.core.pipeline.transport import AioHttpTransport # pylint: disable=no-name-in-module from azure.storage.fileshare import ( AccessPolicy, AccountSasPermissions, @@ -29,15 +36,11 @@ ShareProtocols, ShareRootSquash, ShareSasPermissions, - ShareServiceClient, - StorageErrorCode + StorageErrorCode, ) from azure.storage.fileshare.aio import ShareClient, ShareFileClient, ShareServiceClient -from devtools_testutils.aio import recorded_by_proxy_async -from devtools_testutils.storage import LogCaptured -from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase -from settings.testcase import FileSharePreparer + # ------------------------------------------------------------------------------ TEST_SHARE_PREFIX = 'share' TEST_INTENT = "backup" @@ -58,12 +61,13 @@ def _teardown(self, FILE_PATH): except: pass - async def _delete_shares(self, prefix=TEST_SHARE_PREFIX): + async def _delete_shares(self, prefix=TEST_SHARE_PREFIX): # pylint: disable=unused-argument async for l in self.fsc.list_shares(include_snapshots=True): try: await self.fsc.delete_share(l.name, delete_snapshots=True) except: pass + # --Helpers----------------------------------------------------------------- def _get_share_reference(self, prefix=TEST_SHARE_PREFIX): share_name = self.get_resource_name(prefix) @@ -721,7 +725,7 @@ async def test_unicode_create_share_unicode_name(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_name = u'啊齄丂狛狜' + share_name = '啊齄丂狛狜' # Act with pytest.raises(HttpResponseError): @@ -759,7 +763,12 @@ async def test_list_shares_enable_snapshot_virtual_directory_access(self, **kwar premium_storage_file_account_key = kwargs.pop("premium_storage_file_account_key") self._setup(premium_storage_file_account_name, premium_storage_file_account_key) - share = await self._create_share(protocols="NFS", headers={'x-ms-enable-snapshot-virtual-directory-access': "False"}) + share = await self._create_share( + protocols="NFS", + headers={ + 'x-ms-enable-snapshot-virtual-directory-access': "False" + } + ) # Act list_props = [] @@ -1307,7 +1316,7 @@ async def test_set_share_acl(self, **kwargs): await share.create_share() # Act - resp = await share.set_share_access_policy(signed_identifiers=dict()) + resp = await share.set_share_access_policy(signed_identifiers={}) # Assert acl = await share.get_share_access_policy() @@ -1325,7 +1334,7 @@ async def test_set_share_acl_with_empty_signed_identifiers(self, **kwargs): await share.create_share() # Act - resp = await share.set_share_access_policy(dict()) + resp = await share.set_share_access_policy({}) # Assert acl = await share.get_share_access_policy() @@ -1383,7 +1392,8 @@ async def test_set_share_acl_too_many_ids(self, **kwargs): # Assert with pytest.raises(ValueError) as e: await share.set_share_access_policy(identifiers) - assert str(e.value.args[0]) == 'Too many access policies provided. The server does not support setting more than 5 access policies on a single resource.' + assert str(e.value.args[0]) == ('Too many access policies provided. The server does not ' + 'support setting more than 5 access policies on a single resource.') await self._delete_shares(share.share_name) @FileSharePreparer() @@ -1575,7 +1585,7 @@ async def test_shared_access_share(self, **kwargs): ) # Act - response = requests.get(sas_client.url) + response = requests.get(sas_client.url, timeout=15) # Assert assert response.ok @@ -1943,7 +1953,7 @@ async def test_get_user_delegation_sas(self, **kwargs): @pytest.mark.live_test_only @FileSharePreparer() - async def test_share_cross_tenant_sas(self, **kwargs): + async def test_share_cross_tenant_sas(self, **kwargs): # pylint: disable=too-many-locals storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") @@ -1957,7 +1967,7 @@ async def test_share_cross_tenant_sas(self, **kwargs): start = datetime.utcnow() expiry = datetime.utcnow() + timedelta(hours=1) token = await token_credential.get_token("https://storage.azure.com/.default") - decoded = jwt.decode(token.token, options={"verify_signature": False}) + decoded = jwt.decode(token.token, options={"verify_signature": False}) # pylint: disable=no-member user_delegation_oid = decoded.get("oid") delegated_user_tid = decoded.get("tid") user_delegation_key = await service.get_user_delegation_key( From cdd862af7e41f69567ddf5f97fc78465b3259c47 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 29 Apr 2026 18:53:23 -0400 Subject: [PATCH 3/8] GG --- .../tests/test_directory.py | 22 +-- .../tests/test_file_api_version_async.py | 10 +- .../tests/test_file_client_async.py | 130 +++++++++++++----- .../tests/test_file_service_properties.py | 21 ++- .../test_file_service_properties_async.py | 16 +-- .../tests/test_get_file.py | 44 ++++-- .../tests/test_get_file_async.py | 45 ++++-- .../tests/test_handle_async.py | 8 +- .../tests/test_helpers_async.py | 7 +- .../tests/test_nfs_async.py | 23 ++-- 10 files changed, 216 insertions(+), 110 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/tests/test_directory.py b/sdk/storage/azure-storage-file-share/tests/test_directory.py index 118d9f04f002..1dd881466170 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_directory.py +++ b/sdk/storage/azure-storage-file-share/tests/test_directory.py @@ -8,9 +8,13 @@ from datetime import datetime, timedelta, timezone import pytest -from azure.core.exceptions import ClientAuthenticationError, ResourceExistsError, ResourceNotFoundError + +from devtools_testutils import recorded_by_proxy +from devtools_testutils.storage import StorageRecordedTestCase +from settings.testcase import FileSharePreparer + +from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError from azure.storage.fileshare import ( - ContentSettings, generate_share_sas, NTFSAttributes, ShareDirectoryClient, @@ -19,9 +23,7 @@ StorageErrorCode, ) -from devtools_testutils import recorded_by_proxy -from devtools_testutils.storage import StorageRecordedTestCase -from settings.testcase import FileSharePreparer + # ------------------------------------------------------------------------------ TEST_FILE_PERMISSIONS = 'O:S-1-5-21-2127521184-1604012920-1887927527-21560751G:S-1-5-21-2127521184-' \ '1604012920-1887927527-513D:AI(A;;FA;;;SY)(A;;FA;;;BA)(A;;0x1200a9;;;' \ @@ -111,7 +113,8 @@ def test_create_directory_set_smb_properties(self, **kwargs): directory_client = share_client.get_directory_client('dir1') file_attributes = NTFSAttributes(read_only=True, directory=True) - file_creation_time = file_last_write_time = file_change_time = datetime(2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc) + file_creation_time = file_last_write_time = file_change_time = datetime( + 2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc) # Act directory_client.create_directory( @@ -873,7 +876,8 @@ def test_list_subdirectories_and_files_include_other_data(self, **kwargs): directory.upload_file("file3", "data3") # Act - list_dir = list(directory.list_directories_and_files(include=["timestamps", "Etag", "Attributes", "PermissionKey"])) + list_dir = list(directory.list_directories_and_files( + include=["timestamps", "Etag", "Attributes", "PermissionKey"])) assert len(list_dir) == 6 assert list_dir[0].etag is not None @@ -1279,7 +1283,7 @@ def test_rename_directory_smb_properties(self, **kwargs): props = new_directory.get_directory_properties() assert props is not None assert props.is_directory - assert str(file_attributes), props.file_attributes.replace(' ' == '') + assert str(file_attributes), props.file_attributes.replace(' ', '') assert file_creation_time == props.creation_time assert file_last_write_time == props.last_write_time assert file_change_time == props.change_time @@ -1415,7 +1419,7 @@ def test_bad_audience_directory_client(self, **kwargs): share_client.share_name, 'dir1.', credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://badaudience.file.core.windows.net' + audience='https://badaudience.file.core.windows.net' ) # Assert diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_api_version_async.py b/sdk/storage/azure-storage-file-share/tests/test_file_api_version_async.py index bb347918073a..064591eb7e05 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_api_version_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_api_version_async.py @@ -5,13 +5,15 @@ # -------------------------------------------------------------------------- import pytest -from azure.core.exceptions import ResourceExistsError -from azure.storage.fileshare.aio import ShareClient, ShareDirectoryClient, ShareFileClient, ShareServiceClient -from azure.storage.fileshare._shared.constants import X_MS_VERSION from devtools_testutils.aio import recorded_by_proxy_async -from settings.testcase import FileSharePreparer from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase +from settings.testcase import FileSharePreparer + +from azure.core.exceptions import ResourceExistsError +from azure.storage.fileshare._shared.constants import X_MS_VERSION +from azure.storage.fileshare.aio import ShareClient, ShareDirectoryClient, ShareFileClient, ShareServiceClient + # ------------------------------------------------------------------------------ TEST_FILE_PREFIX = 'file' diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_client_async.py b/sdk/storage/azure-storage-file-share/tests/test_file_client_async.py index a39b81ba430e..d0c4adb3129a 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_client_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_client_async.py @@ -7,14 +7,15 @@ import platform import pytest -from azure.storage.fileshare import LocationMode, VERSION -from azure.storage.fileshare.aio import ShareClient, ShareDirectoryClient, ShareFileClient, ShareServiceClient from devtools_testutils.aio import recorded_by_proxy_async from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase from devtools_testutils.storage.testcase import generate_sas_token from settings.testcase import FileSharePreparer +from azure.storage.fileshare import LocationMode, VERSION +from azure.storage.fileshare.aio import ShareClient, ShareDirectoryClient, ShareFileClient, ShareServiceClient + # ------------------------------------------------------------------------------ SERVICES = { @@ -48,8 +49,10 @@ def validate_standard_account_endpoints(self, service, service_type, protocol='h assert service.account_name == self.account_name assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key.secret - assert service.primary_endpoint.startswith('{}://{}.{}.core.windows.net/'.format(protocol, self.account_name, service_type)) is True - assert service.secondary_endpoint.startswith('{}://{}-secondary.{}.core.windows.net/'.format(protocol, self.account_name, service_type)) is True + assert service.primary_endpoint.startswith( + '{}://{}.{}.core.windows.net/'.format(protocol, self.account_name, service_type)) is True + assert service.secondary_endpoint.startswith( + '{}://{}-secondary.{}.core.windows.net/'.format(protocol, self.account_name, service_type)) is True def validate_ipv6_account_endpoints(self, service, account_name, account_key, primary_endpoint, secondary_endpoint): assert service is not None @@ -130,8 +133,10 @@ async def test_create_service_china(self, **kwargs): assert service.account_name == self.account_name assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key.secret - assert service.primary_hostname == '{}.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1]) - assert service.secondary_hostname == '{}-secondary.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1]) + assert service.primary_hostname == '{}.{}.core.chinacloudapi.cn'.format( + self.account_name, service_type[1]) + assert service.secondary_hostname == '{}-secondary.{}.core.chinacloudapi.cn'.format( + self.account_name, service_type[1]) @FileSharePreparer() async def test_create_service_protocol(self, **kwargs): @@ -160,9 +165,14 @@ async def test_create_service_empty_key(self, **kwargs): # Passing an empty key to create account should fail. with pytest.raises(ValueError) as e: service_type( - self.account_url(storage_account_name, "file"), share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + share_name='foo', + directory_path='bar', + file_path='baz' + ) - assert str(e.value.args[0]) == 'You need to provide either an account shared key or SAS token when creating a storage service.' + assert (str(e.value.args[0]) == + 'You need to provide either an account shared key or SAS token when creating a storage service.') @FileSharePreparer() async def test_create_service_with_socket_timeout(self, **kwargs): @@ -174,11 +184,20 @@ async def test_create_service_with_socket_timeout(self, **kwargs): for service_type in SERVICES.items(): # Act default_service = service_type[0]( - self.account_url(storage_account_name, "file"), credential=self.account_key.secret, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret, + share_name='foo', + directory_path='bar', + file_path='baz' + ) service = service_type[0]( - self.account_url(storage_account_name, "file"), credential=self.account_key.secret, connection_timeout=22, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret, + connection_timeout=22, + share_name='foo', + directory_path='bar', + file_path='baz' + ) # Assert self.validate_standard_account_endpoints(service, service_type[1]) @@ -226,7 +245,7 @@ def test_create_service_ipv6(self, account_url, expected_primary, expected_secon share_name, directory_path, file_path = "foo", "bar", "baz" - for service_type in SERVICES.keys(): + for service_type in SERVICES: service = service_type( account_url, credential=storage_account_key.secret, @@ -269,7 +288,7 @@ def test_create_service_ipv6_custom_domain(self): hostname = "github.com" account_url = f"https://{hostname}" - for service_type in SERVICES.keys(): + for service_type in SERVICES: service = service_type( account_url, credential=token_credential, @@ -329,20 +348,31 @@ async def test_create_service_with_connection_string_endpoint_protocol(self, **k storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};AccountKey={};DefaultEndpointsProtocol=http;EndpointSuffix=core.chinacloudapi.cn;'.format( - self.account_name, self.account_key.secret) + conn_string = ( + 'AccountName={};AccountKey={};DefaultEndpointsProtocol=http;EndpointSuffix=core.chinacloudapi.cn;'.format( + self.account_name, + self.account_key.secret + ) + ) for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string(conn_string, share_name='foo', directory_path='bar', file_path='baz') + service = service_type[0].from_connection_string( + conn_string, + share_name='foo', + directory_path='bar', + file_path='baz' + ) # Assert assert service is not None assert service.account_name == self.account_name assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key.secret - assert service.primary_hostname == '{}.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1]) - assert service.secondary_hostname == '{}-secondary.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1]) + assert service.primary_hostname == '{}.{}.core.chinacloudapi.cn'.format( + self.account_name, service_type[1]) + assert service.secondary_hostname == '{}-secondary.{}.core.chinacloudapi.cn'.format( + self.account_name, service_type[1]) assert service.scheme == 'http' @FileSharePreparer() @@ -356,7 +386,12 @@ async def test_create_service_with_connection_string_emulated(self, **kwargs): # Act with pytest.raises(ValueError): - service_type[0].from_connection_string(conn_string, share_name='foo', directory_path='bar', file_path='baz') + service_type[0].from_connection_string( + conn_string, + share_name='foo', + directory_path='bar', + file_path='baz' + ) @FileSharePreparer() async def test_create_service_with_connection_string_fails_if_secondary_without_primary(self, **kwargs): @@ -400,7 +435,7 @@ async def test_create_service_with_connection_string_succeeds_if_secondary_with_ assert service.secondary_hostname == 'www-sec.mydomain.com' @FileSharePreparer() - async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): + async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): # pylint: disable=too-many-statements storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") @@ -419,7 +454,7 @@ async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key.secret assert service.primary_hostname == 'local-machine:11002/custom/account/path' - + service = ShareServiceClient(account_url=custom_account_url) assert service.account_name == None assert service.credential == None @@ -434,14 +469,20 @@ async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith('http://local-machine:11002/custom/account/path/foo?sharesnapshot=snap&') - service = ShareDirectoryClient(account_url=custom_account_url, share_name='foo', directory_path="bar/baz", snapshot="snap") + service = ShareDirectoryClient( + account_url=custom_account_url, + share_name='foo', + directory_path="bar/baz", + snapshot="snap" + ) assert service.account_name == None assert service.share_name == "foo" assert service.directory_path == "bar/baz" assert service.snapshot == "snap" assert service.credential == None assert service.primary_hostname == 'local-machine:11002/custom/account/path' - assert service.url.startswith('http://local-machine:11002/custom/account/path/foo/bar%2Fbaz?sharesnapshot=snap&') + assert service.url.startswith( + 'http://local-machine:11002/custom/account/path/foo/bar%2Fbaz?sharesnapshot=snap&') service = ShareDirectoryClient(account_url=custom_account_url, share_name='foo', directory_path="") assert service.account_name == None @@ -452,16 +493,22 @@ async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith('http://local-machine:11002/custom/account/path/foo?') - service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="bar/baz/file", snapshot="snap") + service = ShareFileClient( + account_url=custom_account_url, + share_name="foo", + file_path="bar/baz/file", + snapshot="snap" + ) assert service.account_name == None assert service.share_name == "foo" assert service.directory_path == "bar/baz" - assert service.file_path, ["bar", "baz" == "file"] + assert service.file_path, ["bar", "baz", "file"] assert service.file_name == "file" assert service.snapshot == "snap" assert service.credential == None assert service.primary_hostname == 'local-machine:11002/custom/account/path' - assert service.url.startswith('http://local-machine:11002/custom/account/path/foo/bar/baz/file?sharesnapshot=snap&') + assert service.url.startswith( + 'http://local-machine:11002/custom/account/path/foo/bar/baz/file?sharesnapshot=snap&') service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="file") assert service.account_name == None @@ -481,7 +528,10 @@ async def test_user_agent_default(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key.secret) + service = ShareServiceClient( + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret + ) def callback(response): assert 'User-Agent' in response.http_request.headers @@ -498,7 +548,10 @@ async def test_user_agent_custom(self, **kwargs): self._setup(storage_account_name, storage_account_key) custom_app = "TestApp/v1.0" service = ShareServiceClient( - self.account_url(storage_account_name, "file"), credential=self.account_key.secret, user_agent=custom_app) + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret, + user_agent=custom_app + ) def callback1(response): assert 'User-Agent' in response.http_request.headers @@ -525,7 +578,10 @@ async def test_user_agent_append(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key.secret) + service = ShareServiceClient( + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret + ) def callback(response): assert 'User-Agent' in response.http_request.headers @@ -546,7 +602,12 @@ async def test_closing_pipeline_client(self, **kwargs): for client, url in SERVICES.items(): # Act service = client( - self.account_url(storage_account_name, "file"), credential=self.account_key.secret, share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret, + share_name='foo', + directory_path='bar', + file_path='baz' + ) # Assert async with service: @@ -563,5 +624,10 @@ async def test_closing_pipeline_client_simple(self, **kwargs): for client, url in SERVICES.items(): # Act service = client( - self.account_url(storage_account_name, "file"), credential=self.account_key.secret, share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key.secret, + share_name='foo', + directory_path='bar', + file_path='baz' + ) await service.close() diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_service_properties.py b/sdk/storage/azure-storage-file-share/tests/test_file_service_properties.py index 5681e5181e52..fd755112173c 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_service_properties.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_service_properties.py @@ -6,6 +6,11 @@ import os import pytest + +from devtools_testutils import recorded_by_proxy +from devtools_testutils.storage import StorageRecordedTestCase +from settings.testcase import FileSharePreparer + from azure.core.exceptions import HttpResponseError from azure.storage.fileshare import ( CorsRule, @@ -15,12 +20,9 @@ ShareServiceClient, ShareSmbSettings, SmbEncryptionInTransit, - SmbMultichannel + SmbMultichannel, ) -from devtools_testutils import recorded_by_proxy -from devtools_testutils.storage import StorageRecordedTestCase -from settings.testcase import FileSharePreparer # ------------------------------------------------------------------------------ @@ -55,8 +57,7 @@ def _assert_cors_equal(self, cors1, cors2): assert len(cors1) == len(cors2) - for i in range(0, len(cors1)): - rule1 = cors1[i] + for i, rule1 in enumerate(cors1): rule2 = cors2[i] assert len(rule1.allowed_origins) == len(rule2.allowed_origins) assert len(rule1.allowed_methods) == len(rule2.allowed_methods) @@ -105,7 +106,7 @@ def test_file_service_properties(self, **kwargs): assert props['protocol'].smb.encryption_in_transit.required == False with pytest.raises(TypeError): - ShareProtocolSettings(smb=ShareSmbSettings(multichannel=SmbMultichannel())) + ShareProtocolSettings(smb=ShareSmbSettings(multichannel=SmbMultichannel())) # pylint: disable=missing-kwoa with pytest.raises(ValueError): ShareProtocolSettings(smb=ShareSmbSettings()) with pytest.raises(ValueError): @@ -211,10 +212,6 @@ def test_too_many_cors_rules(self, **kwargs): cors.append(CorsRule(['www.xyz.com'], ['GET'])) # Assert - pytest.raises(HttpResponseError, - self.fsc.set_service_properties, - None, None, cors) - + pytest.raises(HttpResponseError, self.fsc.set_service_properties, None, None, cors) # ------------------------------------------------------------------------------ - diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_service_properties_async.py b/sdk/storage/azure-storage-file-share/tests/test_file_service_properties_async.py index ef369db70060..95730f32b8a5 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_service_properties_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_service_properties_async.py @@ -8,6 +8,11 @@ import os import pytest + +from devtools_testutils.aio import recorded_by_proxy_async +from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase +from settings.testcase import FileSharePreparer + from azure.core.exceptions import HttpResponseError from azure.storage.fileshare import ( CorsRule, @@ -16,14 +21,10 @@ ShareProtocolSettings, ShareSmbSettings, SmbEncryptionInTransit, - SmbMultichannel + SmbMultichannel, ) from azure.storage.fileshare.aio import ShareServiceClient -from devtools_testutils.aio import recorded_by_proxy_async -from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase -from settings.testcase import FileSharePreparer - # ------------------------------------------------------------------------------ @@ -58,8 +59,7 @@ def _assert_cors_equal(self, cors1, cors2): assert len(cors1) == len(cors2) - for i in range(0, len(cors1)): - rule1 = cors1[i] + for i, rule1 in enumerate(cors1): rule2 = cors2[i] assert len(rule1.allowed_origins) == len(rule2.allowed_origins) assert len(rule1.allowed_methods) == len(rule2.allowed_methods) @@ -108,7 +108,7 @@ async def test_file_service_properties(self, **kwargs): assert props['protocol'].smb.encryption_in_transit.required == False with pytest.raises(TypeError): - ShareProtocolSettings(smb=ShareSmbSettings(multichannel=SmbMultichannel())) + ShareProtocolSettings(smb=ShareSmbSettings(multichannel=SmbMultichannel())) # pylint: disable=missing-kwoa with pytest.raises(ValueError): ShareProtocolSettings(smb=ShareSmbSettings()) with pytest.raises(ValueError): diff --git a/sdk/storage/azure-storage-file-share/tests/test_get_file.py b/sdk/storage/azure-storage-file-share/tests/test_get_file.py index 59362970ae2a..f9ab7720b2b3 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_get_file.py +++ b/sdk/storage/azure-storage-file-share/tests/test_get_file.py @@ -4,20 +4,20 @@ # license information. # -------------------------------------------------------------------------- import base64 -import os import tempfile -import uuid from io import BytesIO import pytest -from azure.core.exceptions import HttpResponseError, ResourceModifiedError -from azure.storage.fileshare import ShareFileClient, ShareServiceClient from devtools_testutils import recorded_by_proxy from devtools_testutils.storage import StorageRecordedTestCase from settings.testcase import FileSharePreparer from test_helpers import ProgressTracker +from azure.core.exceptions import HttpResponseError, ResourceModifiedError +from azure.storage.fileshare import ShareFileClient, ShareServiceClient + + # ------------------------------------------------------------------------------ TEST_FILE_PREFIX = 'file' # ------------------------------------------------------------------------------ @@ -73,7 +73,7 @@ def write(self, data): def read(self, count): return self.wrapped_file.read(count) - + def seekable(self): return False @@ -86,7 +86,7 @@ def test_unicode_get_file_unicode_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_data = u'hello world啊齄丂狛狜'.encode('utf-8') + file_data = 'hello world啊齄丂狛狜'.encode('utf-8') file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), @@ -110,7 +110,22 @@ def test_unicode_get_file_binary_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - base64_data = 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==' + base64_data = ( + 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0' + 'xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYm' + 'ZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm' + '5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM' + '0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gI' + 'GCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNz' + 's/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRob' + 'HB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2h' + 'pamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tb' + 'a3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECA' + 'wQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9Q' + 'UVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2' + 'en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6' + 'uvs7e7v8PHy8/T19vf4+fr7/P3+/w==' + ) binary_data = base64.b64decode(base64_data) file_name = self._get_file_reference() @@ -541,7 +556,8 @@ def callback(response): # Act with tempfile.TemporaryFile() as temp_file: - bytes_read = snapshot_client.download_file(raw_response_hook=callback, max_concurrency=2).readinto(temp_file) + bytes_read = snapshot_client.download_file( + raw_response_hook=callback, max_concurrency=2).readinto(temp_file) # Assert assert isinstance(bytes_read, int) temp_file.seek(0) @@ -584,7 +600,8 @@ def callback(response): # Act with tempfile.TemporaryFile() as temp_file: - bytes_read = snapshot_client.download_file(raw_response_hook=callback, max_concurrency=1).readinto(temp_file) + bytes_read = snapshot_client.download_file( + raw_response_hook=callback, max_concurrency=1).readinto(temp_file) # Assert assert isinstance(bytes_read, int) temp_file.seek(0) @@ -631,7 +648,8 @@ def callback(response): # Act with tempfile.TemporaryFile() as temp_file: - bytes_read = snapshot_client.download_file(raw_response_hook=callback, max_concurrency=1).readinto(temp_file) + bytes_read = snapshot_client.download_file( + raw_response_hook=callback, max_concurrency=1).readinto(temp_file) # Assert assert isinstance(bytes_read, int) temp_file.seek(0) @@ -1023,7 +1041,7 @@ def test_get_file_to_text_with_encoding(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - text = u'hello 啊齄丂狛狜 world' + text = 'hello 啊齄丂狛狜 world' data = text.encode('utf-16') file_name = self._get_file_reference() file_client = ShareFileClient( @@ -1048,7 +1066,7 @@ def test_get_file_to_text_with_encoding_and_progress(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - text = u'hello 啊齄丂狛狜 world' + text = 'hello 啊齄丂狛狜 world' data = text.encode('utf-16') file_name = self._get_file_reference() file_client = ShareFileClient( @@ -1345,7 +1363,7 @@ def test_get_file_server_encryption(self, **kwargs): # Act file_content = file_client.download_file(offset=0, length=1024, validate_content=True) - + # Assert assert file_content.properties.server_encrypted diff --git a/sdk/storage/azure-storage-file-share/tests/test_get_file_async.py b/sdk/storage/azure-storage-file-share/tests/test_get_file_async.py index f60f2a3eb683..c15f490834e4 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_get_file_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_get_file_async.py @@ -4,21 +4,21 @@ # license information. # -------------------------------------------------------------------------- import base64 -import os import tempfile -import uuid from io import BytesIO import pytest -from azure.core.exceptions import HttpResponseError, ResourceModifiedError -from azure.storage.fileshare import FileProperties -from azure.storage.fileshare.aio import ShareFileClient, ShareServiceClient from devtools_testutils.aio import recorded_by_proxy_async from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase from settings.testcase import FileSharePreparer from test_helpers_async import ProgressTracker +from azure.core.exceptions import HttpResponseError, ResourceModifiedError +from azure.storage.fileshare import FileProperties +from azure.storage.fileshare.aio import ShareFileClient, ShareServiceClient + + # ------------------------------------------------------------------------------ TEST_FILE_PREFIX = 'file' # ------------------------------------------------------------------------------ @@ -74,7 +74,7 @@ def write(self, data): def read(self, count): return self.wrapped_file.read(count) - + def seekable(self): return False @@ -88,7 +88,7 @@ async def test_unicode_get_file_unicode_data(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - file_data = u'hello world啊齄丂狛狜'.encode('utf-8') + file_data = 'hello world啊齄丂狛狜'.encode('utf-8') file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), @@ -114,7 +114,22 @@ async def test_unicode_get_file_binary_data(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - base64_data = 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==' + base64_data = ( + 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0' + 'xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYm' + 'ZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm' + '5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM' + '0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gI' + 'GCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNz' + 's/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRob' + 'HB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2h' + 'pamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tb' + 'a3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECA' + 'wQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9Q' + 'UVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2' + 'en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6' + 'uvs7e7v8PHy8/T19vf4+fr7/P3+/w==' + ) binary_data = base64.b64decode(base64_data) file_name = self._get_file_reference() @@ -814,7 +829,12 @@ def callback(response): temp_file.seek(0) actual = temp_file.read() assert self.byte_data[start_range:end_range + 1] == actual - self.assert_download_progress(end_range - start_range + 1, self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) + self.assert_download_progress( + end_range - start_range + 1, + self.MAX_CHUNK_GET_SIZE, + self.MAX_SINGLE_GET_SIZE, + progress + ) @FileSharePreparer() @recorded_by_proxy_async @@ -1092,7 +1112,7 @@ async def test_get_file_to_text_with_encoding(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - text = u'hello 啊齄丂狛狜 world' + text = 'hello 啊齄丂狛狜 world' data = text.encode('utf-16') file_name = self._get_file_reference() file_client = ShareFileClient( @@ -1119,7 +1139,7 @@ async def test_get_file_to_text_with_encoding_and_progress(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - text = u'hello 啊齄丂狛狜 world' + text = 'hello 啊齄丂狛狜 world' data = text.encode('utf-16') file_name = self._get_file_reference() file_client = ShareFileClient( @@ -1437,7 +1457,7 @@ async def test_get_file_server_encryption(self, **kwargs): # Act file_content = await file_client.download_file(offset=0, length=1024, validate_content=True) - + # Assert assert file_content.properties.server_encrypted @@ -1588,4 +1608,3 @@ async def test_get_file_progress_range_readinto(self, **kwargs): # Assert progress.assert_complete() assert length == read - diff --git a/sdk/storage/azure-storage-file-share/tests/test_handle_async.py b/sdk/storage/azure-storage-file-share/tests/test_handle_async.py index b6f00fa9f6ef..8b540ea2074f 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_handle_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_handle_async.py @@ -3,15 +3,17 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import unittest -import pytest -from azure.storage.fileshare.aio import ShareServiceClient +import unittest from devtools_testutils.aio import recorded_by_proxy_async from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase from settings.testcase import FileSharePreparer +import pytest +from azure.storage.fileshare.aio import ShareServiceClient + + # ------------------------------------------------------------------------------ TEST_SHARE_NAME = 'test-share' # ------------------------------------------------------------------------------ diff --git a/sdk/storage/azure-storage-file-share/tests/test_helpers_async.py b/sdk/storage/azure-storage-file-share/tests/test_helpers_async.py index 0a7da86e53aa..7f8fe5970760 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_helpers_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_helpers_async.py @@ -8,11 +8,12 @@ from collections import deque from typing import Any, Dict, Optional -from azure.core.pipeline.transport import AioHttpTransportResponse, AsyncHttpTransport -from azure.core.rest import HttpRequest from aiohttp import ClientResponse -from aiohttp.streams import StreamReader from aiohttp.client_proto import ResponseHandler +from aiohttp.streams import StreamReader + +from azure.core.pipeline.transport import AioHttpTransportResponse, AsyncHttpTransport # pylint: disable=no-name-in-module +from azure.core.rest import HttpRequest class ProgressTracker: diff --git a/sdk/storage/azure-storage-file-share/tests/test_nfs_async.py b/sdk/storage/azure-storage-file-share/tests/test_nfs_async.py index 52b17b157346..3f368e15b851 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_nfs_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_nfs_async.py @@ -3,28 +3,25 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import pytest + from typing import Any, Dict, Optional, Union from urllib.parse import unquote -from azure.core.exceptions import ( - ClientAuthenticationError, - HttpResponseError, - ResourceExistsError, - ResourceNotFoundError -) +import pytest + +from devtools_testutils.aio import recorded_by_proxy_async +from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase +from settings.testcase import FileSharePreparer + +from azure.core.exceptions import ResourceNotFoundError from azure.storage.fileshare import ( ContentSettings, DirectoryProperties, FileProperties, - ShareServiceClient + ShareServiceClient, ) +from azure.storage.fileshare.aio import ShareDirectoryClient, ShareFileClient from azure.storage.fileshare.aio import ShareServiceClient as AsyncShareServiceClient -from azure.storage.fileshare.aio import ShareFileClient, ShareDirectoryClient - -from devtools_testutils.aio import recorded_by_proxy_async -from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase -from settings.testcase import FileSharePreparer TEST_INTENT = 'backup' From 840119bf891c1908c2053c3d7ac51213028fdf1f Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 8 May 2026 16:48:51 -0400 Subject: [PATCH 4/8] Copilot feedback --- .../azure-storage-file-share/tests/test_directory.py | 2 +- .../tests/test_directory_async.py | 2 +- .../azure-storage-file-share/tests/test_file.py | 2 +- .../azure-storage-file-share/tests/test_file_async.py | 2 +- .../tests/test_file_client.py | 2 +- .../tests/test_file_client_async.py | 2 +- .../tests/test_share_async.py | 11 ++++++----- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/tests/test_directory.py b/sdk/storage/azure-storage-file-share/tests/test_directory.py index 1dd881466170..72ad5cc0030c 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_directory.py +++ b/sdk/storage/azure-storage-file-share/tests/test_directory.py @@ -1283,7 +1283,7 @@ def test_rename_directory_smb_properties(self, **kwargs): props = new_directory.get_directory_properties() assert props is not None assert props.is_directory - assert str(file_attributes), props.file_attributes.replace(' ', '') + assert str(file_attributes).replace(' ', '') == props.file_attributes.replace(' ', '') assert file_creation_time == props.creation_time assert file_last_write_time == props.last_write_time assert file_change_time == props.change_time diff --git a/sdk/storage/azure-storage-file-share/tests/test_directory_async.py b/sdk/storage/azure-storage-file-share/tests/test_directory_async.py index fde85260ceae..70397a88c842 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_directory_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_directory_async.py @@ -1383,7 +1383,7 @@ async def test_rename_directory_smb_properties(self, **kwargs): props = await new_directory.get_directory_properties() assert props is not None assert props.is_directory - assert str(file_attributes), props.file_attributes.replace(' ', '') + assert str(file_attributes) == props.file_attributes.replace(' ', '') assert file_creation_time == props.creation_time assert file_last_write_time == props.last_write_time assert file_change_time == props.change_time diff --git a/sdk/storage/azure-storage-file-share/tests/test_file.py b/sdk/storage/azure-storage-file-share/tests/test_file.py index 02c3eb27d437..0ab9522021e2 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file.py @@ -3649,7 +3649,7 @@ def test_rename_file_smb_properties(self, **kwargs): # Assert props = new_file.get_file_properties() assert props is not None - assert str(file_attributes), props.file_attributes.replace(' ', '') + assert str(file_attributes).replace(' ', '') == props.file_attributes.replace(' ', '') assert file_creation_time == props.creation_time assert file_last_write_time == props.last_write_time assert file_change_time == props.change_time diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_async.py b/sdk/storage/azure-storage-file-share/tests/test_file_async.py index 2e1f0ea3df3a..1d776aa8306c 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_async.py @@ -3802,7 +3802,7 @@ async def test_rename_file_smb_properties(self, **kwargs): # Assert props = await new_file.get_file_properties() assert props is not None - assert str(file_attributes), props.file_attributes.replace(' ', '') + assert str(file_attributes).replace(' ', '') == props.file_attributes.replace(' ', ''), props.file_attributes assert file_creation_time == props.creation_time assert file_last_write_time == props.last_write_time assert file_change_time == props.change_time diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_client.py b/sdk/storage/azure-storage-file-share/tests/test_file_client.py index cefdd9cbea35..5f2e492f8e8c 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_client.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_client.py @@ -502,7 +502,7 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): # py assert service.account_name == None assert service.share_name == "foo" assert service.directory_path == "bar/baz" - assert service.file_path, ["bar", "baz", "file"] + assert service.file_path == ["bar", "baz", "file"] assert service.file_name == "file" assert service.snapshot == "snap" assert service.credential == None diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_client_async.py b/sdk/storage/azure-storage-file-share/tests/test_file_client_async.py index d0c4adb3129a..ba315d445f0c 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_client_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_client_async.py @@ -502,7 +502,7 @@ async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.account_name == None assert service.share_name == "foo" assert service.directory_path == "bar/baz" - assert service.file_path, ["bar", "baz", "file"] + assert service.file_path == ["bar", "baz", "file"] assert service.file_name == "file" assert service.snapshot == "snap" assert service.credential == None diff --git a/sdk/storage/azure-storage-file-share/tests/test_share_async.py b/sdk/storage/azure-storage-file-share/tests/test_share_async.py index 0c1c248cec0c..60808f1f301d 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_share_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_share_async.py @@ -61,12 +61,13 @@ def _teardown(self, FILE_PATH): except: pass - async def _delete_shares(self, prefix=TEST_SHARE_PREFIX): # pylint: disable=unused-argument + async def _delete_shares(self, prefix=TEST_SHARE_PREFIX): async for l in self.fsc.list_shares(include_snapshots=True): - try: - await self.fsc.delete_share(l.name, delete_snapshots=True) - except: - pass + if l.name.startswith(prefix): + try: + await self.fsc.delete_share(l.name, delete_snapshots=True) + except: + pass # --Helpers----------------------------------------------------------------- def _get_share_reference(self, prefix=TEST_SHARE_PREFIX): From 34c20f5dee4c19680d3cde3888e689ed3a65d247 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 8 May 2026 16:53:37 -0400 Subject: [PATCH 5/8] PR feedbacks --- sdk/storage/azure-storage-file-share/tests/test_share.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/tests/test_share.py b/sdk/storage/azure-storage-file-share/tests/test_share.py index 71d3a94eacc7..b285108231d4 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_share.py +++ b/sdk/storage/azure-storage-file-share/tests/test_share.py @@ -76,10 +76,6 @@ def _create_share(self, prefix=TEST_SHARE_PREFIX, **kwargs): pass return share_client - def _create_share_if_not_exists(self, prefix=TEST_SHARE_PREFIX, **kwargs): - share_client = self._get_share_reference(prefix) - return share_client.create_share_if_not_exists(**kwargs) # pylint: disable=no-member - def _delete_shares(self, prefix=TEST_SHARE_PREFIX): # pylint: disable=unused-argument for l in self.fsc.list_shares(include_snapshots=True): try: From e2b12705dece40b30181c35e4355a105a0558e1c Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 11 May 2026 11:44:57 -0400 Subject: [PATCH 6/8] Feedback --- .../azure-storage-file-share/tests/test_share.py | 11 ++++++----- sdk/storage/cspell.yaml | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/tests/test_share.py b/sdk/storage/azure-storage-file-share/tests/test_share.py index b285108231d4..a51e1f0b3878 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_share.py +++ b/sdk/storage/azure-storage-file-share/tests/test_share.py @@ -76,12 +76,13 @@ def _create_share(self, prefix=TEST_SHARE_PREFIX, **kwargs): pass return share_client - def _delete_shares(self, prefix=TEST_SHARE_PREFIX): # pylint: disable=unused-argument + def _delete_shares(self, prefix=TEST_SHARE_PREFIX): for l in self.fsc.list_shares(include_snapshots=True): - try: - self.fsc.delete_share(l.name, delete_snapshots=True) - except: - pass + if l.name.startswith(prefix): + try: + self.fsc.delete_share(l.name, delete_snapshots=True) + except: + pass # --Test cases for shares ----------------------------------------- def test_create_share_client(self): diff --git a/sdk/storage/cspell.yaml b/sdk/storage/cspell.yaml index 46f7c0371048..cf352af546b1 100644 --- a/sdk/storage/cspell.yaml +++ b/sdk/storage/cspell.yaml @@ -22,3 +22,4 @@ words: - testdir2async - testdirasync - oauthdir + - kwoa From 4ef467b2302e937ce23ea013ab1aa3bee162b1cc Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 11 May 2026 15:03:15 -0400 Subject: [PATCH 7/8] Test failures --- .../tests/test_share_async.py | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/tests/test_share_async.py b/sdk/storage/azure-storage-file-share/tests/test_share_async.py index 60808f1f301d..1c109bedc581 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_share_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_share_async.py @@ -1425,7 +1425,7 @@ async def test_list_directories_and_files(self, **kwargs): self.assertNamedItemInContainer(resp, 'dir1') self.assertNamedItemInContainer(resp, 'dir2') self.assertNamedItemInContainer(resp, 'file1') - await self._delete_shares(share) + await self._delete_shares(share.share_name) @FileSharePreparer() @recorded_by_proxy_async @@ -1434,20 +1434,19 @@ async def test_list_directories_and_files_with_snapshot(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_name = await self._create_share() - dir1 = share_name.get_directory_client('dir1') + share = await self._create_share() + dir1 = share.get_directory_client('dir1') await dir1.create_directory() - dir2 = share_name.get_directory_client('dir2') + dir2 = share.get_directory_client('dir2') await dir2.create_directory() - snapshot1 = await share_name.create_snapshot() - dir3 = share_name.get_directory_client('dir3') + snapshot1 = await share.create_snapshot() + dir3 = share.get_directory_client('dir3') await dir3.create_directory() - file1 = share_name.get_file_client('file1') + file1 = share.get_file_client('file1') await file1.upload_file('data') - # Act - snapshot_client = self.fsc.get_share_client(share_name.share_name, snapshot=snapshot1) + snapshot_client = self.fsc.get_share_client(share.share_name, snapshot=snapshot1) resp = [] async for d in snapshot_client.list_directories_and_files(): resp.append(d) @@ -1458,7 +1457,7 @@ async def test_list_directories_and_files_with_snapshot(self, **kwargs): assert resp[0] is not None self.assertNamedItemInContainer(resp, 'dir1') self.assertNamedItemInContainer(resp, 'dir2') - await self._delete_shares(share_name) + await self._delete_shares(share.share_name) @FileSharePreparer() @recorded_by_proxy_async @@ -1467,16 +1466,16 @@ async def test_list_directories_and_files_with_num_results(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_name = await self._create_share() - dir1 = await share_name.create_directory('dir1') - root = share_name.get_directory_client() + share = await self._create_share() + await share.create_directory('dir1') + root = share.get_directory_client() await root.upload_file('filea1', '1024') await root.upload_file('filea2', '1024') await root.upload_file('filea3', '1024') await root.upload_file('fileb1', '1024') # Act - result = share_name.list_directories_and_files(results_per_page=2).by_page() + result = share.list_directories_and_files(results_per_page=2).by_page() results = [] async for r in await result.__anext__(): results.append(r) @@ -1486,7 +1485,7 @@ async def test_list_directories_and_files_with_num_results(self, **kwargs): assert len(results) == 2 self.assertNamedItemInContainer(results, 'dir1') self.assertNamedItemInContainer(results, 'filea1') - await self._delete_shares(share_name) + await self._delete_shares(share.share_name) @FileSharePreparer() @recorded_by_proxy_async @@ -1495,8 +1494,8 @@ async def test_list_directories_and_files_with_num_results_and_marker(self, **kw storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_name = await self._create_share() - dir1 = share_name.get_directory_client('dir1') + share = await self._create_share() + dir1 = share.get_directory_client('dir1') await dir1.create_directory() await dir1.upload_file('filea1', '1024') await dir1.upload_file('filea2', '1024') @@ -1504,13 +1503,13 @@ async def test_list_directories_and_files_with_num_results_and_marker(self, **kw await dir1.upload_file('fileb1', '1024') # Act - generator1 = share_name.list_directories_and_files( + generator1 = share.list_directories_and_files( 'dir1', results_per_page=2).by_page() result1 = [] async for r in await generator1.__anext__(): result1.append(r) - generator2 = share_name.list_directories_and_files( + generator2 = share.list_directories_and_files( 'dir1', results_per_page=2).by_page(continuation_token=generator1.continuation_token) result2 = [] async for r in await generator2.__anext__(): @@ -1524,7 +1523,7 @@ async def test_list_directories_and_files_with_num_results_and_marker(self, **kw self.assertNamedItemInContainer(result2, 'filea3') self.assertNamedItemInContainer(result2, 'fileb1') assert generator2.continuation_token == None - await self._delete_shares(share_name) + await self._delete_shares(share.share_name) @FileSharePreparer() @recorded_by_proxy_async @@ -1554,7 +1553,7 @@ async def test_list_directories_and_files_with_prefix(self, **kwargs): assert resp[0] is not None self.assertNamedItemInContainer(resp, 'pref_file2') self.assertNamedItemInContainer(resp, 'pref_dir3') - await self._delete_shares(share) + await self._delete_shares(share.share_name) @pytest.mark.live_test_only @FileSharePreparer() From 25f76f3855bd287681a55aec18337c40775a306d Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 11 May 2026 17:51:37 -0400 Subject: [PATCH 8/8] Removed unnecessary call --- .../tests/test_file_service_properties.py | 2 -- .../tests/test_file_service_properties_async.py | 2 -- sdk/storage/cspell.yaml | 1 - 3 files changed, 5 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_service_properties.py b/sdk/storage/azure-storage-file-share/tests/test_file_service_properties.py index fd755112173c..eee68273f57a 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_service_properties.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_service_properties.py @@ -105,8 +105,6 @@ def test_file_service_properties(self, **kwargs): assert props['protocol'].smb.multichannel.enabled == False assert props['protocol'].smb.encryption_in_transit.required == False - with pytest.raises(TypeError): - ShareProtocolSettings(smb=ShareSmbSettings(multichannel=SmbMultichannel())) # pylint: disable=missing-kwoa with pytest.raises(ValueError): ShareProtocolSettings(smb=ShareSmbSettings()) with pytest.raises(ValueError): diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_service_properties_async.py b/sdk/storage/azure-storage-file-share/tests/test_file_service_properties_async.py index 95730f32b8a5..56479ca76e49 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_service_properties_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_service_properties_async.py @@ -107,8 +107,6 @@ async def test_file_service_properties(self, **kwargs): assert props['protocol'].smb.multichannel.enabled == False assert props['protocol'].smb.encryption_in_transit.required == False - with pytest.raises(TypeError): - ShareProtocolSettings(smb=ShareSmbSettings(multichannel=SmbMultichannel())) # pylint: disable=missing-kwoa with pytest.raises(ValueError): ShareProtocolSettings(smb=ShareSmbSettings()) with pytest.raises(ValueError): diff --git a/sdk/storage/cspell.yaml b/sdk/storage/cspell.yaml index cf352af546b1..46f7c0371048 100644 --- a/sdk/storage/cspell.yaml +++ b/sdk/storage/cspell.yaml @@ -22,4 +22,3 @@ words: - testdir2async - testdirasync - oauthdir - - kwoa