From 0e83f64050accef394ee53338cb7b21b25391c78 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 28 May 2025 16:45:20 -0700 Subject: [PATCH] Fix doc issues and run black --- .../azure/__init__.py | 2 +- .../azure/storage/__init__.py | 2 +- .../azure/storage/fileshare/__init__.py | 81 +- .../azure/storage/fileshare/_deserialize.py | 48 +- .../storage/fileshare/_directory_client.py | 351 ++--- .../fileshare/_directory_client_helpers.py | 24 +- .../azure/storage/fileshare/_download.py | 55 +- .../azure/storage/fileshare/_file_client.py | 623 +++++---- .../storage/fileshare/_file_client_helpers.py | 97 +- .../azure/storage/fileshare/_lease.py | 78 +- .../azure/storage/fileshare/_models.py | 394 +++--- .../azure/storage/fileshare/_parser.py | 16 +- .../azure/storage/fileshare/_serialize.py | 126 +- .../azure/storage/fileshare/_share_client.py | 415 +++--- .../fileshare/_share_client_helpers.py | 23 +- .../fileshare/_share_service_client.py | 156 ++- .../_share_service_client_helpers.py | 2 +- .../storage/fileshare/_shared/base_client.py | 22 +- .../azure/storage/fileshare/_shared/models.py | 1 + .../storage/fileshare/_shared/policies.py | 34 +- .../fileshare/_shared/policies_async.py | 24 + .../fileshare/_shared_access_signature.py | 90 +- .../azure/storage/fileshare/aio/__init__.py | 12 +- .../fileshare/aio/_directory_client_async.py | 365 ++--- .../storage/fileshare/aio/_download_async.py | 118 +- .../fileshare/aio/_file_client_async.py | 631 +++++---- .../storage/fileshare/aio/_lease_async.py | 79 +- .../azure/storage/fileshare/aio/_models.py | 59 +- .../fileshare/aio/_share_client_async.py | 426 +++--- .../aio/_share_service_client_async.py | 163 ++- .../samples/file_samples_authentication.py | 75 +- .../file_samples_authentication_async.py | 75 +- .../samples/file_samples_client.py | 30 +- .../samples/file_samples_client_async.py | 23 +- .../samples/file_samples_directory.py | 28 +- .../samples/file_samples_directory_async.py | 29 +- .../samples/file_samples_hello_world.py | 32 +- .../samples/file_samples_hello_world_async.py | 38 +- .../samples/file_samples_service.py | 39 +- .../samples/file_samples_service_async.py | 45 +- .../samples/file_samples_share.py | 52 +- .../samples/file_samples_share_async.py | 47 +- sdk/storage/azure-storage-file-share/setup.py | 72 +- .../tests/conftest.py | 3 +- .../tests/encryption_test_helper.py | 44 +- .../T1_legacy_tests/_test_base.py | 30 +- .../T1_legacy_tests/download.py | 9 +- .../T1_legacy_tests/download_to_file.py | 9 +- .../T1_legacy_tests/upload.py | 3 +- .../T1_legacy_tests/upload_from_file.py | 3 +- .../tests/perfstress_tests/_test_base.py | 41 +- .../tests/perfstress_tests/upload.py | 10 +- .../perfstress_tests/upload_from_file.py | 4 +- .../tests/settings/settings_fake.py | 2 +- .../tests/settings/testcase.py | 38 +- .../tests/test_directory.py | 504 +++---- .../tests/test_directory_async.py | 552 ++++---- .../tests/test_file.py | 1124 ++++++++------- .../tests/test_file_api_version.py | 79 +- .../tests/test_file_api_version_async.py | 79 +- .../tests/test_file_async.py | 1210 +++++++++-------- .../tests/test_file_client.py | 290 ++-- .../tests/test_file_client_async.py | 275 ++-- .../tests/test_file_service_properties.py | 50 +- .../test_file_service_properties_async.py | 41 +- .../tests/test_get_file.py | 520 +++---- .../tests/test_get_file_async.py | 509 +++---- .../tests/test_handle.py | 37 +- .../tests/test_handle_async.py | 24 +- .../tests/test_helpers.py | 27 +- .../tests/test_helpers_async.py | 29 +- .../tests/test_nfs.py | 167 +-- .../tests/test_nfs_async.py | 176 ++- .../tests/test_share.py | 414 +++--- .../tests/test_share_async.py | 396 +++--- 75 files changed, 6403 insertions(+), 5398 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/azure/__init__.py b/sdk/storage/azure-storage-file-share/azure/__init__.py index 0c36c2076ba0..d55ccad1f573 100644 --- a/sdk/storage/azure-storage-file-share/azure/__init__.py +++ b/sdk/storage/azure-storage-file-share/azure/__init__.py @@ -1 +1 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore +__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore diff --git a/sdk/storage/azure-storage-file-share/azure/storage/__init__.py b/sdk/storage/azure-storage-file-share/azure/storage/__init__.py index 0c36c2076ba0..d55ccad1f573 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/__init__.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/__init__.py @@ -1 +1 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore +__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/__init__.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/__init__.py index be8da9c27a60..e7a339efd9a4 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/__init__.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/__init__.py @@ -8,6 +8,7 @@ from ._version import VERSION from ._file_client import ShareFileClient from ._directory_client import ShareDirectoryClient +from ._download import StorageStreamDownloader from ._share_client import ShareClient from ._share_service_client import ShareServiceClient from ._lease import ShareLeaseClient @@ -38,48 +39,46 @@ ContentSettings, NTFSAttributes, ) -from ._generated.models import ( - ShareAccessTier, - ShareRootSquash -) +from ._generated.models import ShareAccessTier, ShareRootSquash __version__ = VERSION __all__ = [ - 'ShareFileClient', - 'ShareDirectoryClient', - 'ShareClient', - 'ShareServiceClient', - 'ShareLeaseClient', - 'ExponentialRetry', - 'LinearRetry', - 'LocationMode', - 'ResourceTypes', - 'AccountSasPermissions', - 'StorageErrorCode', - 'Metrics', - 'RetentionPolicy', - 'CorsRule', - 'ShareSmbSettings', - 'ShareAccessTier', - 'SmbMultichannel', - 'ShareProtocolSettings', - 'AccessPolicy', - 'FileSasPermissions', - 'ShareSasPermissions', - 'ShareProtocols', - 'ShareProperties', - 'DirectoryProperties', - 'FileProperties', - 'ContentSettings', - 'Handle', - 'NTFSAttributes', - 'ShareRootSquash', - 'generate_account_sas', - 'generate_share_sas', - 'generate_file_sas', - 'Services' + "ShareFileClient", + "ShareDirectoryClient", + "ShareClient", + "ShareServiceClient", + "ShareLeaseClient", + "ExponentialRetry", + "LinearRetry", + "LocationMode", + "ResourceTypes", + "AccountSasPermissions", + "StorageErrorCode", + "Metrics", + "RetentionPolicy", + "CorsRule", + "ShareSmbSettings", + "ShareAccessTier", + "SmbMultichannel", + "ShareProtocolSettings", + "AccessPolicy", + "FileSasPermissions", + "ShareSasPermissions", + "ShareProtocols", + "ShareProperties", + "DirectoryProperties", + "FileProperties", + "ContentSettings", + "Handle", + "NTFSAttributes", + "ShareRootSquash", + "generate_account_sas", + "generate_share_sas", + "generate_file_sas", + "Services", + "StorageStreamDownloader", ] @@ -88,12 +87,10 @@ # to prevent it from showing in intellisense/docs but we handle it here to prevent # breaking any existing code which may have imported it. def __getattr__(name): - if name == 'HandleItem': + if name == "HandleItem": from ._generated.models import HandleItem - warnings.warn( - "HandleItem is deprecated and should not be used. Use Handle instead.", - DeprecationWarning - ) + + warnings.warn("HandleItem is deprecated and should not be used. Use Handle instead.", DeprecationWarning) return HandleItem raise AttributeError(f"module 'azure.storage.fileshare' has no attribute {name}") diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_deserialize.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_deserialize.py index 5db600d5f5ed..e9119934c63d 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_deserialize.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_deserialize.py @@ -3,10 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # --------------------------------------------------------------------------_ -from typing import ( - Any, cast, Dict, List, Optional, Tuple, - TYPE_CHECKING -) +from typing import Any, cast, Dict, List, Optional, Tuple, TYPE_CHECKING from ._generated.models import ShareFileRangeList from ._models import DirectoryProperties, FileProperties, ShareProperties @@ -19,44 +16,31 @@ def deserialize_share_properties(response: "PipelineResponse", obj: Any, headers: Dict[str, Any]) -> ShareProperties: metadata = deserialize_metadata(response, obj, headers) - share_properties = ShareProperties( - metadata=metadata, - **headers - ) + share_properties = ShareProperties(metadata=metadata, **headers) return share_properties def deserialize_directory_properties( - response: "PipelineResponse", - obj: Any, - headers: Dict[str, Any] + response: "PipelineResponse", obj: Any, headers: Dict[str, Any] ) -> DirectoryProperties: metadata = deserialize_metadata(response, obj, headers) - directory_properties = DirectoryProperties( - metadata=metadata, - **headers - ) + directory_properties = DirectoryProperties(metadata=metadata, **headers) return directory_properties def deserialize_file_properties(response: "PipelineResponse", obj: Any, headers: Dict[str, Any]) -> FileProperties: metadata = deserialize_metadata(response, obj, headers) - file_properties = FileProperties( - metadata=metadata, - **headers - ) - if 'Content-Range' in headers: - if 'x-ms-content-md5' in headers: - file_properties.content_settings.content_md5 = headers['x-ms-content-md5'] + file_properties = FileProperties(metadata=metadata, **headers) + if "Content-Range" in headers: + if "x-ms-content-md5" in headers: + file_properties.content_settings.content_md5 = headers["x-ms-content-md5"] else: file_properties.content_settings.content_md5 = None return file_properties def deserialize_file_stream( - response: "PipelineResponse", - obj: Any, - headers: Dict[str, Any] + response: "PipelineResponse", obj: Any, headers: Dict[str, Any] ) -> Tuple["LocationMode", Any]: file_properties = deserialize_file_properties(response, obj, headers) obj.properties = file_properties @@ -64,22 +48,26 @@ def deserialize_file_stream( # Extracts out file permission -def deserialize_permission(response: "PipelineResponse", obj: Any, headers: Dict[str, Any]) -> Optional[str]: # pylint: disable=unused-argument +def deserialize_permission( + response: "PipelineResponse", obj: Any, headers: Dict[str, Any] +) -> Optional[str]: # pylint: disable=unused-argument return cast(Optional[str], obj.permission) # Extracts out file permission key -def deserialize_permission_key(response: "PipelineResponse", obj: Any, headers: Dict[str, Any]) -> Optional[str]: # pylint: disable=unused-argument +def deserialize_permission_key( + response: "PipelineResponse", obj: Any, headers: Dict[str, Any] +) -> Optional[str]: # pylint: disable=unused-argument if response is None or headers is None: return None - return cast(Optional[str], headers.get('x-ms-file-permission-key', None)) + return cast(Optional[str], headers.get("x-ms-file-permission-key", None)) def get_file_ranges_result(ranges: ShareFileRangeList) -> Tuple[List[Dict[str, int]], List[Dict[str, int]]]: file_ranges = [] clear_ranges = [] if ranges.ranges: - file_ranges = [{'start': file_range.start, 'end': file_range.end} for file_range in ranges.ranges] + file_ranges = [{"start": file_range.start, "end": file_range.end} for file_range in ranges.ranges] if ranges.clear_ranges: - clear_ranges = [{'start': clear_range.start, 'end': clear_range.end} for clear_range in ranges.clear_ranges] + clear_ranges = [{"start": clear_range.start, "end": clear_range.end} for clear_range in ranges.clear_ranges] return file_ranges, clear_ranges diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py index 0d97031fc8e4..f70f08636389 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py @@ -9,10 +9,7 @@ import sys import time from datetime import datetime -from typing import ( - Any, AnyStr, cast, Dict, IO, Iterable, Optional, Union, - TYPE_CHECKING -) +from typing import Any, AnyStr, cast, Dict, IO, Iterable, Optional, Union, TYPE_CHECKING from typing_extensions import Self from azure.core.exceptions import HttpResponseError, ResourceNotFoundError @@ -20,11 +17,7 @@ from azure.core.pipeline import Pipeline from azure.core.tracing.decorator import distributed_trace from ._deserialize import deserialize_directory_properties -from ._directory_client_helpers import ( - _format_url, - _from_directory_url, - _parse_url -) +from ._directory_client_helpers import _format_url, _from_directory_url, _parse_url from ._file_client import ShareFileClient from ._generated import AzureFileStorage from ._models import DirectoryPropertiesPaged, Handle, HandlesPaged @@ -103,46 +96,56 @@ class ShareDirectoryClient(StorageAccountHostsMixin): authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://.file.core.windows.net. """ + def __init__( - self, account_url: str, + self, + account_url: str, share_name: str, directory_path: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long *, - token_intent: Optional[Literal['backup']] = None, - **kwargs: Any + token_intent: Optional[Literal["backup"]] = None, + **kwargs: Any, ) -> None: - if hasattr(credential, 'get_token') and not token_intent: + if hasattr(credential, "get_token") and not token_intent: raise ValueError("'token_intent' keyword is required when 'credential' is an TokenCredential.") parsed_url = _parse_url(account_url, share_name) path_snapshot, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: raise ValueError( - 'You need to provide either an account shared key or SAS token when creating a storage service.') + "You need to provide either an account shared key or SAS token when creating a storage service." + ) self.snapshot = _parse_snapshot(snapshot, path_snapshot) self.share_name = share_name self.directory_path = directory_path - self._query_str, credential = self._format_query_string( - sas_token, credential, share_snapshot=self.snapshot) - super(ShareDirectoryClient, self).__init__( - parsed_url, service='file-share', credential=credential, **kwargs) - self.allow_trailing_dot = kwargs.pop('allow_trailing_dot', None) - self.allow_source_trailing_dot = kwargs.pop('allow_source_trailing_dot', None) + self._query_str, credential = self._format_query_string(sas_token, credential, share_snapshot=self.snapshot) + super(ShareDirectoryClient, self).__init__(parsed_url, service="file-share", credential=credential, **kwargs) + self.allow_trailing_dot = kwargs.pop("allow_trailing_dot", None) + self.allow_source_trailing_dot = kwargs.pop("allow_source_trailing_dot", None) self.file_request_intent = token_intent - self._client = AzureFileStorage(url=self.url, base_url=self.url, pipeline=self._pipeline, - allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, - file_request_intent=self.file_request_intent) + self._client = AzureFileStorage( + url=self.url, + base_url=self.url, + pipeline=self._pipeline, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + file_request_intent=self.file_request_intent, + ) self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] @classmethod def from_directory_url( - cls, directory_url: str, + cls, + directory_url: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """Create a ShareDirectoryClient from a directory url. @@ -173,8 +176,13 @@ def from_directory_url( """ account_url, share_name, directory_path, snapshot = _from_directory_url(directory_url, snapshot) return cls( - account_url=account_url, share_name=share_name, directory_path=directory_path, - snapshot=snapshot, credential=credential, **kwargs) + account_url=account_url, + share_name=share_name, + directory_path=directory_path, + snapshot=snapshot, + credential=credential, + **kwargs, + ) def _format_url(self, hostname: str) -> str: """Format the endpoint URL according to the current location mode hostname. @@ -188,11 +196,14 @@ def _format_url(self, hostname: str) -> str: @classmethod def from_connection_string( - cls, conn_str: str, + cls, + conn_str: str, share_name: str, directory_path: str, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """Create ShareDirectoryClient from a Connection String. @@ -212,18 +223,20 @@ def from_connection_string( If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" should be the storage account key. :type credential: - Optional[Union[str, dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] + ~azure.core.credentials.AzureNamedKeyCredential or + ~azure.core.credentials.AzureSasCredential or + ~azure.core.credentials.TokenCredential or + str or dict[str, str] or None :keyword str audience: The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://.file.core.windows.net. :returns: A directory client. :rtype: ~azure.storage.fileshare.ShareDirectoryClient """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, 'file') - if 'secondary_hostname' not in kwargs: - kwargs['secondary_hostname'] = secondary - return cls( - account_url, share_name=share_name, directory_path=directory_path, credential=credential, **kwargs) + account_url, secondary, credential = parse_connection_str(conn_str, credential, "file") + if "secondary_hostname" not in kwargs: + kwargs["secondary_hostname"] = secondary + return cls(account_url, share_name=share_name, directory_path=directory_path, credential=credential, **kwargs) def get_file_client(self, file_name: str, **kwargs: Any) -> ShareFileClient: """Get a client to interact with a specific file. @@ -235,19 +248,28 @@ def get_file_client(self, file_name: str, **kwargs: Any) -> ShareFileClient: :rtype: ~azure.storage.fileshare.ShareFileClient """ if self.directory_path: - file_name = self.directory_path.rstrip('/') + "/" + file_name + file_name = self.directory_path.rstrip("/") + "/" + file_name _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access - policies=self._pipeline._impl_policies # pylint: disable=protected-access + policies=self._pipeline._impl_policies, # pylint: disable=protected-access ) return ShareFileClient( - self.url, file_path=file_name, share_name=self.share_name, snapshot=self.snapshot, - credential=self.credential, token_intent=self.file_request_intent, api_version=self.api_version, - _hosts=self._hosts, _configuration=self._config, - _pipeline=_pipeline, _location_mode=self._location_mode, + self.url, + file_path=file_name, + share_name=self.share_name, + snapshot=self.snapshot, + credential=self.credential, + token_intent=self.file_request_intent, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, **kwargs) + allow_source_trailing_dot=self.allow_source_trailing_dot, + **kwargs, + ) def get_subdirectory_client(self, directory_name: str, **kwargs: Any) -> "ShareDirectoryClient": """Get a client to interact with a specific subdirectory. @@ -270,18 +292,28 @@ def get_subdirectory_client(self, directory_name: str, **kwargs: Any) -> "ShareD """ directory_path = directory_name if self.directory_path: - directory_path = self.directory_path.rstrip('/') + "/" + directory_name + directory_path = self.directory_path.rstrip("/") + "/" + directory_name _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access - policies=self._pipeline._impl_policies # pylint: disable=protected-access + policies=self._pipeline._impl_policies, # pylint: disable=protected-access ) return ShareDirectoryClient( - self.url, share_name=self.share_name, directory_path=directory_path, snapshot=self.snapshot, - credential=self.credential, token_intent=self.file_request_intent, api_version=self.api_version, - _hosts=self._hosts, _configuration=self._config, _pipeline=_pipeline, - _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, **kwargs) + self.url, + share_name=self.share_name, + directory_path=directory_path, + snapshot=self.snapshot, + credential=self.credential, + token_intent=self.file_request_intent, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + **kwargs, + ) @distributed_trace def create_directory(self, **kwargs: Any) -> Dict[str, Any]: @@ -344,31 +376,35 @@ def create_directory(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 12 :caption: Creates a directory. """ - timeout = kwargs.pop('timeout', None) - metadata = kwargs.pop('metadata', None) - headers = kwargs.pop('headers', {}) + timeout = kwargs.pop("timeout", None) + metadata = kwargs.pop("metadata", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) - file_attributes = kwargs.pop('file_attributes', None) - file_creation_time = kwargs.pop('file_creation_time', None) - file_last_write_time = kwargs.pop('file_last_write_time', None) - file_change_time = kwargs.pop('file_change_time', None) - file_permission = kwargs.pop('file_permission', None) - file_permission_key = kwargs.pop('file_permission_key', None) + file_attributes = kwargs.pop("file_attributes", None) + file_creation_time = kwargs.pop("file_creation_time", None) + file_last_write_time = kwargs.pop("file_last_write_time", None) + file_change_time = kwargs.pop("file_change_time", None) + file_permission = kwargs.pop("file_permission", None) + file_permission_key = kwargs.pop("file_permission_key", None) file_permission = _get_file_permission(file_permission, file_permission_key, None) try: - return cast(Dict[str, Any], self._client.directory.create( - file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, - file_creation_time=_datetime_to_str(file_creation_time), - file_last_write_time=_datetime_to_str(file_last_write_time), - file_change_time=_datetime_to_str(file_change_time), - file_permission=file_permission, - file_permission_key=file_permission_key, - timeout=timeout, - cls=return_response_headers, - headers=headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.directory.create( + file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, + file_creation_time=_datetime_to_str(file_creation_time), + file_last_write_time=_datetime_to_str(file_last_write_time), + file_change_time=_datetime_to_str(file_change_time), + file_permission=file_permission, + file_permission_key=file_permission_key, + timeout=timeout, + cls=return_response_headers, + headers=headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -383,6 +419,7 @@ def delete_directory(self, **kwargs: Any) -> None: This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :returns: None :rtype: None .. admonition:: Example: @@ -394,7 +431,7 @@ def delete_directory(self, **kwargs: Any) -> None: :dedent: 12 :caption: Deletes a directory. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) try: self._client.directory.delete(timeout=timeout, **kwargs) except HttpResponseError as error: @@ -464,31 +501,38 @@ def rename_directory(self, new_name: str, **kwargs: Any) -> "ShareDirectoryClien if not new_name: raise ValueError("Please specify a new directory name.") - new_name = new_name.strip('/') - new_path_and_query = new_name.split('?') + new_name = new_name.strip("/") + new_path_and_query = new_name.split("?") new_dir_path = new_path_and_query[0] if len(new_path_and_query) == 2: - new_dir_sas = new_path_and_query[1] or self._query_str.strip('?') + new_dir_sas = new_path_and_query[1] or self._query_str.strip("?") else: - new_dir_sas = self._query_str.strip('?') + new_dir_sas = self._query_str.strip("?") new_directory_client = ShareDirectoryClient( - f'{self.scheme}://{self.primary_hostname}', self.share_name, new_dir_path, - credential=new_dir_sas or self.credential, api_version=self.api_version, - _hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline, - _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, token_intent=self.file_request_intent + f"{self.scheme}://{self.primary_hostname}", + self.share_name, + new_dir_path, + credential=new_dir_sas or self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=self._pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, ) kwargs.update(get_rename_smb_properties(kwargs)) - timeout = kwargs.pop('timeout', None) - overwrite = kwargs.pop('overwrite', None) - metadata = kwargs.pop('metadata', None) - headers = kwargs.pop('headers', {}) + timeout = kwargs.pop("timeout", None) + overwrite = kwargs.pop("overwrite", None) + metadata = kwargs.pop("metadata", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) - destination_access_conditions = get_dest_access_conditions(kwargs.pop('destination_lease', None)) + destination_access_conditions = get_dest_access_conditions(kwargs.pop("destination_lease", None)) try: new_directory_client._client.directory.rename( # pylint: disable=protected-access @@ -497,7 +541,8 @@ def rename_directory(self, new_name: str, **kwargs: Any) -> "ShareDirectoryClien replace_if_exists=overwrite, destination_lease_access_conditions=destination_access_conditions, headers=headers, - **kwargs) + **kwargs, + ) return new_directory_client except HttpResponseError as error: @@ -505,9 +550,7 @@ def rename_directory(self, new_name: str, **kwargs: Any) -> "ShareDirectoryClien @distributed_trace def list_directories_and_files( - self, - name_starts_with: Optional[str] = None, - **kwargs: Any + self, name_starts_with: Optional[str] = None, **kwargs: Any ) -> ItemPaged[Union["DirectoryProperties", "FileProperties"]]: """Lists all the directories and files under the directory. @@ -547,16 +590,20 @@ def list_directories_and_files( :dedent: 12 :caption: List directories and files. """ - timeout = kwargs.pop('timeout', None) - results_per_page = kwargs.pop('results_per_page', None) + timeout = kwargs.pop("timeout", None) + results_per_page = kwargs.pop("results_per_page", None) command = functools.partial( self._client.directory.list_files_and_directories_segment, sharesnapshot=self.snapshot, timeout=timeout, - **kwargs) + **kwargs, + ) return ItemPaged( - command, prefix=name_starts_with, results_per_page=results_per_page, - page_iterator_class=DirectoryPropertiesPaged) + command, + prefix=name_starts_with, + results_per_page=results_per_page, + page_iterator_class=DirectoryPropertiesPaged, + ) @distributed_trace def list_handles(self, recursive: bool = False, **kwargs: Any) -> ItemPaged[Handle]: @@ -574,17 +621,16 @@ def list_handles(self, recursive: bool = False, **kwargs: Any) -> ItemPaged[Hand :returns: An auto-paging iterable of Handle :rtype: ~azure.core.paging.ItemPaged[~azure.storage.fileshare.Handle] """ - timeout = kwargs.pop('timeout', None) - results_per_page = kwargs.pop('results_per_page', None) + timeout = kwargs.pop("timeout", None) + results_per_page = kwargs.pop("results_per_page", None) command = functools.partial( self._client.directory.list_handles, sharesnapshot=self.snapshot, timeout=timeout, recursive=recursive, - **kwargs) - return ItemPaged( - command, results_per_page=results_per_page, - page_iterator_class=HandlesPaged) + **kwargs, + ) + return ItemPaged(command, results_per_page=results_per_page, page_iterator_class=HandlesPaged) @distributed_trace def close_handle(self, handle: Union[str, Handle], **kwargs: Any) -> Dict[str, int]: @@ -608,7 +654,7 @@ def close_handle(self, handle: Union[str, Handle], **kwargs: Any) -> Dict[str, i handle_id = handle.id else: handle_id = handle - if handle_id == '*': + if handle_id == "*": raise ValueError("Handle ID '*' is not supported. Use 'close_all_handles' instead.") try: response = self._client.directory.force_close_handles( @@ -617,11 +663,11 @@ def close_handle(self, handle: Union[str, Handle], **kwargs: Any) -> Dict[str, i recursive=None, sharesnapshot=self.snapshot, cls=return_response_headers, - **kwargs + **kwargs, ) return { - 'closed_handles_count': response.get('number_of_handles_closed', 0), - 'failed_handles_count': response.get('number_of_handles_failed', 0) + "closed_handles_count": response.get("number_of_handles_closed", 0), + "failed_handles_count": response.get("number_of_handles_failed", 0), } except HttpResponseError as error: process_storage_error(error) @@ -645,7 +691,7 @@ def close_all_handles(self, recursive: bool = False, **kwargs: Any) -> Dict[str, and the number of handles failed to close in a dict. :rtype: dict[str, int] """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) start_time = time.time() try_close = True @@ -655,26 +701,23 @@ def close_all_handles(self, recursive: bool = False, **kwargs: Any) -> Dict[str, while try_close: try: response = self._client.directory.force_close_handles( - handle_id='*', + handle_id="*", timeout=timeout, marker=continuation_token, recursive=recursive, sharesnapshot=self.snapshot, cls=return_response_headers, - **kwargs + **kwargs, ) except HttpResponseError as error: process_storage_error(error) - continuation_token = response.get('marker') + continuation_token = response.get("marker") try_close = bool(continuation_token) - total_closed += response.get('number_of_handles_closed', 0) - total_failed += response.get('number_of_handles_failed', 0) + total_closed += response.get("number_of_handles_closed", 0) + total_failed += response.get("number_of_handles_failed", 0) if timeout: timeout = max(0, timeout - (time.time() - start_time)) - return { - 'closed_handles_count': total_closed, - 'failed_handles_count': total_failed - } + return {"closed_handles_count": total_closed, "failed_handles_count": total_failed} @distributed_trace def get_directory_properties(self, **kwargs: Any) -> "DirectoryProperties": @@ -691,12 +734,12 @@ def get_directory_properties(self, **kwargs: Any) -> "DirectoryProperties": :returns: DirectoryProperties :rtype: ~azure.storage.fileshare.DirectoryProperties """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) try: - response = cast("DirectoryProperties", self._client.directory.get_properties( - timeout=timeout, - cls=deserialize_directory_properties, - **kwargs)) + response = cast( + "DirectoryProperties", + self._client.directory.get_properties(timeout=timeout, cls=deserialize_directory_properties, **kwargs), + ) except HttpResponseError as error: process_storage_error(error) return response @@ -721,15 +764,16 @@ def set_directory_metadata(self, metadata: Dict[str, Any], **kwargs: Any) -> Dic :returns: Directory-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - timeout = kwargs.pop('timeout', None) - headers = kwargs.pop('headers', {}) + timeout = kwargs.pop("timeout", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], self._client.directory.set_metadata( - timeout=timeout, - cls=return_response_headers, - headers=headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.directory.set_metadata( + timeout=timeout, cls=return_response_headers, headers=headers, **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -758,12 +802,13 @@ def exists(self, **kwargs: Any) -> bool: @distributed_trace def set_http_headers( - self, file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, + self, + file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, file_creation_time: Optional[Union[str, datetime]] = None, file_last_write_time: Optional[Union[str, datetime]] = None, file_permission: Optional[str] = None, permission_key: Optional[str] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """Sets HTTP headers on the directory. @@ -813,20 +858,24 @@ def set_http_headers( :returns: File-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) file_permission = _get_file_permission(file_permission, permission_key, None) - file_change_time = kwargs.pop('file_change_time', None) + file_change_time = kwargs.pop("file_change_time", None) try: - return cast(Dict[str, Any], self._client.directory.set_properties( - file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, - file_creation_time=_datetime_to_str(file_creation_time), - file_last_write_time=_datetime_to_str(file_last_write_time), - file_change_time=_datetime_to_str(file_change_time), - file_permission=file_permission, - file_permission_key=permission_key, - timeout=timeout, - cls=return_response_headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.directory.set_properties( + file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, + file_creation_time=_datetime_to_str(file_creation_time), + file_last_write_time=_datetime_to_str(file_last_write_time), + file_change_time=_datetime_to_str(file_change_time), + file_permission=file_permission, + file_permission_key=permission_key, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -858,8 +907,8 @@ def create_subdirectory(self, directory_name: str, **kwargs: Any) -> "ShareDirec :dedent: 12 :caption: Create a subdirectory. """ - metadata = kwargs.pop('metadata', None) - timeout = kwargs.pop('timeout', None) + metadata = kwargs.pop("metadata", None) + timeout = kwargs.pop("timeout", None) subdir = self.get_subdirectory_client(directory_name) subdir.create_directory(metadata=metadata, timeout=timeout, **kwargs) return subdir @@ -887,16 +936,17 @@ def delete_subdirectory(self, directory_name: str, **kwargs: Any) -> None: :dedent: 12 :caption: Delete a subdirectory. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) subdir = self.get_subdirectory_client(directory_name) subdir.delete_directory(timeout=timeout, **kwargs) @distributed_trace def upload_file( - self, file_name: str, + self, + file_name: str, data: Union[bytes, str, Iterable[AnyStr], IO[AnyStr]], length: Optional[int] = None, - **kwargs: Any + **kwargs: Any, ) -> ShareFileClient: """Creates a new file in the directory and returns a ShareFileClient to interact with the file. @@ -949,10 +999,7 @@ def upload_file( :caption: Upload a file to a directory. """ file_client = self.get_file_client(file_name) - file_client.upload_file( - data, - length=length, - **kwargs) + file_client.upload_file(data, length=length, **kwargs) return file_client @distributed_trace diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client_helpers.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client_helpers.py index cf37c24f02e1..4f05e151ffc9 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client_helpers.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client_helpers.py @@ -4,10 +4,7 @@ # license information. # -------------------------------------------------------------------------- -from typing import ( - Any, Dict, Optional, Tuple, Union, - TYPE_CHECKING -) +from typing import Any, Dict, Optional, Tuple, Union, TYPE_CHECKING from urllib.parse import quote, unquote, urlparse from ._shared.base_client import parse_query @@ -18,11 +15,11 @@ def _parse_url(account_url: str, share_name: str) -> "ParseResult": try: - if not account_url.lower().startswith('http'): + if not account_url.lower().startswith("http"): account_url = "https://" + account_url except AttributeError as exc: raise ValueError("Account URL must be a string.") from exc - parsed_url = urlparse(account_url.rstrip('/')) + parsed_url = urlparse(account_url.rstrip("/")) if not share_name: raise ValueError("Please specify a share name.") if not parsed_url.netloc: @@ -32,29 +29,28 @@ def _parse_url(account_url: str, share_name: str) -> "ParseResult": def _format_url(scheme: str, hostname: str, share_name: Union[str, bytes], dir_path: str, query_str: str) -> str: if isinstance(share_name, str): - share_name = share_name.encode('UTF-8') + share_name = share_name.encode("UTF-8") directory_path = "" if dir_path: - directory_path = "/" + quote(dir_path, safe='~') + directory_path = "/" + quote(dir_path, safe="~") return f"{scheme}://{hostname}/{quote(share_name)}{directory_path}{query_str}" def _from_directory_url( - directory_url: str, - snapshot: Optional[Union[str, Dict[str, Any]]] = None + directory_url: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None ) -> Tuple[str, str, str, Optional[Union[str, Dict[str, Any]]]]: try: - if not directory_url.lower().startswith('http'): + if not directory_url.lower().startswith("http"): directory_url = "https://" + directory_url except AttributeError as exc: raise ValueError("Directory URL must be a string.") from exc - parsed_url = urlparse(directory_url.rstrip('/')) + parsed_url = urlparse(directory_url.rstrip("/")) if not parsed_url.path and not parsed_url.netloc: raise ValueError(f"Invalid URL: {directory_url}") - account_url = parsed_url.netloc.rstrip('/') + "?" + parsed_url.query + account_url = parsed_url.netloc.rstrip("/") + "?" + parsed_url.query path_snapshot, _ = parse_query(parsed_url.query) - share_name, _, path_dir = parsed_url.path.lstrip('/').partition('/') + share_name, _, path_dir = parsed_url.path.lstrip("/").partition("/") share_name = unquote(share_name) snapshot = snapshot or path_snapshot diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_download.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_download.py index a37bca9a92e2..bc09b6f8ecbd 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_download.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_download.py @@ -8,10 +8,7 @@ import threading import warnings from io import BytesIO -from typing import ( - Any, Callable, Generator, IO, Iterator, Optional, Tuple, - TYPE_CHECKING -) +from typing import Any, Callable, Generator, IO, Iterator, Optional, Tuple, TYPE_CHECKING from azure.core.exceptions import HttpResponseError, ResourceModifiedError from azure.core.tracing.common import with_current_context @@ -36,7 +33,8 @@ def process_content(data: Any) -> bytes: class _ChunkDownloader(object): # pylint: disable=too-many-instance-attributes def __init__( - self, client: "FileOperations", + self, + client: "FileOperations", total_size: int, chunk_size: int, current_progress: int, @@ -47,7 +45,7 @@ def __init__( stream: Any = None, parallel: Optional[int] = None, progress_hook: Optional[Callable[[int, Optional[int]], None]] = None, - **kwargs: Any + **kwargs: Any, ) -> None: self.client = client self.etag = etag @@ -130,7 +128,7 @@ def _download_chunk(self, chunk_start: int, chunk_end: int) -> bytes: validate_content=self.validate_content, data_stream_total=self.total_size, download_stream_current=self.progress_total, - **self.request_options + **self.request_options, ) if response.properties.etag != self.etag: raise ResourceModifiedError(message="The file has been modified while downloading.") @@ -191,7 +189,7 @@ def __next__(self) -> bytes: def _get_chunk_data(self) -> bytes: chunk_data = self._current_content[: self._chunk_size] - self._current_content = self._current_content[self._chunk_size:] + self._current_content = self._current_content[self._chunk_size :] return chunk_data @@ -212,7 +210,8 @@ class StorageStreamDownloader(object): # pylint: disable=too-many-instance-attr otherwise the total size of the file.""" def __init__( - self, client: "FileOperations" = None, # type: ignore [assignment] + self, + client: "FileOperations" = None, # type: ignore [assignment] config: "StorageConfiguration" = None, # type: ignore [assignment] start_range: Optional[int] = None, end_range: Optional[int] = None, @@ -222,7 +221,7 @@ def __init__( path: str = None, # type: ignore [assignment] share: str = None, # type: ignore [assignment] encoding: Optional[str] = None, - **kwargs: Any + **kwargs: Any, ) -> None: self.name = name self.path = path @@ -236,7 +235,7 @@ def __init__( self._max_concurrency = max_concurrency self._encoding = encoding self._validate_content = validate_content - self._progress_hook = kwargs.pop('progress_hook', None) + self._progress_hook = kwargs.pop("progress_hook", None) self._request_options = kwargs self._location_mode = None self._download_complete = False @@ -291,7 +290,7 @@ def _initial_request(self): self._initial_range[1], start_range_required=False, end_range_required=False, - check_content_md5=self._validate_content + check_content_md5=self._validate_content, ) try: @@ -301,7 +300,7 @@ def _initial_request(self): validate_content=self._validate_content, data_stream_total=None, download_stream_current=0, - **self._request_options + **self._request_options, ) # Check the location we read from to ensure we use the same one @@ -332,7 +331,7 @@ def _initial_request(self): validate_content=self._validate_content, data_stream_total=0, download_stream_current=0, - **self._request_options + **self._request_options, ) except HttpResponseError as e: process_storage_error(e) @@ -376,13 +375,14 @@ def chunks(self) -> Iterator[bytes]: validate_content=self._validate_content, use_location=self._location_mode, etag=self._etag, - **self._request_options + **self._request_options, ) return _ChunkIterator( size=self.size, content=self._current_content, downloader=iter_downloader, - chunk_size=self._config.max_chunk_get_size) + chunk_size=self._config.max_chunk_get_size, + ) def readall(self) -> bytes: """Download the contents of this file. @@ -410,10 +410,7 @@ def content_as_bytes(self, max_concurrency=1): :return: The contents of the file as bytes. :rtype: bytes """ - warnings.warn( - "content_as_bytes is deprecated, use readall instead", - DeprecationWarning - ) + warnings.warn("content_as_bytes is deprecated, use readall instead", DeprecationWarning) self._max_concurrency = max_concurrency return self.readall() @@ -431,10 +428,7 @@ def content_as_text(self, max_concurrency=1, encoding="UTF-8"): :return: The contents of the file as a str. :rtype: str """ - warnings.warn( - "content_as_text is deprecated, use readall instead", - DeprecationWarning - ) + warnings.warn("content_as_text is deprecated, use readall instead", DeprecationWarning) self._max_concurrency = max_concurrency self._encoding = encoding return self.readall() @@ -487,15 +481,13 @@ def readinto(self, stream: IO[bytes]) -> int: use_location=self._location_mode, progress_hook=self._progress_hook, etag=self._etag, - **self._request_options + **self._request_options, ) if parallel: import concurrent.futures + with concurrent.futures.ThreadPoolExecutor(self._max_concurrency) as executor: - list(executor.map( - with_current_context(downloader.process_chunk), - downloader.get_chunk_offsets() - )) + list(executor.map(with_current_context(downloader.process_chunk), downloader.get_chunk_offsets())) else: for chunk in downloader.get_chunk_offsets(): downloader.process_chunk(chunk) @@ -515,10 +507,7 @@ def download_to_stream(self, stream, max_concurrency=1): :returns: The properties of the downloaded file. :rtype: Any """ - warnings.warn( - "download_to_stream is deprecated, use readinto instead", - DeprecationWarning - ) + warnings.warn("download_to_stream is deprecated, use readinto instead", DeprecationWarning) self._max_concurrency = max_concurrency self.readinto(stream) return self.properties diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py index 3ecf241b4044..12cb0defbda3 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py @@ -10,10 +10,7 @@ import time from datetime import datetime from io import BytesIO -from typing import ( - Any, AnyStr, Callable, cast, Dict, IO, Iterable, List, Optional, Tuple, Union, - TYPE_CHECKING -) +from typing import Any, AnyStr, Callable, cast, Dict, IO, Iterable, List, Optional, Tuple, Union, TYPE_CHECKING from typing_extensions import Self from azure.core.exceptions import HttpResponseError, ResourceNotFoundError @@ -26,7 +23,7 @@ _from_file_url, _get_ranges_options, _parse_url, - _upload_range_from_url_options + _upload_range_from_url_options, ) from ._generated import AzureFileStorage from ._generated.models import FileHTTPHeaders @@ -39,7 +36,7 @@ get_dest_access_conditions, get_rename_smb_properties, get_smb_properties, - get_source_access_conditions + get_source_access_conditions, ) from ._shared.base_client import StorageAccountHostsMixin, parse_connection_str, parse_query from ._shared.request_handlers import add_metadata_headers, get_length @@ -73,7 +70,7 @@ def _upload_file_helper( file_permission: Optional[str] = None, file_permission_key: Optional[str] = None, progress_hook: Optional[Callable[[int, Optional[int]], None]] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: try: if size is None or size < 0: @@ -88,7 +85,7 @@ def _upload_file_helper( file_last_write_time=file_last_write_time, file_permission=file_permission, permission_key=file_permission_key, - **kwargs + **kwargs, ) if size == 0: return response @@ -103,9 +100,9 @@ def _upload_file_helper( validate_content=validate_content, progress_hook=progress_hook, timeout=timeout, - **kwargs + **kwargs, ) - return cast(Dict[str, Any], sorted(responses, key=lambda r: r.get('last_modified'))[-1]) + return cast(Dict[str, Any], sorted(responses, key=lambda r: r.get("last_modified"))[-1]) except HttpResponseError as error: process_storage_error(error) @@ -166,48 +163,58 @@ class ShareFileClient(StorageAccountHostsMixin): authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://.file.core.windows.net. """ + def __init__( - self, account_url: str, + self, + account_url: str, share_name: str, file_path: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long *, - token_intent: Optional[Literal['backup']] = None, - **kwargs: Any + token_intent: Optional[Literal["backup"]] = None, + **kwargs: Any, ) -> None: - if hasattr(credential, 'get_token') and not token_intent: + if hasattr(credential, "get_token") and not token_intent: raise ValueError("'token_intent' keyword is required when 'credential' is an TokenCredential.") parsed_url = _parse_url(account_url, share_name, file_path) path_snapshot, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: raise ValueError( - 'You need to provide either an account shared key or SAS token when creating a storage service.') + "You need to provide either an account shared key or SAS token when creating a storage service." + ) self.snapshot = _parse_snapshot(snapshot, path_snapshot) self.share_name = share_name - self.file_path = file_path.split('/') + self.file_path = file_path.split("/") self.file_name = self.file_path[-1] self.directory_path = "/".join(self.file_path[:-1]) - self._query_str, credential = self._format_query_string( - sas_token, credential, share_snapshot=self.snapshot) - super(ShareFileClient, self).__init__( - parsed_url, service='file-share', credential=credential, **kwargs) - self.allow_trailing_dot = kwargs.pop('allow_trailing_dot', None) - self.allow_source_trailing_dot = kwargs.pop('allow_source_trailing_dot', None) + self._query_str, credential = self._format_query_string(sas_token, credential, share_snapshot=self.snapshot) + super(ShareFileClient, self).__init__(parsed_url, service="file-share", credential=credential, **kwargs) + self.allow_trailing_dot = kwargs.pop("allow_trailing_dot", None) + self.allow_source_trailing_dot = kwargs.pop("allow_source_trailing_dot", None) self.file_request_intent = token_intent - self._client = AzureFileStorage(url=self.url, base_url=self.url, pipeline=self._pipeline, - allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, - file_request_intent=self.file_request_intent) + self._client = AzureFileStorage( + url=self.url, + base_url=self.url, + pipeline=self._pipeline, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + file_request_intent=self.file_request_intent, + ) self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] @classmethod def from_file_url( - cls, file_url: str, + cls, + file_url: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """A client to interact with a specific file, although that file may not yet exist. @@ -243,12 +250,15 @@ def _format_url(self, hostname: str): @classmethod def from_connection_string( - cls, conn_str: str, + cls, + conn_str: str, share_name: str, file_path: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """Create ShareFileClient from a Connection String. @@ -290,11 +300,12 @@ def from_connection_string( :dedent: 12 :caption: Creates the file client with connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, 'file') - if 'secondary_hostname' not in kwargs: - kwargs['secondary_hostname'] = secondary + account_url, secondary, credential = parse_connection_str(conn_str, credential, "file") + if "secondary_hostname" not in kwargs: + kwargs["secondary_hostname"] = secondary return cls( - account_url, share_name=share_name, file_path=file_path, snapshot=snapshot, credential=credential, **kwargs) + account_url, share_name=share_name, file_path=file_path, snapshot=snapshot, credential=credential, **kwargs + ) @distributed_trace def acquire_lease(self, lease_id: Optional[str] = None, **kwargs: Any) -> ShareLeaseClient: @@ -325,7 +336,7 @@ def acquire_lease(self, lease_id: Optional[str] = None, **kwargs: Any) -> ShareL :dedent: 12 :caption: Acquiring a lease on a file. """ - kwargs['lease_duration'] = -1 + kwargs["lease_duration"] = -1 lease = ShareLeaseClient(self, lease_id=lease_id) lease.acquire(**kwargs) return lease @@ -355,13 +366,14 @@ def exists(self, **kwargs: Any) -> bool: @distributed_trace def create_file( - self, size: int, + self, + size: int, file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, file_creation_time: Optional[Union[str, datetime]] = None, file_last_write_time: Optional[Union[str, datetime]] = None, file_permission: Optional[str] = None, permission_key: Optional[str] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """Creates a new file. @@ -440,11 +452,11 @@ def create_file( :dedent: 12 :caption: Create a file. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - content_settings = kwargs.pop('content_settings', None) - metadata = kwargs.pop('metadata', None) - timeout = kwargs.pop('timeout', None) - headers = kwargs.pop('headers', {}) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + content_settings = kwargs.pop("content_settings", None) + metadata = kwargs.pop("metadata", None) + timeout = kwargs.pop("timeout", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) file_http_headers = None if content_settings: @@ -454,39 +466,44 @@ def create_file( file_content_md5=bytearray(content_settings.content_md5) if content_settings.content_md5 else None, file_content_encoding=content_settings.content_encoding, file_content_language=content_settings.content_language, - file_content_disposition=content_settings.content_disposition + file_content_disposition=content_settings.content_disposition, ) file_permission = _get_file_permission(file_permission, permission_key, None) - file_change_time = kwargs.pop('file_change_time', None) + file_change_time = kwargs.pop("file_change_time", None) try: - return cast(Dict[str, Any], self._client.file.create( - file_content_length=size, - metadata=metadata, - file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, - file_creation_time=_datetime_to_str(file_creation_time), - file_last_write_time=_datetime_to_str(file_last_write_time), - file_change_time=_datetime_to_str(file_change_time), - file_permission=file_permission, - file_permission_key=permission_key, - file_http_headers=file_http_headers, - lease_access_conditions=access_conditions, - headers=headers, - timeout=timeout, - cls=return_response_headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.file.create( + file_content_length=size, + metadata=metadata, + file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, + file_creation_time=_datetime_to_str(file_creation_time), + file_last_write_time=_datetime_to_str(file_last_write_time), + file_change_time=_datetime_to_str(file_change_time), + file_permission=file_permission, + file_permission_key=permission_key, + file_http_headers=file_http_headers, + lease_access_conditions=access_conditions, + headers=headers, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace def upload_file( - self, data: Union[bytes, str, Iterable[AnyStr], IO[AnyStr]], + self, + data: Union[bytes, str, Iterable[AnyStr], IO[AnyStr]], length: Optional[int] = None, file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, file_creation_time: Optional[Union[str, datetime]] = None, file_last_write_time: Optional[Union[str, datetime]] = None, file_permission: Optional[str] = None, permission_key: Optional[str] = None, - **kwargs + **kwargs, ) -> Dict[str, Any]: """Uploads a new file. @@ -575,13 +592,13 @@ def upload_file( :dedent: 12 :caption: Upload a file. """ - metadata = kwargs.pop('metadata', None) - content_settings = kwargs.pop('content_settings', None) - max_concurrency = kwargs.pop('max_concurrency', 1) - validate_content = kwargs.pop('validate_content', False) - progress_hook = kwargs.pop('progress_hook', None) - timeout = kwargs.pop('timeout', None) - encoding = kwargs.pop('encoding', 'UTF-8') + metadata = kwargs.pop("metadata", None) + content_settings = kwargs.pop("content_settings", None) + max_concurrency = kwargs.pop("max_concurrency", 1) + validate_content = kwargs.pop("validate_content", False) + progress_hook = kwargs.pop("progress_hook", None) + timeout = kwargs.pop("timeout", None) + encoding = kwargs.pop("encoding", "UTF-8") if isinstance(data, str): data = data.encode(encoding) @@ -593,9 +610,9 @@ def upload_file( stream: Optional[Any] = None if isinstance(data, bytes): stream = BytesIO(data) - elif hasattr(data, 'read'): + elif hasattr(data, "read"): stream = data - elif hasattr(data, '__iter__'): + elif hasattr(data, "__iter__"): stream = IterStreamer(data, encoding=encoding) else: raise TypeError(f"Unsupported data type: {type(data)}") @@ -615,7 +632,8 @@ def upload_file( file_permission=file_permission, file_permission_key=permission_key, progress_hook=progress_hook, - **kwargs) + **kwargs, + ) @distributed_trace def start_copy_from_url(self, source_url: str, **kwargs: Any) -> Dict[str, Any]: @@ -757,31 +775,35 @@ def start_copy_from_url(self, source_url: str, **kwargs: Any) -> Dict[str, Any]: :dedent: 12 :caption: Copy a file from a URL """ - metadata = kwargs.pop('metadata', None) - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) - owner = kwargs.pop('owner', None) - group = kwargs.pop('group', None) - file_mode = kwargs.pop('file_mode', None) - file_mode_copy_mode = kwargs.pop('file_mode_copy_mode', None) - file_owner_copy_mode = kwargs.pop('owner_copy_mode', None) - headers = kwargs.pop('headers', {}) + metadata = kwargs.pop("metadata", None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) + owner = kwargs.pop("owner", None) + group = kwargs.pop("group", None) + file_mode = kwargs.pop("file_mode", None) + file_mode_copy_mode = kwargs.pop("file_mode_copy_mode", None) + file_owner_copy_mode = kwargs.pop("owner_copy_mode", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) kwargs.update(get_smb_properties(kwargs)) try: - return cast(Dict[str, Any], self._client.file.start_copy( - source_url, - metadata=metadata, - lease_access_conditions=access_conditions, - owner=owner, - group=group, - file_mode=file_mode, - file_mode_copy_mode=file_mode_copy_mode, - file_owner_copy_mode=file_owner_copy_mode, - headers=headers, - cls=return_response_headers, - timeout=timeout, - **kwargs)) + return cast( + Dict[str, Any], + self._client.file.start_copy( + source_url, + metadata=metadata, + lease_access_conditions=access_conditions, + owner=owner, + group=group, + file_mode=file_mode, + file_mode_copy_mode=file_mode_copy_mode, + file_owner_copy_mode=file_owner_copy_mode, + headers=headers, + cls=return_response_headers, + timeout=timeout, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -809,27 +831,26 @@ def abort_copy(self, copy_id: Union[str, FileProperties], **kwargs: Any) -> None This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :returns: None :rtype: None """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) if isinstance(copy_id, FileProperties): copy_id = copy_id.copy.id elif isinstance(copy_id, Dict): - copy_id = copy_id['copy_id'] + copy_id = copy_id["copy_id"] try: - self._client.file.abort_copy(copy_id=copy_id, - lease_access_conditions=access_conditions, - timeout=timeout, **kwargs) + self._client.file.abort_copy( + copy_id=copy_id, lease_access_conditions=access_conditions, timeout=timeout, **kwargs + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace def download_file( - self, offset: Optional[int] = None, - length: Optional[int] = None, - **kwargs: Any + self, offset: Optional[int] = None, length: Optional[int] = None, **kwargs: Any ) -> StorageStreamDownloader: """Downloads a file to the StorageStreamDownloader. The readall() method must be used to read all the content or readinto() must be used to download the file into @@ -890,7 +911,7 @@ def download_file( raise ValueError("Offset value must not be None if length is set.") range_end = offset + length - 1 # Service actually uses an end-range inclusive index - access_conditions = get_access_conditions(kwargs.pop('lease', None)) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) return StorageStreamDownloader( client=self._client.file, @@ -898,11 +919,12 @@ def download_file( start_range=offset, end_range=range_end, name=self.file_name, - path='/'.join(self.file_path), + path="/".join(self.file_path), share=self.share_name, lease_access_conditions=access_conditions, cls=deserialize_file_stream, - **kwargs) + **kwargs, + ) @distributed_trace def delete_file(self, **kwargs: Any) -> None: @@ -933,8 +955,8 @@ def delete_file(self, **kwargs: Any) -> None: :dedent: 12 :caption: Delete a file. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: self._client.file.delete(lease_access_conditions=access_conditions, timeout=timeout, **kwargs) except HttpResponseError as error: @@ -1015,39 +1037,44 @@ def rename_file(self, new_name: str, **kwargs: Any) -> "ShareFileClient": if not new_name: raise ValueError("Please specify a new file name.") - new_name = new_name.strip('/') - new_path_and_query = new_name.split('?') + new_name = new_name.strip("/") + new_path_and_query = new_name.split("?") new_file_path = new_path_and_query[0] if len(new_path_and_query) == 2: - new_file_sas = new_path_and_query[1] or self._query_str.strip('?') + new_file_sas = new_path_and_query[1] or self._query_str.strip("?") else: - new_file_sas = self._query_str.strip('?') + new_file_sas = self._query_str.strip("?") new_file_client = ShareFileClient( - f'{self.scheme}://{self.primary_hostname}', self.share_name, new_file_path, - credential=new_file_sas or self.credential, api_version=self.api_version, - _hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline, - _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, token_intent=self.file_request_intent + f"{self.scheme}://{self.primary_hostname}", + self.share_name, + new_file_path, + credential=new_file_sas or self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=self._pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, ) kwargs.update(get_rename_smb_properties(kwargs)) file_http_headers = None - content_type = kwargs.pop('content_type', None) + content_type = kwargs.pop("content_type", None) if content_type: - file_http_headers = FileHTTPHeaders( - file_content_type=content_type - ) + file_http_headers = FileHTTPHeaders(file_content_type=content_type) - timeout = kwargs.pop('timeout', None) - overwrite = kwargs.pop('overwrite', None) - metadata = kwargs.pop('metadata', None) - headers = kwargs.pop('headers', {}) + timeout = kwargs.pop("timeout", None) + overwrite = kwargs.pop("overwrite", None) + metadata = kwargs.pop("metadata", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) - source_access_conditions = get_source_access_conditions(kwargs.pop('source_lease', None)) - dest_access_conditions = get_dest_access_conditions(kwargs.pop('destination_lease', None)) + source_access_conditions = get_source_access_conditions(kwargs.pop("source_lease", None)) + dest_access_conditions = get_dest_access_conditions(kwargs.pop("destination_lease", None)) try: new_file_client._client.file.rename( # pylint: disable=protected-access @@ -1058,7 +1085,8 @@ def rename_file(self, new_name: str, **kwargs: Any) -> "ShareFileClient": source_lease_access_conditions=source_access_conditions, destination_lease_access_conditions=dest_access_conditions, headers=headers, - **kwargs) + **kwargs, + ) return new_file_client except HttpResponseError as error: @@ -1085,32 +1113,37 @@ def get_file_properties(self, **kwargs: Any) -> FileProperties: :returns: FileProperties :rtype: ~azure.storage.fileshare.FileProperties """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - file_props = cast(FileProperties, self._client.file.get_properties( - sharesnapshot=self.snapshot, - lease_access_conditions=access_conditions, - timeout=timeout, - cls=deserialize_file_properties, - **kwargs)) + file_props = cast( + FileProperties, + self._client.file.get_properties( + sharesnapshot=self.snapshot, + lease_access_conditions=access_conditions, + timeout=timeout, + cls=deserialize_file_properties, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) file_props.name = self.file_name file_props.share = self.share_name file_props.snapshot = self.snapshot - file_props.path = '/'.join(self.file_path) + file_props.path = "/".join(self.file_path) return file_props @distributed_trace def set_http_headers( - self, content_settings: "ContentSettings", + self, + content_settings: "ContentSettings", file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, file_creation_time: Optional[Union[str, datetime]] = None, file_last_write_time: Optional[Union[str, datetime]] = None, file_permission: Optional[str] = None, permission_key: Optional[str] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """Sets HTTP headers on the file. @@ -1172,33 +1205,37 @@ def set_http_headers( :returns: File-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) - file_content_length = kwargs.pop('size', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) + file_content_length = kwargs.pop("size", None) file_http_headers = FileHTTPHeaders( file_cache_control=content_settings.cache_control, file_content_type=content_settings.content_type, file_content_md5=bytearray(content_settings.content_md5) if content_settings.content_md5 else None, file_content_encoding=content_settings.content_encoding, file_content_language=content_settings.content_language, - file_content_disposition=content_settings.content_disposition + file_content_disposition=content_settings.content_disposition, ) file_permission = _get_file_permission(file_permission, permission_key, None) - file_change_time = kwargs.pop('file_change_time', None) + file_change_time = kwargs.pop("file_change_time", None) try: - return cast(Dict[str, Any], self._client.file.set_http_headers( - file_content_length=file_content_length, - file_http_headers=file_http_headers, - file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, - file_creation_time=_datetime_to_str(file_creation_time), - file_last_write_time=_datetime_to_str(file_last_write_time), - file_change_time=_datetime_to_str(file_change_time), - file_permission=file_permission, - file_permission_key=permission_key, - lease_access_conditions=access_conditions, - timeout=timeout, - cls=return_response_headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.file.set_http_headers( + file_content_length=file_content_length, + file_http_headers=file_http_headers, + file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, + file_creation_time=_datetime_to_str(file_creation_time), + file_last_write_time=_datetime_to_str(file_last_write_time), + file_change_time=_datetime_to_str(file_change_time), + file_permission=file_permission, + file_permission_key=permission_key, + lease_access_conditions=access_conditions, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -1230,28 +1267,27 @@ def set_file_metadata(self, metadata: Optional[Dict[str, Any]] = None, **kwargs: :returns: File-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) - headers = kwargs.pop('headers', {}) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], self._client.file.set_metadata( - timeout=timeout, - cls=return_response_headers, - headers=headers, - metadata=metadata, - lease_access_conditions=access_conditions, - **kwargs)) + return cast( + Dict[str, Any], + self._client.file.set_metadata( + timeout=timeout, + cls=return_response_headers, + headers=headers, + metadata=metadata, + lease_access_conditions=access_conditions, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace - def upload_range( - self, data: bytes, - offset: int, - length: int, - **kwargs: Any - ) -> Dict[str, Any]: + def upload_range(self, data: bytes, offset: int, length: int, **kwargs: Any) -> Dict[str, Any]: """Upload a range of bytes to a file. :param bytes data: @@ -1297,37 +1333,37 @@ def upload_range( :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ - validate_content = kwargs.pop('validate_content', False) - timeout = kwargs.pop('timeout', None) - encoding = kwargs.pop('encoding', 'UTF-8') - file_last_write_mode = kwargs.pop('file_last_write_mode', None) + validate_content = kwargs.pop("validate_content", False) + timeout = kwargs.pop("timeout", None) + encoding = kwargs.pop("encoding", "UTF-8") + file_last_write_mode = kwargs.pop("file_last_write_mode", None) if isinstance(data, str): data = data.encode(encoding) end_range = offset + length - 1 # Reformat to an inclusive range index - content_range = f'bytes={offset}-{end_range}' - access_conditions = get_access_conditions(kwargs.pop('lease', None)) + content_range = f"bytes={offset}-{end_range}" + access_conditions = get_access_conditions(kwargs.pop("lease", None)) try: - return cast(Dict[str, Any], self._client.file.upload_range( - range=content_range, - content_length=length, - optionalbody=data, - timeout=timeout, - validate_content=validate_content, - file_last_written_mode=file_last_write_mode, - lease_access_conditions=access_conditions, - cls=return_response_headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.file.upload_range( + range=content_range, + content_length=length, + optionalbody=data, + timeout=timeout, + validate_content=validate_content, + file_last_written_mode=file_last_write_mode, + lease_access_conditions=access_conditions, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace def upload_range_from_url( - self, source_url: str, - offset: int, - length: int, - source_offset: int, - **kwargs: Any + self, source_url: str, offset: int, length: int, source_offset: int, **kwargs: Any ) -> Dict[str, Any]: """ Writes the bytes from one Azure File endpoint into the specified range of another Azure File endpoint. @@ -1397,11 +1433,7 @@ def upload_range_from_url( :rtype: dict[str, Any] """ options = _upload_range_from_url_options( - source_url=source_url, - offset=offset, - length=length, - source_offset=source_offset, - **kwargs + source_url=source_url, offset=offset, length=length, source_offset=source_offset, **kwargs ) try: return cast(Dict[str, Any], self._client.file.upload_range_from_url(**options)) @@ -1410,9 +1442,7 @@ def upload_range_from_url( @distributed_trace def get_ranges( - self, offset: Optional[int] = None, - length: Optional[int] = None, - **kwargs: Any + self, offset: Optional[int] = None, length: Optional[int] = None, **kwargs: Any ) -> List[Dict[str, int]]: """Returns the list of valid page ranges for a file or snapshot of a file. @@ -1438,25 +1468,22 @@ def get_ranges( A list of valid ranges. :rtype: List[dict[str, int]] """ - options = _get_ranges_options( - snapshot=self.snapshot, - offset=offset, - length=length, - **kwargs) + options = _get_ranges_options(snapshot=self.snapshot, offset=offset, length=length, **kwargs) try: ranges = self._client.file.get_range_list(**options) except HttpResponseError as error: process_storage_error(error) - return [{'start': file_range.start, 'end': file_range.end} for file_range in ranges.ranges] + return [{"start": file_range.start, "end": file_range.end} for file_range in ranges.ranges] @distributed_trace def get_ranges_diff( - self, previous_sharesnapshot: Union[str, Dict[str, Any]], + self, + previous_sharesnapshot: Union[str, Dict[str, Any]], offset: Optional[int] = None, length: Optional[int] = None, *, include_renames: Optional[bool] = None, - **kwargs: Any + **kwargs: Any, ) -> Tuple[List[Dict[str, int]], List[Dict[str, int]]]: """Returns the list of valid page ranges for a file or snapshot of a file. @@ -1497,7 +1524,8 @@ def get_ranges_diff( length=length, previous_sharesnapshot=previous_sharesnapshot, support_rename=include_renames, - **kwargs) + **kwargs, + ) try: ranges = self._client.file.get_range_list(**options) except HttpResponseError as error: @@ -1531,25 +1559,29 @@ def clear_range(self, offset: int, length: int, **kwargs: Any) -> Dict[str, Any] :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) if offset is None or offset % 512 != 0: raise ValueError("offset must be an integer that aligns with 512 bytes file size") if length is None or length % 512 != 0: raise ValueError("length must be an integer that aligns with 512 bytes file size") end_range = length + offset - 1 # Reformat to an inclusive range index - content_range = f'bytes={offset}-{end_range}' + content_range = f"bytes={offset}-{end_range}" try: - return cast(Dict[str, Any], self._client.file.upload_range( - timeout=timeout, - cls=return_response_headers, - content_length=0, - optionalbody=None, - file_range_write="clear", - range=content_range, - lease_access_conditions=access_conditions, - **kwargs)) + return cast( + Dict[str, Any], + self._client.file.upload_range( + timeout=timeout, + cls=return_response_headers, + content_length=0, + optionalbody=None, + file_range_write="clear", + range=content_range, + lease_access_conditions=access_conditions, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -1575,19 +1607,23 @@ def resize_file(self, size: int, **kwargs: Any) -> Dict[str, Any]: :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - return cast(Dict[str, Any], self._client.file.set_http_headers( - file_content_length=size, - file_attributes=None, - file_creation_time=None, - file_last_write_time=None, - file_permission="preserve", - lease_access_conditions=access_conditions, - cls=return_response_headers, - timeout=timeout, - **kwargs)) + return cast( + Dict[str, Any], + self._client.file.set_http_headers( + file_content_length=size, + file_attributes=None, + file_creation_time=None, + file_last_write_time=None, + file_permission="preserve", + lease_access_conditions=access_conditions, + cls=return_response_headers, + timeout=timeout, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -1604,16 +1640,12 @@ def list_handles(self, **kwargs: Any) -> ItemPaged[Handle]: :returns: An auto-paging iterable of Handle :rtype: ~azure.core.paging.ItemPaged[~azure.storage.fileshare.Handle] """ - timeout = kwargs.pop('timeout', None) - results_per_page = kwargs.pop('results_per_page', None) + timeout = kwargs.pop("timeout", None) + results_per_page = kwargs.pop("results_per_page", None) command = functools.partial( - self._client.file.list_handles, - sharesnapshot=self.snapshot, - timeout=timeout, - **kwargs) - return ItemPaged( - command, results_per_page=results_per_page, - page_iterator_class=HandlesPaged) + self._client.file.list_handles, sharesnapshot=self.snapshot, timeout=timeout, **kwargs + ) + return ItemPaged(command, results_per_page=results_per_page, page_iterator_class=HandlesPaged) @distributed_trace def close_handle(self, handle: Union[str, Handle], **kwargs: Any) -> Dict[str, int]: @@ -1637,19 +1669,15 @@ def close_handle(self, handle: Union[str, Handle], **kwargs: Any) -> Dict[str, i handle_id = handle.id else: handle_id = handle - if handle_id == '*': + if handle_id == "*": raise ValueError("Handle ID '*' is not supported. Use 'close_all_handles' instead.") try: response = self._client.file.force_close_handles( - handle_id, - marker=None, - sharesnapshot=self.snapshot, - cls=return_response_headers, - **kwargs + handle_id, marker=None, sharesnapshot=self.snapshot, cls=return_response_headers, **kwargs ) return { - 'closed_handles_count': response.get('number_of_handles_closed', 0), - 'failed_handles_count': response.get('number_of_handles_failed', 0) + "closed_handles_count": response.get("number_of_handles_closed", 0), + "failed_handles_count": response.get("number_of_handles_failed", 0), } except HttpResponseError as error: process_storage_error(error) @@ -1670,7 +1698,7 @@ def close_all_handles(self, **kwargs: Any) -> Dict[str, int]: and the number of handles failed to close in a dict. :rtype: dict[str, int] """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) start_time = time.time() try_close = True @@ -1680,33 +1708,31 @@ def close_all_handles(self, **kwargs: Any) -> Dict[str, int]: while try_close: try: response = self._client.file.force_close_handles( - handle_id='*', + handle_id="*", timeout=timeout, marker=continuation_token, sharesnapshot=self.snapshot, cls=return_response_headers, - **kwargs + **kwargs, ) except HttpResponseError as error: process_storage_error(error) - continuation_token = response.get('marker') + continuation_token = response.get("marker") try_close = bool(continuation_token) - total_closed += response.get('number_of_handles_closed', 0) - total_failed += response.get('number_of_handles_failed', 0) + total_closed += response.get("number_of_handles_closed", 0) + total_failed += response.get("number_of_handles_failed", 0) if timeout: timeout = max(0, timeout - (time.time() - start_time)) - return { - 'closed_handles_count': total_closed, - 'failed_handles_count': total_failed - } + return {"closed_handles_count": total_closed, "failed_handles_count": total_failed} @distributed_trace def create_hardlink( - self, target: str, + self, + target: str, *, lease: Optional[Union[ShareLeaseClient, str]] = None, timeout: Optional[int] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """NFS only. Creates a hard link to the file specified by path. @@ -1728,19 +1754,23 @@ def create_hardlink( :rtype: dict[str, Any] """ try: - return cast(Dict[str, Any], self._client.file.create_hard_link( - target_file=target, - lease_access_conditions=lease, - timeout=timeout, - cls=return_response_headers, - **kwargs - )) + return cast( + Dict[str, Any], + self._client.file.create_hard_link( + target_file=target, + lease_access_conditions=lease, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace def create_symlink( - self, target: str, + self, + target: str, *, metadata: Optional[Dict[str, str]] = None, file_creation_time: Optional[Union[str, datetime]] = None, @@ -1749,7 +1779,7 @@ def create_symlink( group: Optional[str] = None, lease: Optional[Union[ShareLeaseClient, str]] = None, timeout: Optional[int] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """NFS only. Creates a symbolic link to the specified file. @@ -1777,28 +1807,26 @@ def create_symlink( :rtype: dict[str, Any] """ try: - return cast(Dict[str, Any], self._client.file.create_symbolic_link( - link_text=target, - metadata=metadata, - file_creation_time=file_creation_time, - file_last_write_time=file_last_write_time, - owner=owner, - group=group, - lease_access_conditions=lease, - timeout=timeout, - cls=return_response_headers, - **kwargs - )) + return cast( + Dict[str, Any], + self._client.file.create_symbolic_link( + link_text=target, + metadata=metadata, + file_creation_time=file_creation_time, + file_last_write_time=file_last_write_time, + owner=owner, + group=group, + lease_access_conditions=lease, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace - def get_symlink( - self, - *, - timeout: Optional[int] = None, - **kwargs: Any - ) -> Dict[str, Any]: + def get_symlink(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: """NFS only. Gets the symbolic link for the file client. :keyword int timeout: @@ -1811,10 +1839,9 @@ def get_symlink( :rtype: dict[str, Any] """ try: - return cast(Dict[str, Any], self._client.file.get_symbolic_link( - timeout=timeout, - cls=return_response_headers, - **kwargs - )) + return cast( + Dict[str, Any], + self._client.file.get_symbolic_link(timeout=timeout, cls=return_response_headers, **kwargs), + ) except HttpResponseError as error: process_storage_error(error) diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client_helpers.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client_helpers.py index ea225f3c596c..1d4bdf0a3fe7 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client_helpers.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client_helpers.py @@ -4,10 +4,7 @@ # license information. # -------------------------------------------------------------------------- -from typing import ( - Any, Dict, List, Optional, Tuple, Union, - TYPE_CHECKING -) +from typing import Any, Dict, List, Optional, Tuple, Union, TYPE_CHECKING from urllib.parse import quote, unquote, urlparse from ._serialize import get_access_conditions, get_source_conditions @@ -20,11 +17,11 @@ def _parse_url(account_url: str, share_name: str, file_path: str) -> "ParseResult": try: - if not account_url.lower().startswith('http'): + if not account_url.lower().startswith("http"): account_url = "https://" + account_url except AttributeError as exc: raise ValueError("Account URL must be a string.") from exc - parsed_url = urlparse(account_url.rstrip('/')) + parsed_url = urlparse(account_url.rstrip("/")) if not (share_name and file_path): raise ValueError("Please specify a share name and file name.") if not parsed_url.netloc: @@ -33,48 +30,38 @@ def _parse_url(account_url: str, share_name: str, file_path: str) -> "ParseResul def _from_file_url( - file_url: str, - snapshot: Optional[Union[str, Dict[str, Any]]] = None + file_url: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None ) -> Tuple[str, str, str, Optional[Union[str, Dict[str, Any]]]]: try: - if not file_url.lower().startswith('http'): + if not file_url.lower().startswith("http"): file_url = "https://" + file_url except AttributeError as exc: raise ValueError("File URL must be a string.") from exc - parsed_url = urlparse(file_url.rstrip('/')) + parsed_url = urlparse(file_url.rstrip("/")) if not (parsed_url.netloc and parsed_url.path): raise ValueError(f"Invalid URL: {file_url}") - account_url = parsed_url.netloc.rstrip('/') + "?" + parsed_url.query + account_url = parsed_url.netloc.rstrip("/") + "?" + parsed_url.query - path_share, _, path_file = parsed_url.path.lstrip('/').partition('/') + path_share, _, path_file = parsed_url.path.lstrip("/").partition("/") path_snapshot, _ = parse_query(parsed_url.query) snapshot = snapshot or path_snapshot share_name = unquote(path_share) - file_path = '/'.join([unquote(p) for p in path_file.split('/')]) + file_path = "/".join([unquote(p) for p in path_file.split("/")]) return account_url, share_name, file_path, snapshot -def _format_url( - scheme: str, - hostname: str, - share_name: Union[str, bytes], - file_path: List[str], - query_str: str -) -> str: +def _format_url(scheme: str, hostname: str, share_name: Union[str, bytes], file_path: List[str], query_str: str) -> str: if isinstance(share_name, str): - share_name = share_name.encode('UTF-8') - return (f"{scheme}://{hostname}/{quote(share_name)}" - f"/{'/'.join([quote(p, safe='~') for p in file_path])}{query_str}") + share_name = share_name.encode("UTF-8") + return ( + f"{scheme}://{hostname}/{quote(share_name)}" f"/{'/'.join([quote(p, safe='~') for p in file_path])}{query_str}" + ) def _upload_range_from_url_options( - source_url: str, - offset: int, - length: int, - source_offset: int, - **kwargs: Any + source_url: str, offset: int, length: int, source_offset: int, **kwargs: Any ) -> Dict[str, Any]: if offset is None: raise ValueError("offset must be provided.") @@ -85,24 +72,24 @@ def _upload_range_from_url_options( # Format range end_range = offset + length - 1 - destination_range = f'bytes={offset}-{end_range}' - source_range = f'bytes={source_offset}-{source_offset + length - 1}' - source_authorization = kwargs.pop('source_authorization', None) + destination_range = f"bytes={offset}-{end_range}" + source_range = f"bytes={source_offset}-{source_offset + length - 1}" + source_authorization = kwargs.pop("source_authorization", None) source_mod_conditions = get_source_conditions(kwargs) - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - file_last_write_mode = kwargs.pop('file_last_write_mode', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + file_last_write_mode = kwargs.pop("file_last_write_mode", None) options = { - 'copy_source_authorization': source_authorization, - 'copy_source': source_url, - 'content_length': 0, - 'source_range': source_range, - 'range': destination_range, - 'file_last_written_mode': file_last_write_mode, - 'source_modified_access_conditions': source_mod_conditions, - 'lease_access_conditions': access_conditions, - 'timeout': kwargs.pop('timeout', None), - 'cls': return_response_headers + "copy_source_authorization": source_authorization, + "copy_source": source_url, + "content_length": 0, + "source_range": source_range, + "range": destination_range, + "file_last_written_mode": file_last_write_mode, + "source_modified_access_conditions": source_mod_conditions, + "lease_access_conditions": access_conditions, + "timeout": kwargs.pop("timeout", None), + "cls": return_response_headers, } options.update(kwargs) @@ -114,32 +101,32 @@ def _get_ranges_options( offset: Optional[int] = None, length: Optional[int] = None, previous_sharesnapshot: Optional[Union[str, Dict[str, Any]]] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: - access_conditions = get_access_conditions(kwargs.pop('lease', None)) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) content_range = None if offset: if length: end_range = offset + length - 1 # Reformat to an inclusive range index - content_range = f'bytes={offset}-{end_range}' + content_range = f"bytes={offset}-{end_range}" else: - content_range = f'bytes={offset}-' + content_range = f"bytes={offset}-" options = { - 'sharesnapshot': snapshot, - 'lease_access_conditions': access_conditions, - 'timeout': kwargs.pop('timeout', None), - 'range': content_range + "sharesnapshot": snapshot, + "lease_access_conditions": access_conditions, + "timeout": kwargs.pop("timeout", None), + "range": content_range, } if previous_sharesnapshot: - if hasattr(previous_sharesnapshot, 'snapshot'): - options['prevsharesnapshot'] = previous_sharesnapshot.snapshot + if hasattr(previous_sharesnapshot, "snapshot"): + options["prevsharesnapshot"] = previous_sharesnapshot.snapshot elif isinstance(previous_sharesnapshot, Dict): - options['prevsharesnapshot'] = previous_sharesnapshot['snapshot'] + options["prevsharesnapshot"] = previous_sharesnapshot["snapshot"] else: - options['prevsharesnapshot'] = previous_sharesnapshot + options["prevsharesnapshot"] = previous_sharesnapshot options.update(kwargs) return options diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_lease.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_lease.py index aa65f693a188..c6c6c440cbc0 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_lease.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_lease.py @@ -45,16 +45,15 @@ class ShareLeaseClient(object): # pylint: disable=client-accepts-api-version-ke This will be `None` if no lease has yet been acquired or modified.""" def __init__( # pylint: disable=missing-client-constructor-parameter-credential, missing-client-constructor-parameter-kwargs - self, client: Union["ShareFileClient", "ShareClient"], - lease_id: Optional[str] = None + self, client: Union["ShareFileClient", "ShareClient"], lease_id: Optional[str] = None ) -> None: self.id = lease_id or str(uuid.uuid4()) self.last_modified = None self.etag = None - if hasattr(client, 'file_name'): + if hasattr(client, "file_name"): self._client = client._client.file # type: ignore self._snapshot = None - elif hasattr(client, 'share_name'): + elif hasattr(client, "share_name"): self._client = client._client.share self._snapshot = client.snapshot else: @@ -89,23 +88,25 @@ def acquire(self, **kwargs: Any) -> None: This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :return: None :rtype: None """ try: - lease_duration = kwargs.pop('lease_duration', -1) + lease_duration = kwargs.pop("lease_duration", -1) if self._snapshot: - kwargs['sharesnapshot'] = self._snapshot + kwargs["sharesnapshot"] = self._snapshot response = self._client.acquire_lease( - timeout=kwargs.pop('timeout', None), + timeout=kwargs.pop("timeout", None), duration=lease_duration, proposed_lease_id=self.id, cls=return_response_headers, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) - self.id = response.get('lease_id') - self.last_modified = response.get('last_modified') - self.etag = response.get('etag') + self.id = response.get("lease_id") + self.last_modified = response.get("last_modified") + self.etag = response.get("etag") @distributed_trace def renew(self, **kwargs: Any) -> None: @@ -132,15 +133,16 @@ def renew(self, **kwargs: Any) -> None: try: response = self._client.renew_lease( lease_id=self.id, - timeout=kwargs.pop('timeout', None), + timeout=kwargs.pop("timeout", None), sharesnapshot=self._snapshot, cls=return_response_headers, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) - self.etag = response.get('etag') - self.id = response.get('lease_id') - self.last_modified = response.get('last_modified') + self.etag = response.get("etag") + self.id = response.get("lease_id") + self.last_modified = response.get("last_modified") @distributed_trace def release(self, **kwargs: Any) -> None: @@ -155,24 +157,23 @@ def release(self, **kwargs: Any) -> None: see `here `__. :return: None + :rtype: None """ try: if self._snapshot: - kwargs['sharesnapshot'] = self._snapshot + kwargs["sharesnapshot"] = self._snapshot response = self._client.release_lease( - lease_id=self.id, - timeout=kwargs.pop('timeout', None), - cls=return_response_headers, - **kwargs) + lease_id=self.id, timeout=kwargs.pop("timeout", None), cls=return_response_headers, **kwargs + ) except HttpResponseError as error: process_storage_error(error) - self.etag = response.get('etag') - self.id = response.get('lease_id') - self.last_modified = response.get('last_modified') + self.etag = response.get("etag") + self.id = response.get("lease_id") + self.last_modified = response.get("last_modified") @distributed_trace def change(self, proposed_lease_id: str, **kwargs: Any) -> None: - """ Changes the lease ID of an active lease. A change must include the current lease ID in x-ms-lease-id and + """Changes the lease ID of an active lease. A change must include the current lease ID in x-ms-lease-id and a new lease ID in x-ms-proposed-lease-id. :param str proposed_lease_id: @@ -185,21 +186,23 @@ def change(self, proposed_lease_id: str, **kwargs: Any) -> None: see `here `__. :return: None + :rtype: None """ try: if self._snapshot: - kwargs['sharesnapshot'] = self._snapshot + kwargs["sharesnapshot"] = self._snapshot response = self._client.change_lease( lease_id=self.id, proposed_lease_id=proposed_lease_id, - timeout=kwargs.pop('timeout', None), + timeout=kwargs.pop("timeout", None), cls=return_response_headers, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) - self.etag = response.get('etag') - self.id = response.get('lease_id') - self.last_modified = response.get('last_modified') + self.etag = response.get("etag") + self.id = response.get("lease_id") + self.last_modified = response.get("last_modified") @distributed_trace def break_lease(self, **kwargs: Any) -> int: @@ -234,18 +237,17 @@ def break_lease(self, **kwargs: Any) -> int: :rtype: int """ try: - lease_break_period = kwargs.pop('lease_break_period', None) + lease_break_period = kwargs.pop("lease_break_period", None) if self._snapshot: - kwargs['sharesnapshot'] = self._snapshot + kwargs["sharesnapshot"] = self._snapshot if isinstance(self._client, ShareOperations): - kwargs['break_period'] = lease_break_period + kwargs["break_period"] = lease_break_period if isinstance(self._client, FileOperations) and lease_break_period: raise TypeError("Setting a lease break period is only applicable to Share leases.") response = self._client.break_lease( - timeout=kwargs.pop('timeout', None), - cls=return_response_headers, - **kwargs) + timeout=kwargs.pop("timeout", None), cls=return_response_headers, **kwargs + ) except HttpResponseError as error: process_storage_error(error) - return response.get('lease_time') # type: ignore + return response.get("lease_time") # type: ignore diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_models.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_models.py index ec95b64ce4f9..f876ed7807b4 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_models.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_models.py @@ -6,10 +6,7 @@ # pylint: disable=too-few-public-methods, too-many-instance-attributes, super-init-not-called, too-many-lines from enum import Enum -from typing import ( - Any, Callable, Dict, List, Literal, Optional, Union, - TYPE_CHECKING -) +from typing import Any, Callable, Dict, List, Literal, Optional, Union, TYPE_CHECKING from urllib.parse import unquote from typing_extensions import Self @@ -37,8 +34,8 @@ def _wrap_item(item): if isinstance(item, DirectoryItem): - return {'name': item.name, 'is_directory': True} - return {'name': item.name, 'size': item.properties.content_length, 'is_directory': False} + return {"name": item.name, "is_directory": True} + return {"name": item.name, "size": item.properties.content_length, "is_directory": False} class RetentionPolicy(GeneratedRetentionPolicy): @@ -92,7 +89,7 @@ class Metrics(GeneratedMetrics): Determines how long the associated data should persist. """ - version: str = '1.0' + version: str = "1.0" """The version of Storage Analytics to configure.""" enabled: bool = False """Indicates whether metrics are enabled for the File service.""" @@ -102,10 +99,10 @@ class Metrics(GeneratedMetrics): """Determines how long the associated data should persist.""" def __init__(self, **kwargs: Any) -> None: - self.version = kwargs.get('version', '1.0') - self.enabled = kwargs.get('enabled', False) - self.include_apis = kwargs.get('include_apis') # type: ignore [assignment] - self.retention_policy = kwargs.get('retention_policy') or RetentionPolicy() + self.version = kwargs.get("version", "1.0") + self.enabled = kwargs.get("enabled", False) + self.include_apis = kwargs.get("include_apis") # type: ignore [assignment] + self.retention_policy = kwargs.get("retention_policy") or RetentionPolicy() @classmethod def _from_generated(cls, generated): @@ -115,7 +112,9 @@ def _from_generated(cls, generated): version=generated.version, enabled=generated.enabled, include_apis=generated.include_apis, - retention_policy=RetentionPolicy._from_generated(generated.retention_policy) # pylint: disable=protected-access + retention_policy=RetentionPolicy._from_generated( + generated.retention_policy + ), # pylint: disable=protected-access ) @@ -165,11 +164,11 @@ class CorsRule(GeneratedCorsRule): """The number of seconds that the client/browser should cache a pre-flight response.""" def __init__(self, allowed_origins: List[str], allowed_methods: List[str], **kwargs: Any) -> None: - self.allowed_origins = ','.join(allowed_origins) - self.allowed_methods = ','.join(allowed_methods) - self.allowed_headers = ','.join(kwargs.get('allowed_headers', [])) - self.exposed_headers = ','.join(kwargs.get('exposed_headers', [])) - self.max_age_in_seconds = kwargs.get('max_age_in_seconds', 0) + self.allowed_origins = ",".join(allowed_origins) + self.allowed_methods = ",".join(allowed_methods) + self.allowed_headers = ",".join(kwargs.get("allowed_headers", [])) + self.exposed_headers = ",".join(kwargs.get("exposed_headers", [])) + self.max_age_in_seconds = kwargs.get("max_age_in_seconds", 0) @staticmethod def _to_generated(rules: Optional[List["CorsRule"]]) -> Optional[List[GeneratedCorsRule]]: @@ -210,7 +209,7 @@ class SmbMultichannel(GeneratedSmbMultichannel): """If SMB Multichannel is enabled.""" def __init__(self, **kwargs: Any) -> None: - self.enabled = kwargs.get('enabled') + self.enabled = kwargs.get("enabled") if self.enabled is None: raise ValueError("The value 'enabled' must be specified.") @@ -225,7 +224,7 @@ class ShareSmbSettings(GeneratedShareSmbSettings): """Sets the multichannel settings.""" def __init__(self, **kwargs: Any) -> None: - self.multichannel = kwargs.get('multichannel') # type: ignore [assignment] + self.multichannel = kwargs.get("multichannel") # type: ignore [assignment] if self.multichannel is None: raise ValueError("The value 'multichannel' must be specified.") @@ -242,14 +241,13 @@ class ShareProtocolSettings(GeneratedShareProtocolSettings): """Sets the SMB settings.""" def __init__(self, **kwargs: Any) -> None: - self.smb = kwargs.get('smb') # type: ignore [assignment] + self.smb = kwargs.get("smb") # type: ignore [assignment] if self.smb is None: raise ValueError("The value 'smb' must be specified.") @classmethod def _from_generated(cls, generated): - return cls( - smb=generated.smb) + return cls(smb=generated.smb) class ShareSasPermissions(object): @@ -287,22 +285,20 @@ class ShareSasPermissions(object): """The create permission for share SAS.""" def __init__( - self, read: bool = False, - write: bool = False, - delete: bool = False, - list: bool = False, - create: bool = False + self, read: bool = False, write: bool = False, delete: bool = False, list: bool = False, create: bool = False ) -> None: self.read = read self.create = create self.write = write self.delete = delete self.list = list - self._str = (('r' if self.read else '') + - ('c' if self.create else '') + - ('w' if self.write else '') + - ('d' if self.delete else '') + - ('l' if self.list else '')) + self._str = ( + ("r" if self.read else "") + + ("c" if self.create else "") + + ("w" if self.write else "") + + ("d" if self.delete else "") + + ("l" if self.list else "") + ) def __str__(self) -> str: return self._str @@ -320,11 +316,11 @@ def from_string(cls, permission: str) -> Self: :return: A ShareSasPermissions object :rtype: ~azure.storage.fileshare.ShareSasPermissions """ - p_read = 'r' in permission - p_create = 'c' in permission - p_write = 'w' in permission - p_delete = 'd' in permission - p_list = 'l' in permission + p_read = "r" in permission + p_create = "c" in permission + p_write = "w" in permission + p_delete = "d" in permission + p_list = "l" in permission parsed = cls(p_read, p_write, p_delete, p_list, p_create) @@ -384,9 +380,10 @@ class AccessPolicy(GenAccessPolicy): """The time at which the shared access signature becomes valid.""" def __init__( - self, permission: Optional[Union[ShareSasPermissions, str]] = None, + self, + permission: Optional[Union[ShareSasPermissions, str]] = None, expiry: Optional[Union["datetime", str]] = None, - start: Optional[Union["datetime", str]] = None + start: Optional[Union["datetime", str]] = None, ) -> None: self.start = start self.expiry = expiry @@ -404,9 +401,9 @@ class LeaseProperties(DictMixin): """When a file or share is leased, specifies whether the lease is of infinite or fixed duration.""" def __init__(self, **kwargs: Any) -> None: - self.status = get_enum_value(kwargs.get('x-ms-lease-status')) - self.state = get_enum_value(kwargs.get('x-ms-lease-state')) - self.duration = get_enum_value(kwargs.get('x-ms-lease-duration')) + self.status = get_enum_value(kwargs.get("x-ms-lease-status")) + self.state = get_enum_value(kwargs.get("x-ms-lease-state")) + self.duration = get_enum_value(kwargs.get("x-ms-lease-duration")) @classmethod def _from_generated(cls, generated): @@ -457,7 +454,8 @@ class ContentSettings(DictMixin): """The content md5 specified for the file.""" def __init__( - self, content_type: Optional[str] = None, + self, + content_type: Optional[str] = None, content_encoding: Optional[str] = None, content_language: Optional[str] = None, content_disposition: Optional[str] = None, @@ -465,12 +463,12 @@ def __init__( content_md5: Optional[bytearray] = None, **kwargs: Any ) -> None: - self.content_type = content_type or kwargs.get('Content-Type') - self.content_encoding = content_encoding or kwargs.get('Content-Encoding') - self.content_language = content_language or kwargs.get('Content-Language') - self.content_md5 = content_md5 or kwargs.get('Content-MD5') - self.content_disposition = content_disposition or kwargs.get('Content-Disposition') - self.cache_control = cache_control or kwargs.get('Cache-Control') + self.content_type = content_type or kwargs.get("Content-Type") + self.content_encoding = content_encoding or kwargs.get("Content-Encoding") + self.content_language = content_language or kwargs.get("Content-Language") + self.content_md5 = content_md5 or kwargs.get("Content-MD5") + self.content_disposition = content_disposition or kwargs.get("Content-Disposition") + self.cache_control = cache_control or kwargs.get("Cache-Control") @classmethod def _from_generated(cls, generated): @@ -545,36 +543,40 @@ class ShareProperties(DictMixin): def __init__(self, **kwargs: Any) -> None: self.name = None # type: ignore [assignment] - self.last_modified = kwargs.get('Last-Modified') # type: ignore [assignment] - self.etag = kwargs.get('ETag') # type: ignore [assignment] - self.quota = kwargs.get('x-ms-share-quota') # type: ignore [assignment] - self.access_tier = kwargs.get('x-ms-access-tier') # type: ignore [assignment] - self.next_allowed_quota_downgrade_time = kwargs.get('x-ms-share-next-allowed-quota-downgrade-time') - self.metadata = kwargs.get('metadata') # type: ignore [assignment] + self.last_modified = kwargs.get("Last-Modified") # type: ignore [assignment] + self.etag = kwargs.get("ETag") # type: ignore [assignment] + self.quota = kwargs.get("x-ms-share-quota") # type: ignore [assignment] + self.access_tier = kwargs.get("x-ms-access-tier") # type: ignore [assignment] + self.next_allowed_quota_downgrade_time = kwargs.get("x-ms-share-next-allowed-quota-downgrade-time") + self.metadata = kwargs.get("metadata") # type: ignore [assignment] self.snapshot = None self.deleted = None self.deleted_time = None self.version = None self.remaining_retention_days = None - self.provisioned_egress_mbps = kwargs.get('x-ms-share-provisioned-egress-mbps') - self.provisioned_ingress_mbps = kwargs.get('x-ms-share-provisioned-ingress-mbps') - self.provisioned_iops = kwargs.get('x-ms-share-provisioned-iops') - self.provisioned_bandwidth = kwargs.get('x-ms-share-provisioned-bandwidth-mibps') + self.provisioned_egress_mbps = kwargs.get("x-ms-share-provisioned-egress-mbps") + self.provisioned_ingress_mbps = kwargs.get("x-ms-share-provisioned-ingress-mbps") + self.provisioned_iops = kwargs.get("x-ms-share-provisioned-iops") + self.provisioned_bandwidth = kwargs.get("x-ms-share-provisioned-bandwidth-mibps") self.lease = LeaseProperties(**kwargs) - self.protocols = [protocol.strip() for protocol in kwargs.get('x-ms-enabled-protocols', None).split(',')]\ - if kwargs.get('x-ms-enabled-protocols', None) else None - self.root_squash = kwargs.get('x-ms-root-squash', None) - self.enable_snapshot_virtual_directory_access = \ - kwargs.get('x-ms-enable-snapshot-virtual-directory-access') - self.paid_bursting_enabled = kwargs.get('x-ms-share-paid-bursting-enabled') - self.paid_bursting_bandwidth_mibps = kwargs.get('x-ms-share-paid-bursting-max-bandwidth-mibps') - self.paid_bursting_iops = kwargs.get('x-ms-share-paid-bursting-max-iops') - self.included_burst_iops = kwargs.get('x-ms-share-included-burst-iops') - self.max_burst_credits_for_iops = kwargs.get('x-ms-share-max-burst-credits-for-iops') - self.next_provisioned_iops_downgrade = ( # pylint: disable=name-too-long - kwargs.get('x-ms-share-next-allowed-provisioned-iops-downgrade-time')) - self.next_provisioned_bandwidth_downgrade = ( # pylint: disable=name-too-long - kwargs.get('x-ms-share-next-allowed-provisioned-bandwidth-downgrade-time')) + self.protocols = ( + [protocol.strip() for protocol in kwargs.get("x-ms-enabled-protocols", None).split(",")] + if kwargs.get("x-ms-enabled-protocols", None) + else None + ) + self.root_squash = kwargs.get("x-ms-root-squash", None) + self.enable_snapshot_virtual_directory_access = kwargs.get("x-ms-enable-snapshot-virtual-directory-access") + self.paid_bursting_enabled = kwargs.get("x-ms-share-paid-bursting-enabled") + self.paid_bursting_bandwidth_mibps = kwargs.get("x-ms-share-paid-bursting-max-bandwidth-mibps") + self.paid_bursting_iops = kwargs.get("x-ms-share-paid-bursting-max-iops") + self.included_burst_iops = kwargs.get("x-ms-share-included-burst-iops") + self.max_burst_credits_for_iops = kwargs.get("x-ms-share-max-burst-credits-for-iops") + self.next_provisioned_iops_downgrade = kwargs.get( # pylint: disable=name-too-long + "x-ms-share-next-allowed-provisioned-iops-downgrade-time" + ) + self.next_provisioned_bandwidth_downgrade = kwargs.get( # pylint: disable=name-too-long + "x-ms-share-next-allowed-provisioned-bandwidth-downgrade-time" + ) @classmethod def _from_generated(cls, generated): @@ -596,8 +598,11 @@ def _from_generated(cls, generated): props.provisioned_iops = generated.properties.provisioned_iops props.provisioned_bandwidth = generated.properties.provisioned_bandwidth_mi_bps props.lease = LeaseProperties._from_generated(generated) # pylint: disable=protected-access - props.protocols = [protocol.strip() for protocol in generated.properties.enabled_protocols.split(',')]\ - if generated.properties.enabled_protocols else None + props.protocols = ( + [protocol.strip() for protocol in generated.properties.enabled_protocols.split(",")] + if generated.properties.enabled_protocols + else None + ) props.root_squash = generated.properties.root_squash props.enable_snapshot_virtual_directory_access = generated.properties.enable_snapshot_virtual_directory_access props.paid_bursting_enabled = generated.properties.paid_bursting_enabled @@ -606,9 +611,11 @@ def _from_generated(cls, generated): props.included_burst_iops = generated.properties.included_burst_iops props.max_burst_credits_for_iops = generated.properties.max_burst_credits_for_iops props.next_provisioned_iops_downgrade = ( # pylint: disable=name-too-long - generated.properties.next_allowed_provisioned_iops_downgrade_time) + generated.properties.next_allowed_provisioned_iops_downgrade_time + ) props.next_provisioned_bandwidth_downgrade = ( # pylint: disable=name-too-long - generated.properties.next_allowed_provisioned_bandwidth_downgrade_time) + generated.properties.next_allowed_provisioned_bandwidth_downgrade_time + ) return props @@ -637,15 +644,14 @@ class SharePropertiesPaged(PageIterator): """The current page of listed results.""" def __init__( - self, command: Callable, + self, + command: Callable, prefix: Optional[str] = None, results_per_page: Optional[int] = None, - continuation_token: Optional[str] = None + continuation_token: Optional[str] = None, ) -> None: super(SharePropertiesPaged, self).__init__( - get_next=self._get_next_cb, - extract_data=self._extract_data_cb, - continuation_token=continuation_token or "" + get_next=self._get_next_cb, extract_data=self._extract_data_cb, continuation_token=continuation_token or "" ) self._command = command self.service_endpoint = None @@ -662,7 +668,8 @@ def _get_next_cb(self, continuation_token): maxresults=self.results_per_page, prefix=self.prefix, cls=return_context_and_deserialized, - use_location=self.location_mode) + use_location=self.location_mode, + ) except HttpResponseError as error: process_storage_error(error) @@ -672,7 +679,9 @@ def _extract_data_cb(self, get_next_return): self.prefix = self._response.prefix self.marker = self._response.marker self.results_per_page = self._response.max_results - self.current_page = [ShareProperties._from_generated(i) for i in self._response.share_items] # pylint: disable=protected-access + self.current_page = [ + ShareProperties._from_generated(i) for i in self._response.share_items + ] # pylint: disable=protected-access return self._response.next_marker or None, self.current_page @@ -713,20 +722,20 @@ class Handle(DictMixin): """Time when the session that previously opened the handle was last been reconnected. (UTC)""" last_reconnect_time: Optional["datetime"] """Time handle that was last connected to. (UTC)""" - access_rights: List[Literal['Read', 'Write', 'Delete']] + access_rights: List[Literal["Read", "Write", "Delete"]] """Access rights of the handle.""" def __init__(self, **kwargs: Any) -> None: - self.client_name = kwargs.get('client_name') # type: ignore [assignment] - self.id = kwargs.get('handle_id') # type: ignore [assignment] - self.path = kwargs.get('path') # type: ignore [assignment] - self.file_id = kwargs.get('file_id') # type: ignore [assignment] - self.parent_id = kwargs.get('parent_id') # type: ignore [assignment] - self.session_id = kwargs.get('session_id') # type: ignore [assignment] - self.client_ip = kwargs.get('client_ip') # type: ignore [assignment] - self.open_time = kwargs.get('open_time') # type: ignore [assignment] - self.last_reconnect_time = kwargs.get('last_reconnect_time') - self.access_rights = kwargs.get('access_right_list') # type: ignore [assignment] + self.client_name = kwargs.get("client_name") # type: ignore [assignment] + self.id = kwargs.get("handle_id") # type: ignore [assignment] + self.path = kwargs.get("path") # type: ignore [assignment] + self.file_id = kwargs.get("file_id") # type: ignore [assignment] + self.parent_id = kwargs.get("parent_id") # type: ignore [assignment] + self.session_id = kwargs.get("session_id") # type: ignore [assignment] + self.client_ip = kwargs.get("client_ip") # type: ignore [assignment] + self.open_time = kwargs.get("open_time") # type: ignore [assignment] + self.last_reconnect_time = kwargs.get("last_reconnect_time") + self.access_rights = kwargs.get("access_right_list") # type: ignore [assignment] @classmethod def _from_generated(cls, generated): @@ -763,14 +772,10 @@ class HandlesPaged(PageIterator): """The current page of listed results.""" def __init__( - self, command: Callable, - results_per_page: Optional[int] = None, - continuation_token: Optional[str] = None + self, command: Callable, results_per_page: Optional[int] = None, continuation_token: Optional[str] = None ) -> None: super(HandlesPaged, self).__init__( - get_next=self._get_next_cb, - extract_data=self._extract_data_cb, - continuation_token=continuation_token or "" + get_next=self._get_next_cb, extract_data=self._extract_data_cb, continuation_token=continuation_token or "" ) self._command = command self.marker = None @@ -784,13 +789,16 @@ def _get_next_cb(self, continuation_token): marker=continuation_token or None, maxresults=self.results_per_page, cls=return_context_and_deserialized, - use_location=self.location_mode) + use_location=self.location_mode, + ) except HttpResponseError as error: process_storage_error(error) def _extract_data_cb(self, get_next_return): self.location_mode, self._response = get_next_return - self.current_page = [Handle._from_generated(h) for h in self._response.handle_list] # pylint: disable=protected-access + self.current_page = [ + Handle._from_generated(h) for h in self._response.handle_list + ] # pylint: disable=protected-access return self._response.next_marker or None, self.current_page @@ -822,7 +830,8 @@ class NTFSAttributes(object): """Enable/disable 'NoScrubData' attribute for DIRECTORY.""" def __init__( - self, read_only: bool = False, + self, + read_only: bool = False, hidden: bool = False, system: bool = False, none: bool = False, @@ -831,7 +840,7 @@ def __init__( temporary: bool = False, offline: bool = False, not_content_indexed: bool = False, - no_scrub_data: bool = False + no_scrub_data: bool = False, ) -> None: self.read_only = read_only self.hidden = hidden @@ -843,20 +852,22 @@ def __init__( self.offline = offline self.not_content_indexed = not_content_indexed self.no_scrub_data = no_scrub_data - self._str = (('ReadOnly|' if self.read_only else '') + - ('Hidden|' if self.hidden else '') + - ('System|' if self.system else '') + - ('None|' if self.none else '') + - ('Directory|' if self.directory else '') + - ('Archive|' if self.archive else '') + - ('Temporary|' if self.temporary else '') + - ('Offline|' if self.offline else '') + - ('NotContentIndexed|' if self.not_content_indexed else '') + - ('NoScrubData|' if self.no_scrub_data else '')) + self._str = ( + ("ReadOnly|" if self.read_only else "") + + ("Hidden|" if self.hidden else "") + + ("System|" if self.system else "") + + ("None|" if self.none else "") + + ("Directory|" if self.directory else "") + + ("Archive|" if self.archive else "") + + ("Temporary|" if self.temporary else "") + + ("Offline|" if self.offline else "") + + ("NotContentIndexed|" if self.not_content_indexed else "") + + ("NoScrubData|" if self.no_scrub_data else "") + ) def __str__(self): concatenated_params = self._str - return concatenated_params.strip('|') + return concatenated_params.strip("|") @classmethod def from_string(cls, string: str) -> Self: @@ -880,8 +891,9 @@ def from_string(cls, string: str) -> Self: not_content_indexed = "NotContentIndexed" in string no_scrub_data = "NoScrubData" in string - parsed = cls(read_only, hidden, system, none, directory, archive, temporary, offline, not_content_indexed, - no_scrub_data) + parsed = cls( + read_only, hidden, system, none, directory, archive, temporary, offline, not_content_indexed, no_scrub_data + ) parsed._str = string return parsed @@ -923,28 +935,28 @@ class DirectoryProperties(DictMixin): """NFS only. The owning group of the directory.""" file_mode: Optional[str] = None """NFS only. The file mode of the directory.""" - nfs_file_type: Optional[Literal['Directory']] = None + nfs_file_type: Optional[Literal["Directory"]] = None """NFS only. The type of the directory.""" def __init__(self, **kwargs: Any) -> None: self.name = None # type: ignore [assignment] - self.last_modified = kwargs.get('Last-Modified') # type: ignore [assignment] - self.etag = kwargs.get('ETag') # type: ignore [assignment] - self.server_encrypted = kwargs.get('x-ms-server-encrypted') # type: ignore [assignment] - self.metadata = kwargs.get('metadata') # type: ignore [assignment] - self.change_time = _parse_datetime_from_str(kwargs.get('x-ms-file-change-time')) - self.creation_time = _parse_datetime_from_str(kwargs.get('x-ms-file-creation-time')) - self.last_write_time = _parse_datetime_from_str(kwargs.get('x-ms-file-last-write-time')) + self.last_modified = kwargs.get("Last-Modified") # type: ignore [assignment] + self.etag = kwargs.get("ETag") # type: ignore [assignment] + self.server_encrypted = kwargs.get("x-ms-server-encrypted") # type: ignore [assignment] + self.metadata = kwargs.get("metadata") # type: ignore [assignment] + self.change_time = _parse_datetime_from_str(kwargs.get("x-ms-file-change-time")) + self.creation_time = _parse_datetime_from_str(kwargs.get("x-ms-file-creation-time")) + self.last_write_time = _parse_datetime_from_str(kwargs.get("x-ms-file-last-write-time")) self.last_access_time = None - self.file_attributes = kwargs.get('x-ms-file-attributes') # type: ignore [assignment] - self.permission_key = kwargs.get('x-ms-file-permission-key') # type: ignore [assignment] - self.file_id = kwargs.get('x-ms-file-id') # type: ignore [assignment] - self.parent_id = kwargs.get('x-ms-file-parent-id') # type: ignore [assignment] + self.file_attributes = kwargs.get("x-ms-file-attributes") # type: ignore [assignment] + self.permission_key = kwargs.get("x-ms-file-permission-key") # type: ignore [assignment] + self.file_id = kwargs.get("x-ms-file-id") # type: ignore [assignment] + self.parent_id = kwargs.get("x-ms-file-parent-id") # type: ignore [assignment] self.is_directory = True - self.owner = kwargs.get('x-ms-owner') - self.group = kwargs.get('x-ms-group') - self.file_mode = kwargs.get('x-ms-mode') - self.nfs_file_type = kwargs.get('x-ms-file-file-type') + self.owner = kwargs.get("x-ms-owner") + self.group = kwargs.get("x-ms-group") + self.file_mode = kwargs.get("x-ms-mode") + self.nfs_file_type = kwargs.get("x-ms-file-file-type") @classmethod def _from_generated(cls, generated): @@ -992,15 +1004,14 @@ class DirectoryPropertiesPaged(PageIterator): """The current page of listed results.""" def __init__( - self, command: Callable, + self, + command: Callable, prefix: Optional[str] = None, results_per_page: Optional[int] = None, - continuation_token: Optional[str] = None + continuation_token: Optional[str] = None, ) -> None: super(DirectoryPropertiesPaged, self).__init__( - get_next=self._get_next_cb, - extract_data=self._extract_data_cb, - continuation_token=continuation_token or "" + get_next=self._get_next_cb, extract_data=self._extract_data_cb, continuation_token=continuation_token or "" ) self._command = command self.service_endpoint = None @@ -1017,7 +1028,8 @@ def _get_next_cb(self, continuation_token): prefix=self.prefix, maxresults=self.results_per_page, cls=return_context_and_deserialized, - use_location=self.location_mode) + use_location=self.location_mode, + ) except HttpResponseError as error: process_storage_error(error) @@ -1027,8 +1039,12 @@ def _extract_data_cb(self, get_next_return): self.prefix = self._response.prefix self.marker = self._response.marker self.results_per_page = self._response.max_results - self.current_page = [DirectoryProperties._from_generated(i) for i in self._response.segment.directory_items] # pylint: disable = protected-access - self.current_page.extend([FileProperties._from_generated(i) for i in self._response.segment.file_items]) # pylint: disable = protected-access + self.current_page = [ + DirectoryProperties._from_generated(i) for i in self._response.segment.directory_items + ] # pylint: disable = protected-access + self.current_page.extend( + [FileProperties._from_generated(i) for i in self._response.segment.file_items] + ) # pylint: disable = protected-access return self._response.next_marker or None, self.current_page @@ -1079,14 +1095,14 @@ class CopyProperties(DictMixin): failed copy attempt.""" def __init__(self, **kwargs: Any) -> None: - self.id = kwargs.get('x-ms-copy-id') # type: ignore [assignment] - self.source = kwargs.get('x-ms-copy-source') - self.status = get_enum_value(kwargs.get('x-ms-copy-status')) - self.progress = kwargs.get('x-ms-copy-progress') - self.completion_time = kwargs.get('x-ms-copy-completion_time') - self.status_description = kwargs.get('x-ms-copy-status-description') - self.incremental_copy = kwargs.get('x-ms-incremental-copy') - self.destination_snapshot = kwargs.get('x-ms-copy-destination-snapshot') + self.id = kwargs.get("x-ms-copy-id") # type: ignore [assignment] + self.source = kwargs.get("x-ms-copy-source") + self.status = get_enum_value(kwargs.get("x-ms-copy-status")) + self.progress = kwargs.get("x-ms-copy-progress") + self.completion_time = kwargs.get("x-ms-copy-completion_time") + self.status_description = kwargs.get("x-ms-copy-status-description") + self.incremental_copy = kwargs.get("x-ms-incremental-copy") + self.destination_snapshot = kwargs.get("x-ms-copy-destination-snapshot") @classmethod def _from_generated(cls, generated): @@ -1162,39 +1178,39 @@ class FileProperties(DictMixin): """NFS only. The file mode of the file.""" link_count: Optional[int] = None """NFS only. The number of hard links of the file.""" - nfs_file_type: Optional[Literal['Regular']] = None + nfs_file_type: Optional[Literal["Regular"]] = None """NFS only. The type of the file.""" def __init__(self, **kwargs: Any) -> None: - self.name = kwargs.get('name') # type: ignore [assignment] + self.name = kwargs.get("name") # type: ignore [assignment] self.path = None self.share = None self.snapshot = None - self.content_length = kwargs.get('Content-Length') # type: ignore [assignment] - self.metadata = kwargs.get('metadata') # type: ignore [assignment] - self.file_type = kwargs.get('x-ms-type') # type: ignore [assignment] - self.last_modified = kwargs.get('Last-Modified') # type: ignore [assignment] - self.etag = kwargs.get('ETag') # type: ignore [assignment] - self.size = kwargs.get('Content-Length') # type: ignore [assignment] - self.content_range = kwargs.get('Content-Range') - self.server_encrypted = kwargs.get('x-ms-server-encrypted') # type: ignore [assignment] + self.content_length = kwargs.get("Content-Length") # type: ignore [assignment] + self.metadata = kwargs.get("metadata") # type: ignore [assignment] + self.file_type = kwargs.get("x-ms-type") # type: ignore [assignment] + self.last_modified = kwargs.get("Last-Modified") # type: ignore [assignment] + self.etag = kwargs.get("ETag") # type: ignore [assignment] + self.size = kwargs.get("Content-Length") # type: ignore [assignment] + self.content_range = kwargs.get("Content-Range") + self.server_encrypted = kwargs.get("x-ms-server-encrypted") # type: ignore [assignment] self.copy = CopyProperties(**kwargs) self.content_settings = ContentSettings(**kwargs) self.lease = LeaseProperties(**kwargs) - self.change_time = _parse_datetime_from_str(kwargs.get('x-ms-file-change-time')) - self.creation_time = _parse_datetime_from_str(kwargs.get('x-ms-file-creation-time')) - self.last_write_time = _parse_datetime_from_str(kwargs.get('x-ms-file-last-write-time')) + self.change_time = _parse_datetime_from_str(kwargs.get("x-ms-file-change-time")) + self.creation_time = _parse_datetime_from_str(kwargs.get("x-ms-file-creation-time")) + self.last_write_time = _parse_datetime_from_str(kwargs.get("x-ms-file-last-write-time")) self.last_access_time = None - self.file_attributes = kwargs.get('x-ms-file-attributes') # type: ignore [assignment] - self.permission_key = kwargs.get('x-ms-file-permission-key') # type: ignore [assignment] - self.file_id = kwargs.get('x-ms-file-id') # type: ignore [assignment] - self.parent_id = kwargs.get('x-ms-file-parent-id') + self.file_attributes = kwargs.get("x-ms-file-attributes") # type: ignore [assignment] + self.permission_key = kwargs.get("x-ms-file-permission-key") # type: ignore [assignment] + self.file_id = kwargs.get("x-ms-file-id") # type: ignore [assignment] + self.parent_id = kwargs.get("x-ms-file-parent-id") self.is_directory = False - self.owner = kwargs.get('x-ms-owner') - self.group = kwargs.get('x-ms-group') - self.file_mode = kwargs.get('x-ms-mode') - self.link_count = kwargs.get('x-ms-link-count') - self.nfs_file_type = kwargs.get('x-ms-file-file-type') + self.owner = kwargs.get("x-ms-owner") + self.group = kwargs.get("x-ms-group") + self.file_mode = kwargs.get("x-ms-mode") + self.link_count = kwargs.get("x-ms-link-count") + self.nfs_file_type = kwargs.get("x-ms-file-file-type") @classmethod def _from_generated(cls, generated): @@ -1215,6 +1231,7 @@ def _from_generated(cls, generated): class ShareProtocols(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Enabled protocols on the share""" + SMB = "SMB" NFS = "NFS" @@ -1244,20 +1261,17 @@ class FileSasPermissions(object): delete: bool = False """Delete the file.""" - def __init__( - self, read: bool = False, - create: bool = False, - write: bool = False, - delete: bool = False - ) -> None: + def __init__(self, read: bool = False, create: bool = False, write: bool = False, delete: bool = False) -> None: self.read = read self.create = create self.write = write self.delete = delete - self._str = (('r' if self.read else '') + - ('c' if self.create else '') + - ('w' if self.write else '') + - ('d' if self.delete else '')) + self._str = ( + ("r" if self.read else "") + + ("c" if self.create else "") + + ("w" if self.write else "") + + ("d" if self.delete else "") + ) def __str__(self): return self._str @@ -1275,10 +1289,10 @@ def from_string(cls, permission: str) -> Self: :return: A FileSasPermissions object :rtype: ~azure.storage.fileshare.FileSasPermissions """ - p_read = 'r' in permission - p_create = 'c' in permission - p_write = 'w' in permission - p_delete = 'd' in permission + p_read = "r" in permission + p_create = "c" in permission + p_write = "w" in permission + p_delete = "d" in permission parsed = cls(p_read, p_create, p_write, p_delete) @@ -1287,8 +1301,8 @@ def from_string(cls, permission: str) -> Self: def service_properties_deserialize(generated: GeneratedStorageServiceProperties) -> Dict[str, Any]: return { - 'hour_metrics': Metrics._from_generated(generated.hour_metrics), # pylint: disable=protected-access - 'minute_metrics': Metrics._from_generated(generated.minute_metrics), # pylint: disable=protected-access - 'cors': [CorsRule._from_generated(cors) for cors in generated.cors], # type: ignore [union-attr] # pylint: disable=protected-access - 'protocol': ShareProtocolSettings._from_generated(generated.protocol), # pylint: disable=protected-access + "hour_metrics": Metrics._from_generated(generated.hour_metrics), # pylint: disable=protected-access + "minute_metrics": Metrics._from_generated(generated.minute_metrics), # pylint: disable=protected-access + "cors": [CorsRule._from_generated(cors) for cors in generated.cors], # type: ignore [union-attr] # pylint: disable=protected-access + "protocol": ShareProtocolSettings._from_generated(generated.protocol), # pylint: disable=protected-access } diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_parser.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_parser.py index ed7c9488b88d..f97ea39cd262 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_parser.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_parser.py @@ -9,15 +9,16 @@ from ._generated._serialization import Serializer -_ERROR_TOO_MANY_FILE_PERMISSIONS = 'file_permission and file_permission_key should not be set at the same time' -_FILE_PERMISSION_TOO_LONG = 'Size of file_permission is too large. file_permission should be <=8KB, else' \ - 'please use file_permission_key' +_ERROR_TOO_MANY_FILE_PERMISSIONS = "file_permission and file_permission_key should not be set at the same time" +_FILE_PERMISSION_TOO_LONG = ( + "Size of file_permission is too large. file_permission should be <=8KB, else" "please use file_permission_key" +) def _get_file_permission(file_permission, file_permission_key, default_permission): # if file_permission and file_permission_key are both empty, then use the default_permission # value as file permission, file_permission size should be <= 8KB, else file permission_key should be used - if file_permission and len(str(file_permission).encode('utf-8')) > 8 * 1024: + if file_permission and len(str(file_permission).encode("utf-8")) > 8 * 1024: raise ValueError(_FILE_PERMISSION_TOO_LONG) if not file_permission: @@ -50,11 +51,10 @@ def _datetime_to_str(datetime_obj): def _parse_snapshot( - snapshot: Optional[Union[str, Dict[str, Any]]] = None, - path_snapshot: Optional[str] = None + snapshot: Optional[Union[str, Dict[str, Any]]] = None, path_snapshot: Optional[str] = None ) -> Optional[str]: - if hasattr(snapshot, 'snapshot'): + if hasattr(snapshot, "snapshot"): return snapshot.snapshot # type: ignore if isinstance(snapshot, Dict): - return cast(str, snapshot['snapshot']) + return cast(str, snapshot["snapshot"]) return snapshot or path_snapshot diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_serialize.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_serialize.py index a936badfe37a..b613f8f11898 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_serialize.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_serialize.py @@ -14,7 +14,7 @@ LeaseAccessConditions, SourceLeaseAccessConditions, DestinationLeaseAccessConditions, - CopyFileSmbInfo + CopyFileSmbInfo, ) if TYPE_CHECKING: @@ -23,39 +23,37 @@ _SUPPORTED_API_VERSIONS = [ - '2019-02-02', - '2019-07-07', - '2019-10-10', - '2019-12-12', - '2020-02-10', - '2020-04-08', - '2020-06-12', - '2020-08-04', - '2020-10-02', - '2020-12-06', - '2021-02-12', - '2021-04-10', - '2021-06-08', - '2021-08-06', - '2021-12-02', - '2022-11-02', - '2023-01-03', - '2023-05-03', - '2023-08-03', - '2023-11-03', - '2024-05-04', - '2024-08-04', - '2024-11-04', - '2025-01-05', - '2025-05-05', - '2025-07-05', + "2019-02-02", + "2019-07-07", + "2019-10-10", + "2019-12-12", + "2020-02-10", + "2020-04-08", + "2020-06-12", + "2020-08-04", + "2020-10-02", + "2020-12-06", + "2021-02-12", + "2021-04-10", + "2021-06-08", + "2021-08-06", + "2021-12-02", + "2022-11-02", + "2023-01-03", + "2023-05-03", + "2023-08-03", + "2023-11-03", + "2024-05-04", + "2024-08-04", + "2024-11-04", + "2025-01-05", + "2025-05-05", + "2025-07-05", ] def _get_match_headers( - kwargs: Dict[str, Any], - match_param: str, - etag_param: str + kwargs: Dict[str, Any], match_param: str, etag_param: str ) -> Tuple[Optional[str], Optional[str]]: if_match = None if_none_match = None @@ -65,13 +63,13 @@ def _get_match_headers( if not if_match: raise ValueError(f"'{match_param}' specified without '{etag_param}'.") elif match_condition == MatchConditions.IfPresent: - if_match = '*' + if_match = "*" elif match_condition == MatchConditions.IfModified: if_none_match = kwargs.pop(etag_param, None) if not if_none_match: raise ValueError(f"'{match_param}' specified without '{etag_param}'.") elif match_condition == MatchConditions.IfMissing: - if_none_match = '*' + if_none_match = "*" elif match_condition is None: if etag_param in kwargs: raise ValueError(f"'{etag_param}' specified without '{match_param}'.") @@ -81,12 +79,12 @@ def _get_match_headers( def get_source_conditions(kwargs: Dict[str, Any]) -> SourceModifiedAccessConditions: - if_match, if_none_match = _get_match_headers(kwargs, 'source_match_condition', 'source_etag') + if_match, if_none_match = _get_match_headers(kwargs, "source_match_condition", "source_etag") return SourceModifiedAccessConditions( - source_if_modified_since=kwargs.pop('source_if_modified_since', None), - source_if_unmodified_since=kwargs.pop('source_if_unmodified_since', None), - source_if_match=if_match or kwargs.pop('source_if_match', None), - source_if_none_match=if_none_match or kwargs.pop('source_if_none_match', None) + source_if_modified_since=kwargs.pop("source_if_modified_since", None), + source_if_unmodified_since=kwargs.pop("source_if_unmodified_since", None), + source_if_match=if_match or kwargs.pop("source_if_match", None), + source_if_none_match=if_none_match or kwargs.pop("source_if_none_match", None), ) @@ -127,14 +125,14 @@ def get_dest_access_conditions( def get_smb_properties(kwargs: Dict[str, Any]) -> Dict[str, Any]: - ignore_read_only = kwargs.pop('ignore_read_only', None) - set_archive_attribute = kwargs.pop('set_archive_attribute', None) - file_permission = kwargs.pop('file_permission', None) - file_permission_key = kwargs.pop('permission_key', None) - file_attributes = kwargs.pop('file_attributes', None) - file_creation_time = kwargs.pop('file_creation_time', None) - file_last_write_time = kwargs.pop('file_last_write_time', None) - file_change_time = kwargs.pop('file_change_time', None) + ignore_read_only = kwargs.pop("ignore_read_only", None) + set_archive_attribute = kwargs.pop("set_archive_attribute", None) + file_permission = kwargs.pop("file_permission", None) + file_permission_key = kwargs.pop("permission_key", None) + file_attributes = kwargs.pop("file_attributes", None) + file_creation_time = kwargs.pop("file_creation_time", None) + file_last_write_time = kwargs.pop("file_last_write_time", None) + file_change_time = kwargs.pop("file_change_time", None) file_permission_copy_mode = None file_permission = _get_file_permission(file_permission, file_permission_key, None) @@ -152,45 +150,45 @@ def get_smb_properties(kwargs: Dict[str, Any]) -> Dict[str, Any]: else: file_permission_copy_mode = "override" return { - 'file_permission': file_permission, - 'file_permission_key': file_permission_key, - 'copy_file_smb_info': CopyFileSmbInfo( + "file_permission": file_permission, + "file_permission_key": file_permission_key, + "copy_file_smb_info": CopyFileSmbInfo( file_permission_copy_mode=file_permission_copy_mode, ignore_read_only=ignore_read_only, file_attributes=file_attributes, file_creation_time=_datetime_to_str(file_creation_time), file_last_write_time=_datetime_to_str(file_last_write_time), file_change_time=_datetime_to_str(file_change_time), - set_archive_attribute=set_archive_attribute - ) - + set_archive_attribute=set_archive_attribute, + ), } def get_rename_smb_properties(kwargs: Dict[str, Any]) -> Dict[str, Any]: - file_permission = kwargs.pop('file_permission', None) - file_permission_key = kwargs.pop('permission_key', None) - file_attributes = kwargs.pop('file_attributes', None) - file_creation_time = kwargs.pop('file_creation_time', None) - file_last_write_time = kwargs.pop('file_last_write_time', None) - file_change_time = kwargs.pop('file_change_time', None) + file_permission = kwargs.pop("file_permission", None) + file_permission_key = kwargs.pop("permission_key", None) + file_attributes = kwargs.pop("file_attributes", None) + file_creation_time = kwargs.pop("file_creation_time", None) + file_last_write_time = kwargs.pop("file_last_write_time", None) + file_change_time = kwargs.pop("file_change_time", None) file_permission = _get_file_permission(file_permission, file_permission_key, None) return { - 'file_permission': file_permission, - 'file_permission_key': file_permission_key, - 'copy_file_smb_info': CopyFileSmbInfo( + "file_permission": file_permission, + "file_permission_key": file_permission_key, + "copy_file_smb_info": CopyFileSmbInfo( file_attributes=file_attributes, file_creation_time=_datetime_to_str(file_creation_time), file_last_write_time=_datetime_to_str(file_last_write_time), - file_change_time=_datetime_to_str(file_change_time) - )} + file_change_time=_datetime_to_str(file_change_time), + ), + } def get_api_version(kwargs: Dict[str, Any]) -> str: - api_version = kwargs.get('api_version', None) + api_version = kwargs.get("api_version", None) if api_version and api_version not in _SUPPORTED_API_VERSIONS: - versions = '\n'.join(_SUPPORTED_API_VERSIONS) + versions = "\n".join(_SUPPORTED_API_VERSIONS) raise ValueError(f"Unsupported API version '{api_version}'. Please select from:\n{versions}") return api_version or _SUPPORTED_API_VERSIONS[-1] diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py index 602757dd1988..32281f873b3e 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py @@ -5,10 +5,7 @@ # -------------------------------------------------------------------------- # pylint: disable=docstring-keyword-should-match-keyword-only -from typing import ( - Any, cast, Dict, Literal, Optional, Union, - TYPE_CHECKING -) +from typing import Any, cast, Dict, Literal, Optional, Union, TYPE_CHECKING from typing_extensions import Self from azure.core.exceptions import HttpResponseError @@ -19,28 +16,15 @@ from ._directory_client import ShareDirectoryClient from ._file_client import ShareFileClient from ._generated import AzureFileStorage -from ._generated.models import ( - DeleteSnapshotsOptionType, - ShareStats, - SignedIdentifier -) +from ._generated.models import DeleteSnapshotsOptionType, ShareStats, SignedIdentifier from ._lease import ShareLeaseClient from ._models import ShareProtocols from ._parser import _parse_snapshot from ._serialize import get_access_conditions, get_api_version -from ._share_client_helpers import ( - _create_permission_for_share_options, - _format_url, - _from_share_url, - _parse_url -) +from ._share_client_helpers import _create_permission_for_share_options, _format_url, _from_share_url, _parse_url from ._shared.base_client import parse_connection_str, parse_query, StorageAccountHostsMixin, TransportWrapper from ._shared.request_handlers import add_metadata_headers, serialize_iso -from ._shared.response_handlers import ( - process_storage_error, - return_headers_and_deserialized, - return_response_headers -) +from ._shared.response_handlers import process_storage_error, return_headers_and_deserialized, return_response_headers if TYPE_CHECKING: @@ -101,45 +85,58 @@ class ShareClient(StorageAccountHostsMixin): The hostname of the secondary endpoint. :keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024. """ + def __init__( - self, account_url: str, + self, + account_url: str, share_name: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long *, - token_intent: Optional[Literal['backup']] = None, + token_intent: Optional[Literal["backup"]] = None, **kwargs: Any ) -> None: - if hasattr(credential, 'get_token') and not token_intent: + if hasattr(credential, "get_token") and not token_intent: raise ValueError("'token_intent' keyword is required when 'credential' is an TokenCredential.") parsed_url = _parse_url(account_url, share_name) path_snapshot, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: raise ValueError( - 'You need to provide either an account shared key or SAS token when creating a storage service.') + "You need to provide either an account shared key or SAS token when creating a storage service." + ) self.snapshot = _parse_snapshot(snapshot, path_snapshot) self.share_name = share_name self._query_str, credential = self._format_query_string( - sas_token=sas_token, credential=credential, share_snapshot=self.snapshot) - super(ShareClient, self).__init__( - parsed_url=parsed_url, service='file-share', credential=credential, **kwargs) - self.allow_trailing_dot = kwargs.pop('allow_trailing_dot', None) - self.allow_source_trailing_dot = kwargs.pop('allow_source_trailing_dot', None) + sas_token=sas_token, credential=credential, share_snapshot=self.snapshot + ) + super(ShareClient, self).__init__(parsed_url=parsed_url, service="file-share", credential=credential, **kwargs) + self.allow_trailing_dot = kwargs.pop("allow_trailing_dot", None) + self.allow_source_trailing_dot = kwargs.pop("allow_source_trailing_dot", None) self.file_request_intent = token_intent - self._client = AzureFileStorage(url=self.url, base_url=self.url, pipeline=self._pipeline, - allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, - file_request_intent=self.file_request_intent) + self._client = AzureFileStorage( + url=self.url, + base_url=self.url, + pipeline=self._pipeline, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + file_request_intent=self.file_request_intent, + ) self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] @classmethod def from_share_url( - cls, share_url: str, + cls, + share_url: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long **kwargs: Any ) -> Self: - """ + """Create ShareClient from a Share URL. + :param str share_url: The full URI to the share. :param snapshot: An optional share snapshot on which to operate. This can be the snapshot ID string @@ -177,10 +174,13 @@ def _format_url(self, hostname: str) -> str: @classmethod def from_connection_string( - cls, conn_str: str, + cls, + conn_str: str, share_name: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long **kwargs: Any ) -> Self: """Create ShareClient from a Connection String. @@ -218,11 +218,10 @@ def from_connection_string( :dedent: 8 :caption: Gets the share client from connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, 'file') - if 'secondary_hostname' not in kwargs: - kwargs['secondary_hostname'] = secondary - return cls( - account_url, share_name=share_name, snapshot=snapshot, credential=credential, **kwargs) + account_url, secondary, credential = parse_connection_str(conn_str, credential, "file") + if "secondary_hostname" not in kwargs: + kwargs["secondary_hostname"] = secondary + return cls(account_url, share_name=share_name, snapshot=snapshot, credential=credential, **kwargs) def get_directory_client(self, directory_path: Optional[str] = None) -> ShareDirectoryClient: """Get a client to interact with the specified directory. @@ -235,15 +234,24 @@ def get_directory_client(self, directory_path: Optional[str] = None) -> ShareDir """ _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access - policies=self._pipeline._impl_policies # pylint: disable=protected-access + policies=self._pipeline._impl_policies, # pylint: disable=protected-access ) return ShareDirectoryClient( - self.url, share_name=self.share_name, directory_path=directory_path or "", snapshot=self.snapshot, - credential=self.credential, token_intent=self.file_request_intent, api_version=self.api_version, - _hosts=self._hosts, _configuration=self._config, _pipeline=_pipeline, - _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot) + self.url, + share_name=self.share_name, + directory_path=directory_path or "", + snapshot=self.snapshot, + credential=self.credential, + token_intent=self.file_request_intent, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + ) def get_file_client(self, file_path: str) -> ShareFileClient: """Get a client to interact with the specified file. @@ -256,15 +264,24 @@ def get_file_client(self, file_path: str) -> ShareFileClient: """ _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access - policies=self._pipeline._impl_policies # pylint: disable=protected-access + policies=self._pipeline._impl_policies, # pylint: disable=protected-access ) return ShareFileClient( - self.url, share_name=self.share_name, file_path=file_path, snapshot=self.snapshot, - credential=self.credential, token_intent=self.file_request_intent, api_version=self.api_version, - _hosts=self._hosts, _configuration=self._config, - _pipeline=_pipeline, _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot) + self.url, + share_name=self.share_name, + file_path=file_path, + snapshot=self.snapshot, + credential=self.credential, + token_intent=self.file_request_intent, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + ) @distributed_trace def acquire_lease(self, **kwargs: Any) -> ShareLeaseClient: @@ -302,8 +319,8 @@ def acquire_lease(self, **kwargs: Any) -> ShareLeaseClient: :dedent: 8 :caption: Acquiring a lease on a share. """ - kwargs['lease_duration'] = kwargs.pop('lease_duration', -1) - lease_id = kwargs.pop('lease_id', None) + kwargs["lease_duration"] = kwargs.pop("lease_duration", -1) + lease_id = kwargs.pop("lease_id", None) lease = ShareLeaseClient(self, lease_id=lease_id) lease.acquire(**kwargs) return lease @@ -321,7 +338,7 @@ def create_share(self, **kwargs: Any) -> Dict[str, Any]: :keyword access_tier: Specifies the access tier of the share. Possible values: 'TransactionOptimized', 'Hot', 'Cool', 'Premium' - :paramtype access_tier: str or ~azure.storage.fileshare.models.ShareAccessTier + :paramtype access_tier: str or ~azure.storage.fileshare.ShareAccessTier .. versionadded:: 12.4.0 @@ -355,38 +372,42 @@ def create_share(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 8 :caption: Creates a file share. """ - metadata = kwargs.pop('metadata', None) - quota = kwargs.pop('quota', None) - access_tier = kwargs.pop('access_tier', None) - timeout = kwargs.pop('timeout', None) - root_squash = kwargs.pop('root_squash', None) - protocols = kwargs.pop('protocols', None) - paid_bursting_bandwidth_mibps = kwargs.pop('paid_bursting_bandwidth_mibps', None) - paid_bursting_iops = kwargs.pop('paid_bursting_iops', None) - share_provisioned_iops = kwargs.pop('provisioned_iops', None) - share_provisioned_bandwidth_mibps = kwargs.pop('provisioned_bandwidth_mibps', None) - if protocols and protocols not in ['NFS', 'SMB', ShareProtocols.SMB, ShareProtocols.NFS]: + metadata = kwargs.pop("metadata", None) + quota = kwargs.pop("quota", None) + access_tier = kwargs.pop("access_tier", None) + timeout = kwargs.pop("timeout", None) + root_squash = kwargs.pop("root_squash", None) + protocols = kwargs.pop("protocols", None) + paid_bursting_bandwidth_mibps = kwargs.pop("paid_bursting_bandwidth_mibps", None) + paid_bursting_iops = kwargs.pop("paid_bursting_iops", None) + share_provisioned_iops = kwargs.pop("provisioned_iops", None) + share_provisioned_bandwidth_mibps = kwargs.pop("provisioned_bandwidth_mibps", None) + if protocols and protocols not in ["NFS", "SMB", ShareProtocols.SMB, ShareProtocols.NFS]: raise ValueError("The enabled protocol must be set to either SMB or NFS.") - if root_squash and protocols not in ['NFS', ShareProtocols.NFS]: + if root_squash and protocols not in ["NFS", ShareProtocols.NFS]: raise ValueError("The 'root_squash' keyword can only be used on NFS enabled shares.") - headers = kwargs.pop('headers', {}) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], self._client.share.create( - timeout=timeout, - metadata=metadata, - quota=quota, - access_tier=access_tier, - root_squash=root_squash, - enabled_protocols=protocols, - paid_bursting_max_bandwidth_mibps=paid_bursting_bandwidth_mibps, - paid_bursting_max_iops=paid_bursting_iops, - share_provisioned_iops=share_provisioned_iops, - share_provisioned_bandwidth_mibps=share_provisioned_bandwidth_mibps, - cls=return_response_headers, - headers=headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.share.create( + timeout=timeout, + metadata=metadata, + quota=quota, + access_tier=access_tier, + root_squash=root_squash, + enabled_protocols=protocols, + paid_bursting_max_bandwidth_mibps=paid_bursting_bandwidth_mibps, + paid_bursting_max_iops=paid_bursting_iops, + share_provisioned_iops=share_provisioned_iops, + share_provisioned_bandwidth_mibps=share_provisioned_bandwidth_mibps, + cls=return_response_headers, + headers=headers, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -423,23 +444,23 @@ def create_snapshot(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 12 :caption: Creates a snapshot of the file share. """ - metadata = kwargs.pop('metadata', None) - timeout = kwargs.pop('timeout', None) - headers = kwargs.pop('headers', {}) + metadata = kwargs.pop("metadata", None) + timeout = kwargs.pop("timeout", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], self._client.share.create_snapshot( - timeout=timeout, - cls=return_response_headers, - headers=headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.share.create_snapshot( + timeout=timeout, cls=return_response_headers, headers=headers, **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace def delete_share( - self, delete_snapshots: Optional[Union[bool, Literal['include', 'include-leased']]] = False, - **kwargs: Any + self, delete_snapshots: Optional[Union[bool, Literal["include", "include-leased"]]] = False, **kwargs: Any ) -> None: """Marks the specified share for deletion. The share is later deleted during garbage collection. @@ -464,6 +485,8 @@ def delete_share( This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :returns: None + :rtype: None .. admonition:: Example: @@ -474,15 +497,15 @@ def delete_share( :dedent: 12 :caption: Deletes the share and any snapshots. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) delete_include = None if isinstance(delete_snapshots, bool) and delete_snapshots: delete_include = DeleteSnapshotsOptionType.INCLUDE else: - if delete_snapshots == 'include': + if delete_snapshots == "include": delete_include = DeleteSnapshotsOptionType.INCLUDE - elif delete_snapshots == 'include-leased': + elif delete_snapshots == "include-leased": delete_include = DeleteSnapshotsOptionType.INCLUDE_LEASED try: self._client.share.delete( @@ -490,7 +513,8 @@ def delete_share( sharesnapshot=self.snapshot, lease_access_conditions=access_conditions, delete_snapshots=delete_include, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) @@ -526,15 +550,19 @@ def get_share_properties(self, **kwargs: Any) -> "ShareProperties": :dedent: 12 :caption: Gets the share properties. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - props = cast("ShareProperties", self._client.share.get_properties( - timeout=timeout, - sharesnapshot=self.snapshot, - cls=deserialize_share_properties, - lease_access_conditions=access_conditions, - **kwargs)) + props = cast( + "ShareProperties", + self._client.share.get_properties( + timeout=timeout, + sharesnapshot=self.snapshot, + cls=deserialize_share_properties, + lease_access_conditions=access_conditions, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) props.name = self.share_name @@ -574,16 +602,20 @@ def set_share_quota(self, quota: int, **kwargs: Any) -> Dict[str, Any]: :dedent: 12 :caption: Sets the share quota. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - return cast(Dict[str, Any], self._client.share.set_properties( - timeout=timeout, - quota=quota, - access_tier=None, - lease_access_conditions=access_conditions, - cls=return_response_headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.share.set_properties( + timeout=timeout, + quota=quota, + access_tier=None, + lease_access_conditions=access_conditions, + cls=return_response_headers, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -596,7 +628,7 @@ def set_share_properties(self, **kwargs: Any) -> Dict[str, Any]: :keyword access_tier: Specifies the access tier of the share. Possible values: 'TransactionOptimized', 'Hot', 'Cool', 'Premium' - :paramtype access_tier: str or ~azure.storage.fileshare.models.ShareAccessTier + :paramtype access_tier: str or ~azure.storage.fileshare.ShareAccessTier :keyword int quota: Specifies the maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5TB. @@ -630,30 +662,34 @@ def set_share_properties(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 12 :caption: Sets the share properties. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) - access_tier = kwargs.pop('access_tier', None) - quota = kwargs.pop('quota', None) - root_squash = kwargs.pop('root_squash', None) - paid_bursting_bandwidth_mibps = kwargs.pop('paid_bursting_bandwidth_mibps', None) - paid_bursting_iops = kwargs.pop('paid_bursting_iops', None) - share_provisioned_iops = kwargs.pop('provisioned_iops', None) - share_provisioned_bandwidth_mibps = kwargs.pop('provisioned_bandwidth_mibps', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) + access_tier = kwargs.pop("access_tier", None) + quota = kwargs.pop("quota", None) + root_squash = kwargs.pop("root_squash", None) + paid_bursting_bandwidth_mibps = kwargs.pop("paid_bursting_bandwidth_mibps", None) + paid_bursting_iops = kwargs.pop("paid_bursting_iops", None) + share_provisioned_iops = kwargs.pop("provisioned_iops", None) + share_provisioned_bandwidth_mibps = kwargs.pop("provisioned_bandwidth_mibps", None) if all(parameter is None for parameter in [access_tier, quota, root_squash]): raise ValueError("set_share_properties should be called with at least one parameter.") try: - return cast(Dict[str, Any], self._client.share.set_properties( - timeout=timeout, - quota=quota, - access_tier=access_tier, - root_squash=root_squash, - lease_access_conditions=access_conditions, - paid_bursting_max_bandwidth_mibps=paid_bursting_bandwidth_mibps, - paid_bursting_max_iops=paid_bursting_iops, - share_provisioned_iops=share_provisioned_iops, - share_provisioned_bandwidth_mibps=share_provisioned_bandwidth_mibps, - cls=return_response_headers, - **kwargs)) + return cast( + Dict[str, Any], + self._client.share.set_properties( + timeout=timeout, + quota=quota, + access_tier=access_tier, + root_squash=root_squash, + lease_access_conditions=access_conditions, + paid_bursting_max_bandwidth_mibps=paid_bursting_bandwidth_mibps, + paid_bursting_max_iops=paid_bursting_iops, + share_provisioned_iops=share_provisioned_iops, + share_provisioned_bandwidth_mibps=share_provisioned_bandwidth_mibps, + cls=return_response_headers, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -694,17 +730,21 @@ def set_share_metadata(self, metadata: Dict[str, str], **kwargs: Any) -> Dict[st :dedent: 12 :caption: Sets the share metadata. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) - headers = kwargs.pop('headers', {}) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], self._client.share.set_metadata( - timeout=timeout, - cls=return_response_headers, - headers=headers, - lease_access_conditions=access_conditions, - **kwargs)) + return cast( + Dict[str, Any], + self._client.share.set_metadata( + timeout=timeout, + cls=return_response_headers, + headers=headers, + lease_access_conditions=access_conditions, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -730,20 +770,18 @@ def get_share_access_policy(self, **kwargs: Any) -> Dict[str, Any]: :returns: Access policy information in a dict. :rtype: dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: response, identifiers = self._client.share.get_access_policy( timeout=timeout, cls=return_headers_and_deserialized, lease_access_conditions=access_conditions, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) - return { - 'public_access': response.get('share_public_access'), - 'signed_identifiers': identifiers or [] - } + return {"public_access": response.get("share_public_access"), "signed_identifiers": identifiers or []} @distributed_trace def set_share_access_policy(self, signed_identifiers: Dict[str, "AccessPolicy"], **kwargs: Any) -> Dict[str, Any]: @@ -773,12 +811,13 @@ def set_share_access_policy(self, signed_identifiers: Dict[str, "AccessPolicy"], :returns: Share-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) if len(signed_identifiers) > 5: raise ValueError( - 'Too many access policies provided. The server does not support setting ' - 'more than 5 access policies on a single resource.') + "Too many access policies provided. The server does not support setting " + "more than 5 access policies on a single resource." + ) identifiers = [] for key, value in signed_identifiers.items(): if value: @@ -786,12 +825,16 @@ def set_share_access_policy(self, signed_identifiers: Dict[str, "AccessPolicy"], value.expiry = serialize_iso(value.expiry) identifiers.append(SignedIdentifier(id=key, access_policy=value)) try: - return cast(Dict[str, Any], self._client.share.set_access_policy( - share_acl=identifiers or None, - timeout=timeout, - cls=return_response_headers, - lease_access_conditions=access_conditions, - **kwargs)) + return cast( + Dict[str, Any], + self._client.share.set_access_policy( + share_acl=identifiers or None, + timeout=timeout, + cls=return_response_headers, + lease_access_conditions=access_conditions, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -819,20 +862,21 @@ def get_share_stats(self, **kwargs: Any) -> int: :return: The approximate size of the data (in bytes) stored on the share. :rtype: int """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - stats = cast(ShareStats, self._client.share.get_statistics( - timeout=timeout, - lease_access_conditions=access_conditions, - **kwargs)) + stats = cast( + ShareStats, + self._client.share.get_statistics(timeout=timeout, lease_access_conditions=access_conditions, **kwargs), + ) return stats.share_usage_bytes except HttpResponseError as error: process_storage_error(error) @distributed_trace def list_directories_and_files( - self, directory_name: Optional[str] = None, + self, + directory_name: Optional[str] = None, name_starts_with: Optional[str] = None, marker: Optional[str] = None, **kwargs: Any @@ -881,11 +925,12 @@ def list_directories_and_files( :dedent: 12 :caption: List directories and files in the share. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) directory = self.get_directory_client(directory_name) - kwargs.setdefault('merge_span', True) + kwargs.setdefault("merge_span", True) return directory.list_directories_and_files( - name_starts_with=name_starts_with, marker=marker, timeout=timeout, **kwargs) + name_starts_with=name_starts_with, marker=marker, timeout=timeout, **kwargs + ) @distributed_trace def create_permission_for_share(self, file_permission: str, **kwargs: Any) -> Optional[str]: @@ -909,7 +954,7 @@ def create_permission_for_share(self, file_permission: str, **kwargs: Any) -> Op :returns: A file permission key :rtype: str or None """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) options = _create_permission_for_share_options(file_permission, timeout=timeout, **kwargs) try: return cast(Optional[str], self._client.share.create_permission(**options)) @@ -936,13 +981,14 @@ def get_permission_for_share(self, permission_key: str, **kwargs: Any) -> str: :returns: A file permission (a portable SDDL) :rtype: str """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) try: - return cast(str, self._client.share.get_permission( - file_permission_key=permission_key, - cls=deserialize_permission, - timeout=timeout, - **kwargs)) + return cast( + str, + self._client.share.get_permission( + file_permission_key=permission_key, cls=deserialize_permission, timeout=timeout, **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -972,7 +1018,7 @@ def create_directory(self, directory_name: str, **kwargs: Any) -> ShareDirectory :rtype: ~azure.storage.fileshare.ShareDirectoryClient """ directory = self.get_directory_client(directory_name) - kwargs.setdefault('merge_span', True) + kwargs.setdefault("merge_span", True) directory.create_directory(**kwargs) return directory @@ -989,6 +1035,7 @@ def delete_directory(self, directory_name: str, **kwargs: Any) -> None: This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :returns: None :rtype: None """ directory = self.get_directory_client(directory_name) diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client_helpers.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client_helpers.py index 7d3f041db0cf..f951cddd8fc6 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client_helpers.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client_helpers.py @@ -4,10 +4,7 @@ # license information. # -------------------------------------------------------------------------- -from typing import ( - Any, Dict, Optional, Tuple, Union, - TYPE_CHECKING -) +from typing import Any, Dict, Optional, Tuple, Union, TYPE_CHECKING from urllib.parse import quote, unquote, urlparse from ._deserialize import deserialize_permission_key @@ -21,11 +18,11 @@ def _parse_url(account_url: str, share_name: str) -> "ParseResult": try: - if not account_url.lower().startswith('http'): + if not account_url.lower().startswith("http"): account_url = "https://" + account_url except AttributeError as exc: raise ValueError("Account URL must be a string.") from exc - parsed_url = urlparse(account_url.rstrip('/')) + parsed_url = urlparse(account_url.rstrip("/")) if not share_name: raise ValueError("Please specify a share name.") if not parsed_url.netloc: @@ -35,21 +32,21 @@ def _parse_url(account_url: str, share_name: str) -> "ParseResult": def _format_url(scheme: str, hostname: str, share_name: Union[str, bytes], query_str: str) -> str: if isinstance(share_name, str): - share_name = share_name.encode('UTF-8') + share_name = share_name.encode("UTF-8") return f"{scheme}://{hostname}/{quote(share_name)}{query_str}" def _from_share_url(share_url: str, snapshot: Optional[Union[str, Dict[str, Any]]]) -> Tuple[str, str, Optional[str]]: try: - if not share_url.lower().startswith('http'): + if not share_url.lower().startswith("http"): share_url = "https://" + share_url except AttributeError as exc: raise ValueError("Share URL must be a string.") from exc - parsed_url = urlparse(share_url.rstrip('/')) + parsed_url = urlparse(share_url.rstrip("/")) if not (parsed_url.path and parsed_url.netloc): raise ValueError(f"Invalid URL: {share_url}") - share_path = parsed_url.path.lstrip('/').split('/') + share_path = parsed_url.path.lstrip("/").split("/") account_path = "" if len(share_path) > 1: account_path = "/" + "/".join(share_path[:-1]) @@ -67,9 +64,9 @@ def _from_share_url(share_url: str, snapshot: Optional[Union[str, Dict[str, Any] def _create_permission_for_share_options(file_permission: str, **kwargs: Any) -> Dict[str, Any]: options = { - 'share_permission': SharePermission(permission=file_permission), - 'cls': deserialize_permission_key, - 'timeout': kwargs.pop('timeout', None), + "share_permission": SharePermission(permission=file_permission), + "cls": deserialize_permission_key, + "timeout": kwargs.pop("timeout", None), } options.update(kwargs) return options diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py index 4ef878f93e28..e27e5461bb1a 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py @@ -7,10 +7,7 @@ import sys import functools -from typing import ( - Union, Optional, Any, Dict, List, - TYPE_CHECKING -) +from typing import Union, Optional, Any, Dict, List, TYPE_CHECKING from typing_extensions import Self from azure.core.exceptions import HttpResponseError @@ -100,31 +97,39 @@ class ShareServiceClient(StorageAccountHostsMixin): :dedent: 8 :caption: Create the share service client with url and credential. """ + def __init__( - self, account_url: str, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + self, + account_url: str, + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long *, - token_intent: Optional[Literal['backup']] = None, - **kwargs: Any + token_intent: Optional[Literal["backup"]] = None, + **kwargs: Any, ) -> None: - if hasattr(credential, 'get_token') and not token_intent: + if hasattr(credential, "get_token") and not token_intent: raise ValueError("'token_intent' keyword is required when 'credential' is an TokenCredential.") parsed_url = _parse_url(account_url=account_url) _, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: raise ValueError( - 'You need to provide either an account shared key or SAS token when creating a storage service.') + "You need to provide either an account shared key or SAS token when creating a storage service." + ) self._query_str, credential = self._format_query_string(sas_token, credential) - super(ShareServiceClient, self).__init__( - parsed_url, service='file-share', credential=credential, **kwargs) - self.allow_trailing_dot = kwargs.pop('allow_trailing_dot', None) - self.allow_source_trailing_dot = kwargs.pop('allow_source_trailing_dot', None) + super(ShareServiceClient, self).__init__(parsed_url, service="file-share", credential=credential, **kwargs) + self.allow_trailing_dot = kwargs.pop("allow_trailing_dot", None) + self.allow_source_trailing_dot = kwargs.pop("allow_source_trailing_dot", None) self.file_request_intent = token_intent - self._client = AzureFileStorage(url=self.url, base_url=self.url, pipeline=self._pipeline, - allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, - file_request_intent=self.file_request_intent) + self._client = AzureFileStorage( + url=self.url, + base_url=self.url, + pipeline=self._pipeline, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + file_request_intent=self.file_request_intent, + ) self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] def _format_url(self, hostname: str) -> str: @@ -139,9 +144,12 @@ def _format_url(self, hostname: str) -> str: @classmethod def from_connection_string( - cls, conn_str: str, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + cls, + conn_str: str, + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """Create ShareServiceClient from a Connection String. @@ -173,9 +181,9 @@ def from_connection_string( :dedent: 8 :caption: Create the share service client with connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, 'file') - if 'secondary_hostname' not in kwargs: - kwargs['secondary_hostname'] = secondary + account_url, secondary, credential = parse_connection_str(conn_str, credential, "file") + if "secondary_hostname" not in kwargs: + kwargs["secondary_hostname"] = secondary return cls(account_url, credential=credential, **kwargs) @distributed_trace @@ -202,7 +210,7 @@ def get_service_properties(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 8 :caption: Get file share service properties. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) try: service_props = self._client.service.get_properties(timeout=timeout, **kwargs) return service_properties_deserialize(service_props) @@ -211,11 +219,12 @@ def get_service_properties(self, **kwargs: Any) -> Dict[str, Any]: @distributed_trace def set_service_properties( - self, hour_metrics: Optional["Metrics"] = None, + self, + hour_metrics: Optional["Metrics"] = None, minute_metrics: Optional["Metrics"] = None, cors: Optional[List[CorsRule]] = None, protocol: Optional["ShareProtocolSettings"] = None, - **kwargs: Any + **kwargs: Any, ) -> None: """Sets the properties of a storage account's File Share service, including Azure Storage Analytics. If an element (e.g. hour_metrics) is left as None, the @@ -254,12 +263,12 @@ def set_service_properties( :dedent: 8 :caption: Sets file share service properties. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) props = StorageServiceProperties( hour_metrics=hour_metrics, minute_metrics=minute_metrics, cors=CorsRule._to_generated(cors), # pylint: disable=protected-access - protocol=protocol + protocol=protocol, ) try: self._client.service.set_properties(storage_service_properties=props, timeout=timeout, **kwargs) @@ -268,10 +277,11 @@ def set_service_properties( @distributed_trace def list_shares( - self, name_starts_with: Optional[str] = None, + self, + name_starts_with: Optional[str] = None, include_metadata: Optional[bool] = False, include_snapshots: Optional[bool] = False, - **kwargs: Any + **kwargs: Any, ) -> ItemPaged[ShareProperties]: """Returns auto-paging iterable of dict-like ShareProperties under the specified account. The generator will lazily follow the continuation tokens returned by @@ -305,25 +315,26 @@ def list_shares( :dedent: 12 :caption: List shares in the file share service. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) include = [] - include_deleted = kwargs.pop('include_deleted', None) + include_deleted = kwargs.pop("include_deleted", None) if include_deleted: include.append("deleted") if include_metadata: - include.append('metadata') + include.append("metadata") if include_snapshots: - include.append('snapshots') + include.append("snapshots") - results_per_page = kwargs.pop('results_per_page', None) + results_per_page = kwargs.pop("results_per_page", None) command = functools.partial( - self._client.service.list_shares_segment, - include=include, - timeout=timeout, - **kwargs) + self._client.service.list_shares_segment, include=include, timeout=timeout, **kwargs + ) return ItemPaged( - command, prefix=name_starts_with, results_per_page=results_per_page, - page_iterator_class=SharePropertiesPaged) + command, + prefix=name_starts_with, + results_per_page=results_per_page, + page_iterator_class=SharePropertiesPaged, + ) @distributed_trace def create_share(self, share_name: str, **kwargs: Any) -> ShareClient: @@ -357,28 +368,26 @@ def create_share(self, share_name: str, **kwargs: Any) -> ShareClient: :dedent: 8 :caption: Create a share in the file share service. """ - metadata = kwargs.pop('metadata', None) - quota = kwargs.pop('quota', None) - timeout = kwargs.pop('timeout', None) - provisioned_iops = kwargs.pop('provisioned_iops', None) - provisioned_bandwidth_mibps = kwargs.pop('provisioned_bandwidth_mibps', None) + metadata = kwargs.pop("metadata", None) + quota = kwargs.pop("quota", None) + timeout = kwargs.pop("timeout", None) + provisioned_iops = kwargs.pop("provisioned_iops", None) + provisioned_bandwidth_mibps = kwargs.pop("provisioned_bandwidth_mibps", None) share = self.get_share_client(share_name) - kwargs.setdefault('merge_span', True) + kwargs.setdefault("merge_span", True) share.create_share( metadata=metadata, quota=quota, timeout=timeout, provisioned_iops=provisioned_iops, provisioned_bandwidth_mibps=provisioned_bandwidth_mibps, - **kwargs + **kwargs, ) return share @distributed_trace def delete_share( - self, share_name: Union[ShareProperties, str], - delete_snapshots: Optional[bool] = False, - **kwargs: Any + self, share_name: Union[ShareProperties, str], delete_snapshots: Optional[bool] = False, **kwargs: Any ) -> None: """Marks the specified share for deletion. The share is later deleted during garbage collection. @@ -395,6 +404,8 @@ def delete_share( This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :return: None + If the share exists, it will be deleted. :rtype: None .. admonition:: Example: @@ -406,11 +417,10 @@ def delete_share( :dedent: 12 :caption: Delete a share in the file share service. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) share = self.get_share_client(share_name) - kwargs.setdefault('merge_span', True) - share.delete_share( - delete_snapshots=delete_snapshots, timeout=timeout, **kwargs) + kwargs.setdefault("merge_span", True) + share.delete_share(delete_snapshots=delete_snapshots, timeout=timeout, **kwargs) @distributed_trace def undelete_share(self, deleted_share_name: str, deleted_share_version: str, **kwargs: Any) -> ShareClient: @@ -439,16 +449,18 @@ def undelete_share(self, deleted_share_name: str, deleted_share_version: str, ** share = self.get_share_client(deleted_share_name) try: - share._client.share.restore(deleted_share_name=deleted_share_name, # pylint: disable=protected-access - deleted_share_version=deleted_share_version, - timeout=kwargs.pop('timeout', None), **kwargs) + share._client.share.restore( + deleted_share_name=deleted_share_name, # pylint: disable=protected-access + deleted_share_version=deleted_share_version, + timeout=kwargs.pop("timeout", None), + **kwargs, + ) return share except HttpResponseError as error: process_storage_error(error) def get_share_client( - self, share: Union[ShareProperties, str], - snapshot: Optional[Union[Dict[str, Any], str]] = None + self, share: Union[ShareProperties, str], snapshot: Optional[Union[Dict[str, Any], str]] = None ) -> ShareClient: """Get a client to interact with the specified share. The share need not already exist. @@ -478,12 +490,20 @@ def get_share_client( share_name = share _pipeline = Pipeline( - transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access - policies=self._pipeline._impl_policies # pylint: disable=protected-access + transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access + policies=self._pipeline._impl_policies, # pylint: disable=protected-access ) return ShareClient( - self.url, share_name=share_name, snapshot=snapshot, credential=self.credential, - api_version=self.api_version, _hosts=self._hosts, - _configuration=self._config, _pipeline=_pipeline, _location_mode=self._location_mode, - allow_trailing_dot=self.allow_trailing_dot, allow_source_trailing_dot=self.allow_source_trailing_dot, - token_intent=self.file_request_intent) + self.url, + share_name=share_name, + snapshot=snapshot, + credential=self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, + ) diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client_helpers.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client_helpers.py index 9a6ebe8e7c4a..cfc1d7f4ca2d 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client_helpers.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client_helpers.py @@ -17,7 +17,7 @@ def _parse_url(account_url: str) -> "ParseResult": account_url = "https://" + account_url except AttributeError as exc: raise ValueError("Account URL must be a string.") from exc - parsed_url = urlparse(account_url.rstrip('/')) + parsed_url = urlparse(account_url.rstrip("/")) if not parsed_url.netloc: raise ValueError(f"Invalid URL: {account_url}") return parsed_url diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py index 883b597e23ca..a3350cf106b6 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py @@ -141,7 +141,7 @@ def close(self): self._client.close() @property - def url(self): + def url(self) -> str: """The full endpoint URL to this entity, including SAS token if used. This could be either the primary endpoint, @@ -153,52 +153,57 @@ def url(self): return self._format_url(self._hosts[self._location_mode]) @property - def primary_endpoint(self): + def primary_endpoint(self) -> str: """The full primary endpoint URL. + :returns: The full primary endpoint URL. :rtype: str """ return self._format_url(self._hosts[LocationMode.PRIMARY]) @property - def primary_hostname(self): + def primary_hostname(self) -> str: """The hostname of the primary endpoint. + :returns: The hostname of the primary endpoint. :rtype: str """ return self._hosts[LocationMode.PRIMARY] @property - def secondary_endpoint(self): + def secondary_endpoint(self) -> str: """The full secondary endpoint URL if configured. If not available a ValueError will be raised. To explicitly specify a secondary hostname, use the optional `secondary_hostname` keyword argument on instantiation. + :returns: The full secondary endpoint URL. :rtype: str - :raise ValueError: + :raise ValueError: If no secondary endpoint is configured. """ if not self._hosts[LocationMode.SECONDARY]: raise ValueError("No secondary host configured.") return self._format_url(self._hosts[LocationMode.SECONDARY]) @property - def secondary_hostname(self): + def secondary_hostname(self) -> Optional[str]: """The hostname of the secondary endpoint. If not available this will be None. To explicitly specify a secondary hostname, use the optional `secondary_hostname` keyword argument on instantiation. + :returns: The hostname of the secondary endpoint. :rtype: Optional[str] """ return self._hosts[LocationMode.SECONDARY] @property - def location_mode(self): + def location_mode(self) -> str: """The location mode that the client is currently using. By default this will be "primary". Options include "primary" and "secondary". + :returns: The current location mode. :rtype: str """ @@ -213,9 +218,10 @@ def location_mode(self, value): raise ValueError(f"No host URL for location mode: {value}") @property - def api_version(self): + def api_version(self) -> str: """The version of the Storage API used for requests. + :returns: The Storage API version. :rtype: str """ return self._client._config.version # pylint: disable=protected-access diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/models.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/models.py index 8d401fc1f229..185d58860fae 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/models.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/models.py @@ -22,6 +22,7 @@ def get_enum_value(value): class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """Error codes returned by the service.""" # Generic storage values ACCOUNT_ALREADY_EXISTS = "AccountAlreadyExists" diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies.py index 44db476f3e65..2facee65d717 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies.py @@ -428,6 +428,13 @@ def _set_next_host_location(self, settings: Dict[str, Any], request: "PipelineRe request.url = updated.geturl() def configure_retries(self, request: "PipelineRequest") -> Dict[str, Any]: + """ + Configure the retry settings for the request. + + :param PipelineRequest request: A pipeline request object. + :returns: A dictionary containing the retry settings. + :rtype: Dict[str, Any] + """ body_position = None if hasattr(request.http_request.body, "read"): try: @@ -461,6 +468,11 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: # pylint: disabl return 0 def sleep(self, settings, transport): + """Sleep for the backoff time. + + :param Dict[str, Any] settings: The configurable values pertaining to the sleep operation. + :param transport: The transport to use for sleeping. + """ backoff = self.get_backoff_time(settings) if not backoff or backoff < 0: return @@ -476,10 +488,13 @@ def increment( """Increment the retry counters. :param Dict[str, Any] settings: The configurable values pertaining to the increment operation. - :param PipelineRequest request: A pipeline request object. - :param Optional[PipelineResponse] response: A pipeline response object. - :param Optional[AzureError] error: An error encountered during the request, or + :param request: A pipeline request object. + :type request: ~azure.core.pipeline.PipelineRequest + :param response: A pipeline response object. + :type response: ~azure.core.pipeline.PipelineResponse or None + :param error: An error encountered during the request, or None if the response was received successfully. + :type error: ~azure.core.exceptions.AzureError or None :returns: Whether the retry attempts are exhausted. :rtype: bool """ @@ -524,6 +539,12 @@ def increment( return False def send(self, request): + """Send the request with retry logic. + + :param PipelineRequest request: A pipeline request object. + :returns: A pipeline response object. + :rtype: PipelineResponse + """ retries_remaining = True response = None retry_settings = self.configure_retries(request) @@ -678,6 +699,13 @@ def __init__(self, credential: "TokenCredential", audience: str, **kwargs: Any) super(StorageBearerTokenCredentialPolicy, self).__init__(credential, audience, **kwargs) def on_challenge(self, request: "PipelineRequest", response: "PipelineResponse") -> bool: + """Handle the challenge from the service and authorize the request. + + :param PipelineRequest request: The request object. + :param PipelineResponse response: The response object. + :returns: True if the request was authorized, False otherwise. + :rtype: bool + """ try: auth_header = response.http_response.headers.get("WWW-Authenticate") challenge = StorageHttpChallenge(auth_header) diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies_async.py index e26aa6e18496..db1c671b35ce 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies_async.py @@ -110,12 +110,26 @@ class AsyncStorageRetryPolicy(StorageRetryPolicy): """ async def sleep(self, settings, transport): + """ + Sleep for the backoff time specified in the settings. + :param settings: The retry settings containing the backoff time. + :type settings: Dict[str, Any] + :param transport: The transport to use for sleeping. + :type transport: ~azure.core.pipeline.transport.AsyncioBaseTransport + """ backoff = self.get_backoff_time(settings) if not backoff or backoff < 0: return await transport.sleep(backoff) async def send(self, request): + """ + Send the request and handle retries. + :param request: The request to send. + :type request: ~azure.core.pipeline.PipelineRequest + :return: The response from the request. + :rtype: ~azure.core.pipeline.PipelineResponse + """ retries_remaining = True response = None retry_settings = self.configure_retries(request) @@ -272,6 +286,16 @@ def __init__(self, credential: "AsyncTokenCredential", audience: str, **kwargs: super(AsyncStorageBearerTokenCredentialPolicy, self).__init__(credential, audience, **kwargs) async def on_challenge(self, request: "PipelineRequest", response: "PipelineResponse") -> bool: + """ + Handle the challenge response from the service, which may include a + WWW-Authenticate header with a Bearer challenge. + :param request: The request that received the challenge. + :type request: ~azure.core.pipeline.PipelineRequest + :param response: The response that contains the challenge. + :type response: ~azure.core.pipeline.PipelineResponse + :return: True if the challenge was handled and the request should be retried, False otherwise. + :rtype: bool + """ try: auth_header = response.http_response.headers.get("WWW-Authenticate") challenge = StorageHttpChallenge(auth_header) diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared_access_signature.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared_access_signature.py index 24679c722b4f..e02ff90044b8 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared_access_signature.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared_access_signature.py @@ -5,10 +5,7 @@ # -------------------------------------------------------------------------- # pylint: disable=docstring-keyword-should-match-keyword-only -from typing import ( - Any, Callable, List, Optional, Union, - TYPE_CHECKING -) +from typing import Any, Callable, List, Optional, Union, TYPE_CHECKING from urllib.parse import parse_qs from ._shared import sign_string @@ -18,12 +15,7 @@ if TYPE_CHECKING: from datetime import datetime - from azure.storage.fileshare import ( - AccountSasPermissions, - FileSasPermissions, - ShareSasPermissions, - ResourceTypes - ) + from azure.storage.fileshare import AccountSasPermissions, FileSasPermissions, ShareSasPermissions, ResourceTypes class FileSharedAccessSignature(SharedAccessSignature): @@ -44,7 +36,8 @@ def __init__(self, account_name: str, account_key: str) -> None: super(FileSharedAccessSignature, self).__init__(account_name, account_key, x_ms_version=X_MS_VERSION) def generate_file( - self, share_name: str, + self, + share_name: str, directory_name: Optional[str] = None, file_name: Optional[str] = None, permission: Optional[Union["FileSasPermissions", str]] = None, @@ -58,7 +51,7 @@ def generate_file( content_encoding: Optional[str] = None, content_language: Optional[str] = None, content_type: Optional[str] = None, - sts_hook: Optional[Callable[[str], None]] = None + sts_hook: Optional[Callable[[str], None]] = None, ) -> str: """ Generates a shared access signature for the file. @@ -130,17 +123,17 @@ def generate_file( """ resource_path = share_name if directory_name is not None: - resource_path += '/' + str(directory_name) + resource_path += "/" + str(directory_name) if file_name is not None: - resource_path += '/' + str(file_name) + resource_path += "/" + str(file_name) sas = _FileSharedAccessHelper() sas.add_base(permission, expiry, start, ip, protocol, self.x_ms_version) sas.add_id(policy_id) - sas.add_resource('f') - sas.add_override_response_headers(cache_control, content_disposition, - content_encoding, content_language, - content_type) + sas.add_resource("f") + sas.add_override_response_headers( + cache_control, content_disposition, content_encoding, content_language, content_type + ) sas.add_resource_signature(self.account_name, self.account_key, resource_path) if sts_hook is not None: @@ -149,7 +142,8 @@ def generate_file( return sas.get_token() def generate_share( - self, share_name: str, + self, + share_name: str, permission: Optional[Union["ShareSasPermissions", str]] = None, expiry: Optional[Union["datetime", str]] = None, start: Optional[Union["datetime", str]] = None, @@ -163,7 +157,7 @@ def generate_share( content_type: Optional[str] = None, sts_hook: Optional[Callable[[str], None]] = None, ) -> str: - ''' + """ Generates a shared access signature for the share. Use the returned signature with the sas_token parameter of FileService. @@ -225,14 +219,14 @@ def generate_share( :type sts_hook: Optional[Callable[[str], None]] :returns: The generated SAS token for the account. :rtype: str - ''' + """ sas = _FileSharedAccessHelper() sas.add_base(permission, expiry, start, ip, protocol, self.x_ms_version) sas.add_id(policy_id) - sas.add_resource('s') - sas.add_override_response_headers(cache_control, content_disposition, - content_encoding, content_language, - content_type) + sas.add_resource("s") + sas.add_override_response_headers( + cache_control, content_disposition, content_encoding, content_language, content_type + ) sas.add_resource_signature(self.account_name, self.account_key, share_name) if sts_hook is not None: @@ -245,37 +239,37 @@ class _FileSharedAccessHelper(_SharedAccessHelper): def add_resource_signature(self, account_name, account_key, path): def get_value_to_append(query): - return_value = self.query_dict.get(query) or '' - return return_value + '\n' + return_value = self.query_dict.get(query) or "" + return return_value + "\n" - if path[0] != '/': - path = '/' + path + if path[0] != "/": + path = "/" + path - canonicalized_resource = '/file/' + account_name + path + '\n' + canonicalized_resource = "/file/" + account_name + path + "\n" # Form the string to sign from shared_access_policy and canonicalized # resource. The order of values is important. - string_to_sign = \ - (get_value_to_append(QueryStringConstants.SIGNED_PERMISSION) + - get_value_to_append(QueryStringConstants.SIGNED_START) + - get_value_to_append(QueryStringConstants.SIGNED_EXPIRY) + - canonicalized_resource + - get_value_to_append(QueryStringConstants.SIGNED_IDENTIFIER) + - get_value_to_append(QueryStringConstants.SIGNED_IP) + - get_value_to_append(QueryStringConstants.SIGNED_PROTOCOL) + - get_value_to_append(QueryStringConstants.SIGNED_VERSION) + - get_value_to_append(QueryStringConstants.SIGNED_CACHE_CONTROL) + - get_value_to_append(QueryStringConstants.SIGNED_CONTENT_DISPOSITION) + - get_value_to_append(QueryStringConstants.SIGNED_CONTENT_ENCODING) + - get_value_to_append(QueryStringConstants.SIGNED_CONTENT_LANGUAGE) + - get_value_to_append(QueryStringConstants.SIGNED_CONTENT_TYPE)) + string_to_sign = ( + get_value_to_append(QueryStringConstants.SIGNED_PERMISSION) + + get_value_to_append(QueryStringConstants.SIGNED_START) + + get_value_to_append(QueryStringConstants.SIGNED_EXPIRY) + + canonicalized_resource + + get_value_to_append(QueryStringConstants.SIGNED_IDENTIFIER) + + get_value_to_append(QueryStringConstants.SIGNED_IP) + + get_value_to_append(QueryStringConstants.SIGNED_PROTOCOL) + + get_value_to_append(QueryStringConstants.SIGNED_VERSION) + + get_value_to_append(QueryStringConstants.SIGNED_CACHE_CONTROL) + + get_value_to_append(QueryStringConstants.SIGNED_CONTENT_DISPOSITION) + + get_value_to_append(QueryStringConstants.SIGNED_CONTENT_ENCODING) + + get_value_to_append(QueryStringConstants.SIGNED_CONTENT_LANGUAGE) + + get_value_to_append(QueryStringConstants.SIGNED_CONTENT_TYPE) + ) # remove the trailing newline - if string_to_sign[-1] == '\n': + if string_to_sign[-1] == "\n": string_to_sign = string_to_sign[:-1] - self._add_query(QueryStringConstants.SIGNED_SIGNATURE, - sign_string(account_key, string_to_sign)) + self._add_query(QueryStringConstants.SIGNED_SIGNATURE, sign_string(account_key, string_to_sign)) self.string_to_sign = string_to_sign @@ -546,7 +540,7 @@ def generate_file_sas( raise ValueError("'permission' parameter must be provided when not using a stored access policy.") sas = FileSharedAccessSignature(account_name, account_key) if len(file_path) > 1: - dir_path = '/'.join(file_path[:-1]) + dir_path = "/".join(file_path[:-1]) else: dir_path = None return sas.generate_file( diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/__init__.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/__init__.py index 73393b819df4..1bf58897e60a 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/__init__.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/__init__.py @@ -9,12 +9,14 @@ from ._share_client_async import ShareClient from ._share_service_client_async import ShareServiceClient from ._lease_async import ShareLeaseClient +from ._download_async import StorageStreamDownloader __all__ = [ - 'ShareFileClient', - 'ShareDirectoryClient', - 'ShareClient', - 'ShareServiceClient', - 'ShareLeaseClient', + "ShareFileClient", + "ShareDirectoryClient", + "ShareClient", + "ShareServiceClient", + "ShareLeaseClient", + "StorageStreamDownloader", ] diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py index 8673362c38ad..b0923ec4082b 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py @@ -10,10 +10,7 @@ import time import warnings from datetime import datetime -from typing import ( - Any, AnyStr, AsyncIterable, cast, Dict, IO, Iterable, Optional, Union, - TYPE_CHECKING -) +from typing import Any, AnyStr, AsyncIterable, cast, Dict, IO, Iterable, Optional, Union, TYPE_CHECKING from typing_extensions import Self from azure.core.async_paging import AsyncItemPaged @@ -22,11 +19,7 @@ from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from .._deserialize import deserialize_directory_properties -from .._directory_client_helpers import ( - _format_url, - _from_directory_url, - _parse_url -) +from .._directory_client_helpers import _format_url, _from_directory_url, _parse_url from .._generated.aio import AzureFileStorage from .._parser import _datetime_to_str, _get_file_permission, _parse_snapshot from .._serialize import get_api_version, get_dest_access_conditions, get_rename_smb_properties @@ -104,51 +97,64 @@ class ShareDirectoryClient(AsyncStorageAccountHostsMixin, StorageAccountHostsMix authentication. Only has an effect when credential is of type AsyncTokenCredential. The value could be https://storage.azure.com/ (default) or https://.file.core.windows.net. """ + def __init__( - self, account_url: str, + self, + account_url: str, share_name: str, directory_path: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long *, - token_intent: Optional[Literal['backup']] = None, - **kwargs: Any + token_intent: Optional[Literal["backup"]] = None, + **kwargs: Any, ) -> None: - kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) - loop = kwargs.pop('loop', None) + kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) + loop = kwargs.pop("loop", None) if loop and sys.version_info >= (3, 8): - warnings.warn("The 'loop' parameter was deprecated from asyncio's high-level" - "APIs in Python 3.8 and is no longer supported.", DeprecationWarning) - if hasattr(credential, 'get_token') and not token_intent: + warnings.warn( + "The 'loop' parameter was deprecated from asyncio's high-level" + "APIs in Python 3.8 and is no longer supported.", + DeprecationWarning, + ) + if hasattr(credential, "get_token") and not token_intent: raise ValueError("'token_intent' keyword is required when 'credential' is an AsyncTokenCredential.") parsed_url = _parse_url(account_url, share_name) path_snapshot, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: raise ValueError( - 'You need to provide either an account shared key or SAS token when creating a storage service.') + "You need to provide either an account shared key or SAS token when creating a storage service." + ) self.snapshot = _parse_snapshot(snapshot, path_snapshot) self.share_name = share_name self.directory_path = directory_path - self._query_str, credential = self._format_query_string( - sas_token, credential, share_snapshot=self.snapshot) - super(ShareDirectoryClient, self).__init__( - parsed_url, service='file-share', credential=credential, **kwargs) - self.allow_trailing_dot = kwargs.pop('allow_trailing_dot', None) - self.allow_source_trailing_dot = kwargs.pop('allow_source_trailing_dot', None) + self._query_str, credential = self._format_query_string(sas_token, credential, share_snapshot=self.snapshot) + super(ShareDirectoryClient, self).__init__(parsed_url, service="file-share", credential=credential, **kwargs) + self.allow_trailing_dot = kwargs.pop("allow_trailing_dot", None) + self.allow_source_trailing_dot = kwargs.pop("allow_source_trailing_dot", None) self.file_request_intent = token_intent - self._client = AzureFileStorage(url=self.url, base_url=self.url, pipeline=self._pipeline, - allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, - file_request_intent=self.file_request_intent) + self._client = AzureFileStorage( + url=self.url, + base_url=self.url, + pipeline=self._pipeline, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + file_request_intent=self.file_request_intent, + ) self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] @classmethod def from_directory_url( - cls, directory_url: str, + cls, + directory_url: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """Create a ShareDirectoryClient from a directory url. @@ -179,8 +185,13 @@ def from_directory_url( """ account_url, share_name, directory_path, snapshot = _from_directory_url(directory_url, snapshot) return cls( - account_url=account_url, share_name=share_name, directory_path=directory_path, - snapshot=snapshot, credential=credential, **kwargs) + account_url=account_url, + share_name=share_name, + directory_path=directory_path, + snapshot=snapshot, + credential=credential, + **kwargs, + ) def _format_url(self, hostname: str) -> str: """Format the endpoint URL according to the current location mode hostname. @@ -194,11 +205,14 @@ def _format_url(self, hostname: str) -> str: @classmethod def from_connection_string( - cls, conn_str: str, + cls, + conn_str: str, share_name: str, directory_path: str, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """Create ShareDirectoryClient from a Connection String. @@ -218,18 +232,20 @@ def from_connection_string( If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" should be the storage account key. :type credential: - Optional[Union[str, dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "AsyncTokenCredential"]] + ~azure.core.credentials.AzureNamedKeyCredential or + ~azure.core.credentials.AzureSasCredential or + ~azure.core.credentials_async.AsyncTokenCredential or + str or dict[str, str] or None :keyword str audience: The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type AsyncTokenCredential. The value could be https://storage.azure.com/ (default) or https://.file.core.windows.net. :returns: A directory client. :rtype: ~azure.storage.fileshare.aio.ShareDirectoryClient """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, 'file') - if 'secondary_hostname' not in kwargs: - kwargs['secondary_hostname'] = secondary - return cls( - account_url, share_name=share_name, directory_path=directory_path, credential=credential, **kwargs) + account_url, secondary, credential = parse_connection_str(conn_str, credential, "file") + if "secondary_hostname" not in kwargs: + kwargs["secondary_hostname"] = secondary + return cls(account_url, share_name=share_name, directory_path=directory_path, credential=credential, **kwargs) def get_file_client(self, file_name: str, **kwargs: Any) -> ShareFileClient: """Get a client to interact with a specific file. @@ -242,18 +258,28 @@ def get_file_client(self, file_name: str, **kwargs: Any) -> ShareFileClient: :rtype: ~azure.storage.fileshare.ShareFileClient """ if self.directory_path: - file_name = self.directory_path.rstrip('/') + "/" + file_name + file_name = self.directory_path.rstrip("/") + "/" + file_name _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable=protected-access - policies=self._pipeline._impl_policies # type: ignore [arg-type] # pylint: disable=protected-access + policies=self._pipeline._impl_policies, # type: ignore [arg-type] # pylint: disable=protected-access ) return ShareFileClient( - self.url, file_path=file_name, share_name=self.share_name, snapshot=self.snapshot, - credential=self.credential, api_version=self.api_version, _hosts=self._hosts, _configuration=self._config, - _pipeline=_pipeline, _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, token_intent=self.file_request_intent, - **kwargs) + self.url, + file_path=file_name, + share_name=self.share_name, + snapshot=self.snapshot, + credential=self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, + **kwargs, + ) def get_subdirectory_client(self, directory_name: str, **kwargs) -> "ShareDirectoryClient": """Get a client to interact with a specific subdirectory. @@ -276,18 +302,28 @@ def get_subdirectory_client(self, directory_name: str, **kwargs) -> "ShareDirect """ directory_path = directory_name if self.directory_path: - directory_path = self.directory_path.rstrip('/') + "/" + directory_name + directory_path = self.directory_path.rstrip("/") + "/" + directory_name _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable=protected-access - policies=self._pipeline._impl_policies # type: ignore [arg-type] # pylint: disable=protected-access + policies=self._pipeline._impl_policies, # type: ignore [arg-type] # pylint: disable=protected-access ) return ShareDirectoryClient( - self.url, share_name=self.share_name, directory_path=directory_path, snapshot=self.snapshot, - credential=self.credential, api_version=self.api_version, _hosts=self._hosts, _configuration=self._config, - _pipeline=_pipeline, _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, token_intent=self.file_request_intent, - **kwargs) + self.url, + share_name=self.share_name, + directory_path=directory_path, + snapshot=self.snapshot, + credential=self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, + **kwargs, + ) @distributed_trace_async async def create_directory(self, **kwargs: Any) -> Dict[str, Any]: @@ -350,31 +386,35 @@ async def create_directory(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 16 :caption: Creates a directory. """ - metadata = kwargs.pop('metadata', None) - timeout = kwargs.pop('timeout', None) - headers = kwargs.pop('headers', {}) + metadata = kwargs.pop("metadata", None) + timeout = kwargs.pop("timeout", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) - file_attributes = kwargs.pop('file_attributes', None) - file_creation_time = kwargs.pop('file_creation_time', None) - file_last_write_time = kwargs.pop('file_last_write_time', None) - file_change_time = kwargs.pop('file_change_time', None) - file_permission = kwargs.pop('file_permission', None) - file_permission_key = kwargs.pop('file_permission_key', None) + file_attributes = kwargs.pop("file_attributes", None) + file_creation_time = kwargs.pop("file_creation_time", None) + file_last_write_time = kwargs.pop("file_last_write_time", None) + file_change_time = kwargs.pop("file_change_time", None) + file_permission = kwargs.pop("file_permission", None) + file_permission_key = kwargs.pop("file_permission_key", None) file_permission = _get_file_permission(file_permission, file_permission_key, None) try: - return cast(Dict[str, Any], await self._client.directory.create( - file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, - file_creation_time=_datetime_to_str(file_creation_time), - file_last_write_time=_datetime_to_str(file_last_write_time), - file_change_time=_datetime_to_str(file_change_time), - file_permission=file_permission, - file_permission_key=file_permission_key, - timeout=timeout, - cls=return_response_headers, - headers=headers, - **kwargs)) + return cast( + Dict[str, Any], + await self._client.directory.create( + file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, + file_creation_time=_datetime_to_str(file_creation_time), + file_last_write_time=_datetime_to_str(file_last_write_time), + file_change_time=_datetime_to_str(file_change_time), + file_permission=file_permission, + file_permission_key=file_permission_key, + timeout=timeout, + cls=return_response_headers, + headers=headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -389,6 +429,7 @@ async def delete_directory(self, **kwargs: Any) -> None: This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :returns: None :rtype: None .. admonition:: Example: @@ -400,7 +441,7 @@ async def delete_directory(self, **kwargs: Any) -> None: :dedent: 16 :caption: Deletes a directory. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) try: await self._client.directory.delete(timeout=timeout, **kwargs) except HttpResponseError as error: @@ -470,31 +511,38 @@ async def rename_directory(self, new_name: str, **kwargs: Any) -> "ShareDirector if not new_name: raise ValueError("Please specify a new directory name.") - new_name = new_name.strip('/') - new_path_and_query = new_name.split('?') + new_name = new_name.strip("/") + new_path_and_query = new_name.split("?") new_dir_path = new_path_and_query[0] if len(new_path_and_query) == 2: - new_dir_sas = new_path_and_query[1] or self._query_str.strip('?') + new_dir_sas = new_path_and_query[1] or self._query_str.strip("?") else: - new_dir_sas = self._query_str.strip('?') + new_dir_sas = self._query_str.strip("?") new_directory_client = ShareDirectoryClient( - f'{self.scheme}://{self.primary_hostname}', self.share_name, new_dir_path, - credential=new_dir_sas or self.credential, api_version=self.api_version, - _hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline, - _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, token_intent=self.file_request_intent + f"{self.scheme}://{self.primary_hostname}", + self.share_name, + new_dir_path, + credential=new_dir_sas or self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=self._pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, ) kwargs.update(get_rename_smb_properties(kwargs)) - timeout = kwargs.pop('timeout', None) - overwrite = kwargs.pop('overwrite', None) - metadata = kwargs.pop('metadata', None) - headers = kwargs.pop('headers', {}) + timeout = kwargs.pop("timeout", None) + overwrite = kwargs.pop("overwrite", None) + metadata = kwargs.pop("metadata", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) - destination_access_conditions = get_dest_access_conditions(kwargs.pop('destination_lease', None)) + destination_access_conditions = get_dest_access_conditions(kwargs.pop("destination_lease", None)) try: await new_directory_client._client.directory.rename( # pylint: disable=protected-access @@ -503,7 +551,8 @@ async def rename_directory(self, new_name: str, **kwargs: Any) -> "ShareDirector replace_if_exists=overwrite, destination_lease_access_conditions=destination_access_conditions, headers=headers, - **kwargs) + **kwargs, + ) return new_directory_client except HttpResponseError as error: @@ -511,9 +560,7 @@ async def rename_directory(self, new_name: str, **kwargs: Any) -> "ShareDirector @distributed_trace def list_directories_and_files( - self, - name_starts_with: Optional[str] = None, - **kwargs: Any + self, name_starts_with: Optional[str] = None, **kwargs: Any ) -> AsyncItemPaged[Union["DirectoryProperties", "FileProperties"]]: """Lists all the directories and files under the directory. @@ -553,16 +600,20 @@ def list_directories_and_files( :dedent: 16 :caption: List directories and files. """ - timeout = kwargs.pop('timeout', None) - results_per_page = kwargs.pop('results_per_page', None) + timeout = kwargs.pop("timeout", None) + results_per_page = kwargs.pop("results_per_page", None) command = functools.partial( self._client.directory.list_files_and_directories_segment, sharesnapshot=self.snapshot, timeout=timeout, - **kwargs) + **kwargs, + ) return AsyncItemPaged( - command, prefix=name_starts_with, results_per_page=results_per_page, - page_iterator_class=DirectoryPropertiesPaged) + command, + prefix=name_starts_with, + results_per_page=results_per_page, + page_iterator_class=DirectoryPropertiesPaged, + ) @distributed_trace def list_handles(self, recursive: bool = False, **kwargs: Any) -> AsyncItemPaged["Handle"]: @@ -580,17 +631,16 @@ def list_handles(self, recursive: bool = False, **kwargs: Any) -> AsyncItemPaged :returns: An auto-paging iterable of Handle :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.storage.fileshare.Handle] """ - timeout = kwargs.pop('timeout', None) - results_per_page = kwargs.pop('results_per_page', None) + timeout = kwargs.pop("timeout", None) + results_per_page = kwargs.pop("results_per_page", None) command = functools.partial( self._client.directory.list_handles, sharesnapshot=self.snapshot, timeout=timeout, recursive=recursive, - **kwargs) - return AsyncItemPaged( - command, results_per_page=results_per_page, - page_iterator_class=HandlesPaged) + **kwargs, + ) + return AsyncItemPaged(command, results_per_page=results_per_page, page_iterator_class=HandlesPaged) @distributed_trace_async async def exists(self, **kwargs: Any) -> bool: @@ -636,7 +686,7 @@ async def close_handle(self, handle: Union[str, "Handle"], **kwargs: Any) -> Dic handle_id = handle.id else: handle_id = handle - if handle_id == '*': + if handle_id == "*": raise ValueError("Handle ID '*' is not supported. Use 'close_all_handles' instead.") try: response = await self._client.directory.force_close_handles( @@ -645,11 +695,11 @@ async def close_handle(self, handle: Union[str, "Handle"], **kwargs: Any) -> Dic recursive=None, sharesnapshot=self.snapshot, cls=return_response_headers, - **kwargs + **kwargs, ) return { - 'closed_handles_count': response.get('number_of_handles_closed', 0), - 'failed_handles_count': response.get('number_of_handles_failed', 0) + "closed_handles_count": response.get("number_of_handles_closed", 0), + "failed_handles_count": response.get("number_of_handles_failed", 0), } except HttpResponseError as error: process_storage_error(error) @@ -673,7 +723,7 @@ async def close_all_handles(self, recursive: bool = False, **kwargs: Any) -> Dic and the number of handles failed to close in a dict. :rtype: dict[str, int] """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) start_time = time.time() try_close = True @@ -683,26 +733,23 @@ async def close_all_handles(self, recursive: bool = False, **kwargs: Any) -> Dic while try_close: try: response = await self._client.directory.force_close_handles( - handle_id='*', + handle_id="*", timeout=timeout, marker=continuation_token, recursive=recursive, sharesnapshot=self.snapshot, cls=return_response_headers, - **kwargs + **kwargs, ) except HttpResponseError as error: process_storage_error(error) - continuation_token = response.get('marker') + continuation_token = response.get("marker") try_close = bool(continuation_token) - total_closed += response.get('number_of_handles_closed', 0) - total_failed += response.get('number_of_handles_failed', 0) + total_closed += response.get("number_of_handles_closed", 0) + total_failed += response.get("number_of_handles_failed", 0) if timeout: timeout = max(0, timeout - (time.time() - start_time)) - return { - 'closed_handles_count': total_closed, - 'failed_handles_count': total_failed - } + return {"closed_handles_count": total_closed, "failed_handles_count": total_failed} @distributed_trace_async async def get_directory_properties(self, **kwargs: Any) -> "DirectoryProperties": @@ -719,12 +766,14 @@ async def get_directory_properties(self, **kwargs: Any) -> "DirectoryProperties" :returns: DirectoryProperties :rtype: ~azure.storage.fileshare.DirectoryProperties """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) try: - response = cast("DirectoryProperties", await self._client.directory.get_properties( - timeout=timeout, - cls=deserialize_directory_properties, - **kwargs)) + response = cast( + "DirectoryProperties", + await self._client.directory.get_properties( + timeout=timeout, cls=deserialize_directory_properties, **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) return response @@ -749,26 +798,28 @@ async def set_directory_metadata(self, metadata: Dict[str, Any], **kwargs: Any) :returns: Directory-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - timeout = kwargs.pop('timeout', None) - headers = kwargs.pop('headers', {}) + timeout = kwargs.pop("timeout", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], await self._client.directory.set_metadata( - timeout=timeout, - cls=return_response_headers, - headers=headers, - **kwargs)) + return cast( + Dict[str, Any], + await self._client.directory.set_metadata( + timeout=timeout, cls=return_response_headers, headers=headers, **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async async def set_http_headers( - self, file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, + self, + file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, file_creation_time: Optional[Union[str, datetime]] = None, file_last_write_time: Optional[Union[str, datetime]] = None, file_permission: Optional[str] = None, permission_key: Optional[str] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """Sets HTTP headers on the directory. @@ -818,20 +869,24 @@ async def set_http_headers( :returns: File-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) file_permission = _get_file_permission(file_permission, permission_key, None) - file_change_time = kwargs.pop('file_change_time', None) + file_change_time = kwargs.pop("file_change_time", None) try: - return cast(Dict[str, Any], await self._client.directory.set_properties( - file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, - file_creation_time=_datetime_to_str(file_creation_time), - file_last_write_time=_datetime_to_str(file_last_write_time), - file_change_time=_datetime_to_str(file_change_time), - file_permission=file_permission, - file_permission_key=permission_key, - timeout=timeout, - cls=return_response_headers, - **kwargs)) + return cast( + Dict[str, Any], + await self._client.directory.set_properties( + file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, + file_creation_time=_datetime_to_str(file_creation_time), + file_last_write_time=_datetime_to_str(file_last_write_time), + file_change_time=_datetime_to_str(file_change_time), + file_permission=file_permission, + file_permission_key=permission_key, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -863,8 +918,8 @@ async def create_subdirectory(self, directory_name: str, **kwargs: Any) -> "Shar :dedent: 16 :caption: Create a subdirectory. """ - metadata = kwargs.pop('metadata', None) - timeout = kwargs.pop('timeout', None) + metadata = kwargs.pop("metadata", None) + timeout = kwargs.pop("timeout", None) subdir = self.get_subdirectory_client(directory_name) await subdir.create_directory(metadata=metadata, timeout=timeout, **kwargs) return subdir @@ -892,16 +947,17 @@ async def delete_subdirectory(self, directory_name: str, **kwargs: Any) -> None: :dedent: 16 :caption: Delete a subdirectory. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) subdir = self.get_subdirectory_client(directory_name) await subdir.delete_directory(timeout=timeout, **kwargs) @distributed_trace_async async def upload_file( - self, file_name: str, + self, + file_name: str, data: Union[bytes, str, Iterable[AnyStr], AsyncIterable[AnyStr], IO[AnyStr]], length: Optional[int] = None, - **kwargs: Any + **kwargs: Any, ) -> ShareFileClient: """Creates a new file in the directory and returns a ShareFileClient to interact with the file. @@ -954,10 +1010,7 @@ async def upload_file( :caption: Upload a file to a directory. """ file_client = self.get_file_client(file_name) - await file_client.upload_file( - data, - length=length, - **kwargs) + await file_client.upload_file(data, length=length, **kwargs) return file_client @distributed_trace_async diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_download_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_download_async.py index 44b45084a670..3e27be9724a5 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_download_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_download_async.py @@ -11,11 +11,7 @@ import warnings from io import BytesIO from itertools import islice -from typing import ( - Any, AsyncIterator, Awaitable, Callable, - cast, Generator, IO, Optional, Tuple, - TYPE_CHECKING -) +from typing import Any, AsyncIterator, Awaitable, Callable, cast, Generator, IO, Optional, Tuple, TYPE_CHECKING from azure.core.exceptions import HttpResponseError, ResourceModifiedError from .._download import _ChunkDownloader @@ -42,8 +38,8 @@ async def process_content(data: Any) -> bytes: class _AsyncChunkDownloader(_ChunkDownloader): def __init__(self, **kwargs: Any) -> None: super(_AsyncChunkDownloader, self).__init__(**kwargs) - self.stream_lock_async = asyncio.Lock() if kwargs.get('parallel') else None - self.progress_lock_async = asyncio.Lock() if kwargs.get('parallel') else None + self.stream_lock_async = asyncio.Lock() if kwargs.get("parallel") else None + self.progress_lock_async = asyncio.Lock() if kwargs.get("parallel") else None async def process_chunk(self, chunk_start: int) -> None: chunk_start, chunk_end = self._calculate_range(chunk_start) @@ -66,7 +62,8 @@ async def _update_progress(self, length: int) -> None: if self.progress_hook: await cast(Callable[[int, Optional[int]], Awaitable[Any]], self.progress_hook)( - self.progress_total, self.total_size) + self.progress_total, self.total_size + ) async def _write_to_stream(self, chunk_data: bytes, chunk_start: int) -> None: if self.stream_lock_async: @@ -78,19 +75,20 @@ async def _write_to_stream(self, chunk_data: bytes, chunk_start: int) -> None: async def _download_chunk(self, chunk_start: int, chunk_end: int) -> bytes: range_header, range_validation = validate_and_format_range_headers( - chunk_start, - chunk_end, - check_content_md5=self.validate_content + chunk_start, chunk_end, check_content_md5=self.validate_content ) try: - _, response = await cast(Awaitable[Any], self.client.download( - range=range_header, - range_get_content_md5=range_validation, - validate_content=self.validate_content, - data_stream_total=self.total_size, - download_stream_current=self.progress_total, - **self.request_options - )) + _, response = await cast( + Awaitable[Any], + self.client.download( + range=range_header, + range_get_content_md5=range_validation, + validate_content=self.validate_content, + data_stream_total=self.total_size, + download_stream_current=self.progress_total, + **self.request_options, + ), + ) if response.properties.etag != self.etag: raise ResourceModifiedError(message="The file has been modified while downloading.") except HttpResponseError as error: @@ -151,7 +149,7 @@ async def __anext__(self) -> bytes: def _get_chunk_data(self) -> bytes: chunk_data = self._current_content[: self._chunk_size] - self._current_content = self._current_content[self._chunk_size:] + self._current_content = self._current_content[self._chunk_size :] return chunk_data @@ -172,7 +170,8 @@ class StorageStreamDownloader(object): # pylint: disable=too-many-instance-attr otherwise the total size of the file.""" def __init__( - self, client: "FileOperations" = None, # type: ignore [assignment] + self, + client: "FileOperations" = None, # type: ignore [assignment] config: "StorageConfiguration" = None, # type: ignore [assignment] start_range: Optional[int] = None, end_range: Optional[int] = None, @@ -182,7 +181,7 @@ def __init__( path: str = None, # type: ignore [assignment] share: str = None, # type: ignore [assignment] encoding: Optional[str] = None, - **kwargs: Any + **kwargs: Any, ) -> None: self.name = name self.path = path @@ -196,7 +195,7 @@ def __init__( self._max_concurrency = max_concurrency self._encoding = encoding self._validate_content = validate_content - self._progress_hook = kwargs.pop('progress_hook', None) + self._progress_hook = kwargs.pop("progress_hook", None) self._request_options = kwargs self._location_mode = None self._download_complete = False @@ -208,8 +207,9 @@ def __init__( # The service only provides transactional MD5s for chunks under 4MB. # If validate_content is on, get only self.MAX_CHUNK_GET_SIZE for the first # chunk so a transactional MD5 can be retrieved. - self._first_get_size = self._config.max_single_get_size if not self._validate_content \ - else self._config.max_chunk_get_size + self._first_get_size = ( + self._config.max_single_get_size if not self._validate_content else self._config.max_chunk_get_size + ) initial_request_start = self._start_range or 0 if self._end_range is not None and self._end_range - initial_request_start < self._first_get_size: initial_request_end = self._end_range @@ -233,7 +233,7 @@ async def _setup(self) -> None: self.properties.size = self.size # Overwrite the content range to the user requested range - self.properties.content_range = f'bytes {self._start_range}-{self._end_range}/{self._file_size}' + self.properties.content_range = f"bytes {self._start_range}-{self._end_range}/{self._file_size}" # Overwrite the content MD5 as it is the MD5 for the last range instead # of the stored MD5 @@ -251,17 +251,21 @@ async def _initial_request(self): self._initial_range[1], start_range_required=False, end_range_required=False, - check_content_md5=self._validate_content) + check_content_md5=self._validate_content, + ) try: - location_mode, response = cast(Tuple[Optional[str], Any], await self._client.download( - range=range_header, - range_get_content_md5=range_validation, - validate_content=self._validate_content, - data_stream_total=None, - download_stream_current=0, - **self._request_options - )) + location_mode, response = cast( + Tuple[Optional[str], Any], + await self._client.download( + range=range_header, + range_get_content_md5=range_validation, + validate_content=self._validate_content, + data_stream_total=None, + download_stream_current=0, + **self._request_options, + ), + ) # Check the location we read from to ensure we use the same one # for subsequent requests. @@ -287,12 +291,15 @@ async def _initial_request(self): # request a range, do a regular get request in order to get # any properties. try: - _, response = cast(Tuple[Optional[Any], Any], await self._client.download( - validate_content=self._validate_content, - data_stream_total=0, - download_stream_current=0, - **self._request_options - )) + _, response = cast( + Tuple[Optional[Any], Any], + await self._client.download( + validate_content=self._validate_content, + data_stream_total=0, + download_stream_current=0, + **self._request_options, + ), + ) except HttpResponseError as e: process_storage_error(e) @@ -335,12 +342,13 @@ def chunks(self) -> AsyncIterator[bytes]: validate_content=self._validate_content, use_location=self._location_mode, etag=self._etag, - **self._request_options) + **self._request_options, + ) return _AsyncChunkIterator( size=self.size, content=self._current_content, downloader=iter_downloader, - chunk_size=self._config.max_chunk_get_size + chunk_size=self._config.max_chunk_get_size, ) async def readall(self) -> bytes: @@ -369,10 +377,7 @@ async def content_as_bytes(self, max_concurrency=1): :return: The contents of the file as bytes. :rtype: bytes """ - warnings.warn( - "content_as_bytes is deprecated, use readall instead", - DeprecationWarning - ) + warnings.warn("content_as_bytes is deprecated, use readall instead", DeprecationWarning) self._max_concurrency = max_concurrency return await self.readall() @@ -390,10 +395,7 @@ async def content_as_text(self, max_concurrency=1, encoding="UTF-8"): :return: The contents of the file as a str. :rtype: str """ - warnings.warn( - "content_as_text is deprecated, use readall instead", - DeprecationWarning - ) + warnings.warn("content_as_text is deprecated, use readall instead", DeprecationWarning) self._max_concurrency = max_concurrency self._encoding = encoding return await self.readall() @@ -446,17 +448,16 @@ async def readinto(self, stream: IO[bytes]) -> int: use_location=self._location_mode, progress_hook=self._progress_hook, etag=self._etag, - **self._request_options) + **self._request_options, + ) dl_tasks = downloader.get_chunk_offsets() running_futures = { - asyncio.ensure_future(downloader.process_chunk(d)) - for d in islice(dl_tasks, 0, self._max_concurrency) + asyncio.ensure_future(downloader.process_chunk(d)) for d in islice(dl_tasks, 0, self._max_concurrency) } while running_futures: # Wait for some download to finish before adding a new one - done, running_futures = await asyncio.wait( - running_futures, return_when=asyncio.FIRST_COMPLETED) + done, running_futures = await asyncio.wait(running_futures, return_when=asyncio.FIRST_COMPLETED) try: for task in done: task.result() @@ -493,10 +494,7 @@ async def download_to_stream(self, stream, max_concurrency=1): :returns: The properties of the downloaded file. :rtype: Any """ - warnings.warn( - "download_to_stream is deprecated, use readinto instead", - DeprecationWarning - ) + warnings.warn("download_to_stream is deprecated, use readinto instead", DeprecationWarning) self._max_concurrency = max_concurrency await self.readinto(stream) return self.properties diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py index 6b4ddc0cf8af..c062ea638ab2 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py @@ -12,9 +12,20 @@ from datetime import datetime from io import BytesIO from typing import ( - Any, AnyStr, AsyncGenerator, AsyncIterable, Callable, cast, - Dict, IO, Iterable, List, Optional, Tuple, Union, - TYPE_CHECKING + Any, + AnyStr, + AsyncGenerator, + AsyncIterable, + Callable, + cast, + Dict, + IO, + Iterable, + List, + Optional, + Tuple, + Union, + TYPE_CHECKING, ) from typing_extensions import Self @@ -28,7 +39,7 @@ _from_file_url, _get_ranges_options, _parse_url, - _upload_range_from_url_options + _upload_range_from_url_options, ) from .._generated.aio import AzureFileStorage from .._generated.models import FileHTTPHeaders @@ -39,7 +50,7 @@ get_dest_access_conditions, get_rename_smb_properties, get_smb_properties, - get_source_access_conditions + get_source_access_conditions, ) from .._shared.base_client import StorageAccountHostsMixin, parse_query from .._shared.base_client_async import AsyncStorageAccountHostsMixin, parse_connection_str @@ -79,20 +90,22 @@ async def _upload_file_helper( file_permission: Optional[str] = None, file_permission_key: Optional[str] = None, progress_hook: Optional[Callable[[int, Optional[int]], None]] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: try: if size is None or size < 0: raise ValueError("A content size must be specified for a File.") response = await client.create_file( - size, content_settings=content_settings, metadata=metadata, + size, + content_settings=content_settings, + metadata=metadata, file_attributes=file_attributes, file_creation_time=file_creation_time, file_last_write_time=file_last_write_time, file_permission=file_permission, permission_key=file_permission_key, timeout=timeout, - **kwargs + **kwargs, ) if size == 0: return response @@ -107,9 +120,9 @@ async def _upload_file_helper( validate_content=validate_content, progress_hook=progress_hook, timeout=timeout, - **kwargs + **kwargs, ) - return cast(Dict[str, Any], sorted(responses, key=lambda r: r.get('last_modified'))[-1]) + return cast(Dict[str, Any], sorted(responses, key=lambda r: r.get("last_modified"))[-1]) except HttpResponseError as error: process_storage_error(error) @@ -166,53 +179,66 @@ class ShareFileClient(AsyncStorageAccountHostsMixin, StorageAccountHostsMixin): authentication. Only has an effect when credential is of type AsyncTokenCredential. The value could be https://storage.azure.com/ (default) or https://.blob.core.windows.net. """ + def __init__( - self, account_url: str, + self, + account_url: str, share_name: str, file_path: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long *, - token_intent: Optional[Literal['backup']] = None, - **kwargs: Any + token_intent: Optional[Literal["backup"]] = None, + **kwargs: Any, ) -> None: kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) - loop = kwargs.pop('loop', None) + loop = kwargs.pop("loop", None) if loop and sys.version_info >= (3, 8): - warnings.warn("The 'loop' parameter was deprecated from asyncio's high-level" - "APIs in Python 3.8 and is no longer supported.", DeprecationWarning) - if hasattr(credential, 'get_token') and not token_intent: + warnings.warn( + "The 'loop' parameter was deprecated from asyncio's high-level" + "APIs in Python 3.8 and is no longer supported.", + DeprecationWarning, + ) + if hasattr(credential, "get_token") and not token_intent: raise ValueError("'token_intent' keyword is required when 'credential' is an AsyncTokenCredential.") parsed_url = _parse_url(account_url, share_name, file_path) path_snapshot, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: raise ValueError( - 'You need to provide either an account shared key or SAS token when creating a storage service.') + "You need to provide either an account shared key or SAS token when creating a storage service." + ) self.snapshot = _parse_snapshot(snapshot, path_snapshot) self.share_name = share_name - self.file_path = file_path.split('/') + self.file_path = file_path.split("/") self.file_name = self.file_path[-1] self.directory_path = "/".join(self.file_path[:-1]) - self._query_str, credential = self._format_query_string( - sas_token, credential, share_snapshot=self.snapshot) - super(ShareFileClient, self).__init__( - parsed_url, service='file-share', credential=credential, **kwargs) - self.allow_trailing_dot = kwargs.pop('allow_trailing_dot', None) - self.allow_source_trailing_dot = kwargs.pop('allow_source_trailing_dot', None) + self._query_str, credential = self._format_query_string(sas_token, credential, share_snapshot=self.snapshot) + super(ShareFileClient, self).__init__(parsed_url, service="file-share", credential=credential, **kwargs) + self.allow_trailing_dot = kwargs.pop("allow_trailing_dot", None) + self.allow_source_trailing_dot = kwargs.pop("allow_source_trailing_dot", None) self.file_request_intent = token_intent - self._client = AzureFileStorage(url=self.url, base_url=self.url, pipeline=self._pipeline, - allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, - file_request_intent=self.file_request_intent) + self._client = AzureFileStorage( + url=self.url, + base_url=self.url, + pipeline=self._pipeline, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + file_request_intent=self.file_request_intent, + ) self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] @classmethod def from_file_url( - cls, file_url: str, + cls, + file_url: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """A client to interact with a specific file, although that file may not yet exist. @@ -248,12 +274,15 @@ def _format_url(self, hostname: str): @classmethod def from_connection_string( - cls, conn_str: str, + cls, + conn_str: str, share_name: str, file_path: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """Create ShareFileClient from a Connection String. @@ -295,11 +324,12 @@ def from_connection_string( :dedent: 12 :caption: Creates the file client with connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, 'file') - if 'secondary_hostname' not in kwargs: - kwargs['secondary_hostname'] = secondary + account_url, secondary, credential = parse_connection_str(conn_str, credential, "file") + if "secondary_hostname" not in kwargs: + kwargs["secondary_hostname"] = secondary return cls( - account_url, share_name=share_name, file_path=file_path, snapshot=snapshot, credential=credential, **kwargs) + account_url, share_name=share_name, file_path=file_path, snapshot=snapshot, credential=credential, **kwargs + ) @distributed_trace_async async def acquire_lease(self, lease_id: Optional[str] = None, **kwargs: Any) -> ShareLeaseClient: @@ -321,7 +351,7 @@ async def acquire_lease(self, lease_id: Optional[str] = None, **kwargs: Any) -> :returns: A ShareLeaseClient object. :rtype: ~azure.storage.fileshare.aio.ShareLeaseClient """ - kwargs['lease_duration'] = -1 + kwargs["lease_duration"] = -1 lease = ShareLeaseClient(self, lease_id=lease_id) await lease.acquire(**kwargs) return lease @@ -351,13 +381,14 @@ async def exists(self, **kwargs: Any) -> bool: @distributed_trace_async async def create_file( - self, size: int, + self, + size: int, file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, file_creation_time: Optional[Union[str, datetime]] = None, file_last_write_time: Optional[Union[str, datetime]] = None, file_permission: Optional[str] = None, permission_key: Optional[str] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """Creates a new file. @@ -434,10 +465,10 @@ async def create_file( :dedent: 16 :caption: Create a file. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - content_settings = kwargs.pop('content_settings', None) - metadata = kwargs.pop('metadata', None) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + content_settings = kwargs.pop("content_settings", None) + metadata = kwargs.pop("metadata", None) + timeout = kwargs.pop("timeout", None) headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) file_http_headers = None @@ -451,37 +482,41 @@ async def create_file( file_content_disposition=content_settings.content_disposition, ) file_permission = _get_file_permission(file_permission, permission_key, None) - file_change_time = kwargs.pop('file_change_time', None) + file_change_time = kwargs.pop("file_change_time", None) try: - return cast(Dict[str, Any], await self._client.file.create( - file_content_length=size, - metadata=metadata, - file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, - file_creation_time=_datetime_to_str(file_creation_time), - file_last_write_time=_datetime_to_str(file_last_write_time), - file_change_time=_datetime_to_str(file_change_time), - file_permission=file_permission, - file_permission_key=permission_key, - file_http_headers=file_http_headers, - lease_access_conditions=access_conditions, - headers=headers, - timeout=timeout, - cls=return_response_headers, - **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.create( + file_content_length=size, + metadata=metadata, + file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, + file_creation_time=_datetime_to_str(file_creation_time), + file_last_write_time=_datetime_to_str(file_last_write_time), + file_change_time=_datetime_to_str(file_change_time), + file_permission=file_permission, + file_permission_key=permission_key, + file_http_headers=file_http_headers, + lease_access_conditions=access_conditions, + headers=headers, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async async def upload_file( - self, data: Union[bytes, str, Iterable[AnyStr], AsyncIterable[AnyStr], IO[AnyStr]], + self, + data: Union[bytes, str, Iterable[AnyStr], AsyncIterable[AnyStr], IO[AnyStr]], length: Optional[int] = None, file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, file_creation_time: Optional[Union[str, datetime]] = None, file_last_write_time: Optional[Union[str, datetime]] = None, file_permission: Optional[str] = None, permission_key: Optional[str] = None, - **kwargs + **kwargs, ) -> Dict[str, Any]: """Uploads a new file. @@ -568,13 +603,13 @@ async def upload_file( :dedent: 16 :caption: Upload a file. """ - metadata = kwargs.pop('metadata', None) - content_settings = kwargs.pop('content_settings', None) - max_concurrency = kwargs.pop('max_concurrency', 1) - validate_content = kwargs.pop('validate_content', False) - progress_hook = kwargs.pop('progress_hook', None) - timeout = kwargs.pop('timeout', None) - encoding = kwargs.pop('encoding', 'UTF-8') + metadata = kwargs.pop("metadata", None) + content_settings = kwargs.pop("content_settings", None) + max_concurrency = kwargs.pop("max_concurrency", 1) + validate_content = kwargs.pop("validate_content", False) + progress_hook = kwargs.pop("progress_hook", None) + timeout = kwargs.pop("timeout", None) + encoding = kwargs.pop("encoding", "UTF-8") if isinstance(data, str): data = data.encode(encoding) @@ -590,7 +625,7 @@ async def upload_file( stream = data elif hasattr(data, "__iter__"): stream = IterStreamer(data, encoding=encoding) - elif hasattr(data, '__aiter__'): + elif hasattr(data, "__aiter__"): stream = AsyncIterStreamer(cast(AsyncGenerator, data), encoding=encoding) else: raise TypeError(f"Unsupported data type: {type(data)}") @@ -610,7 +645,8 @@ async def upload_file( file_permission=file_permission, file_permission_key=permission_key, progress_hook=progress_hook, - **kwargs) + **kwargs, + ) @distributed_trace_async async def start_copy_from_url(self, source_url: str, **kwargs: Any) -> Dict[str, Any]: @@ -752,32 +788,35 @@ async def start_copy_from_url(self, source_url: str, **kwargs: Any) -> Dict[str, :dedent: 16 :caption: Copy a file from a URL """ - metadata = kwargs.pop('metadata', None) - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) - owner = kwargs.pop('owner', None) - group = kwargs.pop('group', None) - file_mode = kwargs.pop('file_mode', None) - file_mode_copy_mode = kwargs.pop('file_mode_copy_mode', None) - file_owner_copy_mode = kwargs.pop('owner_copy_mode', None) + metadata = kwargs.pop("metadata", None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) + owner = kwargs.pop("owner", None) + group = kwargs.pop("group", None) + file_mode = kwargs.pop("file_mode", None) + file_mode_copy_mode = kwargs.pop("file_mode_copy_mode", None) + file_owner_copy_mode = kwargs.pop("owner_copy_mode", None) headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) kwargs.update(get_smb_properties(kwargs)) try: - return cast(Dict[str, Any], await self._client.file.start_copy( - source_url, - metadata=metadata, - lease_access_conditions=access_conditions, - owner=owner, - group=group, - file_mode=file_mode, - file_mode_copy_mode=file_mode_copy_mode, - file_owner_copy_mode=file_owner_copy_mode, - headers=headers, - cls=return_response_headers, - timeout=timeout, - **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.start_copy( + source_url, + metadata=metadata, + lease_access_conditions=access_conditions, + owner=owner, + group=group, + file_mode=file_mode, + file_mode_copy_mode=file_mode_copy_mode, + file_owner_copy_mode=file_owner_copy_mode, + headers=headers, + cls=return_response_headers, + timeout=timeout, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -805,26 +844,25 @@ async def abort_copy(self, copy_id: Union[str, FileProperties], **kwargs: Any) - This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :returns: None :rtype: None """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) if isinstance(copy_id, FileProperties): copy_id = copy_id.copy.id elif isinstance(copy_id, Dict): - copy_id = copy_id['copy_id'] + copy_id = copy_id["copy_id"] try: - await self._client.file.abort_copy(copy_id=copy_id, - lease_access_conditions=access_conditions, - timeout=timeout, **kwargs) + await self._client.file.abort_copy( + copy_id=copy_id, lease_access_conditions=access_conditions, timeout=timeout, **kwargs + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async async def download_file( - self, offset: Optional[int] = None, - length: Optional[int] = None, - **kwargs: Any + self, offset: Optional[int] = None, length: Optional[int] = None, **kwargs: Any ) -> StorageStreamDownloader: """Downloads a file to the StorageStreamDownloader. The readall() method must be used to read all the content or readinto() must be used to download the file into @@ -888,7 +926,7 @@ async def download_file( raise ValueError("Offset value must not be None if length is set.") range_end = offset + length - 1 # Service actually uses an end-range inclusive index - access_conditions = get_access_conditions(kwargs.pop('lease', None)) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) downloader = StorageStreamDownloader( client=self._client.file, @@ -896,11 +934,11 @@ async def download_file( start_range=offset, end_range=range_end, name=self.file_name, - path='/'.join(self.file_path), + path="/".join(self.file_path), share=self.share_name, lease_access_conditions=access_conditions, cls=deserialize_file_stream, - **kwargs + **kwargs, ) await downloader._setup() # pylint: disable=protected-access return downloader @@ -934,8 +972,8 @@ async def delete_file(self, **kwargs: Any) -> None: :dedent: 16 :caption: Delete a file. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: await self._client.file.delete(lease_access_conditions=access_conditions, timeout=timeout, **kwargs) except HttpResponseError as error: @@ -1016,39 +1054,44 @@ async def rename_file(self, new_name: str, **kwargs: Any) -> "ShareFileClient": if not new_name: raise ValueError("Please specify a new file name.") - new_name = new_name.strip('/') - new_path_and_query = new_name.split('?') + new_name = new_name.strip("/") + new_path_and_query = new_name.split("?") new_file_path = new_path_and_query[0] if len(new_path_and_query) == 2: - new_file_sas = new_path_and_query[1] or self._query_str.strip('?') + new_file_sas = new_path_and_query[1] or self._query_str.strip("?") else: - new_file_sas = self._query_str.strip('?') + new_file_sas = self._query_str.strip("?") new_file_client = ShareFileClient( - f'{self.scheme}://{self.primary_hostname}', self.share_name, new_file_path, - credential=new_file_sas or self.credential, api_version=self.api_version, - _hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline, - _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, token_intent=self.file_request_intent + f"{self.scheme}://{self.primary_hostname}", + self.share_name, + new_file_path, + credential=new_file_sas or self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=self._pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, ) kwargs.update(get_rename_smb_properties(kwargs)) file_http_headers = None - content_type = kwargs.pop('content_type', None) + content_type = kwargs.pop("content_type", None) if content_type: - file_http_headers = FileHTTPHeaders( - file_content_type=content_type - ) + file_http_headers = FileHTTPHeaders(file_content_type=content_type) - timeout = kwargs.pop('timeout', None) - overwrite = kwargs.pop('overwrite', None) - metadata = kwargs.pop('metadata', None) - headers = kwargs.pop('headers', {}) + timeout = kwargs.pop("timeout", None) + overwrite = kwargs.pop("overwrite", None) + metadata = kwargs.pop("metadata", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) - source_access_conditions = get_source_access_conditions(kwargs.pop('source_lease', None)) - dest_access_conditions = get_dest_access_conditions(kwargs.pop('destination_lease', None)) + source_access_conditions = get_source_access_conditions(kwargs.pop("source_lease", None)) + dest_access_conditions = get_dest_access_conditions(kwargs.pop("destination_lease", None)) try: await new_file_client._client.file.rename( # pylint: disable=protected-access @@ -1059,7 +1102,8 @@ async def rename_file(self, new_name: str, **kwargs: Any) -> "ShareFileClient": source_lease_access_conditions=source_access_conditions, destination_lease_access_conditions=dest_access_conditions, headers=headers, - **kwargs) + **kwargs, + ) return new_file_client except HttpResponseError as error: @@ -1086,16 +1130,19 @@ async def get_file_properties(self, **kwargs: Any) -> FileProperties: :returns: FileProperties :rtype: ~azure.storage.fileshare.FileProperties """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - file_props = cast(FileProperties, await self._client.file.get_properties( - sharesnapshot=self.snapshot, - lease_access_conditions=access_conditions, - timeout=timeout, - cls=deserialize_file_properties, - **kwargs - )) + file_props = cast( + FileProperties, + await self._client.file.get_properties( + sharesnapshot=self.snapshot, + lease_access_conditions=access_conditions, + timeout=timeout, + cls=deserialize_file_properties, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) file_props.name = self.file_name @@ -1106,13 +1153,14 @@ async def get_file_properties(self, **kwargs: Any) -> FileProperties: @distributed_trace_async async def set_http_headers( - self, content_settings: "ContentSettings", + self, + content_settings: "ContentSettings", file_attributes: Optional[Union[str, "NTFSAttributes"]] = None, file_creation_time: Optional[Union[str, datetime]] = None, file_last_write_time: Optional[Union[str, datetime]] = None, file_permission: Optional[str] = None, permission_key: Optional[str] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """Sets HTTP headers on the file. @@ -1172,8 +1220,8 @@ async def set_http_headers( :returns: File-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) file_content_length = kwargs.pop("size", None) file_http_headers = FileHTTPHeaders( file_cache_control=content_settings.cache_control, @@ -1184,22 +1232,25 @@ async def set_http_headers( file_content_disposition=content_settings.content_disposition, ) file_permission = _get_file_permission(file_permission, permission_key, None) - file_change_time = kwargs.pop('file_change_time', None) + file_change_time = kwargs.pop("file_change_time", None) try: - return cast(Dict[str, Any], await self._client.file.set_http_headers( - file_content_length=file_content_length, - file_http_headers=file_http_headers, - file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, - file_creation_time=_datetime_to_str(file_creation_time), - file_last_write_time=_datetime_to_str(file_last_write_time), - file_change_time=_datetime_to_str(file_change_time), - file_permission=file_permission, - file_permission_key=permission_key, - lease_access_conditions=access_conditions, - timeout=timeout, - cls=return_response_headers, - **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.set_http_headers( + file_content_length=file_content_length, + file_http_headers=file_http_headers, + file_attributes=str(file_attributes) if file_attributes is not None else file_attributes, + file_creation_time=_datetime_to_str(file_creation_time), + file_last_write_time=_datetime_to_str(file_last_write_time), + file_change_time=_datetime_to_str(file_change_time), + file_permission=file_permission, + file_permission_key=permission_key, + lease_access_conditions=access_conditions, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -1231,25 +1282,27 @@ async def set_file_metadata(self, metadata: Optional[Dict[str, Any]] = None, **k :returns: File-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], await self._client.file.set_metadata( - metadata=metadata, lease_access_conditions=access_conditions, - timeout=timeout, cls=return_response_headers, headers=headers, **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.set_metadata( + metadata=metadata, + lease_access_conditions=access_conditions, + timeout=timeout, + cls=return_response_headers, + headers=headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async - async def upload_range( - self, data: bytes, - offset: int, - length: int, - **kwargs: Any - ) -> Dict[str, Any]: + async def upload_range(self, data: bytes, offset: int, length: int, **kwargs: Any) -> Dict[str, Any]: """Upload a range of bytes to a file. :param bytes data: @@ -1295,37 +1348,36 @@ async def upload_range( :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ - validate_content = kwargs.pop('validate_content', False) - timeout = kwargs.pop('timeout', None) - encoding = kwargs.pop('encoding', 'UTF-8') - file_last_write_mode = kwargs.pop('file_last_write_mode', None) + validate_content = kwargs.pop("validate_content", False) + timeout = kwargs.pop("timeout", None) + encoding = kwargs.pop("encoding", "UTF-8") + file_last_write_mode = kwargs.pop("file_last_write_mode", None) if isinstance(data, str): data = data.encode(encoding) end_range = offset + length - 1 # Reformat to an inclusive range index - content_range = f'bytes={offset}-{end_range}' - access_conditions = get_access_conditions(kwargs.pop('lease', None)) + content_range = f"bytes={offset}-{end_range}" + access_conditions = get_access_conditions(kwargs.pop("lease", None)) try: - return cast(Dict[str, Any], await self._client.file.upload_range( - range=content_range, - content_length=length, - optionalbody=data, - timeout=timeout, - validate_content=validate_content, - file_last_written_mode=file_last_write_mode, - lease_access_conditions=access_conditions, - cls=return_response_headers, - **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.upload_range( + range=content_range, + content_length=length, + optionalbody=data, + timeout=timeout, + validate_content=validate_content, + file_last_written_mode=file_last_write_mode, + lease_access_conditions=access_conditions, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async async def upload_range_from_url( - self, source_url: str, - offset: int, - length: int, - source_offset: int, - **kwargs: Any + self, source_url: str, offset: int, length: int, source_offset: int, **kwargs: Any ) -> Dict[str, Any]: """ Writes the bytes from one Azure File endpoint into the specified range of another Azure File endpoint. @@ -1395,11 +1447,7 @@ async def upload_range_from_url( :rtype: dict[str, Any] """ options = _upload_range_from_url_options( - source_url=source_url, - offset=offset, - length=length, - source_offset=source_offset, - **kwargs + source_url=source_url, offset=offset, length=length, source_offset=source_offset, **kwargs ) try: return cast(Dict[str, Any], await self._client.file.upload_range_from_url(**options)) @@ -1408,9 +1456,7 @@ async def upload_range_from_url( @distributed_trace_async async def get_ranges( - self, offset: Optional[int] = None, - length: Optional[int] = None, - **kwargs: Any + self, offset: Optional[int] = None, length: Optional[int] = None, **kwargs: Any ) -> List[Dict[str, int]]: """Returns the list of valid page ranges for a file or snapshot of a file. @@ -1436,25 +1482,22 @@ async def get_ranges( A list of valid ranges. :rtype: List[dict[str, int]] """ - options = _get_ranges_options( - snapshot=self.snapshot, - offset=offset, - length=length, - **kwargs) + options = _get_ranges_options(snapshot=self.snapshot, offset=offset, length=length, **kwargs) try: ranges = await self._client.file.get_range_list(**options) except HttpResponseError as error: process_storage_error(error) - return [{'start': file_range.start, 'end': file_range.end} for file_range in ranges.ranges] + return [{"start": file_range.start, "end": file_range.end} for file_range in ranges.ranges] @distributed_trace_async async def get_ranges_diff( - self, previous_sharesnapshot: Union[str, Dict[str, Any]], + self, + previous_sharesnapshot: Union[str, Dict[str, Any]], offset: Optional[int] = None, length: Optional[int] = None, *, include_renames: Optional[bool] = None, - **kwargs: Any + **kwargs: Any, ) -> Tuple[List[Dict[str, int]], List[Dict[str, int]]]: """Returns the list of valid page ranges for a file or snapshot of a file. @@ -1495,7 +1538,8 @@ async def get_ranges_diff( length=length, previous_sharesnapshot=previous_sharesnapshot, support_rename=include_renames, - **kwargs) + **kwargs, + ) try: ranges = await self._client.file.get_range_list(**options) except HttpResponseError as error: @@ -1529,8 +1573,8 @@ async def clear_range(self, offset: int, length: int, **kwargs: Any) -> Dict[str :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) if offset is None or offset % 512 != 0: raise ValueError("offset must be an integer that aligns with 512 bytes file size") @@ -1539,16 +1583,19 @@ async def clear_range(self, offset: int, length: int, **kwargs: Any) -> Dict[str end_range = length + offset - 1 # Reformat to an inclusive range index content_range = f"bytes={offset}-{end_range}" try: - return cast(Dict[str, Any], await self._client.file.upload_range( - timeout=timeout, - cls=return_response_headers, - content_length=0, - optionalbody=None, - file_range_write="clear", - range=content_range, - lease_access_conditions=access_conditions, - **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.upload_range( + timeout=timeout, + cls=return_response_headers, + content_length=0, + optionalbody=None, + file_range_write="clear", + range=content_range, + lease_access_conditions=access_conditions, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -1574,20 +1621,23 @@ async def resize_file(self, size: int, **kwargs: Any) -> Dict[str, Any]: :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - return cast(Dict[str, Any], await self._client.file.set_http_headers( - file_content_length=size, - file_attributes=None, - file_creation_time=None, - file_last_write_time=None, - file_permission="preserve", - lease_access_conditions=access_conditions, - cls=return_response_headers, - timeout=timeout, - **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.set_http_headers( + file_content_length=size, + file_attributes=None, + file_creation_time=None, + file_last_write_time=None, + file_permission="preserve", + lease_access_conditions=access_conditions, + cls=return_response_headers, + timeout=timeout, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -1604,16 +1654,12 @@ def list_handles(self, **kwargs: Any) -> AsyncItemPaged[Handle]: :returns: An auto-paging iterable of Handle :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.storage.fileshare.Handle] """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) results_per_page = kwargs.pop("results_per_page", None) command = functools.partial( - self._client.file.list_handles, - sharesnapshot=self.snapshot, - timeout=timeout, - **kwargs) - return AsyncItemPaged( - command, results_per_page=results_per_page, - page_iterator_class=HandlesPaged) + self._client.file.list_handles, sharesnapshot=self.snapshot, timeout=timeout, **kwargs + ) + return AsyncItemPaged(command, results_per_page=results_per_page, page_iterator_class=HandlesPaged) @distributed_trace_async async def close_handle(self, handle: Union[str, Handle], **kwargs: Any) -> Dict[str, int]: @@ -1637,19 +1683,15 @@ async def close_handle(self, handle: Union[str, Handle], **kwargs: Any) -> Dict[ handle_id = handle.id else: handle_id = handle - if handle_id == '*': + if handle_id == "*": raise ValueError("Handle ID '*' is not supported. Use 'close_all_handles' instead.") try: response = await self._client.file.force_close_handles( - handle_id, - marker=None, - sharesnapshot=self.snapshot, - cls=return_response_headers, - **kwargs + handle_id, marker=None, sharesnapshot=self.snapshot, cls=return_response_headers, **kwargs ) return { - 'closed_handles_count': response.get('number_of_handles_closed', 0), - 'failed_handles_count': response.get('number_of_handles_failed', 0) + "closed_handles_count": response.get("number_of_handles_closed", 0), + "failed_handles_count": response.get("number_of_handles_failed", 0), } except HttpResponseError as error: process_storage_error(error) @@ -1671,7 +1713,7 @@ async def close_all_handles(self, **kwargs: Any) -> Dict[str, int]: and the number of handles failed to close in a dict. :rtype: dict[str, int] """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) start_time = time.time() try_close = True @@ -1681,33 +1723,31 @@ async def close_all_handles(self, **kwargs: Any) -> Dict[str, int]: while try_close: try: response = await self._client.file.force_close_handles( - handle_id='*', + handle_id="*", timeout=timeout, marker=continuation_token, sharesnapshot=self.snapshot, cls=return_response_headers, - **kwargs + **kwargs, ) except HttpResponseError as error: process_storage_error(error) - continuation_token = response.get('marker') + continuation_token = response.get("marker") try_close = bool(continuation_token) - total_closed += response.get('number_of_handles_closed', 0) - total_failed += response.get('number_of_handles_failed', 0) + total_closed += response.get("number_of_handles_closed", 0) + total_failed += response.get("number_of_handles_failed", 0) if timeout: timeout = max(0, timeout - (time.time() - start_time)) - return { - 'closed_handles_count': total_closed, - 'failed_handles_count': total_failed - } + return {"closed_handles_count": total_closed, "failed_handles_count": total_failed} @distributed_trace_async async def create_hardlink( - self, target: str, + self, + target: str, *, lease: Optional[Union[ShareLeaseClient, str]] = None, timeout: Optional[int] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """NFS only. Creates a hard link to the file specified by path. @@ -1729,19 +1769,23 @@ async def create_hardlink( :rtype: dict[str, Any] """ try: - return cast(Dict[str, Any], await self._client.file.create_hard_link( - target_file=target, - lease_access_conditions=lease, - timeout=timeout, - cls=return_response_headers, - **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.create_hard_link( + target_file=target, + lease_access_conditions=lease, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async async def create_symlink( - self, target: str, + self, + target: str, *, metadata: Optional[Dict[str, str]] = None, file_creation_time: Optional[Union[str, datetime]] = None, @@ -1750,7 +1794,7 @@ async def create_symlink( group: Optional[str] = None, lease: Optional[Union[ShareLeaseClient, str]] = None, timeout: Optional[int] = None, - **kwargs: Any + **kwargs: Any, ) -> Dict[str, Any]: """NFS only. Creates a symbolic link to the specified file. @@ -1778,28 +1822,26 @@ async def create_symlink( :rtype: dict[str, Any] """ try: - return cast(Dict[str, Any], await self._client.file.create_symbolic_link( - link_text=target, - metadata=metadata, - file_creation_time=file_creation_time, - file_last_write_time=file_last_write_time, - owner=owner, - group=group, - lease_access_conditions=lease, - timeout=timeout, - cls=return_response_headers, - **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.create_symbolic_link( + link_text=target, + metadata=metadata, + file_creation_time=file_creation_time, + file_last_write_time=file_last_write_time, + owner=owner, + group=group, + lease_access_conditions=lease, + timeout=timeout, + cls=return_response_headers, + **kwargs, + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async - async def get_symlink( - self, - *, - timeout: Optional[int] = None, - **kwargs: Any - ) -> Dict[str, Any]: + async def get_symlink(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: """NFS only. Gets the symbolic link for the file client. :keyword int timeout: @@ -1812,10 +1854,9 @@ async def get_symlink( :rtype: dict[str, Any] """ try: - return cast(Dict[str, Any], await self._client.file.get_symbolic_link( - timeout=timeout, - cls=return_response_headers, - **kwargs - )) + return cast( + Dict[str, Any], + await self._client.file.get_symbolic_link(timeout=timeout, cls=return_response_headers, **kwargs), + ) except HttpResponseError as error: process_storage_error(error) diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_lease_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_lease_async.py index 70d6a392c29f..c3937ebbab4b 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_lease_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_lease_async.py @@ -42,17 +42,17 @@ class ShareLeaseClient: # pylint: disable=client-accepts-api-version-keyword A string representing the lease ID of an existing lease. This value does not need to be specified in order to acquire a new lease, or break one. """ + def __init__( # pylint: disable=missing-client-constructor-parameter-credential, missing-client-constructor-parameter-kwargs - self, client: Union["ShareFileClient", "ShareClient"], - lease_id: Optional[str] = None + self, client: Union["ShareFileClient", "ShareClient"], lease_id: Optional[str] = None ) -> None: self.id = lease_id or str(uuid.uuid4()) self.last_modified = None self.etag = None - if hasattr(client, 'file_name'): + if hasattr(client, "file_name"): self._client = client._client.file # type: ignore self._snapshot = None - elif hasattr(client, 'share_name'): + elif hasattr(client, "share_name"): self._client = client._client.share self._snapshot = client.snapshot else: @@ -87,23 +87,25 @@ async def acquire(self, **kwargs: Any) -> None: This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :return: None :rtype: None """ try: - lease_duration = kwargs.pop('lease_duration', -1) + lease_duration = kwargs.pop("lease_duration", -1) if self._snapshot: - kwargs['sharesnapshot'] = self._snapshot + kwargs["sharesnapshot"] = self._snapshot response = await self._client.acquire_lease( - timeout=kwargs.pop('timeout', None), + timeout=kwargs.pop("timeout", None), duration=lease_duration, proposed_lease_id=self.id, cls=return_response_headers, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) - self.id = response.get('lease_id') - self.last_modified = response.get('last_modified') - self.etag = response.get('etag') + self.id = response.get("lease_id") + self.last_modified = response.get("last_modified") + self.etag = response.get("etag") @distributed_trace_async async def renew(self, **kwargs: Any) -> None: @@ -130,15 +132,16 @@ async def renew(self, **kwargs: Any) -> None: try: response = await self._client.renew_lease( lease_id=self.id, - timeout=kwargs.pop('timeout', None), + timeout=kwargs.pop("timeout", None), sharesnapshot=self._snapshot, cls=return_response_headers, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) - self.etag = response.get('etag') - self.id = response.get('lease_id') - self.last_modified = response.get('last_modified') + self.etag = response.get("etag") + self.id = response.get("lease_id") + self.last_modified = response.get("last_modified") @distributed_trace_async async def release(self, **kwargs: Any) -> None: @@ -153,24 +156,23 @@ async def release(self, **kwargs: Any) -> None: see `here `__. :return: None + :rtype: None """ try: if self._snapshot: - kwargs['sharesnapshot'] = self._snapshot + kwargs["sharesnapshot"] = self._snapshot response = await self._client.release_lease( - lease_id=self.id, - timeout=kwargs.pop('timeout', None), - cls=return_response_headers, - **kwargs) + lease_id=self.id, timeout=kwargs.pop("timeout", None), cls=return_response_headers, **kwargs + ) except HttpResponseError as error: process_storage_error(error) - self.etag = response.get('etag') - self.id = response.get('lease_id') - self.last_modified = response.get('last_modified') + self.etag = response.get("etag") + self.id = response.get("lease_id") + self.last_modified = response.get("last_modified") @distributed_trace_async async def change(self, proposed_lease_id: str, **kwargs: Any) -> None: - """ Changes the lease ID of an active lease. A change must include the current lease ID in x-ms-lease-id and + """Changes the lease ID of an active lease. A change must include the current lease ID in x-ms-lease-id and a new lease ID in x-ms-proposed-lease-id. :param str proposed_lease_id: @@ -183,21 +185,23 @@ async def change(self, proposed_lease_id: str, **kwargs: Any) -> None: see `here `__. :return: None + :rtype: None """ try: if self._snapshot: - kwargs['sharesnapshot'] = self._snapshot + kwargs["sharesnapshot"] = self._snapshot response = await self._client.change_lease( lease_id=self.id, proposed_lease_id=proposed_lease_id, - timeout=kwargs.pop('timeout', None), + timeout=kwargs.pop("timeout", None), cls=return_response_headers, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) - self.etag = response.get('etag') - self.id = response.get('lease_id') - self.last_modified = response.get('last_modified') + self.etag = response.get("etag") + self.id = response.get("lease_id") + self.last_modified = response.get("last_modified") @distributed_trace_async async def break_lease(self, **kwargs: Any) -> int: @@ -232,18 +236,17 @@ async def break_lease(self, **kwargs: Any) -> int: :rtype: int """ try: - lease_break_period = kwargs.pop('lease_break_period', None) + lease_break_period = kwargs.pop("lease_break_period", None) if self._snapshot: - kwargs['sharesnapshot'] = self._snapshot + kwargs["sharesnapshot"] = self._snapshot if isinstance(self._client, ShareOperations): - kwargs['break_period'] = lease_break_period + kwargs["break_period"] = lease_break_period if isinstance(self._client, FileOperations) and lease_break_period: raise TypeError("Setting a lease break period is only applicable to Share leases.") response = await self._client.break_lease( - timeout=kwargs.pop('timeout', None), - cls=return_response_headers, - **kwargs) + timeout=kwargs.pop("timeout", None), cls=return_response_headers, **kwargs + ) except HttpResponseError as error: process_storage_error(error) - return response.get('lease_time') # type: ignore + return response.get("lease_time") # type: ignore diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_models.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_models.py index dd7335bbdeff..b782819c2d98 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_models.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_models.py @@ -5,9 +5,7 @@ # -------------------------------------------------------------------------- # pylint: disable=too-few-public-methods -from typing import ( - Any, Callable, Dict, List, Optional -) +from typing import Any, Callable, Dict, List, Optional from azure.core.async_paging import AsyncPageIterator from azure.core.exceptions import HttpResponseError @@ -19,8 +17,8 @@ def _wrap_item(item): if isinstance(item, DirectoryItem): - return {'name': item.name, 'is_directory': True} - return {'name': item.name, 'size': item.properties.content_length, 'is_directory': False} + return {"name": item.name, "is_directory": True} + return {"name": item.name, "size": item.properties.content_length, "is_directory": False} class SharePropertiesPaged(AsyncPageIterator): @@ -49,15 +47,14 @@ class SharePropertiesPaged(AsyncPageIterator): """The current page of listed results.""" def __init__( - self, command: Callable, + self, + command: Callable, prefix: Optional[str] = None, results_per_page: Optional[int] = None, - continuation_token: Optional[str] = None + continuation_token: Optional[str] = None, ) -> None: super(SharePropertiesPaged, self).__init__( - get_next=self._get_next_cb, - extract_data=self._extract_data_cb, - continuation_token=continuation_token or "" + get_next=self._get_next_cb, extract_data=self._extract_data_cb, continuation_token=continuation_token or "" ) self._command = command self.service_endpoint = None @@ -74,7 +71,8 @@ async def _get_next_cb(self, continuation_token): maxresults=self.results_per_page, prefix=self.prefix, cls=return_context_and_deserialized, - use_location=self.location_mode) + use_location=self.location_mode, + ) except HttpResponseError as error: process_storage_error(error) @@ -84,7 +82,9 @@ async def _extract_data_cb(self, get_next_return): self.prefix = self._response.prefix self.marker = self._response.marker self.results_per_page = self._response.max_results - self.current_page = [ShareProperties._from_generated(i) for i in self._response.share_items] # pylint: disable=protected-access + self.current_page = [ + ShareProperties._from_generated(i) for i in self._response.share_items + ] # pylint: disable=protected-access return self._response.next_marker or None, self.current_page @@ -107,14 +107,10 @@ class HandlesPaged(AsyncPageIterator): """The current page of listed results.""" def __init__( - self, command: Callable, - results_per_page: Optional[int] = None, - continuation_token: Optional[str] = None + self, command: Callable, results_per_page: Optional[int] = None, continuation_token: Optional[str] = None ) -> None: super(HandlesPaged, self).__init__( - get_next=self._get_next_cb, - extract_data=self._extract_data_cb, - continuation_token=continuation_token or "" + get_next=self._get_next_cb, extract_data=self._extract_data_cb, continuation_token=continuation_token or "" ) self._command = command self.marker = None @@ -128,13 +124,16 @@ async def _get_next_cb(self, continuation_token): marker=continuation_token or None, maxresults=self.results_per_page, cls=return_context_and_deserialized, - use_location=self.location_mode) + use_location=self.location_mode, + ) except HttpResponseError as error: process_storage_error(error) async def _extract_data_cb(self, get_next_return): self.location_mode, self._response = get_next_return - self.current_page = [Handle._from_generated(h) for h in self._response.handle_list] # pylint: disable=protected-access + self.current_page = [ + Handle._from_generated(h) for h in self._response.handle_list + ] # pylint: disable=protected-access return self._response.next_marker or None, self.current_page @@ -168,15 +167,14 @@ class DirectoryPropertiesPaged(AsyncPageIterator): """The current page of listed results.""" def __init__( - self, command: Callable, + self, + command: Callable, prefix: Optional[str] = None, results_per_page: Optional[int] = None, - continuation_token: Optional[str] = None + continuation_token: Optional[str] = None, ) -> None: super(DirectoryPropertiesPaged, self).__init__( - get_next=self._get_next_cb, - extract_data=self._extract_data_cb, - continuation_token=continuation_token or "" + get_next=self._get_next_cb, extract_data=self._extract_data_cb, continuation_token=continuation_token or "" ) self._command = command self.service_endpoint = None @@ -193,7 +191,8 @@ async def _get_next_cb(self, continuation_token): prefix=self.prefix, maxresults=self.results_per_page, cls=return_context_and_deserialized, - use_location=self.location_mode) + use_location=self.location_mode, + ) except HttpResponseError as error: process_storage_error(error) @@ -203,6 +202,10 @@ async def _extract_data_cb(self, get_next_return): self.prefix = self._response.prefix self.marker = self._response.marker self.results_per_page = self._response.max_results - self.current_page = [DirectoryProperties._from_generated(i) for i in self._response.segment.directory_items] # pylint: disable = protected-access - self.current_page.extend([FileProperties._from_generated(i) for i in self._response.segment.file_items]) # pylint: disable = protected-access + self.current_page = [ + DirectoryProperties._from_generated(i) for i in self._response.segment.directory_items + ] # pylint: disable = protected-access + self.current_page.extend( + [FileProperties._from_generated(i) for i in self._response.segment.file_items] + ) # pylint: disable = protected-access return self._response.next_marker or None, self.current_page diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py index 7f66feb9a883..7e3cd18cd8d1 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py @@ -7,10 +7,7 @@ import sys import warnings -from typing import ( - Any, cast, Dict, Literal, Optional, Union, - TYPE_CHECKING -) +from typing import Any, cast, Dict, Literal, Optional, Union, TYPE_CHECKING from typing_extensions import Self from azure.core.async_paging import AsyncItemPaged @@ -20,28 +17,15 @@ from azure.core.tracing.decorator_async import distributed_trace_async from .._deserialize import deserialize_permission, deserialize_share_properties from .._generated.aio import AzureFileStorage -from .._generated.models import ( - DeleteSnapshotsOptionType, - ShareStats, - SignedIdentifier -) +from .._generated.models import DeleteSnapshotsOptionType, ShareStats, SignedIdentifier from .._models import ShareProtocols from .._parser import _parse_snapshot -from .._share_client_helpers import ( - _create_permission_for_share_options, - _format_url, - _from_share_url, - _parse_url -) +from .._share_client_helpers import _create_permission_for_share_options, _format_url, _from_share_url, _parse_url from .._shared.policies_async import ExponentialRetry from .._shared.base_client import parse_query, StorageAccountHostsMixin from .._shared.base_client_async import AsyncStorageAccountHostsMixin, AsyncTransportWrapper, parse_connection_str from .._shared.request_handlers import add_metadata_headers, serialize_iso -from .._shared.response_handlers import ( - process_storage_error, - return_headers_and_deserialized, - return_response_headers -) +from .._shared.response_handlers import process_storage_error, return_headers_and_deserialized, return_response_headers from .._serialize import get_access_conditions, get_api_version from ..aio._lease_async import ShareLeaseClient from ._directory_client_async import ShareDirectoryClient @@ -102,50 +86,66 @@ class ShareClient(AsyncStorageAccountHostsMixin, StorageAccountHostsMixin): # t The hostname of the secondary endpoint. :keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024. """ + def __init__( - self, account_url: str, + self, + account_url: str, share_name: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long *, - token_intent: Optional[Literal['backup']] = None, + token_intent: Optional[Literal["backup"]] = None, **kwargs: Any ) -> None: - kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) - loop = kwargs.pop('loop', None) + kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) + loop = kwargs.pop("loop", None) if loop and sys.version_info >= (3, 8): - warnings.warn("The 'loop' parameter was deprecated from asyncio's high-level" - "APIs in Python 3.8 and is no longer supported.", DeprecationWarning) - if hasattr(credential, 'get_token') and not token_intent: + warnings.warn( + "The 'loop' parameter was deprecated from asyncio's high-level" + "APIs in Python 3.8 and is no longer supported.", + DeprecationWarning, + ) + if hasattr(credential, "get_token") and not token_intent: raise ValueError("'token_intent' keyword is required when 'credential' is an AsyncTokenCredential.") parsed_url = _parse_url(account_url, share_name) path_snapshot, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: raise ValueError( - 'You need to provide either an account shared key or SAS token when creating a storage service.') + "You need to provide either an account shared key or SAS token when creating a storage service." + ) self.snapshot = _parse_snapshot(snapshot, path_snapshot) self.share_name = share_name self._query_str, credential = self._format_query_string( - sas_token=sas_token, credential=credential, share_snapshot=self.snapshot) - super(ShareClient, self).__init__( - parsed_url=parsed_url, service='file-share', credential=credential, **kwargs) - self.allow_trailing_dot = kwargs.pop('allow_trailing_dot', None) - self.allow_source_trailing_dot = kwargs.pop('allow_source_trailing_dot', None) + sas_token=sas_token, credential=credential, share_snapshot=self.snapshot + ) + super(ShareClient, self).__init__(parsed_url=parsed_url, service="file-share", credential=credential, **kwargs) + self.allow_trailing_dot = kwargs.pop("allow_trailing_dot", None) + self.allow_source_trailing_dot = kwargs.pop("allow_source_trailing_dot", None) self.file_request_intent = token_intent - self._client = AzureFileStorage(url=self.url, base_url=self.url, pipeline=self._pipeline, - allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, - file_request_intent=self.file_request_intent) + self._client = AzureFileStorage( + url=self.url, + base_url=self.url, + pipeline=self._pipeline, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + file_request_intent=self.file_request_intent, + ) self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] @classmethod def from_share_url( - cls, share_url: str, + cls, + share_url: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long **kwargs: Any ) -> Self: - """ + """Create a ShareClient from a share URL. + :param str share_url: The full URI to the share. :param snapshot: An optional share snapshot on which to operate. This can be the snapshot ID string @@ -183,10 +183,13 @@ def _format_url(self, hostname: str) -> str: @classmethod def from_connection_string( - cls, conn_str: str, + cls, + conn_str: str, share_name: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long **kwargs: Any ) -> Self: """Create ShareClient from a Connection String. @@ -224,11 +227,10 @@ def from_connection_string( :dedent: 8 :caption: Gets the share client from connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, 'file') - if 'secondary_hostname' not in kwargs: - kwargs['secondary_hostname'] = secondary - return cls( - account_url, share_name=share_name, snapshot=snapshot, credential=credential, **kwargs) + account_url, secondary, credential = parse_connection_str(conn_str, credential, "file") + if "secondary_hostname" not in kwargs: + kwargs["secondary_hostname"] = secondary + return cls(account_url, share_name=share_name, snapshot=snapshot, credential=credential, **kwargs) def get_directory_client(self, directory_path: Optional[str] = None) -> ShareDirectoryClient: """Get a client to interact with the specified directory. @@ -241,14 +243,24 @@ def get_directory_client(self, directory_path: Optional[str] = None) -> ShareDir """ _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable=protected-access - policies=self._pipeline._impl_policies # type: ignore [arg-type] # pylint: disable=protected-access + policies=self._pipeline._impl_policies, # type: ignore [arg-type] # pylint: disable=protected-access ) return ShareDirectoryClient( - self.url, share_name=self.share_name, directory_path=directory_path or "", snapshot=self.snapshot, - credential=self.credential, api_version=self.api_version, _hosts=self._hosts, _configuration=self._config, - _pipeline=_pipeline, _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, token_intent=self.file_request_intent) + self.url, + share_name=self.share_name, + directory_path=directory_path or "", + snapshot=self.snapshot, + credential=self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, + ) def get_file_client(self, file_path: str) -> ShareFileClient: """Get a client to interact with the specified file. @@ -261,14 +273,24 @@ def get_file_client(self, file_path: str) -> ShareFileClient: """ _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable=protected-access - policies=self._pipeline._impl_policies # type: ignore [arg-type] # pylint: disable=protected-access + policies=self._pipeline._impl_policies, # type: ignore [arg-type] # pylint: disable=protected-access ) return ShareFileClient( - self.url, share_name=self.share_name, file_path=file_path, snapshot=self.snapshot, - credential=self.credential, api_version=self.api_version, _hosts=self._hosts, _configuration=self._config, - _pipeline=_pipeline, _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, token_intent=self.file_request_intent) + self.url, + share_name=self.share_name, + file_path=file_path, + snapshot=self.snapshot, + credential=self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, + ) @distributed_trace_async async def acquire_lease(self, **kwargs: Any) -> ShareLeaseClient: @@ -297,8 +319,8 @@ async def acquire_lease(self, **kwargs: Any) -> ShareLeaseClient: :returns: A ShareLeaseClient object. :rtype: ~azure.storage.fileshare.ShareLeaseClient """ - kwargs['lease_duration'] = kwargs.pop('lease_duration', -1) - lease_id = kwargs.pop('lease_id', None) + kwargs["lease_duration"] = kwargs.pop("lease_duration", -1) + lease_id = kwargs.pop("lease_id", None) lease = ShareLeaseClient(self, lease_id=lease_id) await lease.acquire(**kwargs) return lease @@ -316,7 +338,7 @@ async def create_share(self, **kwargs: Any) -> Dict[str, Any]: :keyword access_tier: Specifies the access tier of the share. Possible values: 'TransactionOptimized', 'Hot', 'Cool', 'Premium' - :paramtype access_tier: str or ~azure.storage.fileshare.models.ShareAccessTier + :paramtype access_tier: str or ~azure.storage.fileshare.ShareAccessTier .. versionadded:: 12.4.0 @@ -350,38 +372,42 @@ async def create_share(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 12 :caption: Creates a file share. """ - metadata = kwargs.pop('metadata', None) - quota = kwargs.pop('quota', None) - access_tier = kwargs.pop('access_tier', None) - timeout = kwargs.pop('timeout', None) - root_squash = kwargs.pop('root_squash', None) - protocols = kwargs.pop('protocols', None) - paid_bursting_bandwidth_mibps = kwargs.pop('paid_bursting_bandwidth_mibps', None) - paid_bursting_iops = kwargs.pop('paid_bursting_iops', None) - share_provisioned_iops = kwargs.pop('provisioned_iops', None) - share_provisioned_bandwidth_mibps = kwargs.pop('provisioned_bandwidth_mibps', None) - if protocols and protocols not in ['NFS', 'SMB', ShareProtocols.SMB, ShareProtocols.NFS]: + metadata = kwargs.pop("metadata", None) + quota = kwargs.pop("quota", None) + access_tier = kwargs.pop("access_tier", None) + timeout = kwargs.pop("timeout", None) + root_squash = kwargs.pop("root_squash", None) + protocols = kwargs.pop("protocols", None) + paid_bursting_bandwidth_mibps = kwargs.pop("paid_bursting_bandwidth_mibps", None) + paid_bursting_iops = kwargs.pop("paid_bursting_iops", None) + share_provisioned_iops = kwargs.pop("provisioned_iops", None) + share_provisioned_bandwidth_mibps = kwargs.pop("provisioned_bandwidth_mibps", None) + if protocols and protocols not in ["NFS", "SMB", ShareProtocols.SMB, ShareProtocols.NFS]: raise ValueError("The enabled protocol must be set to either SMB or NFS.") - if root_squash and protocols not in ['NFS', ShareProtocols.NFS]: + if root_squash and protocols not in ["NFS", ShareProtocols.NFS]: raise ValueError("The 'root_squash' keyword can only be used on NFS enabled shares.") - headers = kwargs.pop('headers', {}) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], await self._client.share.create( - timeout=timeout, - metadata=metadata, - quota=quota, - access_tier=access_tier, - root_squash=root_squash, - enabled_protocols=protocols, - paid_bursting_max_bandwidth_mibps=paid_bursting_bandwidth_mibps, - paid_bursting_max_iops=paid_bursting_iops, - share_provisioned_iops=share_provisioned_iops, - share_provisioned_bandwidth_mibps=share_provisioned_bandwidth_mibps, - cls=return_response_headers, - headers=headers, - **kwargs)) + return cast( + Dict[str, Any], + await self._client.share.create( + timeout=timeout, + metadata=metadata, + quota=quota, + access_tier=access_tier, + root_squash=root_squash, + enabled_protocols=protocols, + paid_bursting_max_bandwidth_mibps=paid_bursting_bandwidth_mibps, + paid_bursting_max_iops=paid_bursting_iops, + share_provisioned_iops=share_provisioned_iops, + share_provisioned_bandwidth_mibps=share_provisioned_bandwidth_mibps, + cls=return_response_headers, + headers=headers, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -418,23 +444,23 @@ async def create_snapshot(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 16 :caption: Creates a snapshot of the file share. """ - metadata = kwargs.pop('metadata', None) - timeout = kwargs.pop('timeout', None) - headers = kwargs.pop('headers', {}) + metadata = kwargs.pop("metadata", None) + timeout = kwargs.pop("timeout", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], await self._client.share.create_snapshot( - timeout=timeout, - cls=return_response_headers, - headers=headers, - **kwargs)) + return cast( + Dict[str, Any], + await self._client.share.create_snapshot( + timeout=timeout, cls=return_response_headers, headers=headers, **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async async def delete_share( - self, delete_snapshots: Optional[Union[bool, Literal['include', 'include-leased']]] = False, - **kwargs: Any + self, delete_snapshots: Optional[Union[bool, Literal["include", "include-leased"]]] = False, **kwargs: Any ) -> None: """Marks the specified share for deletion. The share is later deleted during garbage collection. @@ -458,6 +484,8 @@ async def delete_share( .. versionadded:: 12.5.0 This keyword argument was introduced in API version '2020-08-04'. + :returns: None + :rtype: None .. admonition:: Example: @@ -468,15 +496,15 @@ async def delete_share( :dedent: 16 :caption: Deletes the share and any snapshots. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) delete_include = None if isinstance(delete_snapshots, bool) and delete_snapshots: delete_include = DeleteSnapshotsOptionType.INCLUDE else: - if delete_snapshots == 'include': + if delete_snapshots == "include": delete_include = DeleteSnapshotsOptionType.INCLUDE - elif delete_snapshots == 'include-leased': + elif delete_snapshots == "include-leased": delete_include = DeleteSnapshotsOptionType.INCLUDE_LEASED try: await self._client.share.delete( @@ -484,7 +512,8 @@ async def delete_share( sharesnapshot=self.snapshot, delete_snapshots=delete_include, lease_access_conditions=access_conditions, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) @@ -520,15 +549,19 @@ async def get_share_properties(self, **kwargs: Any) -> "ShareProperties": :dedent: 16 :caption: Gets the share properties. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - props = cast("ShareProperties", await self._client.share.get_properties( - timeout=timeout, - sharesnapshot=self.snapshot, - cls=deserialize_share_properties, - lease_access_conditions=access_conditions, - **kwargs)) + props = cast( + "ShareProperties", + await self._client.share.get_properties( + timeout=timeout, + sharesnapshot=self.snapshot, + cls=deserialize_share_properties, + lease_access_conditions=access_conditions, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) props.name = self.share_name @@ -568,16 +601,20 @@ async def set_share_quota(self, quota: int, **kwargs: Any) -> Dict[str, Any]: :dedent: 16 :caption: Sets the share quota. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - return cast(Dict[str, Any], await self._client.share.set_properties( - timeout=timeout, - quota=quota, - access_tier=None, - cls=return_response_headers, - lease_access_conditions=access_conditions, - **kwargs)) + return cast( + Dict[str, Any], + await self._client.share.set_properties( + timeout=timeout, + quota=quota, + access_tier=None, + cls=return_response_headers, + lease_access_conditions=access_conditions, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -590,7 +627,7 @@ async def set_share_properties(self, **kwargs: Any) -> Dict[str, Any]: :keyword access_tier: Specifies the access tier of the share. Possible values: 'TransactionOptimized', 'Hot', 'Cool', 'Premium' - :paramtype access_tier: str or ~azure.storage.fileshare.models.ShareAccessTier + :paramtype access_tier: str or ~azure.storage.fileshare.ShareAccessTier :keyword int quota: Specifies the maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5TB. @@ -624,30 +661,34 @@ async def set_share_properties(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 16 :caption: Sets the share properties. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) - access_tier = kwargs.pop('access_tier', None) - quota = kwargs.pop('quota', None) - root_squash = kwargs.pop('root_squash', None) - paid_bursting_bandwidth_mibps = kwargs.pop('paid_bursting_bandwidth_mibps', None) - paid_bursting_iops = kwargs.pop('paid_bursting_iops', None) - share_provisioned_iops = kwargs.pop('provisioned_iops', None) - share_provisioned_bandwidth_mibps = kwargs.pop('provisioned_bandwidth_mibps', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) + access_tier = kwargs.pop("access_tier", None) + quota = kwargs.pop("quota", None) + root_squash = kwargs.pop("root_squash", None) + paid_bursting_bandwidth_mibps = kwargs.pop("paid_bursting_bandwidth_mibps", None) + paid_bursting_iops = kwargs.pop("paid_bursting_iops", None) + share_provisioned_iops = kwargs.pop("provisioned_iops", None) + share_provisioned_bandwidth_mibps = kwargs.pop("provisioned_bandwidth_mibps", None) if all(parameter is None for parameter in [access_tier, quota, root_squash]): raise ValueError("set_share_properties should be called with at least one parameter.") try: - return cast(Dict[str, Any], await self._client.share.set_properties( - timeout=timeout, - quota=quota, - access_tier=access_tier, - root_squash=root_squash, - lease_access_conditions=access_conditions, - paid_bursting_max_bandwidth_mibps=paid_bursting_bandwidth_mibps, - paid_bursting_max_iops=paid_bursting_iops, - share_provisioned_iops=share_provisioned_iops, - share_provisioned_bandwidth_mibps=share_provisioned_bandwidth_mibps, - cls=return_response_headers, - **kwargs)) + return cast( + Dict[str, Any], + await self._client.share.set_properties( + timeout=timeout, + quota=quota, + access_tier=access_tier, + root_squash=root_squash, + lease_access_conditions=access_conditions, + paid_bursting_max_bandwidth_mibps=paid_bursting_bandwidth_mibps, + paid_bursting_max_iops=paid_bursting_iops, + share_provisioned_iops=share_provisioned_iops, + share_provisioned_bandwidth_mibps=share_provisioned_bandwidth_mibps, + cls=return_response_headers, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -688,17 +729,21 @@ async def set_share_metadata(self, metadata: Dict[str, str], **kwargs: Any) -> D :dedent: 16 :caption: Sets the share metadata. """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) - headers = kwargs.pop('headers', {}) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) + headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) try: - return cast(Dict[str, Any], await self._client.share.set_metadata( - timeout=timeout, - cls=return_response_headers, - headers=headers, - lease_access_conditions=access_conditions, - **kwargs)) + return cast( + Dict[str, Any], + await self._client.share.set_metadata( + timeout=timeout, + cls=return_response_headers, + headers=headers, + lease_access_conditions=access_conditions, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -724,25 +769,22 @@ async def get_share_access_policy(self, **kwargs: Any) -> Dict[str, Any]: :returns: Access policy information in a dict. :rtype: dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: response, identifiers = await self._client.share.get_access_policy( timeout=timeout, cls=return_headers_and_deserialized, lease_access_conditions=access_conditions, - **kwargs) + **kwargs + ) except HttpResponseError as error: process_storage_error(error) - return { - 'public_access': response.get('share_public_access'), - 'signed_identifiers': identifiers or [] - } + return {"public_access": response.get("share_public_access"), "signed_identifiers": identifiers or []} @distributed_trace_async async def set_share_access_policy( - self, signed_identifiers: Dict[str, "AccessPolicy"], - **kwargs: Any + self, signed_identifiers: Dict[str, "AccessPolicy"], **kwargs: Any ) -> Dict[str, Any]: """Sets the permissions for the share, or stored access policies that may be used with Shared Access Signatures. The permissions @@ -770,12 +812,13 @@ async def set_share_access_policy( :returns: Share-updated property dict (Etag and last modified). :rtype: dict[str, Any] """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) if len(signed_identifiers) > 5: raise ValueError( - 'Too many access policies provided. The server does not support setting ' - 'more than 5 access policies on a single resource.') + "Too many access policies provided. The server does not support setting " + "more than 5 access policies on a single resource." + ) identifiers = [] for key, value in signed_identifiers.items(): if value: @@ -783,12 +826,16 @@ async def set_share_access_policy( value.expiry = serialize_iso(value.expiry) identifiers.append(SignedIdentifier(id=key, access_policy=value)) try: - return cast(Dict[str, Any], await self._client.share.set_access_policy( - share_acl=identifiers or None, - timeout=timeout, - cls=return_response_headers, - lease_access_conditions=access_conditions, - **kwargs)) + return cast( + Dict[str, Any], + await self._client.share.set_access_policy( + share_acl=identifiers or None, + timeout=timeout, + cls=return_response_headers, + lease_access_conditions=access_conditions, + **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -816,20 +863,23 @@ async def get_share_stats(self, **kwargs: Any) -> int: :return: The approximate size of the data (in bytes) stored on the share. :rtype: int """ - access_conditions = get_access_conditions(kwargs.pop('lease', None)) - timeout = kwargs.pop('timeout', None) + access_conditions = get_access_conditions(kwargs.pop("lease", None)) + timeout = kwargs.pop("timeout", None) try: - stats = cast(ShareStats, await self._client.share.get_statistics( - timeout=timeout, - lease_access_conditions=access_conditions, - **kwargs)) + stats = cast( + ShareStats, + await self._client.share.get_statistics( + timeout=timeout, lease_access_conditions=access_conditions, **kwargs + ), + ) return stats.share_usage_bytes except HttpResponseError as error: process_storage_error(error) @distributed_trace def list_directories_and_files( - self, directory_name: Optional[str] = None, + self, + directory_name: Optional[str] = None, name_starts_with: Optional[str] = None, marker: Optional[str] = None, **kwargs: Any @@ -878,10 +928,11 @@ def list_directories_and_files( :dedent: 16 :caption: List directories and files in the share. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) directory = self.get_directory_client(directory_name) return directory.list_directories_and_files( - name_starts_with=name_starts_with, marker=marker, timeout=timeout, **kwargs) + name_starts_with=name_starts_with, marker=marker, timeout=timeout, **kwargs + ) @distributed_trace_async async def create_permission_for_share(self, file_permission: str, **kwargs: Any) -> Optional[str]: @@ -905,7 +956,7 @@ async def create_permission_for_share(self, file_permission: str, **kwargs: Any) :returns: A file permission key :rtype: str or None """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) options = _create_permission_for_share_options(file_permission, timeout=timeout, **kwargs) try: return cast(Optional[str], await self._client.share.create_permission(**options)) @@ -932,13 +983,14 @@ async def get_permission_for_share(self, permission_key: str, **kwargs: Any) -> :returns: A file permission (a portable SDDL) :rtype: str """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) try: - return cast(str, await self._client.share.get_permission( - file_permission_key=permission_key, - cls=deserialize_permission, - timeout=timeout, - **kwargs)) + return cast( + str, + await self._client.share.get_permission( + file_permission_key=permission_key, cls=deserialize_permission, timeout=timeout, **kwargs + ), + ) except HttpResponseError as error: process_storage_error(error) @@ -968,7 +1020,7 @@ async def create_directory(self, directory_name: str, **kwargs: Any) -> ShareDir :rtype: ~azure.storage.fileshare.aio.ShareDirectoryClient """ directory = self.get_directory_client(directory_name) - kwargs.setdefault('merge_span', True) + kwargs.setdefault("merge_span", True) await directory.create_directory(**kwargs) return directory diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py index bf33ac78d12d..3e545ac4061b 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py @@ -8,10 +8,7 @@ import functools import sys import warnings -from typing import ( - Union, Optional, Any, Dict, List, - TYPE_CHECKING -) +from typing import Union, Optional, Any, Dict, List, TYPE_CHECKING from typing_extensions import Self from azure.core.async_paging import AsyncItemPaged @@ -97,37 +94,48 @@ class ShareServiceClient(AsyncStorageAccountHostsMixin, StorageAccountHostsMixin :dedent: 8 :caption: Create the share service client with url and credential. """ + def __init__( - self, account_url: str, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long + self, + account_url: str, + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long *, - token_intent: Optional[Literal['backup']] = None, - **kwargs: Any + token_intent: Optional[Literal["backup"]] = None, + **kwargs: Any, ) -> None: - kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) - loop = kwargs.pop('loop', None) + kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) + loop = kwargs.pop("loop", None) if loop and sys.version_info >= (3, 8): - warnings.warn("The 'loop' parameter was deprecated from asyncio's high-level" - "APIs in Python 3.8 and is no longer supported.", DeprecationWarning) + warnings.warn( + "The 'loop' parameter was deprecated from asyncio's high-level" + "APIs in Python 3.8 and is no longer supported.", + DeprecationWarning, + ) - if hasattr(credential, 'get_token') and not token_intent: + if hasattr(credential, "get_token") and not token_intent: raise ValueError("'token_intent' keyword is required when 'credential' is an AsyncTokenCredential.") parsed_url = _parse_url(account_url=account_url) _, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: raise ValueError( - 'You need to provide either an account shared key or SAS token when creating a storage service.') + "You need to provide either an account shared key or SAS token when creating a storage service." + ) self._query_str, credential = self._format_query_string(sas_token, credential) - super(ShareServiceClient, self).__init__( - parsed_url, service='file-share', credential=credential, **kwargs) - self.allow_trailing_dot = kwargs.pop('allow_trailing_dot', None) - self.allow_source_trailing_dot = kwargs.pop('allow_source_trailing_dot', None) + super(ShareServiceClient, self).__init__(parsed_url, service="file-share", credential=credential, **kwargs) + self.allow_trailing_dot = kwargs.pop("allow_trailing_dot", None) + self.allow_source_trailing_dot = kwargs.pop("allow_source_trailing_dot", None) self.file_request_intent = token_intent - self._client = AzureFileStorage(url=self.url, base_url=self.url, pipeline=self._pipeline, - allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, - file_request_intent=self.file_request_intent) + self._client = AzureFileStorage( + url=self.url, + base_url=self.url, + pipeline=self._pipeline, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + file_request_intent=self.file_request_intent, + ) self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] def _format_url(self, hostname: str) -> str: @@ -142,9 +150,12 @@ def _format_url(self, hostname: str) -> str: @classmethod def from_connection_string( - cls, conn_str: str, - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"]] = None, # pylint: disable=line-too-long - **kwargs: Any + cls, + conn_str: str, + credential: Optional[ + Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + ] = None, # pylint: disable=line-too-long + **kwargs: Any, ) -> Self: """Create ShareServiceClient from a Connection String. @@ -176,9 +187,9 @@ def from_connection_string( :dedent: 8 :caption: Create the share service client with connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, 'file') - if 'secondary_hostname' not in kwargs: - kwargs['secondary_hostname'] = secondary + account_url, secondary, credential = parse_connection_str(conn_str, credential, "file") + if "secondary_hostname" not in kwargs: + kwargs["secondary_hostname"] = secondary return cls(account_url, credential=credential, **kwargs) @distributed_trace_async @@ -205,7 +216,7 @@ async def get_service_properties(self, **kwargs: Any) -> Dict[str, Any]: :dedent: 12 :caption: Get file share service properties. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) try: service_props = await self._client.service.get_properties(timeout=timeout, **kwargs) return service_properties_deserialize(service_props) @@ -214,11 +225,12 @@ async def get_service_properties(self, **kwargs: Any) -> Dict[str, Any]: @distributed_trace_async async def set_service_properties( - self, hour_metrics: Optional["Metrics"] = None, + self, + hour_metrics: Optional["Metrics"] = None, minute_metrics: Optional["Metrics"] = None, cors: Optional[List[CorsRule]] = None, protocol: Optional["ShareProtocolSettings"] = None, - **kwargs: Any + **kwargs: Any, ) -> None: """Sets the properties of a storage account's File Share service, including Azure Storage Analytics. If an element (e.g. hour_metrics) is left as None, the @@ -257,12 +269,12 @@ async def set_service_properties( :dedent: 8 :caption: Sets file share service properties. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) props = StorageServiceProperties( hour_metrics=hour_metrics, minute_metrics=minute_metrics, cors=CorsRule._to_generated(cors), # pylint: disable=protected-access - protocol=protocol + protocol=protocol, ) try: await self._client.service.set_properties(props, timeout=timeout, **kwargs) @@ -271,10 +283,11 @@ async def set_service_properties( @distributed_trace def list_shares( - self, name_starts_with: Optional[str] = None, + self, + name_starts_with: Optional[str] = None, include_metadata: Optional[bool] = False, include_snapshots: Optional[bool] = False, - **kwargs: Any + **kwargs: Any, ) -> AsyncItemPaged[ShareProperties]: """Returns auto-paging iterable of dict-like ShareProperties under the specified account. The generator will lazily follow the continuation tokens returned by @@ -308,25 +321,26 @@ def list_shares( :dedent: 16 :caption: List shares in the file share service. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) include = [] - include_deleted = kwargs.pop('include_deleted', None) + include_deleted = kwargs.pop("include_deleted", None) if include_deleted: include.append("deleted") if include_metadata: - include.append('metadata') + include.append("metadata") if include_snapshots: - include.append('snapshots') + include.append("snapshots") - results_per_page = kwargs.pop('results_per_page', None) + results_per_page = kwargs.pop("results_per_page", None) command = functools.partial( - self._client.service.list_shares_segment, - include=include, - timeout=timeout, - **kwargs) + self._client.service.list_shares_segment, include=include, timeout=timeout, **kwargs + ) return AsyncItemPaged( - command, prefix=name_starts_with, results_per_page=results_per_page, - page_iterator_class=SharePropertiesPaged) + command, + prefix=name_starts_with, + results_per_page=results_per_page, + page_iterator_class=SharePropertiesPaged, + ) @distributed_trace_async async def create_share(self, share_name: str, **kwargs: Any) -> ShareClient: @@ -360,28 +374,26 @@ async def create_share(self, share_name: str, **kwargs: Any) -> ShareClient: :dedent: 12 :caption: Create a share in the file share service. """ - metadata = kwargs.pop('metadata', None) - quota = kwargs.pop('quota', None) - timeout = kwargs.pop('timeout', None) - provisioned_iops = kwargs.pop('provisioned_iops', None) - provisioned_bandwidth_mibps = kwargs.pop('provisioned_bandwidth_mibps', None) + metadata = kwargs.pop("metadata", None) + quota = kwargs.pop("quota", None) + timeout = kwargs.pop("timeout", None) + provisioned_iops = kwargs.pop("provisioned_iops", None) + provisioned_bandwidth_mibps = kwargs.pop("provisioned_bandwidth_mibps", None) share = self.get_share_client(share_name) - kwargs.setdefault('merge_span', True) + kwargs.setdefault("merge_span", True) await share.create_share( metadata=metadata, quota=quota, timeout=timeout, provisioned_iops=provisioned_iops, provisioned_bandwidth_mibps=provisioned_bandwidth_mibps, - **kwargs + **kwargs, ) return share @distributed_trace_async async def delete_share( - self, share_name: Union[ShareProperties, str], - delete_snapshots: Optional[bool] = False, - **kwargs: Any + self, share_name: Union[ShareProperties, str], delete_snapshots: Optional[bool] = False, **kwargs: Any ) -> None: """Marks the specified share for deletion. The share is later deleted during garbage collection. @@ -398,6 +410,7 @@ async def delete_share( This value is not tracked or validated on the client. To configure client-side network timesouts see `here `__. + :return: None :rtype: None .. admonition:: Example: @@ -409,11 +422,10 @@ async def delete_share( :dedent: 16 :caption: Delete a share in the file share service. """ - timeout = kwargs.pop('timeout', None) + timeout = kwargs.pop("timeout", None) share = self.get_share_client(share_name) - kwargs.setdefault('merge_span', True) - await share.delete_share( - delete_snapshots=delete_snapshots, timeout=timeout, **kwargs) + kwargs.setdefault("merge_span", True) + await share.delete_share(delete_snapshots=delete_snapshots, timeout=timeout, **kwargs) @distributed_trace_async async def undelete_share(self, deleted_share_name: str, deleted_share_version: str, **kwargs: Any) -> ShareClient: @@ -441,16 +453,18 @@ async def undelete_share(self, deleted_share_name: str, deleted_share_version: s """ share = self.get_share_client(deleted_share_name) try: - await share._client.share.restore(deleted_share_name=deleted_share_name, # pylint: disable=protected-access - deleted_share_version=deleted_share_version, - timeout=kwargs.pop('timeout', None), **kwargs) + await share._client.share.restore( + deleted_share_name=deleted_share_name, # pylint: disable=protected-access + deleted_share_version=deleted_share_version, + timeout=kwargs.pop("timeout", None), + **kwargs, + ) return share except HttpResponseError as error: process_storage_error(error) def get_share_client( - self, share: Union[ShareProperties, str], - snapshot: Optional[Union[Dict[str, Any], str]] = None + self, share: Union[ShareProperties, str], snapshot: Optional[Union[Dict[str, Any], str]] = None ) -> ShareClient: """Get a client to interact with the specified share. The share need not already exist. @@ -481,10 +495,19 @@ def get_share_client( _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access - policies=self._pipeline._impl_policies # type: ignore [arg-type] # pylint: disable = protected-access + policies=self._pipeline._impl_policies, # type: ignore [arg-type] # pylint: disable = protected-access ) return ShareClient( - self.url, share_name=share_name, snapshot=snapshot, credential=self.credential, - api_version=self.api_version, _hosts=self._hosts, _configuration=self._config, - _pipeline=_pipeline, _location_mode=self._location_mode, allow_trailing_dot=self.allow_trailing_dot, - allow_source_trailing_dot=self.allow_source_trailing_dot, token_intent=self.file_request_intent) + self.url, + share_name=share_name, + snapshot=snapshot, + credential=self.credential, + api_version=self.api_version, + _hosts=self._hosts, + _configuration=self._config, + _pipeline=_pipeline, + _location_mode=self._location_mode, + allow_trailing_dot=self.allow_trailing_dot, + allow_source_trailing_dot=self.allow_source_trailing_dot, + token_intent=self.file_request_intent, + ) 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..72ca101ceb5b 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 @@ -32,6 +32,7 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") + class FileAuthSamples(object): connection_string = os.getenv("STORAGE_CONNECTION_STRING") @@ -42,55 +43,73 @@ class FileAuthSamples(object): def authentication_connection_string(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: authentication_connection_string") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: authentication_connection_string" + ) sys.exit(1) # Instantiate the ShareServiceClient from a connection string # [START create_share_service_client_from_conn_string] from azure.storage.fileshare import ShareServiceClient + share_service_client = ShareServiceClient.from_connection_string(self.connection_string) # [END create_share_service_client_from_conn_string] def authentication_shared_access_key(self): if self.account_url is None: - print("Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + '\n' + - "Test: authentication_shared_access_key") + print( + "Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + + "\n" + + "Test: authentication_shared_access_key" + ) sys.exit(1) if self.access_key is None: - print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + - "Test: authentication_shared_access_key") + print( + "Missing required environment variable: STORAGE_ACCOUNT_KEY." + + "\n" + + "Test: authentication_shared_access_key" + ) sys.exit(1) # Instantiate a ShareServiceClient using a shared access key # [START create_share_service_client] from azure.storage.fileshare import ShareServiceClient - share_service_client = ShareServiceClient( - account_url=self.account_url, - credential=self.access_key - ) + + share_service_client = ShareServiceClient(account_url=self.account_url, credential=self.access_key) # [END create_share_service_client] def authentication_shared_access_signature(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: authentication_shared_access_signature") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: authentication_shared_access_signature" + ) sys.exit(1) if self.account_name is None: - print("Missing required environment variable: STORAGE_ACCOUNT_NAME." + '\n' + - "Test: authentication_shared_access_signature") + print( + "Missing required environment variable: STORAGE_ACCOUNT_NAME." + + "\n" + + "Test: authentication_shared_access_signature" + ) sys.exit(1) if self.access_key is None: - print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + - "Test: authentication_shared_access_signature") + print( + "Missing required environment variable: STORAGE_ACCOUNT_KEY." + + "\n" + + "Test: authentication_shared_access_signature" + ) sys.exit(1) # Instantiate a ShareServiceClient using a connection string # [START generate_sas_token] from azure.storage.fileshare import ShareServiceClient + share_service_client = ShareServiceClient.from_connection_string(self.connection_string) # Create a SAS token to use to authenticate a new client @@ -101,14 +120,17 @@ def authentication_shared_access_signature(self): self.access_key, resource_types=ResourceTypes(service=True), permission=AccountSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1) + expiry=datetime.utcnow() + timedelta(hours=1), ) # [END generate_sas_token] def authentication_default_azure_credential(self): if self.account_url is None: - print("Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + '\n' + - "Test: authentication_default_azure_credential") + print( + "Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + + "\n" + + "Test: authentication_default_azure_credential" + ) sys.exit(1) # [START file_share_oauth] @@ -116,35 +138,36 @@ def authentication_default_azure_credential(self): # DefaultAzureCredential attempts a chained set of authentication methods. # See documentation here: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity from azure.identity import DefaultAzureCredential + default_credential = DefaultAzureCredential() # Instantiate a ShareServiceClient using a token credential and token_intent from azure.storage.fileshare import ShareServiceClient + share_service_client = ShareServiceClient( account_url=self.account_url, credential=default_credential, # When using a token credential, you MUST also specify a token_intent - token_intent='backup' + token_intent="backup", ) # Only Directory and File operations, and a certain few Share operations, are currently supported for OAuth. # Create a ShareFileClient from the ShareServiceClient. share_client = share_service_client.get_share_client("myshare") share_client.create_share() - share_client.create_directory('mydirectory') - directory_client = share_client.get_directory_client('mydirectory') + share_client.create_directory("mydirectory") + directory_client = share_client.get_directory_client("mydirectory") with open(DEST_FILE, "wb") as data: - directory_client.upload_file('myfile', data=data) - share_file_client = directory_client.get_file_client('myfile') + directory_client.upload_file("myfile", data=data) + share_file_client = directory_client.get_file_client("myfile") properties = share_file_client.get_file_properties() # [END file_share_oauth] -if __name__ == '__main__': +if __name__ == "__main__": sample = FileAuthSamples() sample.authentication_connection_string() 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_authentication_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_authentication_async.py index 37cfb1546302..021cff228797 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_authentication_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_authentication_async.py @@ -33,6 +33,7 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") + class FileAuthSamplesAsync(object): connection_string = os.getenv("STORAGE_CONNECTION_STRING") @@ -43,54 +44,72 @@ class FileAuthSamplesAsync(object): async def authentication_connection_string_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: authentication_connection_string_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: authentication_connection_string_async" + ) sys.exit(1) # Instantiate the ShareServiceClient from a connection string # [START create_share_service_client_from_conn_string] from azure.storage.fileshare.aio import ShareServiceClient + file_service = ShareServiceClient.from_connection_string(self.connection_string) # [END create_share_service_client_from_conn_string] async def authentication_shared_access_key_async(self): if self.account_url is None: - print("Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + '\n' + - "Test: authentication_shared_access_key_async") + print( + "Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + + "\n" + + "Test: authentication_shared_access_key_async" + ) sys.exit(1) if self.access_key is None: - print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + - "Test: authentication_shared_access_key_async") + print( + "Missing required environment variable: STORAGE_ACCOUNT_KEY." + + "\n" + + "Test: authentication_shared_access_key_async" + ) sys.exit(1) # Instantiate a ShareServiceClient using a shared access key # [START create_share_service_client] from azure.storage.fileshare.aio import ShareServiceClient - share_service_client = ShareServiceClient( - account_url=self.account_url, - credential=self.access_key - ) + + share_service_client = ShareServiceClient(account_url=self.account_url, credential=self.access_key) # [END create_share_service_client] async def authentication_shared_access_signature_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: authentication_shared_access_signature_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: authentication_shared_access_signature_async" + ) sys.exit(1) if self.account_name is None: - print("Missing required environment variable: STORAGE_ACCOUNT_NAME." + '\n' + - "Test: authentication_shared_access_signature_async") + print( + "Missing required environment variable: STORAGE_ACCOUNT_NAME." + + "\n" + + "Test: authentication_shared_access_signature_async" + ) sys.exit(1) if self.access_key is None: - print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + - "Test: authentication_shared_access_signature_async") + print( + "Missing required environment variable: STORAGE_ACCOUNT_KEY." + + "\n" + + "Test: authentication_shared_access_signature_async" + ) sys.exit(1) # Instantiate a ShareServiceClient using a connection string from azure.storage.fileshare.aio import ShareServiceClient + share_service_client = ShareServiceClient.from_connection_string(self.connection_string) # Create a SAS token to use to authenticate a new client @@ -101,13 +120,16 @@ async def authentication_shared_access_signature_async(self): self.access_key, resource_types=ResourceTypes(service=True), permission=AccountSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1) + expiry=datetime.utcnow() + timedelta(hours=1), ) async def authentication_default_azure_credential_async(self): if self.account_url is None: - print("Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + '\n' + - "Test: authentication_default_azure_credential_async") + print( + "Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + + "\n" + + "Test: authentication_default_azure_credential_async" + ) sys.exit(1) # [START file_share_oauth] @@ -115,25 +137,27 @@ async def authentication_default_azure_credential_async(self): # DefaultAzureCredential attempts a chained set of authentication methods. # See documentation here: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity from azure.identity.aio import DefaultAzureCredential + default_credential = DefaultAzureCredential() # Instantiate a ShareServiceClient using a token credential and token_intent from azure.storage.fileshare.aio import ShareServiceClient + share_service_client = ShareServiceClient( account_url=self.account_url, credential=default_credential, # When using a token credential, you MUST also specify a token_intent - token_intent='backup' + token_intent="backup", ) # Only Directory and File operations, and a certain few Share operations, are currently supported for OAuth. # Create a ShareFileClient from the ShareServiceClient. share_client = share_service_client.get_share_client("myshareasync") await share_client.create_share() - await share_client.create_directory('mydirectory') - directory_client = share_client.get_directory_client('mydirectory') + await share_client.create_directory("mydirectory") + directory_client = share_client.get_directory_client("mydirectory") with open(DEST_FILE, "wb") as data: - await directory_client.upload_file('myfile', data=data) - share_file_client = directory_client.get_file_client('myfile') + await directory_client.upload_file("myfile", data=data) + share_file_client = directory_client.get_file_client("myfile") properties = await share_file_client.get_file_properties() # [END file_share_oauth] @@ -146,5 +170,6 @@ async def main(): await sample.authentication_shared_access_signature_async() await sample.authentication_default_azure_credential_async() -if __name__ == '__main__': + +if __name__ == "__main__": asyncio.run(main()) 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..8da3dda6d560 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 @@ -36,12 +36,16 @@ class FileSamples(object): def simple_file_operations(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: simple_file_operations") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: simple_file_operations" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "filesamples1") # Create the share @@ -82,12 +86,14 @@ def simple_file_operations(self): def copy_file_from_url(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: copy_file_from_url") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + "\n" + "Test: copy_file_from_url" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "filesamples2") # Create the share @@ -104,9 +110,7 @@ def copy_file_from_url(self): # Build the url from which to copy the file source_url = "https://{}.file.core.windows.net/{}/{}".format( - self.account_name, - "filesamples2", - "sourcefile" + self.account_name, "filesamples2", "sourcefile" ) # Copy the sample source file from the url to the destination file @@ -119,12 +123,14 @@ def copy_file_from_url(self): def acquire_file_lease(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: acquire_file_lease") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + "\n" + "Test: acquire_file_lease" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "filesamples3") # Create the share @@ -137,7 +143,7 @@ def acquire_file_lease(self): # [START acquire_and_release_lease_on_file] source_file.create_file(1024) lease = source_file.acquire_lease() - source_file.upload_file(b'hello world', lease=lease) + source_file.upload_file(b"hello world", lease=lease) lease.release() # [END acquire_and_release_lease_on_file] @@ -147,10 +153,8 @@ def acquire_file_lease(self): share.delete_share() -if __name__ == '__main__': +if __name__ == "__main__": sample = FileSamples() 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_client_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_client_async.py index 6b78b23818ea..e7388945dd49 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_client_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_client_async.py @@ -38,12 +38,16 @@ class FileSamplesAsync(object): async def simple_file_operations_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: simple_file_operations_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: simple_file_operations_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "filesamples1async") # Create the share @@ -85,12 +89,16 @@ async def simple_file_operations_async(self): async def copy_file_from_url_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: copy_file_from_url_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: copy_file_from_url_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "filesamples2async") # Create the share @@ -108,9 +116,7 @@ async def copy_file_from_url_async(self): # Build the url from which to copy the file source_url = "https://{}.file.core.windows.net/{}/{}".format( - self.account_name, - 'filesamples2async', - 'sourcefile' + self.account_name, "filesamples2async", "sourcefile" ) # Copy the sample source file from the url to the destination file @@ -127,5 +133,6 @@ async def main(): await sample.simple_file_operations_async() await sample.copy_file_from_url_async() -if __name__ == '__main__': + +if __name__ == "__main__": asyncio.run(main()) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_directory.py b/sdk/storage/azure-storage-file-share/samples/file_samples_directory.py index 756218476608..05e64639acd2 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_directory.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_directory.py @@ -30,16 +30,20 @@ class DirectorySamples(object): - connection_string = os.getenv('STORAGE_CONNECTION_STRING') + connection_string = os.getenv("STORAGE_CONNECTION_STRING") def create_directory_and_file(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_directory_and_file") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: create_directory_and_file" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "directorysamples1") # Create the share @@ -74,12 +78,16 @@ def create_directory_and_file(self): def create_subdirectory_and_file(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_subdirectory_and_file") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: create_subdirectory_and_file" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "directorysamples2") # Create the share @@ -123,12 +131,16 @@ def create_subdirectory_and_file(self): def get_subdirectory_client(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: get_subdirectory_client") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: get_subdirectory_client" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "directorysamples3") # Create the share @@ -149,7 +161,7 @@ def get_subdirectory_client(self): share.delete_share() -if __name__ == '__main__': +if __name__ == "__main__": sample = DirectorySamples() sample.create_directory_and_file() sample.create_subdirectory_and_file() diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_directory_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_directory_async.py index 7455d243f40e..989f7a06761e 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_directory_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_directory_async.py @@ -31,16 +31,20 @@ class DirectorySamplesAsync(object): - connection_string = os.getenv('STORAGE_CONNECTION_STRING') + connection_string = os.getenv("STORAGE_CONNECTION_STRING") async def create_directory_and_file_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_directory_and_file_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: create_directory_and_file_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "directorysamples1async") # Create the share @@ -76,12 +80,16 @@ async def create_directory_and_file_async(self): async def create_subdirectory_and_file_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_subdirectory_and_file_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: create_subdirectory_and_file_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "directorysamples2async") # Create the share @@ -128,12 +136,16 @@ async def create_subdirectory_and_file_async(self): async def get_subdirectory_client_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: get_subdirectory_client_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: get_subdirectory_client_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "directorysamples3async") # Create the share @@ -161,5 +173,6 @@ async def main(): await sample.create_subdirectory_and_file_async() await sample.get_subdirectory_client_async() -if __name__ == '__main__': + +if __name__ == "__main__": asyncio.run(main()) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world.py b/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world.py index c8835ddf4a25..2c5cb80accb5 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world.py @@ -30,26 +30,32 @@ class HelloWorldSamples(object): - connection_string = os.getenv('STORAGE_CONNECTION_STRING') + connection_string = os.getenv("STORAGE_CONNECTION_STRING") def create_client_with_connection_string(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_client_with_connection_string") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: create_client_with_connection_string" + ) sys.exit(1) # Instantiate the ShareServiceClient from a connection string from azure.storage.fileshare import ShareServiceClient + file_service = ShareServiceClient.from_connection_string(self.connection_string) def create_file_share(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_file_share") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + "\n" + "Test: create_file_share" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, share_name="helloworld1") # Create the share @@ -66,12 +72,16 @@ def create_file_share(self): def upload_a_file_to_share(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: upload_a_file_to_share") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: upload_a_file_to_share" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, share_name="helloworld2") # Create the share @@ -81,10 +91,10 @@ def upload_a_file_to_share(self): # Instantiate the ShareFileClient from a connection string # [START create_file_client] from azure.storage.fileshare import ShareFileClient + file = ShareFileClient.from_connection_string( - self.connection_string, - share_name="helloworld2", - file_path="myfile") + self.connection_string, share_name="helloworld2", file_path="myfile" + ) # [END create_file_client] # Upload a file @@ -96,7 +106,7 @@ def upload_a_file_to_share(self): share.delete_share() -if __name__ == '__main__': +if __name__ == "__main__": sample = HelloWorldSamples() sample.create_client_with_connection_string() sample.create_file_share() diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world_async.py index 7da6919838b9..41ebb787fa96 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world_async.py @@ -31,27 +31,34 @@ class HelloWorldSamplesAsync(object): - connection_string = os.getenv('STORAGE_CONNECTION_STRING') + connection_string = os.getenv("STORAGE_CONNECTION_STRING") async def create_client_with_connection_string_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_client_with_connection_string_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: create_client_with_connection_string_async" + ) sys.exit(1) - # Instantiate the ShareServiceClient from a connection string from azure.storage.fileshare.aio import ShareServiceClient + file_service = ShareServiceClient.from_connection_string(self.connection_string) async def create_file_share_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_file_share_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: create_file_share_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, share_name="helloworld1async") # Create the share @@ -69,13 +76,17 @@ async def create_file_share_async(self): async def upload_a_file_to_share_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: upload_a_file_to_share_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: upload_a_file_to_share_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, share_name='helloworld2async') + + share = ShareClient.from_connection_string(self.connection_string, share_name="helloworld2async") # Create the share async with share: @@ -85,10 +96,10 @@ async def upload_a_file_to_share_async(self): # Instantiate the ShareFileClient from a connection string # [START create_file_client] from azure.storage.fileshare.aio import ShareFileClient + file = ShareFileClient.from_connection_string( - self.connection_string, - share_name='helloworld2async', - file_path="myfile") + self.connection_string, share_name="helloworld2async", file_path="myfile" + ) # [END create_file_client] # Upload a file @@ -107,5 +118,6 @@ async def main(): await sample.create_file_share_async() await sample.upload_a_file_to_share_async() -if __name__ == '__main__': + +if __name__ == "__main__": asyncio.run(main()) 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..1675db6bb42c 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 @@ -31,16 +31,20 @@ class FileShareServiceSamples(object): - connection_string = os.getenv('STORAGE_CONNECTION_STRING') + connection_string = os.getenv("STORAGE_CONNECTION_STRING") def file_service_properties(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: file_service_properties") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: file_service_properties" + ) sys.exit(1) # Instantiate the ShareServiceClient from a connection string from azure.storage.fileshare import ShareServiceClient + file_service = ShareServiceClient.from_connection_string(self.connection_string) # [START set_service_properties] @@ -49,13 +53,14 @@ def file_service_properties(self): # Create metrics for requests statistics hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) - minute_metrics = Metrics(enabled=True, include_apis=True, - retention_policy=RetentionPolicy(enabled=True, days=5)) + minute_metrics = Metrics( + enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) + ) # Create CORS rules - cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) - allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] - allowed_methods = ['GET', 'PUT'] + cors_rule1 = CorsRule(["www.xyz.com"], ["GET"]) + allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] + allowed_methods = ["GET", "PUT"] max_age_in_seconds = 500 exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] @@ -64,7 +69,8 @@ def file_service_properties(self): allowed_methods, max_age_in_seconds=max_age_in_seconds, exposed_headers=exposed_headers, - allowed_headers=allowed_headers) + allowed_headers=allowed_headers, + ) cors = [cors_rule1, cors_rule2] @@ -78,12 +84,16 @@ def file_service_properties(self): def list_shares_in_service(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: list_shares_in_service") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: list_shares_in_service" + ) sys.exit(1) # Instantiate the ShareServiceClient from a connection string from azure.storage.fileshare import ShareServiceClient + file_service = ShareServiceClient.from_connection_string(self.connection_string) # [START fsc_create_shares] @@ -106,12 +116,12 @@ def list_shares_in_service(self): def get_share_client(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: get_share_client") + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + "\n" + "Test: get_share_client") sys.exit(1) # [START get_share_client] from azure.storage.fileshare import ShareServiceClient + file_service = ShareServiceClient.from_connection_string(self.connection_string) # Get a share client to interact with a specific share @@ -119,9 +129,8 @@ def get_share_client(self): # [END get_share_client] -if __name__ == '__main__': +if __name__ == "__main__": sample = FileShareServiceSamples() sample.file_service_properties() sample.list_shares_in_service() sample.get_share_client() - diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_service_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_service_async.py index 1658aa158b23..2c1d155577d2 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_service_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_service_async.py @@ -32,16 +32,20 @@ class FileShareServiceSamplesAsync(object): - connection_string = os.getenv('STORAGE_CONNECTION_STRING') + connection_string = os.getenv("STORAGE_CONNECTION_STRING") async def file_service_properties_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: file_service_properties_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: file_service_properties_async" + ) sys.exit(1) # Instantiate the ShareServiceClient from a connection string from azure.storage.fileshare.aio import ShareServiceClient + file_service = ShareServiceClient.from_connection_string(self.connection_string) # [START set_service_properties] @@ -50,13 +54,14 @@ async def file_service_properties_async(self): # Create metrics for requests statistics hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) - minute_metrics = Metrics(enabled=True, include_apis=True, - retention_policy=RetentionPolicy(enabled=True, days=5)) + minute_metrics = Metrics( + enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) + ) # Create CORS rules - cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) - allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] - allowed_methods = ['GET', 'PUT'] + cors_rule1 = CorsRule(["www.xyz.com"], ["GET"]) + allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] + allowed_methods = ["GET", "PUT"] max_age_in_seconds = 500 exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] @@ -65,14 +70,15 @@ async def file_service_properties_async(self): allowed_methods, max_age_in_seconds=max_age_in_seconds, exposed_headers=exposed_headers, - allowed_headers=allowed_headers) + allowed_headers=allowed_headers, + ) cors = [cors_rule1, cors_rule2] async with file_service: # Set the service properties await file_service.set_service_properties(hour_metrics, minute_metrics, cors) - # [END set_service_properties] + # [END set_service_properties] # [START get_service_properties] properties = await file_service.get_service_properties() @@ -80,12 +86,16 @@ async def file_service_properties_async(self): async def list_shares_in_service_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: list_shares_in_service_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: list_shares_in_service_async" + ) sys.exit(1) # Instantiate the ShareServiceClient from a connection string from azure.storage.fileshare.aio import ShareServiceClient + file_service = ShareServiceClient.from_connection_string(self.connection_string) async with file_service: @@ -111,12 +121,16 @@ async def list_shares_in_service_async(self): async def get_share_client_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: get_share_client_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: get_share_client_async" + ) sys.exit(1) # [START get_share_client] from azure.storage.fileshare.aio import ShareServiceClient + file_service = ShareServiceClient.from_connection_string(self.connection_string) # Get a share client to interact with a specific share @@ -130,5 +144,6 @@ async def main(): await sample.list_shares_in_service_async() await sample.get_share_client_async() -if __name__ == '__main__': + +if __name__ == "__main__": asyncio.run(main()) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_share.py b/sdk/storage/azure-storage-file-share/samples/file_samples_share.py index 21547765cef6..5beb9a3fb812 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_share.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_share.py @@ -33,16 +33,20 @@ class ShareSamples(object): - connection_string = os.getenv('STORAGE_CONNECTION_STRING') + connection_string = os.getenv("STORAGE_CONNECTION_STRING") def create_share_snapshot(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_share_snapshot") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: create_share_snapshot" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "sharesamples1") # [START create_share] @@ -60,12 +64,16 @@ def create_share_snapshot(self): def set_share_quota_and_metadata(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: set_share_quota_and_metadata") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: set_share_quota_and_metadata" + ) sys.exit(1) # [START create_share_client_from_conn_string] from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "sharesamples2") # [END create_share_client_from_conn_string] @@ -79,7 +87,7 @@ def set_share_quota_and_metadata(self): # [END set_share_quota] # [START set_share_metadata] - data = {'category': 'test'} + data = {"category": "test"} share.set_share_metadata(metadata=data) # [END set_share_metadata] @@ -92,11 +100,15 @@ def set_share_quota_and_metadata(self): def set_share_properties(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: set_share_properties") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: set_share_properties" + ) sys.exit(1) from azure.storage.fileshare import ShareClient + share1 = ShareClient.from_connection_string(self.connection_string, "sharesamples3a") share2 = ShareClient.from_connection_string(self.connection_string, "sharesamples3b") @@ -127,12 +139,16 @@ def set_share_properties(self): def list_directories_and_files(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: list_directories_and_files") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: list_directories_and_files" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "sharesamples4") # Create the share @@ -157,12 +173,16 @@ def list_directories_and_files(self): def get_directory_or_file_client(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: get_directory_or_file_client") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: get_directory_or_file_client" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "sharesamples5") # Get the directory client to interact with a specific directory @@ -173,12 +193,14 @@ def get_directory_or_file_client(self): def acquire_share_lease(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: acquire_share_lease") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + "\n" + "Test: acquire_share_lease" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "sharesamples") # Create the share @@ -192,7 +214,7 @@ def acquire_share_lease(self): # [END acquire_and_release_lease_on_share] -if __name__ == '__main__': +if __name__ == "__main__": sample = ShareSamples() sample.create_share_snapshot() sample.set_share_quota_and_metadata() diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_share_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_share_async.py index 93aef67615bf..5a8fd8d4cf0f 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_share_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_share_async.py @@ -34,16 +34,20 @@ class ShareSamplesAsync(object): - connection_string = os.getenv('STORAGE_CONNECTION_STRING') + connection_string = os.getenv("STORAGE_CONNECTION_STRING") async def create_share_snapshot_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: create_share_snapshot_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: create_share_snapshot_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "sharesamples1async") async with share: @@ -62,12 +66,16 @@ async def create_share_snapshot_async(self): async def set_share_quota_and_metadata_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: set_share_quota_and_metadata_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: set_share_quota_and_metadata_async" + ) sys.exit(1) # [START create_share_client_from_conn_string] from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "sharesamples2async") # [END create_share_client_from_conn_string] @@ -82,7 +90,7 @@ async def set_share_quota_and_metadata_async(self): # [END set_share_quota] # [START set_share_metadata] - data = {'category': 'test'} + data = {"category": "test"} await share.set_share_metadata(metadata=data) # [END set_share_metadata] @@ -95,11 +103,15 @@ async def set_share_quota_and_metadata_async(self): async def set_share_properties_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: set_share_properties_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: set_share_properties_async" + ) sys.exit(1) from azure.storage.fileshare.aio import ShareClient + share1 = ShareClient.from_connection_string(self.connection_string, "sharesamples3aasync") share2 = ShareClient.from_connection_string(self.connection_string, "sharesamples3basync") @@ -133,12 +145,16 @@ async def set_share_properties_async(self): async def list_directories_and_files_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: list_directories_and_files_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: list_directories_and_files_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "sharesamples4async") # Create the share @@ -166,12 +182,16 @@ async def list_directories_and_files_async(self): async def get_directory_or_file_client_async(self): if self.connection_string is None: - print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + - "Test: get_directory_or_file_client_async") + print( + "Missing required environment variable: STORAGE_CONNECTION_STRING." + + "\n" + + "Test: get_directory_or_file_client_async" + ) sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient + share = ShareClient.from_connection_string(self.connection_string, "sharesamples5async") # Get the directory client to interact with a specific directory @@ -189,5 +209,6 @@ async def main(): await sample.list_directories_and_files_async() await sample.get_directory_or_file_client_async() -if __name__ == '__main__': + +if __name__ == "__main__": asyncio.run(main()) diff --git a/sdk/storage/azure-storage-file-share/setup.py b/sdk/storage/azure-storage-file-share/setup.py index 832fc9c7d6a4..a56a4f1242b1 100644 --- a/sdk/storage/azure-storage-file-share/setup.py +++ b/sdk/storage/azure-storage-file-share/setup.py @@ -1,10 +1,10 @@ #!/usr/bin/env python -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for # license information. -#-------------------------------------------------------------------------- +# -------------------------------------------------------------------------- import re import os.path @@ -17,59 +17,55 @@ PACKAGE_PPRINT_NAME = "Azure File Share Storage" # a.b.c => a/b/c -package_folder_path = NAMESPACE_NAME.replace('.', '/') +package_folder_path = NAMESPACE_NAME.replace(".", "/") # Version extraction inspired from 'requests' -with open(os.path.join(package_folder_path, '_version.py'), 'r') as fd: - version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', - fd.read(), re.MULTILINE).group(1) +with open(os.path.join(package_folder_path, "_version.py"), "r") as fd: + version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1) if not version: - raise RuntimeError('Cannot find version information') + raise RuntimeError("Cannot find version information") -with open('README.md', encoding='utf-8') as f: +with open("README.md", encoding="utf-8") as f: readme = f.read() -with open('CHANGELOG.md', encoding='utf-8') as f: +with open("CHANGELOG.md", encoding="utf-8") as f: changelog = f.read() setup( name=PACKAGE_NAME, version=version, include_package_data=True, - description=f'Microsoft Azure {PACKAGE_PPRINT_NAME} Client Library for Python', - long_description=readme + '\n\n' + changelog, - long_description_content_type='text/markdown', - license='MIT License', - author='Microsoft Corporation', - author_email='ascl@microsoft.com', - url='https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-file-share', + description=f"Microsoft Azure {PACKAGE_PPRINT_NAME} Client Library for Python", + long_description=readme + "\n\n" + changelog, + long_description_content_type="text/markdown", + license="MIT License", + author="Microsoft Corporation", + author_email="ascl@microsoft.com", + url="https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-file-share", keywords="azure, azure sdk", classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - 'License :: OSI Approved :: MIT License', + "Development Status :: 5 - Production/Stable", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "License :: OSI Approved :: MIT License", ], zip_safe=False, - packages=find_packages(exclude=[ - # Exclude packages that will be covered by PEP420 or nspkg - 'azure', - 'azure.storage', - 'tests', - ]), + packages=find_packages( + exclude=[ + # Exclude packages that will be covered by PEP420 or nspkg + "azure", + "azure.storage", + "tests", + ] + ), python_requires=">=3.8", - install_requires=[ - "azure-core>=1.30.0", - "cryptography>=2.1.4", - "typing-extensions>=4.6.0", - "isodate>=0.6.1" - ], + install_requires=["azure-core>=1.30.0", "cryptography>=2.1.4", "typing-extensions>=4.6.0", "isodate>=0.6.1"], extras_require={ "aio": [ "azure-core[aio]>=1.30.0", diff --git a/sdk/storage/azure-storage-file-share/tests/conftest.py b/sdk/storage/azure-storage-file-share/tests/conftest.py index 66cd7dd21ae2..53ba9a93f1d2 100644 --- a/sdk/storage/azure-storage-file-share/tests/conftest.py +++ b/sdk/storage/azure-storage-file-share/tests/conftest.py @@ -15,9 +15,10 @@ add_header_regex_sanitizer, add_oauth_response_sanitizer, add_uri_string_sanitizer, - test_proxy + test_proxy, ) + @pytest.fixture(scope="session", autouse=True) def add_sanitizers(test_proxy): subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") 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..99d462050843 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 @@ -17,26 +17,26 @@ class KeyWrapper: - def __init__(self, kid='local:key1'): + def __init__(self, kid="local:key1"): # Must have constant key value for recorded tests, otherwise we could use a random generator. - self.kek = b'\xbe\xa4\x11K\x9eJ\x07\xdafF\x83\xad+\xadvA C\xe8\xbc\x90\xa4\x11}G\xc3\x0f\xd4\xb4\x19m\x11' + self.kek = b"\xbe\xa4\x11K\x9eJ\x07\xdafF\x83\xad+\xadvA C\xe8\xbc\x90\xa4\x11}G\xc3\x0f\xd4\xb4\x19m\x11" self.backend = default_backend() self.kid = kid - def wrap_key(self, key, algorithm='A256KW'): - if algorithm == 'A256KW': + def wrap_key(self, key, algorithm="A256KW"): + if algorithm == "A256KW": return aes_key_wrap(self.kek, key, self.backend) raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) def unwrap_key(self, key, algorithm): - if algorithm == 'A256KW': + if algorithm == "A256KW": return aes_key_unwrap(self.kek, key, self.backend) raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) def get_key_wrap_algorithm(self): - return 'A256KW' + return "A256KW" def get_kid(self): return self.kid @@ -54,37 +54,29 @@ def resolve_key(self, kid): class RSAKeyWrapper: - def __init__(self, kid='local:key2'): - self.private_key = generate_private_key(public_exponent=65537, - key_size=2048, - backend=default_backend()) + def __init__(self, kid="local:key2"): + self.private_key = generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend()) self.public_key = self.private_key.public_key() self.kid = kid - def wrap_key(self, key, algorithm='RSA'): - if algorithm == 'RSA': - return self.public_key.encrypt(key, - OAEP( - mgf=MGF1(algorithm=SHA1()), # nosec - algorithm=SHA1(), # nosec - label=None) - ) + def wrap_key(self, key, algorithm="RSA"): + if algorithm == "RSA": + return self.public_key.encrypt( + key, OAEP(mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None) # nosec # nosec + ) raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) def unwrap_key(self, key, algorithm): - if algorithm == 'RSA': - return self.private_key.decrypt(key, - OAEP( - mgf=MGF1(algorithm=SHA1()), # nosec - algorithm=SHA1(), # nosec - label=None) - ) + if algorithm == "RSA": + return self.private_key.decrypt( + key, OAEP(mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None) # nosec # nosec + ) raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) def get_key_wrap_algorithm(self): - return 'RSA' + return "RSA" def get_kid(self): return self.kid 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..e707bd60e59f 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 @@ -10,6 +10,7 @@ from azure.storage.file import FileService + class _LegacyServiceTest(PerfStressTest): service_client = None async_service_client = None @@ -27,10 +28,31 @@ 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): diff --git a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/download.py b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/download.py index 1655d95cd073..2783dc073d99 100644 --- a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/download.py +++ b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/download.py @@ -18,10 +18,8 @@ async def global_setup(self): await super().global_setup() data = get_random_bytes(self.args.size) self.service_client.create_file_from_bytes( - share_name=self.share_name, - directory_name=None, - file_name=self.file_name, - file=data) + share_name=self.share_name, directory_name=None, file_name=self.file_name, file=data + ) def run_sync(self): self.download_stream.reset() @@ -30,7 +28,8 @@ def run_sync(self): directory_name=None, file_name=self.file_name, stream=self.download_stream, - max_connections=self.args.max_concurrency) + max_connections=self.args.max_concurrency, + ) async def run_async(self): raise NotImplementedError("Async not supported for legacy T1 tests.") diff --git a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/download_to_file.py b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/download_to_file.py index 08719e5515dc..15dd8242a500 100644 --- a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/download_to_file.py +++ b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/download_to_file.py @@ -19,10 +19,8 @@ async def global_setup(self): await super().global_setup() data = get_random_bytes(self.args.size) self.service_client.create_file_from_bytes( - share_name=self.share_name, - directory_name=None, - file_name=self.file_name, - file=data) + share_name=self.share_name, directory_name=None, file_name=self.file_name, file=data + ) async def setup(self): await super().setup() @@ -38,7 +36,8 @@ def run_sync(self): directory_name=None, file_name=self.file_name, file_path=self.temp_file, - max_connections=self.args.max_concurrency) + max_connections=self.args.max_concurrency, + ) async def run_async(self): raise NotImplementedError("Async not supported for legacy T1 tests.") 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..bb23d1ee960f 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 @@ -24,7 +24,8 @@ def run_sync(self): file_name=self.file_name, stream=self.upload_stream, count=self.args.size, - max_connections=self.args.max_concurrency) + max_connections=self.args.max_concurrency, + ) async def run_async(self): raise NotImplementedError("Async not supported for legacy T1 tests.") diff --git a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/upload_from_file.py b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/upload_from_file.py index 46b121963b75..fb73f2cafcc7 100644 --- a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/upload_from_file.py +++ b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/T1_legacy_tests/upload_from_file.py @@ -36,7 +36,8 @@ def run_sync(self): directory_name=None, file_name=self.file_name, local_file_path=LegacyUploadFromFileTest.temp_file, - max_connections=self.args.max_concurrency) + max_connections=self.args.max_concurrency, + ) async def run_async(self): raise NotImplementedError("Async not supported for legacy T1 tests.") 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 5f711d15cc1f..5f7efdda5a1f 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 @@ -21,12 +21,16 @@ def __init__(self, arguments): connection_string = self.get_from_env("AZURE_STORAGE_CONNECTION_STRING") kwargs = {} if self.args.max_range_size: - kwargs['max_range_size'] = self.args.max_range_size + 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 + self.async_service_client = _ServiceTest.async_service_client async def close(self): await self.async_service_client.close() @@ -35,10 +39,31 @@ 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 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 _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..d0407b0c8bbe 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 @@ -18,13 +18,11 @@ def __init__(self, arguments): def run_sync(self): self.upload_stream.reset() self.sharefile_client.upload_file( - self.upload_stream, - length=self.args.size, - max_concurrency=self.args.max_concurrency) + self.upload_stream, length=self.args.size, max_concurrency=self.args.max_concurrency + ) async def run_async(self): self.upload_stream_async.reset() await self.async_sharefile_client.upload_file( - self.upload_stream_async, - length=self.args.size, - max_concurrency=self.args.max_concurrency) + self.upload_stream_async, length=self.args.size, max_concurrency=self.args.max_concurrency + ) diff --git a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/upload_from_file.py b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/upload_from_file.py index e113cc804436..781543fcd79e 100644 --- a/sdk/storage/azure-storage-file-share/tests/perfstress_tests/upload_from_file.py +++ b/sdk/storage/azure-storage-file-share/tests/perfstress_tests/upload_from_file.py @@ -27,9 +27,9 @@ async def global_cleanup(self): await super().global_cleanup() def run_sync(self): - with open(UploadFromFileTest.temp_file, 'rb') as fp: + with open(UploadFromFileTest.temp_file, "rb") as fp: self.sharefile_client.upload_file(fp, max_concurrency=self.args.max_concurrency) async def run_async(self): - with open(UploadFromFileTest.temp_file, 'rb') as fp: + with open(UploadFromFileTest.temp_file, "rb") as fp: await self.async_sharefile_client.upload_file(fp, max_concurrency=self.args.max_concurrency) diff --git a/sdk/storage/azure-storage-file-share/tests/settings/settings_fake.py b/sdk/storage/azure-storage-file-share/tests/settings/settings_fake.py index 84dcade5460f..bbd8f1db9757 100644 --- a/sdk/storage/azure-storage-file-share/tests/settings/settings_fake.py +++ b/sdk/storage/azure-storage-file-share/tests/settings/settings_fake.py @@ -11,7 +11,7 @@ SECONDARY_STORAGE_ACCOUNT_NAME = "fakename" SECONDARY_STORAGE_ACCOUNT_KEY = "fakekey" -ACCOUNT_URL_SUFFIX = 'core.windows.net' +ACCOUNT_URL_SUFFIX = "core.windows.net" RUN_IN_LIVE = "False" SKIP_LIVE_RECORDING = "True" 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 c54a3c33e4ef..1d88dbf4f7f5 100644 --- a/sdk/storage/azure-storage-file-share/tests/settings/testcase.py +++ b/sdk/storage/azure-storage-file-share/tests/settings/testcase.py @@ -17,8 +17,9 @@ import logging from devtools_testutils import PowerShellPreparer from devtools_testutils.fake_credentials import STORAGE_ACCOUNT_FAKE_KEY + try: - from cStringIO import StringIO # Python 2 + from cStringIO import StringIO # Python 2 except ImportError: from io import StringIO @@ -35,23 +36,31 @@ 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 +) -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['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 -os.environ['PROTOCOL'] = PROTOCOL -os.environ['ACCOUNT_URL_SUFFIX'] = ACCOUNT_URL_SUFFIX +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 +os.environ["PROTOCOL"] = PROTOCOL +os.environ["ACCOUNT_URL_SUFFIX"] = ACCOUNT_URL_SUFFIX FileSharePreparer = functools.partial( - PowerShellPreparer, "storage", + PowerShellPreparer, + "storage", storage_account_name="storagename", storage_account_key=STORAGE_ACCOUNT_FAKE_KEY, premium_storage_file_account_name="pyacrstoragestorname", @@ -64,4 +73,5 @@ def not_for_emulator(test): def skip_test_if_targeting_emulator(self): test(self) + return skip_test_if_targeting_emulator 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 391438bec752..452a77f2ed68 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_directory.py +++ b/sdk/storage/azure-storage-file-share/tests/test_directory.py @@ -21,10 +21,13 @@ 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;;;' \ - 'S-1-5-21-397955417-626881126-188441444-3053964)' +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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)" +) TEST_INTENT = "backup" @@ -33,7 +36,7 @@ def _setup(self, storage_account_name, storage_account_key): url = self.account_url(storage_account_name, "file") credential = storage_account_key self.fsc = ShareServiceClient(url, credential=credential) - self.share_name = self.get_resource_name('utshare') + self.share_name = self.get_resource_name("utshare") if not self.is_playback(): try: @@ -47,6 +50,7 @@ def _teardown(self, FILE_PATH): os.remove(FILE_PATH) except: pass + # --Helpers----------------------------------------------------------------- # --Test cases for directories ---------------------------------------------- @@ -60,7 +64,7 @@ def test_create_directories(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) # Act - created = share_client.create_directory('dir1') + created = share_client.create_directory("dir1") # Assert assert created @@ -73,10 +77,10 @@ def test_create_directories_with_metadata(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act - directory = share_client.create_directory('dir1', metadata=metadata) + directory = share_client.create_directory("dir1", metadata=metadata) # Assert md = directory.get_directory_properties().metadata @@ -92,9 +96,9 @@ def test_create_directories_fail_on_exist(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) # Act - created = share_client.create_directory('dir1') + created = share_client.create_directory("dir1") with pytest.raises(ResourceExistsError): - share_client.create_directory('dir1') + share_client.create_directory("dir1") # Assert assert created @@ -108,7 +112,7 @@ def test_create_directory_set_smb_properties(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory_client = share_client.get_directory_client('dir1') + 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) @@ -117,7 +121,8 @@ def test_create_directory_set_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, + ) directory_properties = directory_client.get_directory_properties() # Assert @@ -125,8 +130,8 @@ def test_create_directory_set_smb_properties(self, **kwargs): assert file_creation_time == directory_properties.creation_time assert file_last_write_time == directory_properties.last_write_time assert file_change_time == directory_properties.change_time - assert 'ReadOnly' in directory_properties.file_attributes - assert 'Directory' in directory_properties.file_attributes + assert "ReadOnly" in directory_properties.file_attributes + assert "Directory" in directory_properties.file_attributes @FileSharePreparer() @recorded_by_proxy @@ -139,10 +144,12 @@ def test_create_directory_with_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act created = directory_client.create_directory() @@ -158,20 +165,22 @@ def test_create_directory_with_trailing_dot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory_name = 'dir1' + directory_name = "dir1" directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, directory_name + '.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + directory_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) # Act created = directory_client.create_directory() # Assert assert created - assert directory_client.directory_path == directory_name + '.' + assert directory_client.directory_path == directory_name + "." @FileSharePreparer() @recorded_by_proxy @@ -181,14 +190,14 @@ def test_create_subdirectories(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") # Act - created = directory.create_subdirectory('dir2') + created = directory.create_subdirectory("dir2") # Assert assert created - assert created.directory_path == 'dir1/dir2' + assert created.directory_path == "dir1/dir2" @FileSharePreparer() @recorded_by_proxy @@ -198,15 +207,15 @@ def test_create_subdirectories_with_metadata(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') - metadata = {'hello': 'world', 'number': '42'} + directory = share_client.create_directory("dir1") + metadata = {"hello": "world", "number": "42"} # Act - created = directory.create_subdirectory('dir2', metadata=metadata) + created = directory.create_subdirectory("dir2", metadata=metadata) # Assert assert created - assert created.directory_path == 'dir1/dir2' + assert created.directory_path == "dir1/dir2" sub_metadata = created.get_directory_properties().metadata assert sub_metadata == metadata @@ -218,19 +227,19 @@ def test_create_subdirectory_in_root(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - share_client.create_directory('dir1') + share_client.create_directory("dir1") # Act rooted_directory = share_client.get_directory_client() - sub_dir_client = rooted_directory.get_subdirectory_client('dir2') + sub_dir_client = rooted_directory.get_subdirectory_client("dir2") sub_dir_client.create_directory() list_dir = list(share_client.list_directories_and_files()) # Assert assert len(list_dir) == 2 - assert list_dir[0]['name'] == 'dir1' - assert list_dir[1]['name'] == 'dir2' + assert list_dir[0]["name"] == "dir1" + assert list_dir[1]["name"] == "dir2" @FileSharePreparer() @recorded_by_proxy @@ -239,10 +248,10 @@ def test_create_file_in_directory(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_data = b'12345678' * 1024 - file_name = self.get_resource_name('file') + file_data = b"12345678" * 1024 + file_name = self.get_resource_name("file") share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") # Act new_file = directory.upload_file(file_name, file_data) @@ -258,9 +267,9 @@ def test_delete_file_in_directory(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_name = self.get_resource_name('file') + file_name = self.get_resource_name("file") share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") new_file = directory.upload_file(file_name, "hello world") # Act @@ -279,7 +288,7 @@ def test_share_directory_exists(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") directory2 = share_client.get_directory_client("dir2") @@ -294,15 +303,15 @@ def test_delete_subdirectories(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') - directory.create_subdirectory('dir2') + directory = share_client.create_directory("dir1") + directory.create_subdirectory("dir2") # Act - deleted = directory.delete_subdirectory('dir2') + deleted = directory.delete_subdirectory("dir2") # Assert assert deleted is None - subdir = directory.get_subdirectory_client('dir2') + subdir = directory.get_subdirectory_client("dir2") with pytest.raises(ResourceNotFoundError): subdir.get_directory_properties() @@ -314,7 +323,7 @@ def test_get_directory_properties(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") # Act props = directory.get_directory_properties() @@ -335,10 +344,12 @@ def test_get_directory_properties_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act directory_client.create_directory() @@ -358,14 +369,14 @@ def test_get_directory_properties_with_snapshot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) metadata = {"test1": "foo", "test2": "bar"} - directory = share_client.create_directory('dir1', metadata=metadata) + directory = share_client.create_directory("dir1", metadata=metadata) snapshot1 = share_client.create_snapshot() metadata2 = {"test100": "foo100", "test200": "bar200"} directory.set_directory_metadata(metadata2) # Act share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot1) - snap_dir = share_client.get_directory_client('dir1') + snap_dir = share_client.get_directory_client("dir1") props = snap_dir.get_directory_properties() # Assert @@ -383,10 +394,12 @@ def test_get_directory_properties_with_trailing_dot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) # Act directory.create_directory() @@ -406,14 +419,14 @@ def test_get_directory_metadata_with_snapshot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) metadata = {"test1": "foo", "test2": "bar"} - directory = share_client.create_directory('dir1', metadata=metadata) + directory = share_client.create_directory("dir1", metadata=metadata) snapshot1 = share_client.create_snapshot() metadata2 = {"test100": "foo100", "test200": "bar200"} directory.set_directory_metadata(metadata2) # Act share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot1) - snap_dir = share_client.get_directory_client('dir1') + snap_dir = share_client.get_directory_client("dir1") snapshot_metadata = snap_dir.get_directory_properties().metadata # Assert @@ -428,7 +441,7 @@ def test_get_directory_properties_with_non_existing_directory(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.get_directory_client('dir1') + directory = share_client.get_directory_client("dir1") # Act with pytest.raises(ResourceNotFoundError): @@ -444,7 +457,7 @@ def test_directory_exists(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") # Act exists = directory.get_directory_properties() @@ -460,7 +473,7 @@ def test_directory_not_exists(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.get_directory_client('dir1') + directory = share_client.get_directory_client("dir1") # Act with pytest.raises(ResourceNotFoundError): @@ -476,7 +489,7 @@ def test_directory_parent_not_exists(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.get_directory_client('missing1/missing2') + directory = share_client.get_directory_client("missing1/missing2") # Act with pytest.raises(ResourceNotFoundError) as e: @@ -493,13 +506,13 @@ def test_directory_exists_with_snapshot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") snapshot = share_client.create_snapshot() directory.delete_directory() # Act share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot) - snap_dir = share_client.get_directory_client('dir1') + snap_dir = share_client.get_directory_client("dir1") exists = snap_dir.get_directory_properties() # Assert @@ -514,11 +527,11 @@ def test_directory_not_exists_with_snapshot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) snapshot = share_client.create_snapshot() - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") # Act share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot) - snap_dir = share_client.get_directory_client('dir1') + snap_dir = share_client.get_directory_client("dir1") with pytest.raises(ResourceNotFoundError): snap_dir.get_directory_properties() @@ -533,8 +546,8 @@ def test_get_set_directory_metadata(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') - metadata = {'hello': 'world', 'number': '43'} + directory = share_client.create_directory("dir1") + metadata = {"hello": "world", "number": "43"} # Act directory.set_directory_metadata(metadata) @@ -553,11 +566,13 @@ def test_get_set_directory_metadata_with_oauth(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) - metadata = {'hello': 'world', 'number': '43'} + token_intent=TEST_INTENT, + ) + metadata = {"hello": "world", "number": "43"} # Act directory_client.create_directory() @@ -575,7 +590,7 @@ def test_set_directory_properties_with_empty_smb_properties(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory_client = share_client.create_directory('dir1') + directory_client = share_client.create_directory("dir1") directory_properties_on_creation = directory_client.get_directory_properties() # Act @@ -599,10 +614,12 @@ def test_set_directory_properties_with_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act directory_client.create_directory() @@ -617,10 +634,10 @@ def test_set_directory_properties_with_oauth(self, **kwargs): # Act directory_client.set_http_headers( - file_attributes='None', + file_attributes="None", file_creation_time=new_creation_time, file_last_write_time=new_last_write_time, - file_change_time=new_change_time + file_change_time=new_change_time, ) directory_properties = directory_client.get_directory_properties() @@ -638,7 +655,7 @@ def test_set_directory_properties_with_file_permission_key(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory_client = share_client.create_directory('dir1') + directory_client = share_client.create_directory("dir1") directory_properties_on_creation = directory_client.get_directory_properties() permission_key = directory_properties_on_creation.permission_key @@ -652,11 +669,12 @@ def test_set_directory_properties_with_file_permission_key(self, **kwargs): # Act directory_client.set_http_headers( - file_attributes='None', + file_attributes="None", file_creation_time=new_creation_time, file_last_write_time=new_last_write_time, file_change_time=new_change_time, - permission_key=permission_key) + permission_key=permission_key, + ) directory_properties = directory_client.get_directory_properties() # Assert @@ -674,10 +692,12 @@ def test_set_http_headers_with_trailing_dot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) directory_client.create_directory() directory_properties_on_creation = directory_client.get_directory_properties() @@ -692,11 +712,12 @@ def test_set_http_headers_with_trailing_dot(self, **kwargs): # Act directory_client.set_http_headers( - file_attributes='None', + file_attributes="None", file_creation_time=new_creation_time, file_last_write_time=new_last_write_time, file_change_time=new_change_time, - permission_key=permission_key) + permission_key=permission_key, + ) directory_properties = directory_client.get_directory_properties() # Assert @@ -713,7 +734,7 @@ def test_list_subdirectories_and_files(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") directory.create_subdirectory("subdir1") directory.create_subdirectory("subdir2") directory.create_subdirectory("subdir3") @@ -726,18 +747,18 @@ def test_list_subdirectories_and_files(self, **kwargs): # Assert assert len(list_dir) == 6 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'subdir3' - assert list_dir[2]['is_directory'] == True - assert list_dir[3]['name'] == 'file1' - assert list_dir[3]['is_directory'] == False - assert list_dir[4]['name'] == 'file2' - assert list_dir[4]['is_directory'] == False - assert list_dir[5]['name'] == 'file3' - assert list_dir[5]['is_directory'] == False + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2" + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "subdir3" + assert list_dir[2]["is_directory"] == True + assert list_dir[3]["name"] == "file1" + assert list_dir[3]["is_directory"] == False + assert list_dir[4]["name"] == "file2" + assert list_dir[4]["is_directory"] == False + assert list_dir[5]["name"] == "file3" + assert list_dir[5]["is_directory"] == False @FileSharePreparer() @recorded_by_proxy @@ -750,10 +771,12 @@ def test_list_subdirectories_and_files_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act directory_client.create_directory() @@ -769,18 +792,18 @@ def test_list_subdirectories_and_files_oauth(self, **kwargs): # Assert assert len(list_dir) == 6 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'subdir3' - assert list_dir[2]['is_directory'] == True - assert list_dir[3]['name'] == 'file1' - assert list_dir[3]['is_directory'] == False - assert list_dir[4]['name'] == 'file2' - assert list_dir[4]['is_directory'] == False - assert list_dir[5]['name'] == 'file3' - assert list_dir[5]['is_directory'] == False + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2" + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "subdir3" + assert list_dir[2]["is_directory"] == True + assert list_dir[3]["name"] == "file1" + assert list_dir[3]["is_directory"] == False + assert list_dir[4]["name"] == "file2" + assert list_dir[4]["is_directory"] == False + assert list_dir[5]["name"] == "file3" + assert list_dir[5]["is_directory"] == False @FileSharePreparer() @recorded_by_proxy @@ -791,10 +814,12 @@ def test_list_subdirectories_with_trailing_dot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) directory.create_directory() directory.create_subdirectory("subdir1.") directory.create_subdirectory("subdir2.") @@ -804,12 +829,12 @@ def test_list_subdirectories_with_trailing_dot(self, **kwargs): # Assert assert len(list_dir) == 3 - assert list_dir[0]['name'] == 'subdir1.' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2.' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'subdir3.' - assert list_dir[2]['is_directory'] == True + assert list_dir[0]["name"] == "subdir1." + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2." + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "subdir3." + assert list_dir[2]["is_directory"] == True @FileSharePreparer() @recorded_by_proxy @@ -819,7 +844,7 @@ def test_list_subdirectories_and_files_encoded(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('directory\uFFFE') + directory = share_client.create_directory("directory\uFFFE") directory.create_subdirectory("subdir1\uFFFE") directory.upload_file("file\uFFFE", "data1") @@ -828,10 +853,10 @@ def test_list_subdirectories_and_files_encoded(self, **kwargs): # Assert assert len(list_dir) == 2 - assert list_dir[0]['name'] == 'subdir1\uFFFE' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'file\uFFFE' - assert list_dir[1]['is_directory'] == False + assert list_dir[0]["name"] == "subdir1\uFFFE" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "file\uFFFE" + assert list_dir[1]["is_directory"] == False @FileSharePreparer() @recorded_by_proxy @@ -841,7 +866,7 @@ def test_list_subdirectories_and_files_encoded_prefix(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('\uFFFFdirectory') + directory = share_client.create_directory("\uFFFFdirectory") directory.create_subdirectory("\uFFFFsubdir1") directory.upload_file("\uFFFFfile", "data1") @@ -850,10 +875,10 @@ def test_list_subdirectories_and_files_encoded_prefix(self, **kwargs): # Assert assert len(list_dir) == 2 - assert list_dir[0]['name'] == '\uFFFFsubdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == '\uFFFFfile' - assert list_dir[1]['is_directory'] == False + assert list_dir[0]["name"] == "\uFFFFsubdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "\uFFFFfile" + assert list_dir[1]["is_directory"] == False @FileSharePreparer() @recorded_by_proxy @@ -863,7 +888,7 @@ def test_list_subdirectories_and_files_include_other_data(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") directory.create_subdirectory("subdir1") directory.create_subdirectory("subdir2") directory.create_subdirectory("subdir3") @@ -872,7 +897,9 @@ 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 @@ -895,7 +922,7 @@ def test_list_subdirectories_and_files_include_extended_info(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") directory.create_subdirectory("subdir1") list_dir = list(directory.list_directories_and_files(include_extended_info=True)) @@ -912,7 +939,7 @@ def test_list_subdirectories_and_files_with_prefix(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") directory.create_subdirectory("subdir1") directory.create_subdirectory("subdir2") directory.create_subdirectory("subdir3") @@ -925,12 +952,12 @@ def test_list_subdirectories_and_files_with_prefix(self, **kwargs): # Assert assert len(list_dir) == 3 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'subdir3' - assert list_dir[2]['is_directory'] == True + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2" + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "subdir3" + assert list_dir[2]["is_directory"] == True @FileSharePreparer() @recorded_by_proxy @@ -940,31 +967,31 @@ def test_list_subdirectories_and_files_with_snapshot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") directory.create_subdirectory("subdir1") directory.create_subdirectory("subdir2") directory.upload_file("file1", "data1") - + snapshot = share_client.create_snapshot() directory.create_subdirectory("subdir3") directory.upload_file("file2", "data2") directory.upload_file("file3", "data3") share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot) - snapshot_dir = share_client.get_directory_client('dir1') + snapshot_dir = share_client.get_directory_client("dir1") # Act list_dir = list(snapshot_dir.list_directories_and_files()) # Assert assert len(list_dir) == 3 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'file1' - assert list_dir[2]['is_directory'] == False - assert list_dir[2]['size'] == 5 + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2" + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "file1" + assert list_dir[2]["is_directory"] == False + assert list_dir[2]["size"] == 5 @FileSharePreparer() @recorded_by_proxy @@ -974,7 +1001,7 @@ def test_list_nested_subdirectories_and_files(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") subdir = directory.create_subdirectory("subdir1") subdir.create_subdirectory("subdir2") subdir.create_subdirectory("subdir3") @@ -987,11 +1014,11 @@ def test_list_nested_subdirectories_and_files(self, **kwargs): # Assert assert len(list_dir) == 2 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'file1' - assert list_dir[1]['is_directory'] == False - assert list_dir[1]['size'] == 5 + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "file1" + assert list_dir[1]["is_directory"] == False + assert list_dir[1]["size"] == 5 @FileSharePreparer() @recorded_by_proxy @@ -1001,7 +1028,7 @@ def test_delete_directory_with_existing_share(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") # Act deleted = directory.delete_directory() @@ -1022,10 +1049,12 @@ def test_delete_directory_with_existing_share_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act created = directory_client.create_directory() @@ -1046,10 +1075,12 @@ def test_delete_directory_with_trailing_dot(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) # Act directory.create_directory() @@ -1068,7 +1099,7 @@ def test_delete_directory_with_non_existing_directory(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.get_directory_client('dir1') + directory = share_client.get_directory_client("dir1") # Act with pytest.raises(ResourceNotFoundError): @@ -1084,7 +1115,7 @@ def test_get_directory_properties_server_encryption(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.create_directory('dir1') + directory = share_client.create_directory("dir1") # Act props = directory.get_directory_properties() @@ -1104,10 +1135,10 @@ def test_rename_directory(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = share_client.create_directory('dir1') + source_directory = share_client.create_directory("dir1") # Act - new_directory = source_directory.rename_directory('dir2') + new_directory = source_directory.rename_directory("dir2") # Assert props = new_directory.get_directory_properties() @@ -1124,14 +1155,16 @@ def test_rename_directory_with_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act directory_client.create_directory() - new_directory = directory_client.rename_directory('dir2') + new_directory = directory_client.rename_directory("dir2") # Assert props = new_directory.get_directory_properties() @@ -1146,13 +1179,13 @@ def test_rename_directory_different_directory(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - parent_source_directory = share_client.create_directory('dir1') - source_directory = parent_source_directory.create_subdirectory('sub1') + parent_source_directory = share_client.create_directory("dir1") + source_directory = parent_source_directory.create_subdirectory("sub1") - dest_parent_directory = share_client.create_directory('dir2') + dest_parent_directory = share_client.create_directory("dir2") # Act - new_directory_path = dest_parent_directory.directory_path + '/sub2' + new_directory_path = dest_parent_directory.directory_path + "/sub2" new_directory = source_directory.rename_directory(new_directory_path) # Assert @@ -1168,17 +1201,17 @@ def test_rename_directory_ignore_readonly(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = share_client.create_directory('dir1') - dest_directory = share_client.create_directory('dir2') - dest_file = dest_directory.get_file_client('test') + source_directory = share_client.create_directory("dir1") + dest_directory = share_client.create_directory("dir2") + dest_file = dest_directory.get_file_client("test") file_attributes = NTFSAttributes(read_only=True) dest_file.create_file(1024, file_attributes=file_attributes) # Act new_directory = source_directory.rename_directory( - dest_directory.directory_path + '/' + dest_file.file_name, - overwrite=True, ignore_read_only=True) + dest_directory.directory_path + "/" + dest_file.file_name, overwrite=True, ignore_read_only=True + ) # Assert props = new_directory.get_directory_properties() @@ -1195,10 +1228,10 @@ def test_rename_directory_file_permission(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) file_permission_key = share_client.create_permission_for_share(TEST_FILE_PERMISSIONS) - source_directory = share_client.create_directory('dir1') + source_directory = share_client.create_directory("dir1") # Act - new_directory = source_directory.rename_directory('dir2', file_permission=TEST_FILE_PERMISSIONS) + new_directory = source_directory.rename_directory("dir2", file_permission=TEST_FILE_PERMISSIONS) # Assert props = new_directory.get_directory_properties() @@ -1214,12 +1247,12 @@ def test_rename_directory_preserve_permission(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = share_client.create_directory('dir1', file_permission=TEST_FILE_PERMISSIONS) + source_directory = share_client.create_directory("dir1", file_permission=TEST_FILE_PERMISSIONS) source_props = source_directory.get_directory_properties() source_permission_key = source_props.permission_key # Act - new_directory = source_directory.rename_directory('dir2', file_permission='preserve') + new_directory = source_directory.rename_directory("dir2", file_permission="preserve") # Assert props = new_directory.get_directory_properties() @@ -1235,7 +1268,7 @@ def test_rename_directory_smb_properties(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = share_client.create_directory('dir1') + source_directory = share_client.create_directory("dir1") file_attributes = NTFSAttributes(read_only=True, directory=True) file_creation_time = datetime(2022, 1, 26, 10, 9, 30, 500000) @@ -1244,17 +1277,18 @@ def test_rename_directory_smb_properties(self, **kwargs): # Act new_directory = source_directory.rename_directory( - 'dir2', + "dir2", 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_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 @@ -1268,15 +1302,15 @@ def test_rename_directory_dest_lease(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = share_client.create_directory('dir1') - dest_directory = share_client.create_directory('dir2') - dest_file = dest_directory.upload_file('test', b'Hello World') - lease = dest_file.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + source_directory = share_client.create_directory("dir1") + dest_directory = share_client.create_directory("dir2") + dest_file = dest_directory.upload_file("test", b"Hello World") + lease = dest_file.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act new_directory = source_directory.rename_directory( - dest_directory.directory_path + '/' + dest_file.file_name, - overwrite=True, destination_lease=lease) + dest_directory.directory_path + "/" + dest_file.file_name, overwrite=True, destination_lease=lease + ) # Assert props = new_directory.get_directory_properties() @@ -1298,16 +1332,16 @@ def test_rename_directory_share_sas(self, **kwargs): share_client.share_name, share_client.credential.account_key, expiry=datetime.utcnow() + timedelta(hours=1), - permission=ShareSasPermissions(read=True, write=True)) + permission=ShareSasPermissions(read=True, write=True), + ) source_directory = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', - credential=token) + self.account_url(storage_account_name, "file"), share_client.share_name, "dir1", credential=token + ) source_directory.create_directory() # Act - new_directory = source_directory.rename_directory('dir2' + '?' + token) + new_directory = source_directory.rename_directory("dir2" + "?" + token) # Assert props = new_directory.get_directory_properties() @@ -1321,14 +1355,16 @@ def test_rename_directory_trailing_dot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - dest_dir_name = 'dir2' + '.' + dest_dir_name = "dir2" + "." directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, allow_trailing_dot=True, - allow_source_trailing_dot=True) + allow_source_trailing_dot=True, + ) # Act directory_client.create_directory() @@ -1347,20 +1383,22 @@ def test_storage_account_audience_directory_client(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', - credential=storage_account_key + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", + credential=storage_account_key, ) directory_client.exists() # Act token_credential = self.get_credential(ShareServiceClient) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://{storage_account_name}.file.core.windows.net' + audience=f"https://{storage_account_name}.file.core.windows.net", ) # Assert @@ -1377,20 +1415,22 @@ def test_bad_audience_directory_client(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', - credential=storage_account_key + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", + credential=storage_account_key, ) directory_client.exists() # Act token_credential = self.get_credential(ShareServiceClient) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://badaudience.file.core.windows.net' + audience=f"https://badaudience.file.core.windows.net", ) # Assert @@ -1404,55 +1444,51 @@ def test_file_permission_format_directory(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - user_given_permission_sddl = ("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;;;" - "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL") - user_given_permission_binary = ("AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" - "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" - "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=") + user_given_permission_sddl = ( + "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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL" + ) + user_given_permission_binary = ( + "AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" + "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" + "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=" + ) directory_client = share_client.create_directory( - 'dir1', - file_permission=user_given_permission_binary, - file_permission_format="binary" + "dir1", file_permission=user_given_permission_binary, file_permission_format="binary" ) props = directory_client.get_directory_properties() assert props is not None assert props.permission_key is not None - directory_client.set_http_headers( - file_permission=user_given_permission_binary, - file_permission_format="binary" - ) + directory_client.set_http_headers(file_permission=user_given_permission_binary, file_permission_format="binary") props = directory_client.get_directory_properties() assert props is not None assert props.permission_key is not None server_returned_permission = share_client.get_permission_for_share( - props.permission_key, - file_permission_format="sddl" + props.permission_key, file_permission_format="sddl" ) assert server_returned_permission == user_given_permission_sddl new_directory_client = directory_client.rename_directory( - 'dir2', - file_permission=user_given_permission_binary, - file_permission_format="binary" + "dir2", file_permission=user_given_permission_binary, file_permission_format="binary" ) props = new_directory_client.get_directory_properties() assert props is not None assert props.permission_key is not None server_returned_permission = share_client.get_permission_for_share( - props.permission_key, - file_permission_format="binary" + props.permission_key, file_permission_format="binary" ) assert server_returned_permission == user_given_permission_binary new_directory_client.delete_directory() + # ------------------------------------------------------------------------------ -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() 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 4648df892090..f6aa4f1f76da 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 @@ -11,12 +11,7 @@ import pytest from azure.core.exceptions import ClientAuthenticationError, ResourceExistsError, ResourceNotFoundError -from azure.storage.fileshare import ( - generate_share_sas, - NTFSAttributes, - ShareSasPermissions, - StorageErrorCode -) +from azure.storage.fileshare import generate_share_sas, NTFSAttributes, ShareSasPermissions, StorageErrorCode from azure.storage.fileshare.aio import ShareDirectoryClient, ShareServiceClient from devtools_testutils.aio import recorded_by_proxy_async @@ -24,9 +19,11 @@ 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;;;' \ - 'S-1-5-21-397955417-626881126-188441444-3053964)' +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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)" +) TEST_INTENT = "backup" @@ -36,7 +33,7 @@ async def _setup(self, storage_account_name, storage_account_key): url = self.account_url(storage_account_name, "file") credential = storage_account_key self.fsc = ShareServiceClient(url, credential=credential) - self.share_name = self.get_resource_name('utshare') + self.share_name = self.get_resource_name("utshare") if not self.is_playback(): try: await self.fsc.create_share(self.share_name) @@ -62,7 +59,7 @@ async def test_create_directories(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) # Act - created = await share_client.create_directory('dir1') + created = await share_client.create_directory("dir1") # Assert assert created @@ -76,10 +73,10 @@ async def test_create_directories_with_metadata(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act - directory = await share_client.create_directory('dir1', metadata=metadata) + directory = await share_client.create_directory("dir1", metadata=metadata) # Assert props = await directory.get_directory_properties() @@ -96,9 +93,9 @@ async def test_create_directories_fail_on_exist(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) # Act - created = await share_client.create_directory('dir1') + created = await share_client.create_directory("dir1") with pytest.raises(ResourceExistsError): - await share_client.create_directory('dir1') + await share_client.create_directory("dir1") # Assert assert created @@ -113,7 +110,7 @@ async def test_create_directory_set_smb_properties(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory_client = share_client.get_directory_client('dir1') + 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) @@ -122,7 +119,8 @@ async def test_create_directory_set_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, + ) directory_properties = await directory_client.get_directory_properties() # Assert @@ -130,8 +128,8 @@ async def test_create_directory_set_smb_properties(self, **kwargs): assert file_creation_time == directory_properties.creation_time assert file_last_write_time == directory_properties.last_write_time assert file_change_time == directory_properties.change_time - assert 'ReadOnly' in directory_properties.file_attributes - assert 'Directory' in directory_properties.file_attributes + assert "ReadOnly" in directory_properties.file_attributes + assert "Directory" in directory_properties.file_attributes @FileSharePreparer() @recorded_by_proxy_async @@ -145,10 +143,12 @@ async def test_create_directory_with_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act created = await directory_client.create_directory() @@ -165,20 +165,22 @@ async def test_create_directory_with_trailing_dot(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory_name = 'dir1' + directory_name = "dir1" directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, directory_name + '.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + directory_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) # Act created = await directory_client.create_directory() # Assert assert created - assert directory_client.directory_path == directory_name + '.' + assert directory_client.directory_path == directory_name + "." @FileSharePreparer() @recorded_by_proxy_async @@ -189,15 +191,14 @@ async def test_create_subdirectories(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") # Act - created = await directory.create_subdirectory('dir2') + created = await directory.create_subdirectory("dir2") # Assert assert created - assert created.directory_path == 'dir1/dir2' - + assert created.directory_path == "dir1/dir2" @FileSharePreparer() @recorded_by_proxy_async @@ -208,15 +209,15 @@ async def test_create_subdirectories_with_metadata(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') - metadata = {'hello': 'world', 'number': '42'} + directory = await share_client.create_directory("dir1") + metadata = {"hello": "world", "number": "42"} # Act - created = await directory.create_subdirectory('dir2', metadata=metadata) + created = await directory.create_subdirectory("dir2", metadata=metadata) # Assert assert created - assert created.directory_path == 'dir1/dir2' + assert created.directory_path == "dir1/dir2" properties = await created.get_directory_properties() assert properties.metadata == metadata @@ -228,11 +229,11 @@ async def test_create_subdirectory_in_root(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - await share_client.create_directory('dir1') + await share_client.create_directory("dir1") # Act rooted_directory = share_client.get_directory_client() - sub_dir_client = rooted_directory.get_subdirectory_client('dir2') + sub_dir_client = rooted_directory.get_subdirectory_client("dir2") await sub_dir_client.create_directory() list_dir = [] @@ -241,8 +242,8 @@ async def test_create_subdirectory_in_root(self, **kwargs): # Assert assert len(list_dir) == 2 - assert list_dir[0]['name'] == 'dir1' - assert list_dir[1]['name'] == 'dir2' + assert list_dir[0]["name"] == "dir1" + assert list_dir[1]["name"] == "dir2" @FileSharePreparer() @recorded_by_proxy_async @@ -252,10 +253,10 @@ async def test_create_file_in_directory(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - file_data = b'12345678' * 1024 - file_name = self.get_resource_name('file') + file_data = b"12345678" * 1024 + file_name = self.get_resource_name("file") share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") # Act new_file = await directory.upload_file(file_name, file_data) @@ -273,9 +274,9 @@ async def test_delete_file_in_directory(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - file_name = self.get_resource_name('file') + file_name = self.get_resource_name("file") share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") new_file = await directory.upload_file(file_name, "hello world") # Act @@ -295,15 +296,15 @@ async def test_delete_subdirectories(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') - await directory.create_subdirectory('dir2') + directory = await share_client.create_directory("dir1") + await directory.create_subdirectory("dir2") # Act - deleted = await directory.delete_subdirectory('dir2') + deleted = await directory.delete_subdirectory("dir2") # Assert assert deleted is None - subdir = directory.get_subdirectory_client('dir2') + subdir = directory.get_subdirectory_client("dir2") with pytest.raises(ResourceNotFoundError): await subdir.get_directory_properties() @@ -316,7 +317,7 @@ async def test_get_directory_properties(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") # Act props = await directory.get_directory_properties() @@ -338,10 +339,12 @@ async def test_get_directory_properties_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act await directory_client.create_directory() @@ -362,14 +365,14 @@ async def test_get_directory_properties_with_snapshot(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) metadata = {"test1": "foo", "test2": "bar"} - directory = await share_client.create_directory('dir1', metadata=metadata) + directory = await share_client.create_directory("dir1", metadata=metadata) snapshot1 = await share_client.create_snapshot() metadata2 = {"test100": "foo100", "test200": "bar200"} await directory.set_directory_metadata(metadata2) # Act share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot1) - snap_dir = share_client.get_directory_client('dir1') + snap_dir = share_client.get_directory_client("dir1") props = await snap_dir.get_directory_properties() # Assert @@ -388,10 +391,12 @@ async def test_get_directory_properties_with_trailing_dot(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) # Act await directory.create_directory() @@ -412,14 +417,14 @@ async def test_get_directory_metadata_with_snapshot(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) metadata = {"test1": "foo", "test2": "bar"} - directory = await share_client.create_directory('dir1', metadata=metadata) + directory = await share_client.create_directory("dir1", metadata=metadata) snapshot1 = await share_client.create_snapshot() metadata2 = {"test100": "foo100", "test200": "bar200"} await directory.set_directory_metadata(metadata2) # Act share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot1) - snap_dir = share_client.get_directory_client('dir1') + snap_dir = share_client.get_directory_client("dir1") snapshot_props = await snap_dir.get_directory_properties() # Assert @@ -435,7 +440,7 @@ async def test_get_directory_properties_with_non_existing_directory(self, **kwar # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.get_directory_client('dir1') + directory = share_client.get_directory_client("dir1") # Act with pytest.raises(ResourceNotFoundError): @@ -451,7 +456,7 @@ async def test_share_directory_exists(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") directory2 = share_client.get_directory_client("dir2") @@ -469,7 +474,7 @@ async def test_directory_exists(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") # Act exists = await directory.get_directory_properties() @@ -486,7 +491,7 @@ async def test_directory_not_exists(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.get_directory_client('dir1') + directory = share_client.get_directory_client("dir1") # Act with pytest.raises(ResourceNotFoundError): @@ -503,7 +508,7 @@ async def test_directory_parent_not_exists(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.get_directory_client('missing1/missing2') + directory = share_client.get_directory_client("missing1/missing2") # Act with pytest.raises(ResourceNotFoundError) as e: @@ -521,13 +526,13 @@ async def test_directory_exists_with_snapshot(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") snapshot = await share_client.create_snapshot() await directory.delete_directory() # Act share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot) - snap_dir = share_client.get_directory_client('dir1') + snap_dir = share_client.get_directory_client("dir1") exists = await snap_dir.get_directory_properties() # Assert @@ -543,11 +548,11 @@ async def test_directory_not_exists_with_snapshot(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) snapshot = await share_client.create_snapshot() - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") # Act share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot) - snap_dir = share_client.get_directory_client('dir1') + snap_dir = share_client.get_directory_client("dir1") with pytest.raises(ResourceNotFoundError): await snap_dir.get_directory_properties() @@ -563,8 +568,8 @@ async def test_get_set_directory_metadata(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') - metadata = {'hello': 'world', 'number': '43'} + directory = await share_client.create_directory("dir1") + metadata = {"hello": "world", "number": "43"} # Act await directory.set_directory_metadata(metadata) @@ -584,11 +589,13 @@ async def test_get_set_directory_metadata_with_oauth(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) - metadata = {'hello': 'world', 'number': '43'} + token_intent=TEST_INTENT, + ) + metadata = {"hello": "world", "number": "43"} # Act await directory_client.create_directory() @@ -607,7 +614,7 @@ async def test_set_directory_properties_with_empty_smb_properties(self, **kwargs # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory_client = await share_client.create_directory('dir1') + directory_client = await share_client.create_directory("dir1") directory_properties_on_creation = await directory_client.get_directory_properties() # Act @@ -631,10 +638,12 @@ async def test_set_directory_properties_with_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act await directory_client.create_directory() @@ -649,10 +658,10 @@ async def test_set_directory_properties_with_oauth(self, **kwargs): # Act await directory_client.set_http_headers( - file_attributes='None', + file_attributes="None", file_creation_time=new_creation_time, file_last_write_time=new_last_write_time, - file_change_time=new_change_time + file_change_time=new_change_time, ) directory_properties = await directory_client.get_directory_properties() @@ -671,7 +680,7 @@ async def test_set_directory_properties_with_file_permission_key(self, **kwargs) # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory_client = await share_client.create_directory('dir1') + directory_client = await share_client.create_directory("dir1") directory_properties_on_creation = await directory_client.get_directory_properties() permission_key = directory_properties_on_creation.permission_key @@ -685,11 +694,12 @@ async def test_set_directory_properties_with_file_permission_key(self, **kwargs) # Act await directory_client.set_http_headers( - file_attributes='None', + file_attributes="None", file_creation_time=new_creation_time, file_last_write_time=new_last_write_time, file_change_time=new_change_time, - permission_key=permission_key) + permission_key=permission_key, + ) directory_properties = await directory_client.get_directory_properties() # Assert @@ -707,10 +717,12 @@ async def test_set_http_headers_with_trailing_dot(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) await directory_client.create_directory() directory_properties_on_creation = await directory_client.get_directory_properties() @@ -725,11 +737,12 @@ async def test_set_http_headers_with_trailing_dot(self, **kwargs): # Act await directory_client.set_http_headers( - file_attributes='None', + file_attributes="None", file_creation_time=new_creation_time, file_last_write_time=new_last_write_time, file_change_time=new_change_time, - permission_key=permission_key) + permission_key=permission_key, + ) directory_properties = await directory_client.get_directory_properties() # Assert @@ -746,14 +759,15 @@ async def test_list_subdirectories_and_files(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") await asyncio.gather( directory.create_subdirectory("subdir1"), directory.create_subdirectory("subdir2"), directory.create_subdirectory("subdir3"), directory.upload_file("file1", "data1"), directory.upload_file("file2", "data2"), - directory.upload_file("file3", "data3")) + directory.upload_file("file3", "data3"), + ) # Act list_dir = [] @@ -763,21 +777,21 @@ async def test_list_subdirectories_and_files(self, **kwargs): # Assert assert len(list_dir) == 6 assert len(list_dir) == 6 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'subdir3' - assert list_dir[2]['is_directory'] == True - assert list_dir[3]['name'] == 'file1' - assert list_dir[3]['is_directory'] == False - assert list_dir[3]['size'] == 5 - assert list_dir[4]['name'] == 'file2' - assert list_dir[4]['is_directory'] == False - assert list_dir[4]['size'] == 5 - assert list_dir[5]['name'] == 'file3' - assert list_dir[5]['is_directory'] == False - assert list_dir[5]['size'] == 5 + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2" + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "subdir3" + assert list_dir[2]["is_directory"] == True + assert list_dir[3]["name"] == "file1" + assert list_dir[3]["is_directory"] == False + assert list_dir[3]["size"] == 5 + assert list_dir[4]["name"] == "file2" + assert list_dir[4]["is_directory"] == False + assert list_dir[4]["size"] == 5 + assert list_dir[5]["name"] == "file3" + assert list_dir[5]["is_directory"] == False + assert list_dir[5]["size"] == 5 @FileSharePreparer() @recorded_by_proxy_async @@ -791,10 +805,12 @@ async def test_list_subdirectories_and_files_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act await directory_client.create_directory() @@ -804,7 +820,8 @@ async def test_list_subdirectories_and_files_oauth(self, **kwargs): directory_client.create_subdirectory("subdir3"), directory_client.upload_file("file1", "data1"), directory_client.upload_file("file2", "data2"), - directory_client.upload_file("file3", "data3")) + directory_client.upload_file("file3", "data3"), + ) # Act list_dir = [] @@ -814,21 +831,21 @@ async def test_list_subdirectories_and_files_oauth(self, **kwargs): # Assert assert len(list_dir) == 6 assert len(list_dir) == 6 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'subdir3' - assert list_dir[2]['is_directory'] == True - assert list_dir[3]['name'] == 'file1' - assert list_dir[3]['is_directory'] == False - assert list_dir[3]['size'] == 5 - assert list_dir[4]['name'] == 'file2' - assert list_dir[4]['is_directory'] == False - assert list_dir[4]['size'] == 5 - assert list_dir[5]['name'] == 'file3' - assert list_dir[5]['is_directory'] == False - assert list_dir[5]['size'] == 5 + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2" + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "subdir3" + assert list_dir[2]["is_directory"] == True + assert list_dir[3]["name"] == "file1" + assert list_dir[3]["is_directory"] == False + assert list_dir[3]["size"] == 5 + assert list_dir[4]["name"] == "file2" + assert list_dir[4]["is_directory"] == False + assert list_dir[4]["size"] == 5 + assert list_dir[5]["name"] == "file3" + assert list_dir[5]["is_directory"] == False + assert list_dir[5]["size"] == 5 @FileSharePreparer() @recorded_by_proxy_async @@ -840,15 +857,17 @@ async def test_list_subdirectories_with_trailing_dot(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) await directory.create_directory() await asyncio.gather( directory.create_subdirectory("subdir1."), directory.create_subdirectory("subdir2."), - directory.create_subdirectory("subdir3.") + directory.create_subdirectory("subdir3."), ) # Act @@ -858,12 +877,12 @@ async def test_list_subdirectories_with_trailing_dot(self, **kwargs): # Assert assert len(list_dir) == 3 - assert list_dir[0]['name'] == 'subdir1.' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2.' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'subdir3.' - assert list_dir[2]['is_directory'] == True + assert list_dir[0]["name"] == "subdir1." + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2." + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "subdir3." + assert list_dir[2]["is_directory"] == True @FileSharePreparer() @recorded_by_proxy_async @@ -874,10 +893,10 @@ async def test_list_subdirectories_and_files_encoded_async(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1\uFFFE') + directory = await share_client.create_directory("dir1\uFFFE") await asyncio.gather( - directory.create_subdirectory("subdir1\uFFFE"), - directory.upload_file("file1\uFFFE", "data1")) + directory.create_subdirectory("subdir1\uFFFE"), directory.upload_file("file1\uFFFE", "data1") + ) # Act list_dir = [] @@ -886,10 +905,10 @@ async def test_list_subdirectories_and_files_encoded_async(self, **kwargs): # Assert assert len(list_dir) == 2 - assert list_dir[0]['name'] == 'subdir1\uFFFE' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'file1\uFFFE' - assert list_dir[1]['is_directory'] == False + assert list_dir[0]["name"] == "subdir1\uFFFE" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "file1\uFFFE" + assert list_dir[1]["is_directory"] == False @FileSharePreparer() @recorded_by_proxy_async @@ -900,10 +919,10 @@ async def test_list_subdirectories_and_files_encoded_prefix_async(self, **kwargs # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('\uFFFFdir1') + directory = await share_client.create_directory("\uFFFFdir1") await asyncio.gather( - directory.create_subdirectory("\uFFFFsubdir1"), - directory.upload_file("\uFFFFfile1", "data1")) + directory.create_subdirectory("\uFFFFsubdir1"), directory.upload_file("\uFFFFfile1", "data1") + ) # Act list_dir = [] @@ -912,10 +931,10 @@ async def test_list_subdirectories_and_files_encoded_prefix_async(self, **kwargs # Assert assert len(list_dir) == 2 - assert list_dir[0]['name'] == '\uFFFFsubdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == '\uFFFFfile1' - assert list_dir[1]['is_directory'] == False + assert list_dir[0]["name"] == "\uFFFFsubdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "\uFFFFfile1" + assert list_dir[1]["is_directory"] == False @FileSharePreparer() @recorded_by_proxy_async @@ -926,18 +945,21 @@ async def test_list_subdirectories_and_files_include_other_data_async(self, **kw # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") await asyncio.gather( directory.create_subdirectory("subdir1"), directory.create_subdirectory("subdir2"), directory.create_subdirectory("subdir3"), directory.upload_file("file1", "data1"), directory.upload_file("file2", "data2"), - directory.upload_file("file3", "data3")) + directory.upload_file("file3", "data3"), + ) # 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 @@ -963,9 +985,8 @@ async def test_list_subdirectories_and_files_include_extended_info(self, **kwarg # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') - await asyncio.gather( - directory.create_subdirectory("subdir1")) + directory = await share_client.create_directory("dir1") + await asyncio.gather(directory.create_subdirectory("subdir1")) # Act list_dir = [] @@ -986,14 +1007,15 @@ async def test_list_subdirectories_and_files_with_prefix(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") await asyncio.gather( directory.create_subdirectory("subdir1"), directory.create_subdirectory("subdir2"), directory.create_subdirectory("subdir3"), directory.upload_file("file1", "data1"), directory.upload_file("file2", "data2"), - directory.upload_file("file3", "data3")) + directory.upload_file("file3", "data3"), + ) # Act list_dir = [] @@ -1002,12 +1024,12 @@ async def test_list_subdirectories_and_files_with_prefix(self, **kwargs): # Assert assert len(list_dir) == 3 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'subdir3' - assert list_dir[2]['is_directory'] == True + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2" + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "subdir3" + assert list_dir[2]["is_directory"] == True @FileSharePreparer() @recorded_by_proxy_async @@ -1018,20 +1040,22 @@ async def test_list_subdirectories_and_files_with_snapshot(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") await asyncio.gather( directory.create_subdirectory("subdir1"), directory.create_subdirectory("subdir2"), - directory.upload_file("file1", "data1")) - + directory.upload_file("file1", "data1"), + ) + snapshot = await share_client.create_snapshot() await asyncio.gather( directory.create_subdirectory("subdir3"), directory.upload_file("file2", "data2"), - directory.upload_file("file3", "data3")) + directory.upload_file("file3", "data3"), + ) share_client = self.fsc.get_share_client(self.share_name, snapshot=snapshot) - snapshot_dir = share_client.get_directory_client('dir1') + snapshot_dir = share_client.get_directory_client("dir1") # Act list_dir = [] @@ -1040,13 +1064,13 @@ async def test_list_subdirectories_and_files_with_snapshot(self, **kwargs): # Assert assert len(list_dir) == 3 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'subdir2' - assert list_dir[1]['is_directory'] == True - assert list_dir[2]['name'] == 'file1' - assert list_dir[2]['is_directory'] == False - assert list_dir[2]['size'] == 5 + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "subdir2" + assert list_dir[1]["is_directory"] == True + assert list_dir[2]["name"] == "file1" + assert list_dir[2]["is_directory"] == False + assert list_dir[2]["size"] == 5 @FileSharePreparer() @recorded_by_proxy_async @@ -1057,14 +1081,15 @@ async def test_list_nested_subdirectories_and_files(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") subdir = await directory.create_subdirectory("subdir1") await subdir.create_subdirectory("subdir2") await subdir.create_subdirectory("subdir3") await asyncio.gather( directory.upload_file("file1", "data1"), subdir.upload_file("file2", "data2"), - subdir.upload_file("file3", "data3")) + subdir.upload_file("file3", "data3"), + ) # Act list_dir = [] @@ -1073,11 +1098,11 @@ async def test_list_nested_subdirectories_and_files(self, **kwargs): # Assert assert len(list_dir) == 2 - assert list_dir[0]['name'] == 'subdir1' - assert list_dir[0]['is_directory'] == True - assert list_dir[1]['name'] == 'file1' - assert list_dir[1]['is_directory'] == False - assert list_dir[1]['size'] == 5 + assert list_dir[0]["name"] == "subdir1" + assert list_dir[0]["is_directory"] == True + assert list_dir[1]["name"] == "file1" + assert list_dir[1]["is_directory"] == False + assert list_dir[1]["size"] == 5 @FileSharePreparer() @recorded_by_proxy_async @@ -1088,7 +1113,7 @@ async def test_delete_directory_with_existing_share(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") # Act deleted = await directory.delete_directory() @@ -1110,10 +1135,12 @@ async def test_delete_directory_with_existing_share_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act await directory_client.create_directory() @@ -1135,10 +1162,12 @@ async def test_delete_directory_with_trailing_dot(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) # Act await directory.create_directory() @@ -1158,7 +1187,7 @@ async def test_delete_directory_with_non_existing_directory(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = share_client.get_directory_client('dir1') + directory = share_client.get_directory_client("dir1") # Act with pytest.raises(ResourceNotFoundError): @@ -1175,7 +1204,7 @@ async def test_get_directory_properties_server_encryption(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - directory = await share_client.create_directory('dir1') + directory = await share_client.create_directory("dir1") # Act props = await directory.get_directory_properties() @@ -1196,10 +1225,10 @@ async def test_rename_directory(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = await share_client.create_directory('dir1') + source_directory = await share_client.create_directory("dir1") # Act - new_directory = await source_directory.rename_directory('dir2') + new_directory = await source_directory.rename_directory("dir2") # Assert props = await new_directory.get_directory_properties() @@ -1217,14 +1246,16 @@ async def test_rename_directory_with_oauth(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act await directory_client.create_directory() - new_directory = await directory_client.rename_directory('dir2') + new_directory = await directory_client.rename_directory("dir2") # Assert props = await new_directory.get_directory_properties() @@ -1240,13 +1271,13 @@ async def test_rename_directory_different_directory(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - parent_source_directory = await share_client.create_directory('dir1') - source_directory = await parent_source_directory.create_subdirectory('sub1') + parent_source_directory = await share_client.create_directory("dir1") + source_directory = await parent_source_directory.create_subdirectory("sub1") - dest_parent_directory = await share_client.create_directory('dir2') + dest_parent_directory = await share_client.create_directory("dir2") # Act - new_directory_path = dest_parent_directory.directory_path + '/sub2' + new_directory_path = dest_parent_directory.directory_path + "/sub2" new_directory = await source_directory.rename_directory(new_directory_path) # Assert @@ -1263,17 +1294,17 @@ async def test_rename_directory_ignore_readonly(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = await share_client.create_directory('dir1') - dest_directory = await share_client.create_directory('dir2') - dest_file = dest_directory.get_file_client('test') + source_directory = await share_client.create_directory("dir1") + dest_directory = await share_client.create_directory("dir2") + dest_file = dest_directory.get_file_client("test") file_attributes = NTFSAttributes(read_only=True) await dest_file.create_file(1024, file_attributes=file_attributes) # Act new_directory = await source_directory.rename_directory( - dest_directory.directory_path + '/' + dest_file.file_name, - overwrite=True, ignore_read_only=True) + dest_directory.directory_path + "/" + dest_file.file_name, overwrite=True, ignore_read_only=True + ) # Assert props = await new_directory.get_directory_properties() @@ -1291,10 +1322,10 @@ async def test_rename_directory_file_permission(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) file_permission_key = await share_client.create_permission_for_share(TEST_FILE_PERMISSIONS) - source_directory = await share_client.create_directory('dir1') + source_directory = await share_client.create_directory("dir1") # Act - new_directory = await source_directory.rename_directory('dir2', file_permission=TEST_FILE_PERMISSIONS) + new_directory = await source_directory.rename_directory("dir2", file_permission=TEST_FILE_PERMISSIONS) # Assert props = await new_directory.get_directory_properties() @@ -1311,12 +1342,12 @@ async def test_rename_directory_preserve_permission(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = await share_client.create_directory('dir1', file_permission=TEST_FILE_PERMISSIONS) + source_directory = await share_client.create_directory("dir1", file_permission=TEST_FILE_PERMISSIONS) source_props = await source_directory.get_directory_properties() source_permission_key = source_props.permission_key # Act - new_directory = await source_directory.rename_directory('dir2', file_permission='preserve') + new_directory = await source_directory.rename_directory("dir2", file_permission="preserve") # Assert props = await new_directory.get_directory_properties() @@ -1333,7 +1364,7 @@ async def test_rename_directory_smb_properties(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = await share_client.create_directory('dir1') + source_directory = await share_client.create_directory("dir1") file_attributes = NTFSAttributes(read_only=True, directory=True) file_creation_time = datetime(2022, 1, 26, 10, 9, 30, 500000) @@ -1342,17 +1373,18 @@ async def test_rename_directory_smb_properties(self, **kwargs): # Act new_directory = await source_directory.rename_directory( - 'dir2', + "dir2", 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 = 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 @@ -1367,15 +1399,15 @@ async def test_rename_directory_dest_lease(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = await share_client.create_directory('dir1') - dest_directory = await share_client.create_directory('dir2') - dest_file = await dest_directory.upload_file('test', b'Hello World') - lease = await dest_file.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + source_directory = await share_client.create_directory("dir1") + dest_directory = await share_client.create_directory("dir2") + dest_file = await dest_directory.upload_file("test", b"Hello World") + lease = await dest_file.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act new_directory = await source_directory.rename_directory( - dest_directory.directory_path + '/' + dest_file.file_name, - overwrite=True, destination_lease=lease) + dest_directory.directory_path + "/" + dest_file.file_name, overwrite=True, destination_lease=lease + ) # Assert props = await new_directory.get_directory_properties() @@ -1398,16 +1430,16 @@ async def test_rename_directory_share_sas(self, **kwargs): share_client.share_name, share_client.credential.account_key, expiry=datetime.utcnow() + timedelta(hours=1), - permission=ShareSasPermissions(read=True, write=True)) + permission=ShareSasPermissions(read=True, write=True), + ) source_directory = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1', - credential=token) + self.account_url(storage_account_name, "file"), share_client.share_name, "dir1", credential=token + ) await source_directory.create_directory() # Act - new_directory = await source_directory.rename_directory('dir2' + '?' + token) + new_directory = await source_directory.rename_directory("dir2" + "?" + token) # Assert props = await new_directory.get_directory_properties() @@ -1422,14 +1454,16 @@ async def test_rename_directory_trailing_dot(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - dest_dir_name = 'dir2' + '.' + dest_dir_name = "dir2" + "." directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=storage_account_key, allow_trailing_dot=True, - allow_source_trailing_dot=True) + allow_source_trailing_dot=True, + ) # Act await directory_client.create_directory() @@ -1448,20 +1482,22 @@ async def test_storage_account_audience_directory_client(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', - credential=storage_account_key + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", + credential=storage_account_key, ) await directory_client.exists() # Act token_credential = self.get_credential(ShareServiceClient, is_async=True) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://{storage_account_name}.file.core.windows.net' + audience=f"https://{storage_account_name}.file.core.windows.net", ) # Assert @@ -1478,20 +1514,22 @@ async def test_bad_audience_directory_client(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', - credential=storage_account_key + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", + credential=storage_account_key, ) await directory_client.exists() # Act token_credential = self.get_credential(ShareServiceClient, is_async=True) directory_client = ShareDirectoryClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'dir1.', + self.account_url(storage_account_name, "file"), + share_client.share_name, + "dir1.", credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://badaudience.file.core.windows.net' + audience=f"https://badaudience.file.core.windows.net", ) # Assert @@ -1505,17 +1543,19 @@ async def test_file_permission_format_directory(self, **kwargs): await self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - user_given_permission_sddl = ("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;;;" - "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL") - user_given_permission_binary = ("AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" - "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" - "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=") + user_given_permission_sddl = ( + "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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL" + ) + user_given_permission_binary = ( + "AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" + "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" + "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=" + ) directory_client = await share_client.create_directory( - 'dir1', - file_permission=user_given_permission_binary, - file_permission_format="binary" + "dir1", file_permission=user_given_permission_binary, file_permission_format="binary" ) props = await directory_client.get_directory_properties() @@ -1523,8 +1563,7 @@ async def test_file_permission_format_directory(self, **kwargs): assert props.permission_key is not None await directory_client.set_http_headers( - file_permission=user_given_permission_binary, - file_permission_format="binary" + file_permission=user_given_permission_binary, file_permission_format="binary" ) props = await directory_client.get_directory_properties() @@ -1532,26 +1571,23 @@ async def test_file_permission_format_directory(self, **kwargs): assert props.permission_key is not None server_returned_permission = await share_client.get_permission_for_share( - props.permission_key, - file_permission_format="sddl" + props.permission_key, file_permission_format="sddl" ) assert server_returned_permission == user_given_permission_sddl new_directory_client = await directory_client.rename_directory( - 'dir2', - file_permission=user_given_permission_binary, - file_permission_format="binary" + "dir2", file_permission=user_given_permission_binary, file_permission_format="binary" ) props = await new_directory_client.get_directory_properties() assert props is not None assert props.permission_key is not None server_returned_permission = await share_client.get_permission_for_share( - props.permission_key, - file_permission_format="binary" + props.permission_key, file_permission_format="binary" ) assert server_returned_permission == user_given_permission_binary await new_directory_client.delete_directory() + # ------------------------------------------------------------------------------ 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 78aa779be7f4..62e81510ecb0 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file.py @@ -11,7 +11,12 @@ import requests 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 ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, +) from azure.storage.blob import BlobServiceClient from azure.storage.fileshare import ( AccessPolicy, @@ -26,7 +31,7 @@ ShareFileClient, ShareSasPermissions, ShareServiceClient, - StorageErrorCode + StorageErrorCode, ) from devtools_testutils import recorded_by_proxy @@ -35,14 +40,16 @@ from test_helpers import MockStorageTransport, ProgressTracker # ------------------------------------------------------------------------------ -TEST_SHARE_PREFIX = 'share' -TEST_BLOB_PREFIX = 'blob' -TEST_DIRECTORY_PREFIX = 'dir' -TEST_FILE_PREFIX = 'file' +TEST_SHARE_PREFIX = "share" +TEST_BLOB_PREFIX = "blob" +TEST_DIRECTORY_PREFIX = "dir" +TEST_FILE_PREFIX = "file" LARGE_FILE_SIZE = 64 * 1024 + 5 -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;;;' \ - 'S-1-5-21-397955417-626881126-188441444-3053964)' +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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)" +) TEST_INTENT = "backup" # ------------------------------------------------------------------------------ @@ -59,8 +66,8 @@ def _setup(self, storage_account_name, storage_account_key, rmt_account=None, rm # the tests would take too long to execute self.fsc = ShareServiceClient(url, credential=credential, max_range_size=4 * 1024) self.bsc = BlobServiceClient(blob_url, credential=credential) - self.share_name = self.get_resource_name('utshare') - self.source_container_name = self.get_resource_name('sourceshare') + self.share_name = self.get_resource_name("utshare") + self.source_container_name = self.get_resource_name("sourceshare") if self.is_live: try: self.fsc.create_share(self.share_name) @@ -94,7 +101,7 @@ def _create_source_blob(self): except: pass blob_client = self.bsc.get_blob_client(self.source_container_name, self.get_resource_name(TEST_BLOB_PREFIX)) - blob_client.upload_blob(b'abcdefghijklmnop' * 32, overwrite=True) + blob_client.upload_blob(b"abcdefghijklmnop" * 32, overwrite=True) return blob_client def _create_empty_file(self, file_name=None, file_size=2048): @@ -111,7 +118,7 @@ def _get_file_client(self): return file_client def _create_remote_share(self): - self.remote_share_name = self.get_resource_name('remoteshare') + self.remote_share_name = self.get_resource_name("remoteshare") remote_share = self.fsc2.get_share_client(self.remote_share_name) try: remote_share.create_share() @@ -121,7 +128,7 @@ def _create_remote_share(self): def _create_remote_file(self, file_data=None): if not file_data: - file_data = b'12345678' * 1024 + file_data = b"12345678" * 1024 source_file_name = self._get_file_reference() remote_share = self.fsc2.get_share_client(self.remote_share_name) remote_file = remote_share.get_file_client(source_file_name) @@ -133,13 +140,13 @@ def _wait_for_async_copy(self, share_name, file_path): share_client = self.fsc.get_share_client(share_name) file_client = share_client.get_file_client(file_path) properties = file_client.get_file_properties() - while properties.copy.status != 'success': + while properties.copy.status != "success": count = count + 1 if count > 10: - self.fail('Timed out waiting for async copy to complete.') + self.fail("Timed out waiting for async copy to complete.") self.sleep(6) properties = file_client.get_file_properties() - assert properties.copy.status == 'success' + assert properties.copy.status == "success" def assertFileEqual(self, file_client, expected_data): actual_data = file_client.download_file().readall() @@ -171,7 +178,7 @@ def test_make_file_url(self, **kwargs): res = file_client.url # Assert - assert res == ('https://' + storage_account_name + '.file.core.windows.net/vhds/vhd_dir/my.vhd') + assert res == ("https://" + storage_account_name + ".file.core.windows.net/vhds/vhd_dir/my.vhd") @FileSharePreparer() @recorded_by_proxy @@ -187,7 +194,7 @@ def test_make_file_url_no_directory(self, **kwargs): res = file_client.url # Assert - assert res == ('https://' + storage_account_name + '.file.core.windows.net/vhds/my.vhd') + assert res == ("https://" + storage_account_name + ".file.core.windows.net/vhds/my.vhd") @FileSharePreparer() @recorded_by_proxy @@ -196,7 +203,7 @@ def test_make_file_url_with_protocol(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - url = self.account_url(storage_account_name, "file").replace('https', 'http') + url = self.account_url(storage_account_name, "file").replace("https", "http") fsc = ShareServiceClient(url, credential=storage_account_key) share = fsc.get_share_client("vhds") file_client = share.get_file_client("vhd_dir/my.vhd") @@ -205,7 +212,7 @@ def test_make_file_url_with_protocol(self, **kwargs): res = file_client.url # Assert - assert res == ('http://' + storage_account_name + '.file.core.windows.net/vhds/vhd_dir/my.vhd') + assert res == ("http://" + storage_account_name + ".file.core.windows.net/vhds/vhd_dir/my.vhd") @FileSharePreparer() @recorded_by_proxy @@ -215,19 +222,19 @@ 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", file_path="vhd_dir/my.vhd", - credential=sas + credential=sas, ) # Act res = file_client.url # Assert - assert res == ('https://' + storage_account_name + '.file.core.windows.net/vhds/vhd_dir/my.vhd{}'.format(sas)) + assert res == ("https://" + storage_account_name + ".file.core.windows.net/vhds/vhd_dir/my.vhd{}".format(sas)) @FileSharePreparer() @recorded_by_proxy @@ -241,7 +248,8 @@ def test_exists(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act / Assert assert not file_client.exists() @@ -261,7 +269,8 @@ def test_create_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act resp = file_client.create_file(1024, file_attributes="hidden") @@ -272,8 +281,8 @@ def test_create_file(self, **kwargs): assert props.lease is not None assert props.lease.state is not None assert props.lease.status is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] @FileSharePreparer() @recorded_by_proxy @@ -289,7 +298,8 @@ def test_create_file_with_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act resp = file_client.create_file(1024) @@ -300,8 +310,8 @@ def test_create_file_with_oauth(self, **kwargs): assert props.lease is not None assert props.lease.state is not None assert props.lease.status is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] @FileSharePreparer() @recorded_by_proxy @@ -333,9 +343,10 @@ def test_create_file_with_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) # Act resp = file_client.create_file(1024) @@ -346,9 +357,9 @@ def test_create_file_with_trailing_dot(self, **kwargs): assert props.lease is not None assert props.lease.state is not None assert props.lease.status is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] - assert props.name == file_name + '.' + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy @@ -361,9 +372,10 @@ def test_create_file_with_trailing_dot_false(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=False) + allow_trailing_dot=False, + ) # Act resp = file_client.create_file(1024) @@ -372,9 +384,10 @@ def test_create_file_with_trailing_dot_false(self, **kwargs): file_client_dotted = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=False) + allow_trailing_dot=False, + ) # create file client without dot file_client_no_dot = ShareFileClient( @@ -382,17 +395,18 @@ def test_create_file_with_trailing_dot_false(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - allow_trailing_dot=False) + allow_trailing_dot=False, + ) props = file_client.get_file_properties() props_dotted = file_client_dotted.get_file_properties() props_no_dot = file_client_no_dot.get_file_properties() # Assert - assert props.name == file_name + '.' - assert props.path == file_name + '.' - assert props_dotted.name == file_name + '.' - assert props_dotted.path == file_name + '.' + assert props.name == file_name + "." + assert props.path == file_name + "." + assert props_dotted.name == file_name + "." + assert props_dotted.path == file_name + "." assert props_no_dot.name == file_name assert props_no_dot.path == file_name @@ -403,13 +417,14 @@ def test_create_file_with_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act resp = file_client.create_file(1024, metadata=metadata) @@ -417,8 +432,8 @@ def test_create_file_with_metadata(self, **kwargs): # Assert props = file_client.get_file_properties() assert props is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] assert props.metadata == metadata @FileSharePreparer() @@ -428,14 +443,15 @@ def test_create_file_with_metadata_with_trailing_dot(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) # Act resp = file_client.create_file(1024, metadata=metadata) @@ -443,10 +459,10 @@ def test_create_file_with_metadata_with_trailing_dot(self, **kwargs): # Assert props = file_client.get_file_properties() assert props is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] assert props.metadata == metadata - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy @@ -482,7 +498,7 @@ def test_create_file_with_lease(self, **kwargs): file_client = self._get_file_client() file_client.create_file(1024) - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") resp = file_client.create_file(1024, lease=lease) assert resp is not None @@ -507,10 +523,11 @@ def test_create_file_with_lease_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) file_client.create_file(1024) - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") resp = file_client.create_file(1024, lease=lease) assert resp is not None @@ -531,9 +548,9 @@ def test_create_file_with_changed_lease(self, **kwargs): file_client = self._get_file_client() file_client.create_file(1024) - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") old_lease_id = lease.id - lease.change('44444444-3333-2222-1111-000000000000') + lease.change("44444444-3333-2222-1111-000000000000") # use the old lease id to create file will throw exception. with pytest.raises(HttpResponseError): @@ -558,12 +575,13 @@ def test_create_file_with_changed_lease_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) file_client.create_file(1024) - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") old_lease_id = lease.id - lease.change('44444444-3333-2222-1111-000000000000') + lease.change("44444444-3333-2222-1111-000000000000") # use the old lease id to create file will throw exception. with pytest.raises(HttpResponseError): @@ -585,14 +603,15 @@ def test_lease_operations_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) file_client.create_file(1024) - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") old_lease_id = lease.id - lease.change('44444444-3333-2222-1111-000000000000') + lease.change("44444444-3333-2222-1111-000000000000") # use the old lease id to create file will throw exception. with pytest.raises(HttpResponseError): @@ -610,7 +629,7 @@ def test_lease_operations_trailing_dot(self, **kwargs): # Assert assert resp is not None - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy @@ -650,7 +669,8 @@ def test_create_file_set_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, + ) file_properties = file_client.get_file_properties() # Assert @@ -658,8 +678,8 @@ def test_create_file_set_smb_properties(self, **kwargs): assert file_creation_time == file_properties.creation_time assert file_last_write_time == file_properties.last_write_time assert file_change_time == file_properties.change_time - assert 'ReadOnly' in file_properties.file_attributes - assert 'Archive' in file_properties.file_attributes + assert "ReadOnly" in file_properties.file_attributes + assert "Archive" in file_properties.file_attributes @FileSharePreparer() @recorded_by_proxy @@ -688,7 +708,8 @@ def test_file_not_exists(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path="missingdir/" + file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act with pytest.raises(ResourceNotFoundError): @@ -714,7 +735,8 @@ def test_file_exists_with_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) props = snapshot_client.get_file_properties() # Assert @@ -765,7 +787,8 @@ def test_file_not_exists_with_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) # Assert with pytest.raises(ResourceNotFoundError): @@ -795,7 +818,7 @@ def test_resize_file_with_lease(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_client = self._create_file() - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act with pytest.raises(HttpResponseError): @@ -816,9 +839,7 @@ def test_set_file_properties(self, **kwargs): file_client = self._create_file() # Act - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") resp = file_client.set_http_headers(content_settings=content_settings) # Assert @@ -852,14 +873,10 @@ def test_set_datetime_all_ms_precision(self, **kwargs): ] # Act / Assert - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") for date1, date2 in zip(date_times[::2], date_times[1::2]): file_client.set_http_headers( - content_settings=content_settings, - file_creation_time=date1, - file_last_write_time=date2 + content_settings=content_settings, file_creation_time=date1, file_last_write_time=date2 ) @FileSharePreparer() @@ -873,15 +890,14 @@ def test_set_file_properties_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) file_client.create_file(1024) # Act - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") resp = file_client.set_http_headers(content_settings=content_settings) # Assert @@ -891,7 +907,7 @@ def test_set_file_properties_trailing_dot(self, **kwargs): assert properties.last_write_time is not None assert properties.creation_time is not None assert properties.permission_key is not None - assert properties.name == file_name + '.' + assert properties.name == file_name + "." @FileSharePreparer() @recorded_by_proxy @@ -903,9 +919,7 @@ def test_set_file_properties_with_file_permission(self, **kwargs): file_client = self._create_file() properties_on_creation = file_client.get_file_properties() - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") ntfs_attributes = NTFSAttributes(archive=True, temporary=True) last_write_time = properties_on_creation.last_write_time + timedelta(hours=3) @@ -918,7 +932,7 @@ def test_set_file_properties_with_file_permission(self, **kwargs): file_attributes=ntfs_attributes, file_last_write_time=last_write_time, file_creation_time=creation_time, - file_change_time=change_time + file_change_time=change_time, ) # Assert @@ -945,11 +959,12 @@ def test_set_file_properties_with_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act file_client.create_file(1024) - content_settings = ContentSettings(content_language='spanish', content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") resp = file_client.set_http_headers(content_settings=content_settings) # Assert @@ -990,7 +1005,8 @@ def test_get_file_properties_with_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act resp = file_client.create_file(1024) @@ -1011,9 +1027,10 @@ def test_get_file_properties_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) resp = file_client.create_file(1024) # Ensure allow_trailing_dot=True is enforced properly by attempting to construct without trailing dot @@ -1021,7 +1038,8 @@ def test_get_file_properties_trailing_dot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) with pytest.raises(HttpResponseError): file_client_no_dot.get_file_properties() @@ -1039,11 +1057,11 @@ def test_get_file_properties_with_invalid_lease_fails(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_client = self._create_file() - file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act with pytest.raises(HttpResponseError): - file_client.get_file_properties(lease='44444444-3333-2222-1111-000000000000') + file_client.get_file_properties(lease="44444444-3333-2222-1111-000000000000") # get properties on a leased file will succeed properties = file_client.get_file_properties() @@ -1075,7 +1093,8 @@ def test_get_file_properties_with_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) snapshot_props = snapshot_client.get_file_properties() # Assert @@ -1102,7 +1121,8 @@ def test_get_file_metadata_with_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) metadata2 = {"test100": "foo100", "test200": "bar200"} file_client.set_file_metadata(metadata2) @@ -1127,7 +1147,8 @@ def test_get_file_properties_with_non_existing_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act with pytest.raises(ResourceNotFoundError): @@ -1158,7 +1179,7 @@ def test_set_file_metadata_with_upper_case(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42', 'UP': 'UPval'} + metadata = {"hello": "world", "number": "42", "UP": "UPval"} file_client = self._create_file() # Act @@ -1167,10 +1188,10 @@ def test_set_file_metadata_with_upper_case(self, **kwargs): # Assert md = file_client.get_file_properties().metadata assert 3 == len(md) - assert md['hello'] == 'world' - assert md['number'] == '42' - assert md['UP'] == 'UPval' - assert not 'up' in md + assert md["hello"] == "world" + assert md["number"] == "42" + assert md["UP"] == "UPval" + assert not "up" in md @FileSharePreparer() @recorded_by_proxy @@ -1186,8 +1207,9 @@ def test_set_file_metadata_with_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) - metadata = {'hello': 'world', 'number': '42', 'UP': 'UPval'} + token_intent=TEST_INTENT, + ) + metadata = {"hello": "world", "number": "42", "UP": "UPval"} # Act file_client.create_file(1024) @@ -1196,10 +1218,10 @@ def test_set_file_metadata_with_oauth(self, **kwargs): # Assert md = file_client.get_file_properties().metadata assert 3 == len(md) - assert md['hello'] == 'world' - assert md['number'] == '42' - assert md['UP'] == 'UPval' - assert not 'up' in md + assert md["hello"] == "world" + assert md["number"] == "42" + assert md["UP"] == "UPval" + assert not "up" in md @FileSharePreparer() @recorded_by_proxy @@ -1209,7 +1231,7 @@ def test_break_lease_with_broken_period_fails(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_client = self._create_file() - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Assert assert lease is not None @@ -1223,10 +1245,10 @@ def test_set_file_metadata_with_broken_lease(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42', 'UP': 'UPval'} + metadata = {"hello": "world", "number": "42", "UP": "UPval"} file_client = self._create_file() - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") with pytest.raises(HttpResponseError): file_client.set_file_metadata(metadata) @@ -1234,12 +1256,12 @@ def test_set_file_metadata_with_broken_lease(self, **kwargs): lease.break_lease() # lease is broken, set metadata doesn't require a lease - file_client.set_file_metadata({'hello': 'world'}) + file_client.set_file_metadata({"hello": "world"}) # Act md = file_client.get_file_properties().metadata # Assert assert 1 == len(md) - assert md['hello'] == 'world' + assert md["hello"] == "world" # Act file_client.acquire_lease(lease_id=lease_id_to_be_broken) @@ -1248,10 +1270,10 @@ def test_set_file_metadata_with_broken_lease(self, **kwargs): # Assert md = file_client.get_file_properties().metadata assert 3 == len(md) - assert md['hello'] == 'world' - assert md['number'] == '42' - assert md['UP'] == 'UPval' - assert not 'up' in md + assert md["hello"] == "world" + assert md["number"] == "42" + assert md["UP"] == "UPval" + assert not "up" in md @FileSharePreparer() @recorded_by_proxy @@ -1283,7 +1305,8 @@ def test_delete_file_with_existing_file_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act file_client.create_file(1024) @@ -1304,9 +1327,10 @@ def test_delete_file_with_existing_file_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) resp = file_client.create_file(1024) # Act @@ -1328,7 +1352,8 @@ def test_delete_file_with_non_existing_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act with pytest.raises(ResourceNotFoundError): @@ -1346,7 +1371,7 @@ def test_update_range(self, **kwargs): file_client = self._create_file() # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 file_client.upload_range(data, offset=0, length=512) # Assert @@ -1366,13 +1391,14 @@ def test_update_range_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) file_client.upload_file(self.short_byte_data) # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 file_client.upload_range(data, offset=0, length=512) props = file_client.get_file_properties() @@ -1381,7 +1407,7 @@ def test_update_range_trailing_dot(self, **kwargs): assert len(data) == 512 assert data == content[:512] assert self.short_byte_data[512:] == content[512:] - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy @@ -1391,10 +1417,10 @@ def test_update_range_with_lease(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_client = self._create_file() - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 with pytest.raises(HttpResponseError): file_client.upload_range(data, offset=0, length=512) @@ -1416,7 +1442,7 @@ def test_update_range_with_md5(self, **kwargs): file_client = self._create_file() # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 file_client.upload_range(data, offset=0, length=512, validate_content=True) # Assert @@ -1432,13 +1458,14 @@ def test_update_range_with_oauth(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1', + file_path="file1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act file_client.create_file(1024) - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 file_client.upload_range(data, offset=0, length=512) @FileSharePreparer() @@ -1452,7 +1479,7 @@ def test_update_range_last_written_mode_now(self, **kwargs): current_last_write_time = file_client.get_file_properties().last_write_time # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 file_client.upload_range(data, offset=0, length=512, file_last_write_mode="Now") # Assert @@ -1470,7 +1497,7 @@ def test_update_range_last_written_mode_preserve(self, **kwargs): current_last_write_time = file_client.get_file_properties().last_write_time # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 file_client.upload_range(data, offset=0, length=512, file_last_write_mode="Preserve") # Assert @@ -1484,10 +1511,10 @@ def test_update_range_from_file_url_when_source_file_does_not_have_enough_bytes( storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file_name = 'testfile1' + source_file_name = "testfile1" source_file_client = self._create_file(source_file_name) - destination_file_name = 'filetoupdate' + destination_file_name = "filetoupdate" destination_file_client = self._create_file(destination_file_name) # generate SAS for the source file @@ -1498,10 +1525,10 @@ def test_update_range_from_file_url_when_source_file_does_not_have_enough_bytes( source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1) + expiry=datetime.utcnow() + timedelta(hours=1), ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act with pytest.raises(HttpResponseError): @@ -1515,12 +1542,12 @@ def test_update_range_from_file_url(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file_name = 'testfile' + source_file_name = "testfile" source_file_client = self._create_file(file_name=source_file_name) - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 resp = source_file_client.upload_range(data, offset=0, length=512) - destination_file_name = 'filetoupdate' + destination_file_name = "filetoupdate" destination_file_client = self._create_empty_file(file_name=destination_file_name) # generate SAS for the source file @@ -1531,21 +1558,27 @@ def test_update_range_from_file_url(self, **kwargs): source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act - destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0, - source_etag=resp['etag'], - source_match_condition=MatchConditions.IfNotModified) + destination_file_client.upload_range_from_url( + source_file_url, + offset=0, + length=512, + source_offset=0, + source_etag=resp["etag"], + source_match_condition=MatchConditions.IfNotModified, + ) # Assert # To make sure the range of the file is actually updated file_ranges = destination_file_client.get_ranges() file_content = destination_file_client.download_file(offset=0, length=512).readall() assert 1 == len(file_ranges) - assert 0 == file_ranges[0].get('start') - assert 511 == file_ranges[0].get('end') + assert 0 == file_ranges[0].get("start") + assert 511 == file_ranges[0].get("end") assert data == file_content @FileSharePreparer() @@ -1556,15 +1589,18 @@ 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_name = "filetoupdate" destination_file_client = self._create_empty_file(file_name=destination_file_name) with pytest.raises(HttpResponseError): destination_file_client.upload_range_from_url(source_blob_client.url, offset=0, length=512, source_offset=0) - destination_file_client.upload_range_from_url(source_blob_client.url, offset=0, length=512, source_offset=0, - source_authorization=token) + destination_file_client.upload_range_from_url( + source_blob_client.url, offset=0, length=512, source_offset=0, source_authorization=token + ) @FileSharePreparer() @recorded_by_proxy @@ -1573,14 +1609,14 @@ def test_update_range_from_file_url_with_lease(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file_name = 'testfile' + source_file_name = "testfile" source_file_client = self._create_file(file_name=source_file_name) - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 resp = source_file_client.upload_range(data, offset=0, length=512) - destination_file_name = 'filetoupdate' + destination_file_name = "filetoupdate" destination_file_client = self._create_empty_file(file_name=destination_file_name) - lease = destination_file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = destination_file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # generate SAS for the source file sas_token_for_source_file = self.generate_sas( @@ -1590,27 +1626,38 @@ def test_update_range_from_file_url_with_lease(self, **kwargs): source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act with pytest.raises(HttpResponseError): - destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0, - source_etag=resp['etag'], - source_match_condition=MatchConditions.IfNotModified) + destination_file_client.upload_range_from_url( + source_file_url, + offset=0, + length=512, + source_offset=0, + source_etag=resp["etag"], + source_match_condition=MatchConditions.IfNotModified, + ) - destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0, - source_etag=resp['etag'], - source_match_condition=MatchConditions.IfNotModified, - lease=lease) + destination_file_client.upload_range_from_url( + source_file_url, + offset=0, + length=512, + source_offset=0, + source_etag=resp["etag"], + source_match_condition=MatchConditions.IfNotModified, + lease=lease, + ) # Assert # To make sure the range of the file is actually updated file_ranges = destination_file_client.get_ranges() file_content = destination_file_client.download_file(offset=0, length=512).readall() assert 1 == len(file_ranges) - assert 0 == file_ranges[0].get('start') - assert 511 == file_ranges[0].get('end') + assert 0 == file_ranges[0].get("start") + assert 511 == file_ranges[0].get("end") assert data == file_content @FileSharePreparer() @@ -1620,14 +1667,14 @@ def test_update_big_range_from_file_url(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file_name = 'testfile1' + source_file_name = "testfile1" end = 1048575 source_file_client = self._create_empty_file(file_name=source_file_name, file_size=1024 * 1024) - data = b'abcdefghijklmnop' * 65536 - source_file_client.upload_range(data, offset=0, length=end+1) + data = b"abcdefghijklmnop" * 65536 + source_file_client.upload_range(data, offset=0, length=end + 1) - destination_file_name = 'filetoupdate1' + destination_file_name = "filetoupdate1" destination_file_client = self._create_empty_file(file_name=destination_file_name, file_size=1024 * 1024) # generate SAS for the source file @@ -1638,20 +1685,21 @@ def test_update_big_range_from_file_url(self, **kwargs): source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act - destination_file_client.upload_range_from_url(source_file_url, offset=0, length=end+1, source_offset=0) + destination_file_client.upload_range_from_url(source_file_url, offset=0, length=end + 1, source_offset=0) # Assert # To make sure the range of the file is actually updated file_ranges = destination_file_client.get_ranges() file_content = destination_file_client.download_file(offset=0, length=end + 1).readall() assert 1 == len(file_ranges) - assert 0 == file_ranges[0].get('start') - assert end == file_ranges[0].get('end') + assert 0 == file_ranges[0].get("start") + assert end == file_ranges[0].get("end") assert data == file_content @FileSharePreparer() @@ -1661,11 +1709,11 @@ def test_update_range_from_file_url_last_written_mode_now(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file_client = self._create_file(file_name='testfile') - data = b'abcdefghijklmnop' * 32 + source_file_client = self._create_file(file_name="testfile") + data = b"abcdefghijklmnop" * 32 source_file_client.upload_range(data, offset=0, length=512) - destination_file_client = self._create_empty_file(file_name='filetoupdate') + destination_file_client = self._create_empty_file(file_name="filetoupdate") current_last_write_time = destination_file_client.get_file_properties().last_write_time # generate SAS for the source file @@ -1676,13 +1724,15 @@ def test_update_range_from_file_url_last_written_mode_now(self, **kwargs): source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act - destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0, - file_last_write_mode="Now") + destination_file_client.upload_range_from_url( + source_file_url, offset=0, length=512, source_offset=0, file_last_write_mode="Now" + ) # Assert new_last_write_time = destination_file_client.get_file_properties().last_write_time @@ -1695,11 +1745,11 @@ def test_update_range_from_file_url_last_written_mode_preserve(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file_client = self._create_file(file_name='testfile') - data = b'abcdefghijklmnop' * 32 + source_file_client = self._create_file(file_name="testfile") + data = b"abcdefghijklmnop" * 32 source_file_client.upload_range(data, offset=0, length=512) - destination_file_client = self._create_empty_file(file_name='filetoupdate') + destination_file_client = self._create_empty_file(file_name="filetoupdate") current_last_write_time = destination_file_client.get_file_properties().last_write_time # generate SAS for the source file @@ -1710,13 +1760,15 @@ def test_update_range_from_file_url_last_written_mode_preserve(self, **kwargs): source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act - destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0, - file_last_write_mode="Preserve") + destination_file_client.upload_range_from_url( + source_file_url, offset=0, length=512, source_offset=0, file_last_write_mode="Preserve" + ) # Assert new_last_write_time = destination_file_client.get_file_properties().last_write_time @@ -1736,7 +1788,7 @@ def test_clear_range(self, **kwargs): # Assert content = file_client.download_file().readall() - assert b'\x00' * 512 == content[:512] + assert b"\x00" * 512 == content[:512] assert self.short_byte_data[512:] == content[512:] @FileSharePreparer() @@ -1750,9 +1802,10 @@ def test_clear_range_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) file_client.upload_file(self.short_byte_data) # Act @@ -1761,9 +1814,9 @@ def test_clear_range_trailing_dot(self, **kwargs): # Assert content = file_client.download_file().readall() - assert b'\x00' * 512 == content[:512] + assert b"\x00" * 512 == content[:512] assert self.short_byte_data[512:] == content[512:] - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy @@ -1775,10 +1828,10 @@ 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') + encoded = data.encode("utf-8") # Assert content = file_client.download_file().readall() @@ -1799,7 +1852,8 @@ def test_list_ranges_none(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.create_file(1024) # Act @@ -1820,9 +1874,10 @@ def test_list_ranges_none_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) file_client.create_file(1024) # Act @@ -1832,7 +1887,7 @@ def test_list_ranges_none_trailing_dot(self, **kwargs): # Assert assert ranges is not None assert len(ranges) == 0 - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy @@ -1846,14 +1901,15 @@ def test_list_ranges_none_with_invalid_lease_fails(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.create_file(1024) - file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act with pytest.raises(HttpResponseError): - file_client.get_ranges(lease='44444444-3333-2222-1111-000000000000') + file_client.get_ranges(lease="44444444-3333-2222-1111-000000000000") # Get ranges on a leased file will succeed without provide the lease ranges = file_client.get_ranges() @@ -1874,7 +1930,8 @@ def test_list_ranges_diff(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.create_file(2048) share_client = self.fsc.get_share_client(self.share_name) @@ -1886,7 +1943,7 @@ def test_list_ranges_diff(self, **kwargs): file_client.clear_range(offset=512, length=512) ranges1, cleared1 = file_client.get_ranges_diff(previous_sharesnapshot=snapshot1) - ranges2, cleared2 = file_client.get_ranges_diff(previous_sharesnapshot=snapshot2['snapshot']) + ranges2, cleared2 = file_client.get_ranges_diff(previous_sharesnapshot=snapshot2["snapshot"]) # Assert assert ranges1 is not None @@ -1894,20 +1951,20 @@ def test_list_ranges_diff(self, **kwargs): assert len(ranges1) == 2 assert isinstance(cleared1, list) assert len(cleared1) == 1 - assert ranges1[0]['start'] == 0 - assert ranges1[0]['end'] == 511 - assert cleared1[0]['start'] == 512 - assert cleared1[0]['end'] == 1023 - assert ranges1[1]['start'] == 1024 - assert ranges1[1]['end'] == 1535 + assert ranges1[0]["start"] == 0 + assert ranges1[0]["end"] == 511 + assert cleared1[0]["start"] == 512 + assert cleared1[0]["end"] == 1023 + assert ranges1[1]["start"] == 1024 + assert ranges1[1]["end"] == 1535 assert ranges2 is not None assert isinstance(ranges2, list) assert len(ranges2) == 0 assert isinstance(cleared2, list) assert len(cleared2) == 1 - assert cleared2[0]['start'] == 512 - assert cleared2[0]['end'] == 1023 + assert cleared2[0]["start"] == 512 + assert cleared2[0]["end"] == 1023 @FileSharePreparer() @recorded_by_proxy @@ -1923,7 +1980,8 @@ def test_list_ranges_diff_with_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) file_client.create_file(2048) share_client = self.fsc.get_share_client(self.share_name) @@ -1935,7 +1993,7 @@ def test_list_ranges_diff_with_oauth(self, **kwargs): file_client.clear_range(offset=512, length=512) ranges1, cleared1 = file_client.get_ranges_diff(previous_sharesnapshot=snapshot1) - ranges2, cleared2 = file_client.get_ranges_diff(previous_sharesnapshot=snapshot2['snapshot']) + ranges2, cleared2 = file_client.get_ranges_diff(previous_sharesnapshot=snapshot2["snapshot"]) # Assert assert ranges1 is not None @@ -1943,20 +2001,20 @@ def test_list_ranges_diff_with_oauth(self, **kwargs): assert len(ranges1) == 2 assert isinstance(cleared1, list) assert len(cleared1) == 1 - assert ranges1[0]['start'] == 0 - assert ranges1[0]['end'] == 511 - assert cleared1[0]['start'] == 512 - assert cleared1[0]['end'] == 1023 - assert ranges1[1]['start'] == 1024 - assert ranges1[1]['end'] == 1535 + assert ranges1[0]["start"] == 0 + assert ranges1[0]["end"] == 511 + assert cleared1[0]["start"] == 512 + assert cleared1[0]["end"] == 1023 + assert ranges1[1]["start"] == 1024 + assert ranges1[1]["end"] == 1535 assert ranges2 is not None assert isinstance(ranges2, list) assert len(ranges2) == 0 assert isinstance(cleared2, list) assert len(cleared2) == 1 - assert cleared2[0]['start'] == 512 - assert cleared2[0]['end'] == 1023 + assert cleared2[0]["start"] == 512 + assert cleared2[0]["end"] == 1023 @FileSharePreparer() @recorded_by_proxy @@ -1969,9 +2027,10 @@ def test_list_ranges_diff_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) file_client.create_file(2048) share_client = self.fsc.get_share_client(self.share_name) @@ -1983,7 +2042,7 @@ def test_list_ranges_diff_trailing_dot(self, **kwargs): file_client.clear_range(offset=512, length=512) ranges1, cleared1 = file_client.get_ranges_diff(previous_sharesnapshot=snapshot1) - ranges2, cleared2 = file_client.get_ranges_diff(previous_sharesnapshot=snapshot2['snapshot']) + ranges2, cleared2 = file_client.get_ranges_diff(previous_sharesnapshot=snapshot2["snapshot"]) props = file_client.get_file_properties() # Assert @@ -1992,22 +2051,22 @@ def test_list_ranges_diff_trailing_dot(self, **kwargs): assert len(ranges1) == 2 assert isinstance(cleared1, list) assert len(cleared1) == 1 - assert ranges1[0]['start'] == 0 - assert ranges1[0]['end'] == 511 - assert cleared1[0]['start'] == 512 - assert cleared1[0]['end'] == 1023 - assert ranges1[1]['start'] == 1024 - assert ranges1[1]['end'] == 1535 + assert ranges1[0]["start"] == 0 + assert ranges1[0]["end"] == 511 + assert cleared1[0]["start"] == 512 + assert cleared1[0]["end"] == 1023 + assert ranges1[1]["start"] == 1024 + assert ranges1[1]["end"] == 1535 assert ranges2 is not None assert isinstance(ranges2, list) assert len(ranges2) == 0 assert isinstance(cleared2, list) assert len(cleared2) == 1 - assert cleared2[0]['start'] == 512 - assert cleared2[0]['end'] == 1023 + assert cleared2[0]["start"] == 512 + assert cleared2[0]["end"] == 1023 - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy @@ -2021,7 +2080,8 @@ def test_list_ranges_diff_support_rename(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.create_file(2048) share_client = self.fsc.get_share_client(self.share_name) @@ -2032,7 +2092,7 @@ def test_list_ranges_diff_support_rename(self, **kwargs): previous_snapshot = share_client.create_snapshot() file_client.clear_range(offset=512, length=512) file_client.upload_range(data2, offset=512, length=512) - file_client = file_client.rename_file(file_name + 'renamed') + file_client = file_client.rename_file(file_name + "renamed") # Assert with pytest.raises(ResourceExistsError): @@ -2045,8 +2105,8 @@ def test_list_ranges_diff_support_rename(self, **kwargs): assert len(ranges) == 1 assert isinstance(cleared, list) assert len(cleared) == 0 - assert ranges[0]['start'] == 512 - assert ranges[0]['end'] == 1023 + assert ranges[0]["start"] == 512 + assert ranges[0]["end"] == 1023 @FileSharePreparer() @recorded_by_proxy @@ -2060,10 +2120,11 @@ def test_list_ranges_2(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.create_file(2048) - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 resp1 = file_client.upload_range(data, offset=0, length=512) resp2 = file_client.upload_range(data, offset=1024, length=512) @@ -2073,10 +2134,10 @@ def test_list_ranges_2(self, **kwargs): # Assert assert ranges is not None assert len(ranges) == 2 - assert ranges[0]['start'] == 0 - assert ranges[0]['end'] == 511 - assert ranges[1]['start'] == 1024 - assert ranges[1]['end'] == 1535 + assert ranges[0]["start"] == 0 + assert ranges[0]["end"] == 511 + assert ranges[1]["start"] == 1024 + assert ranges[1]["end"] == 1535 @FileSharePreparer() @recorded_by_proxy @@ -2090,7 +2151,8 @@ def test_list_ranges_none_from_snapshot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.create_file(1024) share_client = self.fsc.get_share_client(self.share_name) @@ -2100,7 +2162,8 @@ def test_list_ranges_none_from_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.delete_file() @@ -2125,7 +2188,8 @@ def test_list_ranges_none_from_snapshot_with_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) file_client.create_file(1024) share_client = self.fsc.get_share_client(self.share_name) @@ -2136,7 +2200,8 @@ def test_list_ranges_none_from_snapshot_with_oauth(self, **kwargs): file_path=file_client.file_name, snapshot=snapshot, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) file_client.delete_file() @@ -2159,9 +2224,10 @@ def test_list_ranges_2_from_snapshot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.create_file(2048) - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 resp1 = file_client.upload_range(data, offset=0, length=512) resp2 = file_client.upload_range(data, offset=1024, length=512) @@ -2172,7 +2238,8 @@ def test_list_ranges_2_from_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.delete_file() @@ -2182,10 +2249,10 @@ def test_list_ranges_2_from_snapshot(self, **kwargs): # Assert assert ranges is not None assert len(ranges) == 2 - assert ranges[0]['start'] == 0 - assert ranges[0]['end'] == 511 - assert ranges[1]['start'] == 1024 - assert ranges[1]['end'] == 1535 + assert ranges[0]["start"] == 0 + assert ranges[0]["end"] == 511 + assert ranges[1]["start"] == 1024 + assert ranges[1]["end"] == 1535 @FileSharePreparer() @recorded_by_proxy @@ -2198,16 +2265,17 @@ def test_copy_file_with_existing_file(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) # Act copy = file_client.start_copy_from_url(source_client.url) # Assert assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = file_client.download_file().readall() assert copy_file == self.short_byte_data @@ -2224,17 +2292,18 @@ def test_copy_file_with_existing_file_oauth(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', + file_path="file1copy", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act copy = file_client.start_copy_from_url(source_client.url) # Assert assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = file_client.download_file().readall() assert copy_file == self.short_byte_data @@ -2250,26 +2319,28 @@ def test_copy_file_with_existing_file_trailing_dot(self, **kwargs): source_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) source_client.upload_file(self.short_byte_data) dest_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy.', + file_path="file1copy.", credential=storage_account_key, allow_trailing_dot=True, - allow_source_trailing_dot=True) + allow_source_trailing_dot=True, + ) # Act copy = dest_client.start_copy_from_url(source_client.url) # Assert assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = dest_client.download_file().readall() assert copy_file == self.short_byte_data @@ -2285,10 +2356,11 @@ def test_copy_existing_file_with_lease(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) file_client.create_file(1024) - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act with pytest.raises(HttpResponseError): @@ -2298,8 +2370,8 @@ def test_copy_existing_file_with_lease(self, **kwargs): # Assert assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = file_client.download_file().readall() assert copy_file == self.short_byte_data @@ -2315,8 +2387,9 @@ def test_copy_file_ignore_readonly(self, **kwargs): dest_file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) file_attributes = NTFSAttributes(read_only=True) dest_file.create_file(1024, file_attributes=file_attributes) @@ -2329,8 +2402,8 @@ def test_copy_file_ignore_readonly(self, **kwargs): # Assert assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = dest_file.download_file().readall() assert copy_file == self.short_byte_data @@ -2346,8 +2419,9 @@ def test_copy_file_with_specifying_acl_copy_behavior_attributes(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) source_props = source_client.get_file_properties() file_creation_time = source_props.creation_time - timedelta(hours=1) @@ -2369,15 +2443,15 @@ def test_copy_file_with_specifying_acl_copy_behavior_attributes(self, **kwargs): # Assert dest_prop = file_client.get_file_properties() # to make sure the attributes are the same as the set ones - assert file_creation_time == dest_prop['creation_time'] - assert file_last_write_time == dest_prop['last_write_time'] - assert file_change_time == dest_prop['change_time'] - assert 'Temporary' in dest_prop['file_attributes'] - assert 'NoScrubData' in dest_prop['file_attributes'] + assert file_creation_time == dest_prop["creation_time"] + assert file_last_write_time == dest_prop["last_write_time"] + assert file_change_time == dest_prop["change_time"] + assert "Temporary" in dest_prop["file_attributes"] + assert "NoScrubData" in dest_prop["file_attributes"] assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = file_client.download_file().readall() assert copy_file == self.short_byte_data @@ -2395,23 +2469,21 @@ def test_copy_file_with_specifying_acl_and_attributes_from_source(self, **kwargs file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) # Act - copy = file_client.start_copy_from_url( - source_client.url, - permission_key='source' - ) + copy = file_client.start_copy_from_url(source_client.url, permission_key="source") # Assert dest_prop = file_client.get_file_properties() # to make sure the acl is copied from source - assert source_prop['permission_key'] == dest_prop['permission_key'] + assert source_prop["permission_key"] == dest_prop["permission_key"] assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = file_client.download_file().readall() assert copy_file == self.short_byte_data @@ -2424,17 +2496,20 @@ 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) + self._setup( + storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key + ) self._create_remote_share() source_file = self._create_remote_file() # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, - credential=storage_account_key) + credential=storage_account_key, + ) with pytest.raises(HttpResponseError) as e: file_client.start_copy_from_url(source_file.url) @@ -2448,8 +2523,10 @@ 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) - data = b'12345678' * 1024 + self._setup( + storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key + ) + data = b"12345678" * 1024 self._create_remote_share() source_file = self._create_remote_file(file_data=data) sas_token = self.generate_sas( @@ -2461,19 +2538,20 @@ def test_copy_file_async_private_file_with_sas(self, **kwargs): permission=FileSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), ) - source_url = source_file.url + '?' + sas_token + source_url = source_file.url + "?" + sas_token # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, - credential=storage_account_key) + credential=storage_account_key, + ) copy_resp = file_client.start_copy_from_url(source_url) # Assert - assert copy_resp['copy_status'] in ['success', 'pending'] + assert copy_resp["copy_status"] in ["success", "pending"] self._wait_for_async_copy(self.share_name, target_file_name) actual_data = file_client.download_file().readall() @@ -2487,8 +2565,10 @@ 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) - data = b'12345678' * 1024 * 1024 + self._setup( + storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key + ) + data = b"12345678" * 1024 * 1024 self._create_remote_share() source_file = self._create_remote_file(file_data=data) sas_token = self.generate_sas( @@ -2500,23 +2580,24 @@ def test_abort_copy_file(self, **kwargs): permission=FileSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), ) - source_url = source_file.url + '?' + sas_token + source_url = source_file.url + "?" + sas_token # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, - credential=storage_account_key) + credential=storage_account_key, + ) copy_resp = file_client.start_copy_from_url(source_url) - assert copy_resp['copy_status'] == 'pending' + assert copy_resp["copy_status"] == "pending" file_client.abort_copy(copy_resp) # Assert target_file = file_client.download_file() - assert target_file.readall() == b'' - assert target_file.properties.copy.status == 'aborted' + assert target_file.readall() == b"" + assert target_file.properties.copy.status == "aborted" @pytest.mark.live_test_only @FileSharePreparer() @@ -2527,9 +2608,10 @@ def test_abort_copy_file_with_oauth(self, **kwargs): secondary_storage_account_key = kwargs.pop("secondary_storage_account_key") token_credential = self.get_credential(ShareServiceClient) - self._setup(storage_account_name, storage_account_key, secondary_storage_account_name, - secondary_storage_account_key) - data = b'12345678' * 1024 * 1024 + self._setup( + storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key + ) + data = b"12345678" * 1024 * 1024 self._create_remote_share() source_file = self._create_remote_file(file_data=data) sas_token = self.generate_sas( @@ -2541,24 +2623,25 @@ def test_abort_copy_file_with_oauth(self, **kwargs): permission=FileSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), ) - source_url = source_file.url + '?' + sas_token + source_url = source_file.url + "?" + sas_token # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) copy_resp = file_client.start_copy_from_url(source_url) - assert copy_resp['copy_status'] == 'pending' + assert copy_resp["copy_status"] == "pending" file_client.abort_copy(copy_resp) # Assert target_file = file_client.download_file() - assert target_file.readall() == b'' - assert target_file.properties.copy.status == 'aborted' + assert target_file.readall() == b"" + assert target_file.properties.copy.status == "aborted" @FileSharePreparer() @recorded_by_proxy @@ -2570,19 +2653,20 @@ def test_abort_copy_file_with_synchronous_copy_fails(self, **kwargs): source_file = self._create_file() # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, - credential=storage_account_key) + credential=storage_account_key, + ) copy_resp = file_client.start_copy_from_url(source_file.url) with pytest.raises(HttpResponseError): file_client.abort_copy(copy_resp) # Assert - assert copy_resp['copy_status'] == 'success' + assert copy_resp["copy_status"] == "success" @FileSharePreparer() @recorded_by_proxy @@ -2591,19 +2675,20 @@ def test_unicode_get_file_unicode_name(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_name = '啊齄丂狛狜' + file_name = "啊齄丂狛狜" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) - file_client.upload_file(b'hello world') + credential=storage_account_key, + ) + file_client.upload_file(b"hello world") # Act content = file_client.download_file().readall() # Assert - assert content == b'hello world' + assert content == b"hello world" @FileSharePreparer() @recorded_by_proxy @@ -2612,28 +2697,29 @@ def test_unicode_get_file_unicode_name_with_lease(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_name = '啊齄丂狛狜' + file_name = "啊齄丂狛狜" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.create_file(1024) - lease = file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") with pytest.raises(HttpResponseError): - file_client.upload_file(b'hello world') + file_client.upload_file(b"hello world") - file_client.upload_file(b'hello world', lease=lease) + file_client.upload_file(b"hello world", lease=lease) # Act # download the file with a wrong lease id will fail with pytest.raises(HttpResponseError): - file_client.upload_file(b'hello world', lease='44444444-3333-2222-1111-000000000000') + file_client.upload_file(b"hello world", lease="44444444-3333-2222-1111-000000000000") content = file_client.download_file(lease=lease).readall() # Assert - assert content == b'hello world' + assert content == b"hello world" @FileSharePreparer() @recorded_by_proxy @@ -2647,10 +2733,11 @@ def test_file_unicode_data(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act - data = u'hello world啊齄丂狛狜'.encode('utf-8') + data = "hello world啊齄丂狛狜".encode("utf-8") file_client.upload_file(data) # Assert @@ -2667,14 +2754,14 @@ 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 content = file_client.download_file().readall() properties = file_client.get_file_properties() assert content == data - assert 'Temporary' in properties.file_attributes + assert "Temporary" in properties.file_attributes @FileSharePreparer() @recorded_by_proxy @@ -2683,7 +2770,7 @@ 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+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==" binary_data = base64.b64decode(base64_data) file_name = self._get_file_reference() @@ -2691,7 +2778,8 @@ def test_unicode_get_file_binary_data(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) file_client.upload_file(binary_data) # Act @@ -2714,20 +2802,22 @@ def test_create_file_from_bytes_with_progress(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act progress = [] + def callback(response): - current = response.context['upload_stream_current'] - total = response.context['data_stream_total'] + current = response.context["upload_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) response = file_client.upload_file(data, max_concurrency=2, raw_response_hook=callback) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert self.assertFileEqual(file_client, data) @@ -2747,13 +2837,14 @@ def test_create_file_from_bytes_with_index(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act response = file_client.upload_file(data[index:], max_concurrency=2) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert self.assertFileEqual(file_client, data[1024:]) @@ -2774,16 +2865,17 @@ def test_create_file_from_bytes_with_index_and_count(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act response = file_client.upload_file(data[index:], length=count, max_concurrency=2) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert - self.assertFileEqual(file_client, data[index:index + count]) + self.assertFileEqual(file_client, data[index : index + count]) @pytest.mark.live_test_only @FileSharePreparer() @@ -2799,7 +2891,8 @@ def test_create_file_from_path(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -2807,8 +2900,8 @@ def test_create_file_from_path(self, **kwargs): temp_file.seek(0) response = file_client.upload_file(temp_file, max_concurrency=2) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert self.assertFileEqual(file_client, data) @@ -2827,13 +2920,15 @@ def test_create_file_from_path_with_progress(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act progress = [] + def callback(response): - current = response.context['upload_stream_current'] - total = response.context['data_stream_total'] + current = response.context["upload_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -2842,8 +2937,8 @@ def callback(response): temp_file.seek(0) response = file_client.upload_file(temp_file, max_concurrency=2, raw_response_hook=callback) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert self.assertFileEqual(file_client, data) @@ -2863,7 +2958,8 @@ def test_create_file_from_stream(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_size = len(data) @@ -2872,8 +2968,8 @@ def test_create_file_from_stream(self, **kwargs): temp_file.seek(0) response = file_client.upload_file(temp_file, max_concurrency=2) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert self.assertFileEqual(file_client, data[:file_size]) @@ -2892,7 +2988,8 @@ def test_create_file_from_stream_non_seekable(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_size = len(data) @@ -2919,13 +3016,15 @@ def test_create_file_from_stream_with_progress(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act progress = [] + def callback(response): - current = response.context['upload_stream_current'] - total = response.context['data_stream_total'] + current = response.context["upload_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -2953,7 +3052,8 @@ def test_create_file_from_stream_truncated(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_size = len(data) - 512 @@ -2979,13 +3079,15 @@ def test_create_file_from_stream_with_progress_truncated(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act progress = [] + def callback(response): - current = response.context['upload_stream_current'] - total = response.context['data_stream_total'] + current = response.context["upload_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -3007,14 +3109,15 @@ 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' - data = text.encode('utf-8') + text = "hello 啊齄丂狛狜 world" + data = text.encode("utf-8") file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_client.upload_file(text) @@ -3030,17 +3133,18 @@ 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' - data = text.encode('utf-16') + text = "hello 啊齄丂狛狜 world" + data = text.encode("utf-16") file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act - file_client.upload_file(text, encoding='UTF-16') + file_client.upload_file(text, encoding="UTF-16") # Assert self.assertFileEqual(file_client, data) @@ -3054,13 +3158,14 @@ def test_create_file_from_text_chunked_upload(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_name = self._get_file_reference() data = self.get_random_text_data(LARGE_FILE_SIZE) - encoded_data = data.encode('utf-8') + encoded_data = data.encode("utf-8") file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_client.upload_file(data) @@ -3082,7 +3187,8 @@ def test_create_file_with_md5_small(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_client.upload_file(data, validate_content=True) @@ -3103,7 +3209,8 @@ def test_create_file_with_md5_large(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_client.upload_file(data, validate_content=True, max_concurrency=2) @@ -3124,9 +3231,10 @@ def test_create_file_progress(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=1024) + max_range_size=1024, + ) - data = b'a' * 5 * 1024 + data = b"a" * 5 * 1024 progress = ProgressTracker(len(data), 1024) # Act @@ -3150,9 +3258,10 @@ def test_create_file_progress_parallel(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=1024) + max_range_size=1024, + ) - data = b'a' * 5 * 1024 + data = b"a" * 5 * 1024 progress = ProgressTracker(len(data), 1024) # Act @@ -3185,7 +3294,8 @@ def test_sas_access_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=token) + credential=token, + ) content = file_client.download_file().readall() # Assert @@ -3196,19 +3306,19 @@ def test_sas_access_file(self, **kwargs): def test_sas_signed_identifier(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - variables = kwargs.pop('variables', {}) + variables = kwargs.pop("variables", {}) self._setup(storage_account_name, storage_account_key) file_client = self._create_file() share_client = self.fsc.get_share_client(self.share_name) access_policy = AccessPolicy() - start_time = self.get_datetime_variable(variables, 'start_time', datetime.utcnow() - timedelta(hours=1)) - expiry_time = self.get_datetime_variable(variables, 'expiry_time', datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(hours=1)) + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) access_policy.start = start_time access_policy.expiry = expiry_time access_policy.permission = FileSasPermissions(read=True) - identifiers = {'testid': access_policy} + identifiers = {"testid": access_policy} share_client.set_share_access_policy(identifiers) token = self.generate_sas( @@ -3217,12 +3327,11 @@ def test_sas_signed_identifier(self, **kwargs): file_client.share_name, file_client.file_path, file_client.credential.account_key, - policy_id='testid') + policy_id="testid", + ) # Act - sas_file = ShareFileClient.from_file_url( - file_client.url, - credential=token) + sas_file = ShareFileClient.from_file_url(file_client.url, credential=token) content = file_client.download_file().readall() @@ -3253,7 +3362,8 @@ def test_account_sas(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=token) + credential=token, + ) response = requests.get(file_client.url) @@ -3283,7 +3393,8 @@ def test_account_sas_credential(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=AzureSasCredential(token)) + credential=AzureSasCredential(token), + ) properties = file_client.get_file_properties() @@ -3296,7 +3407,6 @@ def test_azure_named_key_credential_access(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_client = self._create_file() named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) @@ -3306,7 +3416,8 @@ def test_azure_named_key_credential_access(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=named_key) + credential=named_key, + ) properties = file_client.get_file_properties() @@ -3322,7 +3433,8 @@ def test_account_sas_raises_if_sas_already_in_uri(self, **kwargs): self.account_url(storage_account_name, "file") + "?sig=foo", share_name="foo", file_path="foo", - credential=AzureSasCredential("?foo=bar")) + credential=AzureSasCredential("?foo=bar"), + ) @pytest.mark.live_test_only @FileSharePreparer() @@ -3347,7 +3459,8 @@ def test_shared_read_access_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=token) + credential=token, + ) response = requests.get(file_client.url) # Assert @@ -3370,11 +3483,11 @@ def test_shared_read_access_file_with_content_query_params(self, **kwargs): file_client.credential.account_key, permission=FileSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), - cache_control='no-cache', - content_disposition='inline', - content_encoding='utf-8', - content_language='fr', - content_type='text', + cache_control="no-cache", + content_disposition="inline", + content_encoding="utf-8", + content_language="fr", + content_type="text", ) # Act @@ -3382,16 +3495,17 @@ def test_shared_read_access_file_with_content_query_params(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=token) + credential=token, + ) response = requests.get(file_client.url) # Assert assert self.short_byte_data == response.content - assert response.headers['cache-control'] == 'no-cache' - assert response.headers['content-disposition'] == 'inline' - assert response.headers['content-encoding'] == 'utf-8' - assert response.headers['content-language'] == 'fr' - assert response.headers['content-type'] == 'text' + assert response.headers["cache-control"] == "no-cache" + assert response.headers["content-disposition"] == "inline" + assert response.headers["content-encoding"] == "utf-8" + assert response.headers["content-language"] == "fr" + assert response.headers["content-type"] == "text" @pytest.mark.live_test_only @FileSharePreparer() @@ -3400,7 +3514,7 @@ def test_shared_write_access_file(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - updated_data = b'updated file data' + updated_data = b"updated file data" file_client_admin = self._create_file() token = self.generate_sas( generate_file_sas, @@ -3415,16 +3529,17 @@ def test_shared_write_access_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client_admin.file_name, - credential=token) + credential=token, + ) # 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) + headers = {"x-ms-range": "bytes=0-16", "x-ms-write": "update"} + response = requests.put(file_client.url + "&comp=range", headers=headers, data=updated_data) # Assert assert response.ok file_content = file_client_admin.download_file().readall() - assert updated_data == file_content[:len(updated_data)] + assert updated_data == file_content[: len(updated_data)] @pytest.mark.live_test_only @FileSharePreparer() @@ -3447,7 +3562,8 @@ def test_shared_delete_access_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client_admin.file_name, - credential=token) + credential=token, + ) # Act response = requests.delete(file_client.url) @@ -3464,13 +3580,13 @@ def test_rename_file(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file = self._create_file('file1') + source_file = self._create_file("file1") # Act - new_file = source_file.rename_file('file2') + new_file = source_file.rename_file("file2") # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = new_file.get_file_properties() assert props is not None @@ -3488,14 +3604,15 @@ def test_rename_file_with_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act file_client.create_file(1024) - new_file = file_client.rename_file('file2') + new_file = file_client.rename_file("file2") # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = new_file.get_file_properties() assert props is not None @@ -3508,15 +3625,15 @@ def test_rename_file_different_directory(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = share_client.create_directory('dir1') - dest_directory = share_client.create_directory('dir2') - source_file = source_directory.upload_file('file1', self.short_byte_data) + source_directory = share_client.create_directory("dir1") + dest_directory = share_client.create_directory("dir2") + source_file = source_directory.upload_file("file1", self.short_byte_data) # Act - new_file = source_file.rename_file(dest_directory.directory_path + '/' + source_file.file_name) + new_file = source_file.rename_file(dest_directory.directory_path + "/" + source_file.file_name) # Assert - assert 'dir2' in new_file.file_path + assert "dir2" in new_file.file_path props = new_file.get_file_properties() assert props is not None @@ -3529,9 +3646,9 @@ def test_rename_file_ignore_readonly(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_file = share_client.get_file_client('file1') + source_file = share_client.get_file_client("file1") source_file.create_file(1024) - dest_file = share_client.get_file_client('file2') + dest_file = share_client.get_file_client("file2") file_attributes = NTFSAttributes(read_only=True) dest_file.create_file(1024, file_attributes=file_attributes) @@ -3540,7 +3657,7 @@ def test_rename_file_ignore_readonly(self, **kwargs): new_file = source_file.rename_file(dest_file.file_name, overwrite=True, ignore_read_only=True) # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = new_file.get_file_properties() assert props is not None @@ -3554,11 +3671,11 @@ def test_rename_file_file_permission(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) file_permission_key = share_client.create_permission_for_share(TEST_FILE_PERMISSIONS) - source_file = share_client.get_file_client('file1') + source_file = share_client.get_file_client("file1") source_file.create_file(1024) # Act - new_file = source_file.rename_file('file2', file_permission=TEST_FILE_PERMISSIONS) + new_file = source_file.rename_file("file2", file_permission=TEST_FILE_PERMISSIONS) # Assert props = new_file.get_file_properties() @@ -3574,14 +3691,14 @@ def test_rename_file_preserve_permission(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_file = share_client.get_file_client('file1') + source_file = share_client.get_file_client("file1") source_file.create_file(1024, file_permission=TEST_FILE_PERMISSIONS) source_props = source_file.get_file_properties() source_permission_key = source_props.permission_key # Act - new_file = source_file.rename_file('file2', file_permission='preserve') + new_file = source_file.rename_file("file2", file_permission="preserve") # Assert props = new_file.get_file_properties() @@ -3595,7 +3712,7 @@ def test_rename_file_smb_properties(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file = self._create_file('file1') + source_file = self._create_file("file1") file_attributes = NTFSAttributes(read_only=True, archive=True) file_creation_time = datetime(2022, 1, 26, 10, 9, 30, 500000) @@ -3604,16 +3721,17 @@ def test_rename_file_smb_properties(self, **kwargs): # Act new_file = source_file.rename_file( - 'file2', + "file2", 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 @@ -3625,13 +3743,11 @@ def test_rename_file_content_type(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file = self._create_file('file1') - content_type = 'text/plain' + source_file = self._create_file("file1") + content_type = "text/plain" # Act - new_file = source_file.rename_file( - 'file2', - content_type=content_type) + new_file = source_file.rename_file("file2", content_type=content_type) # Assert props = new_file.get_file_properties() @@ -3646,20 +3762,18 @@ def test_rename_file_with_lease(self, **kwargs): self._setup(storage_account_name, storage_account_key) - source_file = self._create_file('file1') - dest_file = self._create_file('file2') - source_lease = source_file.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') - dest_lease = dest_file.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + source_file = self._create_file("file1") + dest_file = self._create_file("file2") + source_lease = source_file.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") + dest_lease = dest_file.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act new_file = source_file.rename_file( - dest_file.file_name, - overwrite=True, - source_lease=source_lease, - destination_lease=dest_lease) + dest_file.file_name, overwrite=True, source_lease=source_lease, destination_lease=dest_lease + ) # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = new_file.get_file_properties() assert props is not None @@ -3678,19 +3792,19 @@ def test_rename_file_share_sas(self, **kwargs): share_client.share_name, share_client.credential.account_key, expiry=datetime.utcnow() + timedelta(hours=1), - permission=ShareSasPermissions(read=True, write=True)) + permission=ShareSasPermissions(read=True, write=True), + ) source_file = ShareFileClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'file1', - credential=token) + self.account_url(storage_account_name, "file"), share_client.share_name, "file1", credential=token + ) source_file.create_file(1024) # Act - new_file = source_file.rename_file('file2' + '?' + token) + new_file = source_file.rename_file("file2" + "?" + token) # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = new_file.get_file_properties() assert props is not None @@ -3707,7 +3821,7 @@ def test_storage_account_audience_file_client(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key + credential=storage_account_key, ) file_client.create_file(1024) @@ -3722,7 +3836,7 @@ def test_storage_account_audience_file_client(self, **kwargs): file_path=file_name, credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://{storage_account_name}.file.core.windows.net' + audience=f"https://{storage_account_name}.file.core.windows.net", ) # Assert @@ -3742,7 +3856,7 @@ def test_bad_audience_file_client(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key + credential=storage_account_key, ) file_client.create_file(1024) @@ -3757,7 +3871,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=f"https://badaudience.file.core.windows.net", ) # Assert @@ -3771,20 +3885,20 @@ def test_file_permission_format(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_file = share_client.get_file_client('file1') - user_given_permission_sddl = ("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;;;" - "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL") - user_given_permission_binary = ("AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" - "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" - "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=") + source_file = share_client.get_file_client("file1") + user_given_permission_sddl = ( + "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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL" + ) + user_given_permission_binary = ( + "AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" + "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" + "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=" + ) # Create file - source_file.create_file( - 1024, - file_permission=user_given_permission_binary, - file_permission_format="binary" - ) + source_file.create_file(1024, file_permission=user_given_permission_binary, file_permission_format="binary") props = source_file.get_file_properties() assert props is not None @@ -3792,29 +3906,23 @@ def test_file_permission_format(self, **kwargs): # Rename file new_file = source_file.rename_file( - 'file2', - file_permission=user_given_permission_binary, - file_permission_format="binary" + "file2", file_permission=user_given_permission_binary, file_permission_format="binary" ) props = new_file.get_file_properties() assert props is not None assert props.permission_key is not None server_returned_permission = share_client.get_permission_for_share( - props.permission_key, - file_permission_format="binary" + props.permission_key, file_permission_format="binary" ) assert server_returned_permission == user_given_permission_binary # Set HTTP headers - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline' - ) + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") new_file.set_http_headers( content_settings=content_settings, file_permission=user_given_permission_binary, - file_permission_format="binary" + file_permission_format="binary", ) props = new_file.get_file_properties() assert props is not None @@ -3823,8 +3931,7 @@ def test_file_permission_format(self, **kwargs): assert props.content_settings.content_disposition == content_settings.content_disposition server_returned_permission = share_client.get_permission_for_share( - props.permission_key, - file_permission_format="sddl" + props.permission_key, file_permission_format="sddl" ) assert server_returned_permission == user_given_permission_sddl @@ -3832,17 +3939,15 @@ def test_file_permission_format(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='filecopy', - credential=storage_account_key + file_path="filecopy", + credential=storage_account_key, ) copy = file_client.start_copy_from_url( - new_file.url, - file_permission=user_given_permission_binary, - file_permission_format="binary" + new_file.url, file_permission=user_given_permission_binary, file_permission_format="binary" ) assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None new_file.delete_file() file_client.delete_file() @@ -3861,7 +3966,7 @@ def test_mock_transport_no_content_validation(self, **kwargs): file_path="filemocktransport", credential=storage_account_key, transport=transport, - retry_total=0 + retry_total=0, ) data = file_client.download_file() @@ -3891,7 +3996,7 @@ def test_mock_transport_with_content_validation(self, **kwargs): file_path="filemocktransport", credential=storage_account_key, transport=transport, - retry_total=0 + retry_total=0, ) data = b"Hello World!" @@ -3901,4 +4006,5 @@ def test_mock_transport_with_content_validation(self, **kwargs): file_data = file_client.download_file(validate_content=True).readall() assert file_data == b"Hello World!" # data is fixed by mock transport + # ------------------------------------------------------------------------------ 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 2a2e06ee7ffa..ad57cdf4e08c 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 @@ -14,7 +14,7 @@ from settings.testcase import FileSharePreparer # ------------------------------------------------------------------------------ -TEST_FILE_PREFIX = 'file' +TEST_FILE_PREFIX = "file" class TestStorageClient(StorageRecordedTestCase): @@ -29,7 +29,7 @@ def _get_file_reference(self, prefix=TEST_FILE_PREFIX): return self.get_resource_name(prefix) def _create_share(self, fsc): - share_name = self.get_resource_name('utshare') + share_name = self.get_resource_name("utshare") share = fsc.get_share_client(share_name) try: share.create_share() @@ -44,14 +44,11 @@ def _delete_share(self, share): pass return share - # --Test Cases-------------------------------------------------------------- def test_service_client_api_version_property(self): self.setUp() - service_client = ShareServiceClient( - "https://foo.file.core.windows.net/account", - credential="fake_key") + service_client = ShareServiceClient("https://foo.file.core.windows.net/account", credential="fake_key") assert service_client.api_version == self.api_version_2 assert service_client._client._config.version == self.api_version_2 @@ -59,9 +56,8 @@ def test_service_client_api_version_property(self): service_client.api_version = self.api_version_1 service_client = ShareServiceClient( - "https://foo.file.core.windows.net/account", - credential="fake_key", - api_version=self.api_version_1) + "https://foo.file.core.windows.net/account", credential="fake_key", api_version=self.api_version_1 + ) assert service_client.api_version == self.api_version_1 assert service_client._client._config.version == self.api_version_1 @@ -71,10 +67,7 @@ def test_service_client_api_version_property(self): def test_share_client_api_version_property(self): self.setUp() - share_client = ShareClient( - "https://foo.file.core.windows.net/account", - "share_name", - credential="fake_key") + share_client = ShareClient("https://foo.file.core.windows.net/account", "share_name", credential="fake_key") assert share_client.api_version == self.api_version_2 assert share_client._client._config.version == self.api_version_2 @@ -82,7 +75,8 @@ def test_share_client_api_version_property(self): "https://foo.file.core.windows.net/account", "share_name", credential="fake_key", - api_version=self.api_version_1) + api_version=self.api_version_1, + ) assert share_client.api_version == self.api_version_1 assert share_client._client._config.version == self.api_version_1 @@ -97,10 +91,8 @@ def test_share_client_api_version_property(self): def test_directory_client_api_version_property(self): self.setUp() dir_client = ShareDirectoryClient( - "https://foo.file.core.windows.net/account", - "share_name", - "dir_path", - credential="fake_key") + "https://foo.file.core.windows.net/account", "share_name", "dir_path", credential="fake_key" + ) assert dir_client.api_version == self.api_version_2 assert dir_client._client._config.version == self.api_version_2 @@ -109,7 +101,8 @@ def test_directory_client_api_version_property(self): "share_name", "dir_path", credential="fake_key", - api_version=self.api_version_1) + api_version=self.api_version_1, + ) assert dir_client.api_version == self.api_version_1 assert dir_client._client._config.version == self.api_version_1 @@ -124,10 +117,8 @@ def test_directory_client_api_version_property(self): def test_file_client_api_version_property(self): self.setUp() file_client = ShareFileClient( - "https://foo.file.core.windows.net/account", - "share", - self._get_file_reference(), - credential="fake_key") + "https://foo.file.core.windows.net/account", "share", self._get_file_reference(), credential="fake_key" + ) assert file_client.api_version == self.api_version_2 assert file_client._client._config.version == self.api_version_2 @@ -136,25 +127,21 @@ def test_file_client_api_version_property(self): "share", self._get_file_reference(), credential="fake_key", - api_version=self.api_version_1) + api_version=self.api_version_1, + ) assert file_client.api_version == self.api_version_1 assert file_client._client._config.version == self.api_version_1 def test_invalid_api_version(self): self.setUp() with pytest.raises(ValueError) as error: - ShareServiceClient( - "https://foo.file.core.windows.net/account", - credential="fake_key", - api_version="foo") + ShareServiceClient("https://foo.file.core.windows.net/account", credential="fake_key", api_version="foo") assert str(error.value).startswith("Unsupported API version 'foo'.") with pytest.raises(ValueError) as error: ShareClient( - "https://foo.file.core.windows.net/account", - "share_name", - credential="fake_key", - api_version="foo") + "https://foo.file.core.windows.net/account", "share_name", credential="fake_key", api_version="foo" + ) assert str(error.value).startswith("Unsupported API version 'foo'.") with pytest.raises(ValueError) as error: @@ -163,7 +150,8 @@ def test_invalid_api_version(self): "share_name", "dir_path", credential="fake_key", - api_version="foo") + api_version="foo", + ) assert str(error.value).startswith("Unsupported API version 'foo'.") with pytest.raises(ValueError) as error: @@ -172,7 +160,8 @@ def test_invalid_api_version(self): "share", self._get_file_reference(), credential="fake_key", - api_version="foo") + api_version="foo", + ) assert str(error.value).startswith("Unsupported API version 'foo'.") @FileSharePreparer() @@ -186,7 +175,7 @@ def test_old_api_copy_file_succeeds(self, **kwargs): self.account_url(storage_account_name, "file"), credential=storage_account_key, max_range_size=4 * 1024, - api_version=self.api_version_1 + api_version=self.api_version_1, ) share = self._create_share(fsc) file_name = self._get_file_reference() @@ -194,19 +183,20 @@ def test_old_api_copy_file_succeeds(self, **kwargs): source_client = share.get_file_client(file_name) source_client.upload_file( self.short_byte_data, - file_attributes='none', - file_creation_time='now', - file_last_write_time='now', - file_permission='inherit' + file_attributes="none", + file_creation_time="now", + file_last_write_time="now", + file_permission="inherit", ) source_prop = source_client.get_file_properties() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=share.share_name, - file_path='file1copy', + file_path="file1copy", credential=storage_account_key, - api_version=self.api_version_1) + api_version=self.api_version_1, + ) # Act copy = file_client.start_copy_from_url(source_client.url) @@ -214,13 +204,14 @@ def test_old_api_copy_file_succeeds(self, **kwargs): # Assert dest_prop = file_client.get_file_properties() # to make sure the acl is copied from source - assert source_prop['permission_key'] == dest_prop['permission_key'] + assert source_prop["permission_key"] == dest_prop["permission_key"] assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = file_client.download_file().readall() assert copy_file == self.short_byte_data + # ------------------------------------------------------------------------------ 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 39109b2a6a40..9c18c858f15a 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 @@ -14,7 +14,7 @@ from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase # ------------------------------------------------------------------------------ -TEST_FILE_PREFIX = 'file' +TEST_FILE_PREFIX = "file" class TestAsyncStorageClient(AsyncStorageRecordedTestCase): @@ -29,7 +29,7 @@ def _get_file_reference(self, prefix=TEST_FILE_PREFIX): return self.get_resource_name(prefix) async def _create_share(self, fsc): - share_name = self.get_resource_name('utshare') + share_name = self.get_resource_name("utshare") share = fsc.get_share_client(share_name) try: await share.create_share() @@ -44,14 +44,11 @@ async def _delete_share(self, share): pass return share - # --Test Cases-------------------------------------------------------------- def test_service_client_api_version_property(self): self.setUp() - service_client = ShareServiceClient( - "https://foo.file.core.windows.net/account", - credential="fake_key") + service_client = ShareServiceClient("https://foo.file.core.windows.net/account", credential="fake_key") assert service_client.api_version == self.api_version_2 assert service_client._client._config.version == self.api_version_2 @@ -59,9 +56,8 @@ def test_service_client_api_version_property(self): service_client.api_version = self.api_version_1 service_client = ShareServiceClient( - "https://foo.file.core.windows.net/account", - credential="fake_key", - api_version=self.api_version_1) + "https://foo.file.core.windows.net/account", credential="fake_key", api_version=self.api_version_1 + ) assert service_client.api_version == self.api_version_1 assert service_client._client._config.version == self.api_version_1 @@ -71,10 +67,7 @@ def test_service_client_api_version_property(self): def test_share_client_api_version_property(self): self.setUp() - share_client = ShareClient( - "https://foo.file.core.windows.net/account", - "share_name", - credential="fake_key") + share_client = ShareClient("https://foo.file.core.windows.net/account", "share_name", credential="fake_key") assert share_client.api_version == self.api_version_2 assert share_client._client._config.version == self.api_version_2 @@ -82,7 +75,8 @@ def test_share_client_api_version_property(self): "https://foo.file.core.windows.net/account", "share_name", credential="fake_key", - api_version=self.api_version_1) + api_version=self.api_version_1, + ) assert share_client.api_version == self.api_version_1 assert share_client._client._config.version == self.api_version_1 @@ -97,10 +91,8 @@ def test_share_client_api_version_property(self): def test_directory_client_api_version_property(self): self.setUp() dir_client = ShareDirectoryClient( - "https://foo.file.core.windows.net/account", - "share_name", - "dir_path", - credential="fake_key") + "https://foo.file.core.windows.net/account", "share_name", "dir_path", credential="fake_key" + ) assert dir_client.api_version == self.api_version_2 assert dir_client._client._config.version == self.api_version_2 @@ -109,7 +101,8 @@ def test_directory_client_api_version_property(self): "share_name", "dir_path", credential="fake_key", - api_version=self.api_version_1) + api_version=self.api_version_1, + ) assert dir_client.api_version == self.api_version_1 assert dir_client._client._config.version == self.api_version_1 @@ -124,10 +117,8 @@ def test_directory_client_api_version_property(self): def test_file_client_api_version_property(self): self.setUp() file_client = ShareFileClient( - "https://foo.file.core.windows.net/account", - "share", - self._get_file_reference(), - credential="fake_key") + "https://foo.file.core.windows.net/account", "share", self._get_file_reference(), credential="fake_key" + ) assert file_client.api_version == self.api_version_2 assert file_client._client._config.version == self.api_version_2 @@ -136,25 +127,21 @@ def test_file_client_api_version_property(self): "share", self._get_file_reference(), credential="fake_key", - api_version=self.api_version_1) + api_version=self.api_version_1, + ) assert file_client.api_version == self.api_version_1 assert file_client._client._config.version == self.api_version_1 def test_invalid_api_version(self): self.setUp() with pytest.raises(ValueError) as error: - ShareServiceClient( - "https://foo.file.core.windows.net/account", - credential="fake_key", - api_version="foo") + ShareServiceClient("https://foo.file.core.windows.net/account", credential="fake_key", api_version="foo") assert str(error.value).startswith("Unsupported API version 'foo'.") with pytest.raises(ValueError) as error: ShareClient( - "https://foo.file.core.windows.net/account", - "share_name", - credential="fake_key", - api_version="foo") + "https://foo.file.core.windows.net/account", "share_name", credential="fake_key", api_version="foo" + ) assert str(error.value).startswith("Unsupported API version 'foo'.") with pytest.raises(ValueError) as error: @@ -163,7 +150,8 @@ def test_invalid_api_version(self): "share_name", "dir_path", credential="fake_key", - api_version="foo") + api_version="foo", + ) assert str(error.value).startswith("Unsupported API version 'foo'.") with pytest.raises(ValueError) as error: @@ -172,7 +160,8 @@ def test_invalid_api_version(self): "share", self._get_file_reference(), credential="fake_key", - api_version="foo") + api_version="foo", + ) assert str(error.value).startswith("Unsupported API version 'foo'.") @FileSharePreparer() @@ -187,7 +176,7 @@ async def test_old_api_copy_file_succeeds(self, **kwargs): self.account_url(storage_account_name, "file"), credential=storage_account_key, max_range_size=4 * 1024, - api_version=self.api_version_1 + api_version=self.api_version_1, ) share = await self._create_share(fsc) file_name = self._get_file_reference() @@ -195,19 +184,20 @@ async def test_old_api_copy_file_succeeds(self, **kwargs): source_client = share.get_file_client(file_name) await source_client.upload_file( self.short_byte_data, - file_attributes='none', - file_creation_time='now', - file_last_write_time='now', - file_permission='inherit' + file_attributes="none", + file_creation_time="now", + file_last_write_time="now", + file_permission="inherit", ) source_prop = await source_client.get_file_properties() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=share.share_name, - file_path='file1copy', + file_path="file1copy", credential=storage_account_key, - api_version=self.api_version_1) + api_version=self.api_version_1, + ) # Act copy = await file_client.start_copy_from_url(source_client.url) @@ -215,13 +205,14 @@ async def test_old_api_copy_file_succeeds(self, **kwargs): # Assert dest_prop = await file_client.get_file_properties() # to make sure the acl is copied from source - assert source_prop['permission_key'] == dest_prop['permission_key'] + assert source_prop["permission_key"] == dest_prop["permission_key"] assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = await (await file_client.download_file()).readall() assert copy_file == self.short_byte_data + # ------------------------------------------------------------------------------ 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 178b7d66d7e4..4b7919f1080c 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 @@ -13,7 +13,12 @@ import pytest import requests from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, +) from azure.storage.blob.aio import BlobServiceClient from azure.storage.fileshare import ( AccessPolicy, @@ -26,7 +31,7 @@ NTFSAttributes, ResourceTypes, ShareSasPermissions, - StorageErrorCode + StorageErrorCode, ) from azure.storage.fileshare.aio import ShareFileClient, ShareServiceClient @@ -36,14 +41,16 @@ from test_helpers_async import AsyncStream, MockStorageTransport, ProgressTracker # ------------------------------------------------------------------------------ -TEST_SHARE_PREFIX = 'share' -TEST_DIRECTORY_PREFIX = 'dir' -TEST_FILE_PREFIX = 'file' -TEST_BLOB_PREFIX = 'blob' +TEST_SHARE_PREFIX = "share" +TEST_DIRECTORY_PREFIX = "dir" +TEST_FILE_PREFIX = "file" +TEST_BLOB_PREFIX = "blob" LARGE_FILE_SIZE = 64 * 1024 + 5 -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;;;' \ - 'S-1-5-21-397955417-626881126-188441444-3053964)' +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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)" +) TEST_INTENT = "backup" # ------------------------------------------------------------------------------ @@ -57,11 +64,10 @@ def _setup(self, storage_account_name, storage_account_key, rmt_account=None, rm # test chunking functionality by reducing the threshold # for chunking and the size of each chunk, otherwise # the tests would take too long to execute - self.fsc = ShareServiceClient( - url, credential=credential, max_range_size=4 * 1024) + self.fsc = ShareServiceClient(url, credential=credential, max_range_size=4 * 1024) self.bsc = BlobServiceClient(blob_url, credential=credential) - self.source_container_name = self.get_resource_name('sourceshare') - self.share_name = self.get_resource_name('utshare') + self.source_container_name = self.get_resource_name("sourceshare") + self.share_name = self.get_resource_name("utshare") self.short_byte_data = self.get_random_bytes(1024) remote_url = self.account_url(rmt_account, "file") @@ -87,15 +93,14 @@ async def _create_source_blob(self): except: pass blob_client = self.bsc.get_blob_client(self.source_container_name, self.get_resource_name(TEST_BLOB_PREFIX)) - await blob_client.upload_blob(b'abcdefghijklmnop' * 32, overwrite=True) + await blob_client.upload_blob(b"abcdefghijklmnop" * 32, overwrite=True) return blob_client async def _setup_share(self, storage_account_name, storage_account_key, remote=False): share_name = self.remote_share_name if remote else self.share_name async with ShareServiceClient( - self.account_url(storage_account_name, "file"), - credential=storage_account_key, - max_range_size=4 * 1024) as fsc: + self.account_url(storage_account_name, "file"), credential=storage_account_key, max_range_size=4 * 1024 + ) as fsc: if not self.is_playback(): try: await fsc.create_share(share_name) @@ -126,7 +131,7 @@ async def _get_file_client(self, storage_account_name, storage_account_key): return file_client async def _create_remote_share(self): - self.remote_share_name = self.get_resource_name('remoteshare') + self.remote_share_name = self.get_resource_name("remoteshare") remote_share = self.fsc2.get_share_client(self.remote_share_name) try: await remote_share.create_share() @@ -136,7 +141,7 @@ async def _create_remote_share(self): async def _create_remote_file(self, file_data=None): if not file_data: - file_data = b'12345678' * 1024 + file_data = b"12345678" * 1024 source_file_name = self._get_file_reference() remote_share = self.fsc2.get_share_client(self.remote_share_name) remote_file = remote_share.get_file_client(source_file_name) @@ -148,13 +153,13 @@ async def _wait_for_async_copy(self, share_name, file_path): share_client = self.fsc.get_share_client(share_name) file_client = share_client.get_file_client(file_path) properties = await file_client.get_file_properties() - while properties.copy.status != 'success': + while properties.copy.status != "success": count = count + 1 if count > 10: - self.fail('Timed out waiting for async copy to complete.') + self.fail("Timed out waiting for async copy to complete.") self.sleep(6) properties = await file_client.get_file_properties() - assert properties.copy.status == 'success' + assert properties.copy.status == "success" async def assertFileEqual(self, file_client, expected_data, **kwargs): content = await file_client.download_file(**kwargs) @@ -187,7 +192,7 @@ async def test_make_file_url(self, **kwargs): res = file_client.url # Assert - assert res == ('https://' + storage_account_name + '.file.core.windows.net/vhds/vhd_dir/my.vhd') + assert res == ("https://" + storage_account_name + ".file.core.windows.net/vhds/vhd_dir/my.vhd") @FileSharePreparer() @recorded_by_proxy_async @@ -203,7 +208,7 @@ async def test_make_file_url_no_directory(self, **kwargs): res = file_client.url # Assert - assert res == ('https://' + storage_account_name + '.file.core.windows.net/vhds/my.vhd') + assert res == ("https://" + storage_account_name + ".file.core.windows.net/vhds/my.vhd") @FileSharePreparer() @recorded_by_proxy_async @@ -212,7 +217,7 @@ async def test_make_file_url_with_protocol(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - url = self.account_url(storage_account_name, "file").replace('https', 'http') + url = self.account_url(storage_account_name, "file").replace("https", "http") fsc = ShareServiceClient(url, credential=storage_account_key) share = fsc.get_share_client("vhds") file_client = share.get_file_client("vhd_dir/my.vhd") @@ -221,7 +226,7 @@ async def test_make_file_url_with_protocol(self, **kwargs): res = file_client.url # Assert - assert res == ('http://' + storage_account_name + '.file.core.windows.net/vhds/vhd_dir/my.vhd') + assert res == ("http://" + storage_account_name + ".file.core.windows.net/vhds/vhd_dir/my.vhd") @FileSharePreparer() @recorded_by_proxy_async @@ -231,19 +236,19 @@ 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", file_path="vhd_dir/my.vhd", - credential=sas + credential=sas, ) # Act res = file_client.url # Assert - assert res == ('https://' + storage_account_name + '.file.core.windows.net/vhds/vhd_dir/my.vhd{}'.format(sas)) + assert res == ("https://" + storage_account_name + ".file.core.windows.net/vhds/vhd_dir/my.vhd{}".format(sas)) @FileSharePreparer() @recorded_by_proxy_async @@ -258,7 +263,8 @@ async def test_exists(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) as file_client: + credential=storage_account_key, + ) as file_client: # Act / Assert assert not await file_client.exists() @@ -279,7 +285,8 @@ async def test_create_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) as file_client: + credential=storage_account_key, + ) as file_client: # Act resp = await file_client.create_file(1024) @@ -287,8 +294,8 @@ async def test_create_file(self, **kwargs): # Assert props = await file_client.get_file_properties() assert props is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] @FileSharePreparer() @recorded_by_proxy_async @@ -301,19 +308,20 @@ async def test_create_file_with_oauth(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) file_name = self._get_file_reference() async with ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name, - credential=token_credential, - token_intent=TEST_INTENT) as file_client: + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_name, + credential=token_credential, + token_intent=TEST_INTENT, + ) as file_client: # Act resp = await file_client.create_file(1024) # Assert props = await file_client.get_file_properties() assert props is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] @FileSharePreparer() @recorded_by_proxy_async @@ -332,7 +340,7 @@ async def test_create_file_with_oauth_no_token_intent(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=token_credential + credential=token_credential, ) @FileSharePreparer() @@ -345,20 +353,21 @@ async def test_create_file_with_trailing_dot(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) file_name = self._get_file_reference() async with ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name + '.', - credential=storage_account_key, - allow_trailing_dot=True) as file_client: + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_name + ".", + credential=storage_account_key, + allow_trailing_dot=True, + ) as file_client: # Act resp = await file_client.create_file(1024) # Assert props = await file_client.get_file_properties() assert props is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] - assert props.name == file_name + '.' + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy_async @@ -372,9 +381,10 @@ async def test_create_file_with_trailing_dot_false(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=False) + allow_trailing_dot=False, + ) # Act resp = await file_client.create_file(1024) @@ -383,9 +393,10 @@ async def test_create_file_with_trailing_dot_false(self, **kwargs): file_client_dotted = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=False) + allow_trailing_dot=False, + ) # create file client without dot file_client_no_dot = ShareFileClient( @@ -393,17 +404,18 @@ async def test_create_file_with_trailing_dot_false(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - allow_trailing_dot=False) + allow_trailing_dot=False, + ) props = await file_client.get_file_properties() props_dotted = await file_client_dotted.get_file_properties() props_no_dot = await file_client_no_dot.get_file_properties() # Assert - assert props.name == file_name + '.' - assert props.path == file_name + '.' - assert props_dotted.name == file_name + '.' - assert props_dotted.path == file_name + '.' + assert props.name == file_name + "." + assert props.path == file_name + "." + assert props_dotted.name == file_name + "." + assert props_dotted.path == file_name + "." assert props_no_dot.name == file_name assert props_no_dot.path == file_name @@ -415,13 +427,14 @@ async def test_create_file_with_metadata(self, **kwargs): self._setup(storage_account_name, storage_account_key) await self._setup_share(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} file_name = self._get_file_reference() async with ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) as file_client: + credential=storage_account_key, + ) as file_client: # Act resp = await file_client.create_file(1024, metadata=metadata) @@ -429,8 +442,8 @@ async def test_create_file_with_metadata(self, **kwargs): # Assert props = await file_client.get_file_properties() assert props is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] assert props.metadata == metadata @FileSharePreparer() @@ -441,24 +454,25 @@ async def test_create_file_with_metadata_with_trailing_dot(self, **kwargs): self._setup(storage_account_name, storage_account_key) await self._setup_share(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} file_name = self._get_file_reference() async with ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name + '.', - credential=storage_account_key, - allow_trailing_dot=True) as file_client: + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_name + ".", + credential=storage_account_key, + allow_trailing_dot=True, + ) as file_client: # Act resp = await file_client.create_file(1024, metadata=metadata) # Assert props = await file_client.get_file_properties() assert props is not None - assert props.etag == resp['etag'] - assert props.last_modified == resp['last_modified'] + assert props.etag == resp["etag"] + assert props.last_modified == resp["last_modified"] assert props.metadata == metadata - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy_async @@ -494,7 +508,7 @@ async def test_create_file_with_lease(self, **kwargs): file_client = await self._get_file_client(storage_account_name, storage_account_key) await file_client.create_file(1024) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") resp = await file_client.create_file(1024, lease=lease) assert resp is not None @@ -520,10 +534,11 @@ async def test_create_file_with_lease_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) await file_client.create_file(1024) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") resp = await file_client.create_file(1024, lease=lease) assert resp is not None @@ -544,9 +559,9 @@ async def test_create_file_with_changed_lease(self, **kwargs): file_client = await self._get_file_client(storage_account_name, storage_account_key) await file_client.create_file(1024) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") old_lease_id = lease.id - await lease.change('44444444-3333-2222-1111-000000000000') + await lease.change("44444444-3333-2222-1111-000000000000") # use the old lease id to create file will throw exception. with pytest.raises(HttpResponseError): @@ -572,12 +587,13 @@ async def test_create_file_with_changed_lease_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) await file_client.create_file(1024) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") old_lease_id = lease.id - await lease.change('44444444-3333-2222-1111-000000000000') + await lease.change("44444444-3333-2222-1111-000000000000") # use the old lease id to create file will throw exception. with pytest.raises(HttpResponseError): @@ -600,14 +616,15 @@ async def test_lease_operations_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) await file_client.create_file(1024) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") old_lease_id = lease.id - await lease.change('44444444-3333-2222-1111-000000000000') + await lease.change("44444444-3333-2222-1111-000000000000") # use the old lease id to create file will throw exception. with pytest.raises(HttpResponseError): @@ -625,7 +642,7 @@ async def test_lease_operations_trailing_dot(self, **kwargs): # Assert assert resp is not None - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy_async @@ -665,7 +682,8 @@ async def test_create_file_set_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, + ) file_properties = await file_client.get_file_properties() # Assert @@ -673,8 +691,8 @@ async def test_create_file_set_smb_properties(self, **kwargs): assert file_creation_time == file_properties.creation_time assert file_last_write_time == file_properties.last_write_time assert file_change_time == file_properties.change_time - assert 'ReadOnly' in file_properties.file_attributes - assert 'Archive' in file_properties.file_attributes + assert "ReadOnly" in file_properties.file_attributes + assert "Archive" in file_properties.file_attributes @FileSharePreparer() @recorded_by_proxy_async @@ -730,7 +748,8 @@ async def test_file_not_exists(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path="missingdir/" + file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act with pytest.raises(ResourceNotFoundError): @@ -754,7 +773,8 @@ async def test_file_exists_with_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) props = await snapshot_client.get_file_properties() # Assert @@ -779,7 +799,8 @@ async def test_file_not_exists_with_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) # Assert with pytest.raises(ResourceNotFoundError): @@ -809,7 +830,7 @@ async def test_resize_file_with_lease(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_client = await self._create_file(storage_account_name, storage_account_key) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act with pytest.raises(HttpResponseError): @@ -830,9 +851,7 @@ async def test_set_file_properties(self, **kwargs): file_client = await self._create_file(storage_account_name, storage_account_key) # Act - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") resp = await file_client.set_http_headers(content_settings=content_settings) # Assert @@ -866,14 +885,10 @@ async def test_set_datetime_all_ms_precision(self, **kwargs): ] # Act / Assert - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") for date1, date2 in zip(date_times[::2], date_times[1::2]): await file_client.set_http_headers( - content_settings=content_settings, - file_creation_time=date1, - file_last_write_time=date2 + content_settings=content_settings, file_creation_time=date1, file_last_write_time=date2 ) @FileSharePreparer() @@ -886,17 +901,16 @@ async def test_set_file_properties_trailing_dot(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) file_name = self._get_file_reference() file_client = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name + '.', - credential=storage_account_key, - allow_trailing_dot=True) + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_name + ".", + credential=storage_account_key, + allow_trailing_dot=True, + ) await file_client.create_file(1024) # Act - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") resp = await file_client.set_http_headers(content_settings=content_settings) # Assert @@ -906,7 +920,7 @@ async def test_set_file_properties_trailing_dot(self, **kwargs): assert properties.last_write_time is not None assert properties.creation_time is not None assert properties.permission_key is not None - assert properties.name == file_name + '.' + assert properties.name == file_name + "." @FileSharePreparer() @recorded_by_proxy_async @@ -918,9 +932,7 @@ async def test_set_file_properties_with_file_permission(self, **kwargs): file_client = await self._create_file(storage_account_name, storage_account_key) properties_on_creation = await file_client.get_file_properties() - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") ntfs_attributes = NTFSAttributes(archive=True, temporary=True) last_write_time = properties_on_creation.last_write_time + timedelta(hours=3) @@ -933,7 +945,7 @@ async def test_set_file_properties_with_file_permission(self, **kwargs): file_attributes=ntfs_attributes, file_last_write_time=last_write_time, file_creation_time=creation_time, - file_change_time=change_time + file_change_time=change_time, ) # Assert @@ -957,14 +969,15 @@ async def test_set_file_properties_with_oauth(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) file_name = self._get_file_reference() async with ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name, - credential=token_credential, - token_intent=TEST_INTENT) as file_client: + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_name, + credential=token_credential, + token_intent=TEST_INTENT, + ) as file_client: # Act await file_client.create_file(1024) - content_settings = ContentSettings(content_language='spanish', content_disposition='inline') + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") resp = await file_client.set_http_headers(content_settings=content_settings) # Assert @@ -1002,11 +1015,12 @@ async def test_get_file_properties_with_oauth(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) file_name = self._get_file_reference() async with ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name, - credential=token_credential, - token_intent=TEST_INTENT) as file_client: + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_name, + credential=token_credential, + token_intent=TEST_INTENT, + ) as file_client: # Act resp = await file_client.create_file(1024) @@ -1028,9 +1042,10 @@ async def test_get_file_properties_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) await file_client.create_file(1024) # Ensure allow_trailing_dot=True is enforced properly by attempting to connect without trailing dot @@ -1038,7 +1053,8 @@ async def test_get_file_properties_trailing_dot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) with pytest.raises(HttpResponseError): await file_client_no_dot.get_file_properties() @@ -1056,11 +1072,11 @@ async def test_get_file_properties_with_invalid_lease_fails(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_client = await self._create_file(storage_account_name, storage_account_key) - await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act with pytest.raises(HttpResponseError): - await file_client.get_file_properties(lease='44444444-3333-2222-1111-000000000000') + await file_client.get_file_properties(lease="44444444-3333-2222-1111-000000000000") # get properties on a leased file will succeed properties = await file_client.get_file_properties() @@ -1093,7 +1109,8 @@ async def test_get_file_properties_with_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) snapshot_props = await snapshot_client.get_file_properties() # Assert assert file_props is not None @@ -1119,7 +1136,8 @@ async def test_get_file_metadata_with_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) metadata2 = {"test100": "foo100", "test200": "bar200"} await file_client.set_file_metadata(metadata2) @@ -1144,7 +1162,8 @@ async def test_get_file_properties_with_non_existing_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act with pytest.raises(ResourceNotFoundError): @@ -1175,7 +1194,7 @@ async def test_set_file_metadata_with_upper_case(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42', 'UP': 'UPval'} + metadata = {"hello": "world", "number": "42", "UP": "UPval"} file_client = await self._create_file(storage_account_name, storage_account_key) # Act @@ -1185,10 +1204,10 @@ async def test_set_file_metadata_with_upper_case(self, **kwargs): props = await file_client.get_file_properties() md = props.metadata assert 3 == len(md) - assert md['hello'] == 'world' - assert md['number'] == '42' - assert md['UP'] == 'UPval' - assert not 'up' in md + assert md["hello"] == "world" + assert md["number"] == "42" + assert md["UP"] == "UPval" + assert not "up" in md @FileSharePreparer() @recorded_by_proxy_async @@ -1201,12 +1220,13 @@ async def test_set_file_metadata_with_oauth(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) file_name = self._get_file_reference() async with ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name, - credential=token_credential, - token_intent=TEST_INTENT) as file_client: - metadata = {'hello': 'world', 'number': '42', 'UP': 'UPval'} + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_name, + credential=token_credential, + token_intent=TEST_INTENT, + ) as file_client: + metadata = {"hello": "world", "number": "42", "UP": "UPval"} # Act resp = await file_client.create_file(1024) @@ -1216,10 +1236,10 @@ async def test_set_file_metadata_with_oauth(self, **kwargs): props = await file_client.get_file_properties() md = props.metadata assert 3 == len(md) - assert md['hello'] == 'world' - assert md['number'] == '42' - assert md['UP'] == 'UPval' - assert not 'up' in md + assert md["hello"] == "world" + assert md["number"] == "42" + assert md["UP"] == "UPval" + assert not "up" in md @FileSharePreparer() @recorded_by_proxy_async @@ -1229,7 +1249,7 @@ async def test_break_lease_with_broken_period_fails(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_client = await self._create_file(storage_account_name, storage_account_key) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Assert assert lease is not None @@ -1243,10 +1263,10 @@ async def test_set_file_metadata_with_broken_lease(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42', 'UP': 'UPval'} + metadata = {"hello": "world", "number": "42", "UP": "UPval"} file_client = await self._create_file(storage_account_name, storage_account_key) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") with pytest.raises(HttpResponseError): await file_client.set_file_metadata(metadata) @@ -1255,11 +1275,11 @@ async def test_set_file_metadata_with_broken_lease(self, **kwargs): # Act # lease is broken, set metadata doesn't require a lease - await file_client.set_file_metadata({'hello': 'world'}) + await file_client.set_file_metadata({"hello": "world"}) props = await file_client.get_file_properties() # Assert assert 1 == len(props.metadata) - assert props.metadata['hello'] == 'world' + assert props.metadata["hello"] == "world" # Act await file_client.acquire_lease(lease_id=lease_id_to_be_broken) @@ -1268,10 +1288,10 @@ async def test_set_file_metadata_with_broken_lease(self, **kwargs): props = await file_client.get_file_properties() md = props.metadata assert 3 == len(md) - assert md['hello'] == 'world' - assert md['number'] == '42' - assert md['UP'] == 'UPval' - assert not 'up' in md + assert md["hello"] == "world" + assert md["number"] == "42" + assert md["UP"] == "UPval" + assert not "up" in md @FileSharePreparer() @recorded_by_proxy_async @@ -1304,7 +1324,8 @@ async def test_delete_file_with_existing_file_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act resp = await file_client.create_file(1024) @@ -1326,9 +1347,10 @@ async def test_delete_file_with_existing_file_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) await file_client.create_file(1024) # Act @@ -1350,7 +1372,8 @@ async def test_delete_file_with_non_existing_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act with pytest.raises(ResourceNotFoundError): @@ -1368,7 +1391,7 @@ async def test_update_range(self, **kwargs): file_client = await self._create_file(storage_account_name, storage_account_key) # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 await file_client.upload_range(data, offset=0, length=512) # Assert @@ -1389,13 +1412,14 @@ async def test_update_range_with_oauth(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1', + file_path="file1", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act await file_client.upload_file(self.short_byte_data) - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 await file_client.upload_range(data, offset=0, length=512) # Assert @@ -1416,13 +1440,14 @@ async def test_update_range_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) await file_client.upload_file(self.short_byte_data) # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 await file_client.upload_range(data, offset=0, length=512) props = await file_client.get_file_properties() @@ -1431,7 +1456,7 @@ async def test_update_range_trailing_dot(self, **kwargs): content = await content.readall() assert data == content[:512] assert self.short_byte_data[512:] == content[512:] - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy_async @@ -1441,10 +1466,10 @@ async def test_update_range_with_lease(self, **kwargs): self._setup(storage_account_name, storage_account_key) file_client = await self._create_file(storage_account_name, storage_account_key) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 with pytest.raises(HttpResponseError): await file_client.upload_range(data, offset=0, length=512) await file_client.upload_range(data, offset=0, length=512, lease=lease) @@ -1465,7 +1490,7 @@ async def test_update_range_with_md5(self, **kwargs): file_client = await self._create_file(storage_account_name, storage_account_key) # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 await file_client.upload_range(data, offset=0, length=512, validate_content=True) # Assert @@ -1481,7 +1506,7 @@ async def test_update_range_last_written_mode_now(self, **kwargs): current_last_write_time = (await file_client.get_file_properties()).last_write_time # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 await file_client.upload_range(data, offset=0, length=512, file_last_write_mode="Now") # Assert @@ -1499,7 +1524,7 @@ async def test_update_range_last_written_mode_preserve(self, **kwargs): current_last_write_time = (await file_client.get_file_properties()).last_write_time # Act - data = b'abcdefghijklmnop' * 32 + data = b"abcdefghijklmnop" * 32 await file_client.upload_range(data, offset=0, length=512, file_last_write_mode="Preserve") # Assert @@ -1513,11 +1538,15 @@ async def test_update_range_from_file_url_when_source_file_does_not_have_enough_ storage_account_key = kwargs.pop("storage_account_key") 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_name = "testfile1" + 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_name = "filetoupdate" + 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( @@ -1527,10 +1556,10 @@ async def test_update_range_from_file_url_when_source_file_does_not_have_enough_ source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1) + expiry=datetime.utcnow() + timedelta(hours=1), ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act with pytest.raises(HttpResponseError): @@ -1544,13 +1573,17 @@ async def test_update_range_from_file_url(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") 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) - data = b'abcdefghijklmnop' * 32 + source_file_name = "testfile" + 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_name = "filetoupdate" + 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( @@ -1560,9 +1593,10 @@ async def test_update_range_from_file_url(self, **kwargs): source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act await destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0) @@ -1572,8 +1606,8 @@ async def test_update_range_from_file_url(self, **kwargs): file_content = await destination_file_client.download_file(offset=0, length=512) file_content = await file_content.readall() assert 1 == len(file_ranges) - assert 0 == file_ranges[0].get('start') - assert 511 == file_ranges[0].get('end') + assert 0 == file_ranges[0].get("start") + assert 511 == file_ranges[0].get("end") assert data == file_content @FileSharePreparer() @@ -1584,18 +1618,23 @@ 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' + destination_file_name = "filetoupdate" destination_file_client = await self._create_empty_file( - storage_account_name, storage_account_key, file_name=destination_file_name) + storage_account_name, storage_account_key, file_name=destination_file_name + ) with pytest.raises(HttpResponseError): await destination_file_client.upload_range_from_url( - source_blob_client.url, offset=0, length=512, source_offset=0) + source_blob_client.url, offset=0, length=512, source_offset=0 + ) await destination_file_client.upload_range_from_url( - source_blob_client.url, offset=0, length=512, source_offset=0, source_authorization=token) + source_blob_client.url, offset=0, length=512, source_offset=0, source_authorization=token + ) @FileSharePreparer() @recorded_by_proxy_async @@ -1604,14 +1643,18 @@ async def test_update_range_from_file_url_with_lease(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") 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) - data = b'abcdefghijklmnop' * 32 + source_file_name = "testfile" + 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) - lease = await destination_file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + destination_file_name = "filetoupdate" + 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 sas_token_for_source_file = self.generate_sas( @@ -1621,14 +1664,16 @@ async def test_update_range_from_file_url_with_lease(self, **kwargs): source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act with pytest.raises(HttpResponseError): await destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0) - await destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0, - lease=lease) + await destination_file_client.upload_range_from_url( + source_file_url, offset=0, length=512, source_offset=0, lease=lease + ) # Assert # To make sure the range of the file is actually updated @@ -1636,8 +1681,8 @@ async def test_update_range_from_file_url_with_lease(self, **kwargs): file_content = await destination_file_client.download_file(offset=0, length=512) file_content = await file_content.readall() assert 1 == len(file_ranges) - assert 0 == file_ranges[0].get('start') - assert 511 == file_ranges[0].get('end') + assert 0 == file_ranges[0].get("start") + assert 511 == file_ranges[0].get("end") assert data == file_content @FileSharePreparer() @@ -1647,15 +1692,19 @@ async def test_update_big_range_from_file_url(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file_name = 'testfile1' + 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) - data = b'abcdefghijklmnop' * 65536 - await source_file_client.upload_range(data, offset=0, length=end+1) + 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_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 + ) # generate SAS for the source file sas_token_for_source_file = self.generate_sas( @@ -1665,12 +1714,13 @@ async def test_update_big_range_from_file_url(self, **kwargs): source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act - await destination_file_client.upload_range_from_url(source_file_url, offset=0, length=end+1, source_offset=0) + await destination_file_client.upload_range_from_url(source_file_url, offset=0, length=end + 1, source_offset=0) # Assert # To make sure the range of the file is actually updated @@ -1678,8 +1728,8 @@ async def test_update_big_range_from_file_url(self, **kwargs): file_content = await destination_file_client.download_file(offset=0, length=end + 1) file_content = await file_content.readall() assert 1 == len(file_ranges) - assert 0 == file_ranges[0].get('start') - assert end == file_ranges[0].get('end') + assert 0 == file_ranges[0].get("start") + assert end == file_ranges[0].get("end") assert data == file_content @FileSharePreparer() @@ -1689,14 +1739,13 @@ async def test_update_range_from_file_url_last_written_mode_now(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file_client = await self._create_file(storage_account_name, storage_account_key, file_name='testfile') - data = b'abcdefghijklmnop' * 32 + source_file_client = await self._create_file(storage_account_name, storage_account_key, file_name="testfile") + data = b"abcdefghijklmnop" * 32 await source_file_client.upload_range(data, offset=0, length=512) destination_file_client = await self._create_empty_file( - storage_account_name, - storage_account_key, - file_name='filetoupdate') + storage_account_name, storage_account_key, file_name="filetoupdate" + ) current_last_write_time = (await destination_file_client.get_file_properties()).last_write_time # generate SAS for the source file @@ -1707,13 +1756,15 @@ async def test_update_range_from_file_url_last_written_mode_now(self, **kwargs): source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act - await destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0, - file_last_write_mode="Now") + await destination_file_client.upload_range_from_url( + source_file_url, offset=0, length=512, source_offset=0, file_last_write_mode="Now" + ) # Assert new_last_write_time = (await destination_file_client.get_file_properties()).last_write_time @@ -1726,14 +1777,13 @@ async def test_update_range_from_file_url_last_written_mode_preserve(self, **kwa storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file_client = await self._create_file(storage_account_name, storage_account_key, file_name='testfile') - data = b'abcdefghijklmnop' * 32 + source_file_client = await self._create_file(storage_account_name, storage_account_key, file_name="testfile") + data = b"abcdefghijklmnop" * 32 await source_file_client.upload_range(data, offset=0, length=512) destination_file_client = await self._create_empty_file( - storage_account_name, - storage_account_key, - file_name='filetoupdate') + storage_account_name, storage_account_key, file_name="filetoupdate" + ) current_last_write_time = (await destination_file_client.get_file_properties()).last_write_time # generate SAS for the source file @@ -1744,13 +1794,15 @@ async def test_update_range_from_file_url_last_written_mode_preserve(self, **kwa source_file_client.file_path, source_file_client.credential.account_key, FileSasPermissions(read=True), - expiry=datetime.utcnow() + timedelta(hours=1)) + expiry=datetime.utcnow() + timedelta(hours=1), + ) - source_file_url = source_file_client.url + '?' + sas_token_for_source_file + source_file_url = source_file_client.url + "?" + sas_token_for_source_file # Act - await destination_file_client.upload_range_from_url(source_file_url, offset=0, length=512, source_offset=0, - file_last_write_mode="Preserve") + await destination_file_client.upload_range_from_url( + source_file_url, offset=0, length=512, source_offset=0, file_last_write_mode="Preserve" + ) # Assert new_last_write_time = (await destination_file_client.get_file_properties()).last_write_time @@ -1771,7 +1823,7 @@ async def test_clear_range(self, **kwargs): # Assert content = await file_client.download_file() content = await content.readall() - assert b'\x00' * 512 == content[:512] + assert b"\x00" * 512 == content[:512] assert self.short_byte_data[512:] == content[512:] @FileSharePreparer() @@ -1786,9 +1838,10 @@ async def test_clear_range_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) await file_client.upload_file(self.short_byte_data) # Act @@ -1798,9 +1851,9 @@ async def test_clear_range_trailing_dot(self, **kwargs): # Assert content = await file_client.download_file() content = await content.readall() - assert b'\x00' * 512 == content[:512] + assert b"\x00" * 512 == content[:512] assert self.short_byte_data[512:] == content[512:] - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy_async @@ -1812,10 +1865,10 @@ 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') + encoded = data.encode("utf-8") # Assert content = await file_client.download_file() @@ -1838,7 +1891,8 @@ async def test_list_ranges_none(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.create_file(1024) # Act @@ -1860,9 +1914,10 @@ async def test_list_ranges_none_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) await file_client.create_file(1024) # Act @@ -1872,7 +1927,7 @@ async def test_list_ranges_none_trailing_dot(self, **kwargs): # Assert assert ranges is not None assert len(ranges) == 0 - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy_async @@ -1887,13 +1942,14 @@ async def test_list_ranges_none_with_invalid_lease_fails(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.create_file(1024) - await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act with pytest.raises(HttpResponseError): - await file_client.get_ranges(lease='44444444-3333-2222-1111-000000000000') + await file_client.get_ranges(lease="44444444-3333-2222-1111-000000000000") # Get ranges on a leased file will succeed without provide the lease ranges = await file_client.get_ranges() @@ -1915,7 +1971,8 @@ async def test_list_ranges_diff(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.create_file(2048) share_client = self.fsc.get_share_client(self.share_name) @@ -1927,7 +1984,7 @@ async def test_list_ranges_diff(self, **kwargs): await file_client.clear_range(offset=512, length=512) ranges1, cleared1 = await file_client.get_ranges_diff(previous_sharesnapshot=snapshot1) - ranges2, cleared2 = await file_client.get_ranges_diff(previous_sharesnapshot=snapshot2['snapshot']) + ranges2, cleared2 = await file_client.get_ranges_diff(previous_sharesnapshot=snapshot2["snapshot"]) # Assert assert ranges1 is not None @@ -1935,20 +1992,20 @@ async def test_list_ranges_diff(self, **kwargs): assert len(ranges1) == 2 assert isinstance(cleared1, list) assert len(cleared1) == 1 - assert ranges1[0]['start'] == 0 - assert ranges1[0]['end'] == 511 - assert cleared1[0]['start'] == 512 - assert cleared1[0]['end'] == 1023 - assert ranges1[1]['start'] == 1024 - assert ranges1[1]['end'] == 1535 + assert ranges1[0]["start"] == 0 + assert ranges1[0]["end"] == 511 + assert cleared1[0]["start"] == 512 + assert cleared1[0]["end"] == 1023 + assert ranges1[1]["start"] == 1024 + assert ranges1[1]["end"] == 1535 assert ranges2 is not None assert isinstance(ranges2, list) assert len(ranges2) == 0 assert isinstance(cleared2, list) assert len(cleared2) == 1 - assert cleared2[0]['start'] == 512 - assert cleared2[0]['end'] == 1023 + assert cleared2[0]["start"] == 512 + assert cleared2[0]["end"] == 1023 @FileSharePreparer() @recorded_by_proxy_async @@ -1965,7 +2022,8 @@ async def test_list_ranges_diff_with_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) await file_client.create_file(2048) share_client = self.fsc.get_share_client(self.share_name) @@ -1977,7 +2035,7 @@ async def test_list_ranges_diff_with_oauth(self, **kwargs): await file_client.clear_range(offset=512, length=512) ranges1, cleared1 = await file_client.get_ranges_diff(previous_sharesnapshot=snapshot1) - ranges2, cleared2 = await file_client.get_ranges_diff(previous_sharesnapshot=snapshot2['snapshot']) + ranges2, cleared2 = await file_client.get_ranges_diff(previous_sharesnapshot=snapshot2["snapshot"]) # Assert assert ranges1 is not None @@ -1985,20 +2043,20 @@ async def test_list_ranges_diff_with_oauth(self, **kwargs): assert len(ranges1) == 2 assert isinstance(cleared1, list) assert len(cleared1) == 1 - assert ranges1[0]['start'] == 0 - assert ranges1[0]['end'] == 511 - assert cleared1[0]['start'] == 512 - assert cleared1[0]['end'] == 1023 - assert ranges1[1]['start'] == 1024 - assert ranges1[1]['end'] == 1535 + assert ranges1[0]["start"] == 0 + assert ranges1[0]["end"] == 511 + assert cleared1[0]["start"] == 512 + assert cleared1[0]["end"] == 1023 + assert ranges1[1]["start"] == 1024 + assert ranges1[1]["end"] == 1535 assert ranges2 is not None assert isinstance(ranges2, list) assert len(ranges2) == 0 assert isinstance(cleared2, list) assert len(cleared2) == 1 - assert cleared2[0]['start'] == 512 - assert cleared2[0]['end'] == 1023 + assert cleared2[0]["start"] == 512 + assert cleared2[0]["end"] == 1023 @FileSharePreparer() @recorded_by_proxy_async @@ -2012,9 +2070,10 @@ async def test_list_ranges_diff_trailing_dot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, - allow_trailing_dot=True) + allow_trailing_dot=True, + ) await file_client.create_file(2048) share_client = self.fsc.get_share_client(self.share_name) @@ -2026,7 +2085,7 @@ async def test_list_ranges_diff_trailing_dot(self, **kwargs): await file_client.clear_range(offset=512, length=512) ranges1, cleared1 = await file_client.get_ranges_diff(previous_sharesnapshot=snapshot1) - ranges2, cleared2 = await file_client.get_ranges_diff(previous_sharesnapshot=snapshot2['snapshot']) + ranges2, cleared2 = await file_client.get_ranges_diff(previous_sharesnapshot=snapshot2["snapshot"]) props = await file_client.get_file_properties() # Assert @@ -2035,22 +2094,22 @@ async def test_list_ranges_diff_trailing_dot(self, **kwargs): assert len(ranges1) == 2 assert isinstance(cleared1, list) assert len(cleared1) == 1 - assert ranges1[0]['start'] == 0 - assert ranges1[0]['end'] == 511 - assert cleared1[0]['start'] == 512 - assert cleared1[0]['end'] == 1023 - assert ranges1[1]['start'] == 1024 - assert ranges1[1]['end'] == 1535 + assert ranges1[0]["start"] == 0 + assert ranges1[0]["end"] == 511 + assert cleared1[0]["start"] == 512 + assert cleared1[0]["end"] == 1023 + assert ranges1[1]["start"] == 1024 + assert ranges1[1]["end"] == 1535 assert ranges2 is not None assert isinstance(ranges2, list) assert len(ranges2) == 0 assert isinstance(cleared2, list) assert len(cleared2) == 1 - assert cleared2[0]['start'] == 512 - assert cleared2[0]['end'] == 1023 + assert cleared2[0]["start"] == 512 + assert cleared2[0]["end"] == 1023 - assert props.name == file_name + '.' + assert props.name == file_name + "." @FileSharePreparer() @recorded_by_proxy_async @@ -2065,7 +2124,8 @@ async def test_list_ranges_diff_support_rename(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.create_file(2048) share_client = self.fsc.get_share_client(self.share_name) @@ -2076,21 +2136,23 @@ async def test_list_ranges_diff_support_rename(self, **kwargs): previous_snapshot = await share_client.create_snapshot() await file_client.clear_range(offset=512, length=512) await file_client.upload_range(data2, offset=512, length=512) - file_client = await file_client.rename_file(file_name + 'renamed') + file_client = await file_client.rename_file(file_name + "renamed") # Assert with pytest.raises(ResourceExistsError): 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 assert isinstance(cleared, list) assert len(cleared) == 0 - assert ranges[0]['start'] == 512 - assert ranges[0]['end'] == 1023 + assert ranges[0]["start"] == 512 + assert ranges[0]["end"] == 1023 @FileSharePreparer() @recorded_by_proxy_async @@ -2105,10 +2167,11 @@ async def test_list_ranges_2(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.create_file(2048) - data = b'abcdefghijklmnop' * 32 + 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) @@ -2118,10 +2181,10 @@ async def test_list_ranges_2(self, **kwargs): # Assert assert ranges is not None assert len(ranges) == 2 - assert ranges[0]['start'] == 0 - assert ranges[0]['end'] == 511 - assert ranges[1]['start'] == 1024 - assert ranges[1]['end'] == 1535 + assert ranges[0]["start"] == 0 + assert ranges[0]["end"] == 511 + assert ranges[1]["start"] == 1024 + assert ranges[1]["end"] == 1535 @FileSharePreparer() @recorded_by_proxy_async @@ -2136,9 +2199,10 @@ async def test_list_ranges_none_from_snapshot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) 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( @@ -2146,7 +2210,8 @@ async def test_list_ranges_none_from_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.delete_file() @@ -2172,7 +2237,8 @@ async def test_list_ranges_none_from_snapshot_with_oauth(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) await file_client.create_file(1024) share_client = self.fsc.get_share_client(self.share_name) @@ -2183,7 +2249,8 @@ async def test_list_ranges_none_from_snapshot_with_oauth(self, **kwargs): file_path=file_client.file_name, snapshot=snapshot, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) await file_client.delete_file() @@ -2207,12 +2274,13 @@ async def test_list_ranges_2_from_snapshot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.create_file(2048) - data = b'abcdefghijklmnop' * 32 + 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( @@ -2220,7 +2288,8 @@ async def test_list_ranges_2_from_snapshot(self, **kwargs): share_name=self.share_name, file_path=file_client.file_name, snapshot=snapshot, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.delete_file() @@ -2230,10 +2299,10 @@ async def test_list_ranges_2_from_snapshot(self, **kwargs): # Assert assert ranges is not None assert len(ranges) == 2 - assert ranges[0]['start'] == 0 - assert ranges[0]['end'] == 511 - assert ranges[1]['start'] == 1024 - assert ranges[1]['end'] == 1535 + assert ranges[0]["start"] == 0 + assert ranges[0]["end"] == 511 + assert ranges[1]["start"] == 1024 + assert ranges[1]["end"] == 1535 @FileSharePreparer() @recorded_by_proxy_async @@ -2246,16 +2315,17 @@ async def test_copy_file_with_existing_file(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) # Act copy = await file_client.start_copy_from_url(source_client.url) # Assert assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = await file_client.download_file() content = await copy_file.readall() @@ -2273,17 +2343,18 @@ async def test_copy_file_with_existing_file_oauth(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', + file_path="file1copy", credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) # Act copy = await file_client.start_copy_from_url(source_client.url) # Assert assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = await file_client.download_file() content = await copy_file.readall() @@ -2301,19 +2372,21 @@ async def test_copy_file_with_existing_file_trailing_dot(self, **kwargs): source_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=file_name + '.', + file_path=file_name + ".", credential=storage_account_key, allow_trailing_dot=True, - allow_source_trailing_dot=True) + allow_source_trailing_dot=True, + ) await source_client.upload_file(self.short_byte_data) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy.', + file_path="file1copy.", credential=storage_account_key, allow_trailing_dot=True, - allow_source_trailing_dot=True) + allow_source_trailing_dot=True, + ) @FileSharePreparer() @recorded_by_proxy_async @@ -2326,10 +2399,11 @@ async def test_copy_existing_file_with_lease(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) await file_client.create_file(1024) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act with pytest.raises(HttpResponseError): @@ -2339,8 +2413,8 @@ async def test_copy_existing_file_with_lease(self, **kwargs): # Assert assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = await file_client.download_file() content = await copy_file.readall() @@ -2357,8 +2431,9 @@ async def test_copy_file_ignore_readonly(self, **kwargs): dest_file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) file_attributes = NTFSAttributes(read_only=True) await dest_file.create_file(1024, file_attributes=file_attributes) @@ -2371,8 +2446,8 @@ async def test_copy_file_ignore_readonly(self, **kwargs): # Assert assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = await dest_file.download_file() content = await copy_file.readall() @@ -2389,8 +2464,9 @@ async def test_copy_file_with_specifying_acl_copy_behavior_attributes(self, **kw file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) source_props = await source_client.get_file_properties() file_creation_time = source_props.creation_time - timedelta(hours=1) @@ -2412,15 +2488,15 @@ async def test_copy_file_with_specifying_acl_copy_behavior_attributes(self, **kw # Assert dest_prop = await file_client.get_file_properties() # to make sure the attributes are the same as the set ones - assert file_creation_time == dest_prop['creation_time'] - assert file_last_write_time == dest_prop['last_write_time'] - assert file_change_time == dest_prop['change_time'] - assert 'Temporary' in dest_prop['file_attributes'] - assert 'NoScrubData' in dest_prop['file_attributes'] + assert file_creation_time == dest_prop["creation_time"] + assert file_last_write_time == dest_prop["last_write_time"] + assert file_change_time == dest_prop["change_time"] + assert "Temporary" in dest_prop["file_attributes"] + assert "NoScrubData" in dest_prop["file_attributes"] assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = await file_client.download_file() content = await copy_file.readall() @@ -2438,23 +2514,21 @@ async def test_copy_file_with_specifying_acl_and_attributes_from_source(self, ** file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='file1copy', - credential=storage_account_key) + file_path="file1copy", + credential=storage_account_key, + ) # Act - copy = await file_client.start_copy_from_url( - source_client.url, - permission_key='source' - ) + copy = await file_client.start_copy_from_url(source_client.url, permission_key="source") # Assert dest_prop = await file_client.get_file_properties() # to make sure the acl is copied from source - assert source_prop['permission_key'] == dest_prop['permission_key'] + assert source_prop["permission_key"] == dest_prop["permission_key"] assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None copy_file = await file_client.download_file() content = await copy_file.readall() @@ -2468,18 +2542,21 @@ 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) + self._setup( + storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key + ) await self._setup_share(storage_account_name, storage_account_key) await self._create_remote_share() source_file = await self._create_remote_file() # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, - credential=storage_account_key) + credential=storage_account_key, + ) with pytest.raises(HttpResponseError) as e: await file_client.start_copy_from_url(source_file.url) @@ -2495,8 +2572,10 @@ 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) - data = b'12345678' * 1024 + self._setup( + storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key + ) + data = b"12345678" * 1024 await self._create_remote_share() source_file = await self._create_remote_file(file_data=data) sas_token = self.generate_sas( @@ -2508,21 +2587,22 @@ async def test_copy_file_async_private_file_with_sas_async(self, **kwargs): permission=FileSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), ) - source_url = source_file.url + '?' + sas_token + source_url = source_file.url + "?" + sas_token # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" await self._setup_share(storage_account_name, storage_account_key) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, - credential=storage_account_key) + credential=storage_account_key, + ) copy_resp = await file_client.start_copy_from_url(source_url) # Assert - assert copy_resp['copy_status'] in ['success', 'pending'] - await self._wait_for_async_copy(self.share_name, target_file_name) + assert copy_resp["copy_status"] in ["success", "pending"] + await self._wait_for_async_copy(self.share_name, target_file_name) content = await file_client.download_file() actual_data = await content.readall() @@ -2536,8 +2616,10 @@ 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) - data = b'12345678' * 1024 * 1024 + self._setup( + storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key + ) + data = b"12345678" * 1024 * 1024 await self._setup_share(storage_account_name, storage_account_key) await self._create_remote_share() source_file = await self._create_remote_file(file_data=data) @@ -2550,24 +2632,25 @@ async def test_abort_copy_file_async(self, **kwargs): permission=FileSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), ) - source_url = source_file.url + '?' + sas_token + source_url = source_file.url + "?" + sas_token # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, - credential=storage_account_key) + credential=storage_account_key, + ) copy_resp = await file_client.start_copy_from_url(source_url) - assert copy_resp['copy_status'] == 'pending' + assert copy_resp["copy_status"] == "pending" await file_client.abort_copy(copy_resp) # Assert target_file = await file_client.download_file() content = await target_file.readall() - assert content == b'' - assert target_file.properties.copy.status == 'aborted' + assert content == b"" + assert target_file.properties.copy.status == "aborted" @pytest.mark.live_test_only @FileSharePreparer() @@ -2578,8 +2661,10 @@ 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) - data = b'12345678' * 1024 * 1024 + self._setup( + storage_account_name, storage_account_key, secondary_storage_account_name, secondary_storage_account_key + ) + data = b"12345678" * 1024 * 1024 await self._setup_share(storage_account_name, storage_account_key) await self._create_remote_share() source_file = await self._create_remote_file(file_data=data) @@ -2592,25 +2677,26 @@ async def test_abort_copy_file_async_with_oauth(self, **kwargs): permission=FileSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), ) - source_url = source_file.url + '?' + sas_token + source_url = source_file.url + "?" + sas_token # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, credential=token_credential, - token_intent=TEST_INTENT) + token_intent=TEST_INTENT, + ) copy_resp = await file_client.start_copy_from_url(source_url) - assert copy_resp['copy_status'] == 'pending' + assert copy_resp["copy_status"] == "pending" await file_client.abort_copy(copy_resp) # Assert target_file = await file_client.download_file() content = await target_file.readall() - assert content == b'' - assert target_file.properties.copy.status == 'aborted' + assert content == b"" + assert target_file.properties.copy.status == "aborted" @FileSharePreparer() @recorded_by_proxy_async @@ -2622,19 +2708,20 @@ async def test_abort_copy_file_with_synchronous_copy_fails(self, **kwargs): source_file = await self._create_file(storage_account_name, storage_account_key) # Act - target_file_name = 'targetfile' + target_file_name = "targetfile" file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=target_file_name, - credential=storage_account_key) + credential=storage_account_key, + ) copy_resp = await file_client.start_copy_from_url(source_file.url) with pytest.raises(HttpResponseError): await file_client.abort_copy(copy_resp) # Assert - assert copy_resp['copy_status'] == 'success' + assert copy_resp["copy_status"] == "success" @FileSharePreparer() @recorded_by_proxy_async @@ -2643,21 +2730,22 @@ async def test_unicode_get_file_unicode_name(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_name = '啊齄丂狛狜' + file_name = "啊齄丂狛狜" await self._setup_share(storage_account_name, storage_account_key) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) - await file_client.upload_file(b'hello world') + credential=storage_account_key, + ) + await file_client.upload_file(b"hello world") # Act content = await file_client.download_file() content = await content.readall() # Assert - assert content == b'hello world' + assert content == b"hello world" @FileSharePreparer() @recorded_by_proxy_async @@ -2666,31 +2754,32 @@ async def test_unicode_get_file_unicode_name_with_lease(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_name = '啊齄丂狛狜' + file_name = "啊齄丂狛狜" await self._setup_share(storage_account_name, storage_account_key) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.create_file(1024) - lease = await file_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await file_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") with pytest.raises(HttpResponseError): - await file_client.upload_file(b'hello world') + await file_client.upload_file(b"hello world") - await file_client.upload_file(b'hello world', lease=lease) + await file_client.upload_file(b"hello world", lease=lease) # Act # download the file with a wrong lease id will fail with pytest.raises(HttpResponseError): - await file_client.upload_file(b'hello world', lease='44444444-3333-2222-1111-000000000000') + await file_client.upload_file(b"hello world", lease="44444444-3333-2222-1111-000000000000") content = await file_client.download_file() content = await content.readall() # Assert - assert content == b'hello world' + assert content == b"hello world" @FileSharePreparer() @recorded_by_proxy_async @@ -2705,10 +2794,11 @@ async def test_file_unicode_data(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act - data = u'hello world啊齄丂狛狜'.encode('utf-8') + data = "hello world啊齄丂狛狜".encode("utf-8") await file_client.upload_file(data) # Assert @@ -2726,7 +2816,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 @@ -2734,7 +2824,7 @@ async def test_file_unicode_data_and_file_attributes(self, **kwargs): transformed_content = await content.readall() properties = await file_client.get_file_properties() assert transformed_content == data - assert 'Temporary' in properties.file_attributes + assert "Temporary" in properties.file_attributes @FileSharePreparer() @recorded_by_proxy_async @@ -2743,7 +2833,7 @@ 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+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==" binary_data = base64.b64decode(base64_data) await self._setup_share(storage_account_name, storage_account_key) @@ -2752,7 +2842,8 @@ async def test_unicode_get_file_binary_data(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) await file_client.upload_file(binary_data) # Act @@ -2777,13 +2868,15 @@ async def test_create_file_from_bytes_with_progress(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act progress = [] + def callback(response): - current = response.context['upload_stream_current'] - total = response.context['data_stream_total'] + current = response.context["upload_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -2808,13 +2901,14 @@ async def test_create_file_from_bytes_with_index(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act response = await file_client.upload_file(data[index:], max_concurrency=2) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert await self.assertFileEqual(file_client, data[1024:]) @@ -2836,16 +2930,17 @@ async def test_create_file_from_bytes_with_index_and_count(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act response = await file_client.upload_file(data[index:], length=count, max_concurrency=2) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert - await self.assertFileEqual(file_client, data[index:index + count]) + await self.assertFileEqual(file_client, data[index : index + count]) @pytest.mark.live_test_only @FileSharePreparer() @@ -2862,7 +2957,8 @@ async def test_create_file_from_path(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -2870,8 +2966,8 @@ async def test_create_file_from_path(self, **kwargs): temp_file.seek(0) response = await file_client.upload_file(temp_file, max_concurrency=2) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert await self.assertFileEqual(file_client, data) @@ -2891,13 +2987,15 @@ async def test_create_file_from_path_with_progress(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act progress = [] + def callback(response): - current = response.context['upload_stream_current'] - total = response.context['data_stream_total'] + current = response.context["upload_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -2906,8 +3004,8 @@ def callback(response): temp_file.seek(0) response = await file_client.upload_file(temp_file, max_concurrency=2, raw_response_hook=callback) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert await self.assertFileEqual(file_client, data) @@ -2928,7 +3026,8 @@ async def test_create_file_from_stream(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_size = len(data) @@ -2937,8 +3036,8 @@ async def test_create_file_from_stream(self, **kwargs): temp_file.seek(0) response = await file_client.upload_file(temp_file, max_concurrency=2) assert isinstance(response, dict) - assert 'last_modified' in response - assert 'etag' in response + assert "last_modified" in response + assert "etag" in response # Assert await self.assertFileEqual(file_client, data[:file_size]) @@ -2958,7 +3057,8 @@ async def test_create_file_from_stream_non_seekable(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_size = len(data) @@ -2986,13 +3086,15 @@ async def test_create_file_from_stream_with_progress(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act progress = [] + def callback(response): - current = response.context['upload_stream_current'] - total = response.context['data_stream_total'] + current = response.context["upload_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -3021,7 +3123,8 @@ async def test_create_file_from_stream_truncated(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act file_size = len(data) - 512 @@ -3048,13 +3151,15 @@ async def test_create_file_from_stream_with_progress_truncated(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act progress = [] + def callback(response): - current = response.context['upload_stream_current'] - total = response.context['data_stream_total'] + current = response.context["upload_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -3077,7 +3182,7 @@ async def test_create_file_from_async_generator(self, **kwargs): self._setup(storage_account_name, storage_account_key) await self._setup_share(storage_account_name, storage_account_key) file_name = self._get_file_reference() - data = b'Hello Async World!' + data = b"Hello Async World!" async def data_generator(): for _ in range(3): @@ -3088,14 +3193,15 @@ async def data_generator(): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key) + credential=storage_account_key, + ) # Act - file_size = len(data*3) + file_size = len(data * 3) await file_client.upload_file(data_generator(), length=file_size) # Assert - await self.assertFileEqual(file_client, data*3) + await self.assertFileEqual(file_client, data * 3) @FileSharePreparer() @recorded_by_proxy_async @@ -3106,14 +3212,15 @@ 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' - data = text.encode('utf-8') + text = "hello 啊齄丂狛狜 world" + data = text.encode("utf-8") file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act await file_client.upload_file(text) @@ -3130,17 +3237,18 @@ 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' - data = text.encode('utf-16') + text = "hello 啊齄丂狛狜 world" + data = text.encode("utf-16") file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act - await file_client.upload_file(text, encoding='UTF-16') + await file_client.upload_file(text, encoding="UTF-16") # Assert await self.assertFileEqual(file_client, data) @@ -3156,13 +3264,14 @@ async def test_create_file_from_text_chunked_upload(self, **kwargs): file_name = self._get_file_reference() await self._setup_share(storage_account_name, storage_account_key) data = self.get_random_text_data(LARGE_FILE_SIZE) - encoded_data = data.encode('utf-8') + encoded_data = data.encode("utf-8") file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act await file_client.upload_file(data) @@ -3186,7 +3295,8 @@ async def test_create_file_with_md5_small(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act await file_client.upload_file(data, validate_content=True) @@ -3208,7 +3318,8 @@ async def test_create_file_with_md5_large(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=4 * 1024) + max_range_size=4 * 1024, + ) # Act await file_client.upload_file(data, validate_content=True, max_concurrency=2) @@ -3230,9 +3341,10 @@ async def test_create_file_progress(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=1024) + max_range_size=1024, + ) - data = b'a' * 5 * 1024 + data = b"a" * 5 * 1024 progress = ProgressTracker(len(data), 1024) # Act @@ -3257,9 +3369,10 @@ async def test_create_file_progress_parallel(self, **kwargs): share_name=self.share_name, file_path=file_name, credential=storage_account_key, - max_range_size=1024) + max_range_size=1024, + ) - data = b'a' * 5 * 1024 + data = b"a" * 5 * 1024 progress = ProgressTracker(len(data), 1024) # Act @@ -3292,7 +3405,8 @@ async def test_sas_access_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=token) + credential=token, + ) content = await file_client.download_file() content = await content.readall() @@ -3304,19 +3418,19 @@ async def test_sas_access_file(self, **kwargs): async def test_sas_signed_identifier(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - variables = kwargs.pop('variables', {}) + variables = kwargs.pop("variables", {}) self._setup(storage_account_name, storage_account_key) file_client = await self._create_file(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) access_policy = AccessPolicy() - start_time = self.get_datetime_variable(variables, 'start_time', datetime.utcnow() - timedelta(hours=1)) - expiry_time = self.get_datetime_variable(variables, 'expiry_time', datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(hours=1)) + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) access_policy.start = start_time access_policy.expiry = expiry_time access_policy.permission = FileSasPermissions(read=True) - identifiers = {'testid': access_policy} + identifiers = {"testid": access_policy} await share_client.set_share_access_policy(identifiers) token = self.generate_sas( @@ -3325,12 +3439,11 @@ async def test_sas_signed_identifier(self, **kwargs): file_client.share_name, file_client.file_path, file_client.credential.account_key, - policy_id='testid') + policy_id="testid", + ) # Act - sas_file = ShareFileClient.from_file_url( - file_client.url, - credential=token) + sas_file = ShareFileClient.from_file_url(file_client.url, credential=token) content = await file_client.download_file() content = await content.readall() @@ -3362,7 +3475,8 @@ async def test_account_sas(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=token) + credential=token, + ) response = requests.get(file_client.url) @@ -3392,7 +3506,8 @@ async def test_account_sas_credential(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=AzureSasCredential(token)) + credential=AzureSasCredential(token), + ) properties = await file_client.get_file_properties() @@ -3405,7 +3520,6 @@ async def test_azure_named_key_credential_access(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_client = await self._create_file(storage_account_name, storage_account_key) named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) @@ -3415,7 +3529,8 @@ async def test_azure_named_key_credential_access(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=named_key) + credential=named_key, + ) properties = await file_client.get_file_properties() @@ -3431,7 +3546,8 @@ async def test_account_sas_raises_if_sas_already_in_uri(self, **kwargs): self.account_url(storage_account_name, "file") + "?sig=foo", share_name="foo", file_path="foo", - credential=AzureSasCredential("?foo=bar")) + credential=AzureSasCredential("?foo=bar"), + ) @pytest.mark.live_test_only @FileSharePreparer() @@ -3456,7 +3572,8 @@ async def test_shared_read_access_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=token) + credential=token, + ) response = requests.get(file_client.url) # Assert @@ -3479,11 +3596,11 @@ async def test_shared_read_access_file_with_content_query_params(self, **kwargs) file_client.credential.account_key, permission=FileSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), - cache_control='no-cache', - content_disposition='inline', - content_encoding='utf-8', - content_language='fr', - content_type='text', + cache_control="no-cache", + content_disposition="inline", + content_encoding="utf-8", + content_language="fr", + content_type="text", ) # Act @@ -3491,16 +3608,17 @@ async def test_shared_read_access_file_with_content_query_params(self, **kwargs) self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client.file_name, - credential=token) + credential=token, + ) response = requests.get(file_client.url) # Assert assert self.short_byte_data == response.content - assert response.headers['cache-control'] == 'no-cache' - assert response.headers['content-disposition'] == 'inline' - assert response.headers['content-encoding'] == 'utf-8' - assert response.headers['content-language'] == 'fr' - assert response.headers['content-type'] == 'text' + assert response.headers["cache-control"] == "no-cache" + assert response.headers["content-disposition"] == "inline" + assert response.headers["content-encoding"] == "utf-8" + assert response.headers["content-language"] == "fr" + assert response.headers["content-type"] == "text" @pytest.mark.live_test_only @FileSharePreparer() @@ -3509,7 +3627,7 @@ async def test_shared_write_access_file(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - updated_data = b'updated file data' + updated_data = b"updated file data" file_client_admin = await self._create_file(storage_account_name, storage_account_key) token = self.generate_sas( generate_file_sas, @@ -3524,17 +3642,18 @@ async def test_shared_write_access_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client_admin.file_name, - credential=token) + credential=token, + ) # 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) + headers = {"x-ms-range": "bytes=0-16", "x-ms-write": "update"} + response = requests.put(file_client.url + "&comp=range", headers=headers, data=updated_data) # Assert assert response.ok file_content = await file_client_admin.download_file() file_content = await file_content.readall() - assert updated_data == file_content[:len(updated_data)] + assert updated_data == file_content[: len(updated_data)] @pytest.mark.live_test_only @FileSharePreparer() @@ -3557,7 +3676,8 @@ async def test_shared_delete_access_file(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_client_admin.file_name, - credential=token) + credential=token, + ) # Act response = requests.delete(file_client.url) @@ -3574,13 +3694,13 @@ async def test_rename_file(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file = await self._create_file(storage_account_name, storage_account_key, 'file1') + source_file = await self._create_file(storage_account_name, storage_account_key, "file1") # Act - new_file = await source_file.rename_file('file2') + new_file = await source_file.rename_file("file2") # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = await new_file.get_file_properties() assert props is not None @@ -3594,20 +3714,20 @@ async def test_rename_file_with_oauth(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) file_name = self._get_file_reference() async with ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=file_name, - credential=storage_account_key) as file_client: + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_name, + credential=storage_account_key, + ) as file_client: # Act resp = await file_client.create_file(1024) - new_file = await file_client.rename_file('file2') + new_file = await file_client.rename_file("file2") # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = await new_file.get_file_properties() assert props is not None - @FileSharePreparer() @recorded_by_proxy_async async def test_rename_file_different_directory(self, **kwargs): @@ -3618,15 +3738,15 @@ async def test_rename_file_different_directory(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_directory = await share_client.create_directory('dir1') - dest_directory = await share_client.create_directory('dir2') - source_file = await source_directory.upload_file('file1', self.short_byte_data) + source_directory = await share_client.create_directory("dir1") + dest_directory = await share_client.create_directory("dir2") + source_file = await source_directory.upload_file("file1", self.short_byte_data) # Act - new_file = await source_file.rename_file(dest_directory.directory_path + '/' + source_file.file_name) + new_file = await source_file.rename_file(dest_directory.directory_path + "/" + source_file.file_name) # Assert - assert 'dir2' in new_file.file_path + assert "dir2" in new_file.file_path props = await new_file.get_file_properties() assert props is not None @@ -3640,9 +3760,9 @@ async def test_rename_file_ignore_readonly(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_file = share_client.get_file_client('file1') + source_file = share_client.get_file_client("file1") await source_file.create_file(1024) - dest_file = share_client.get_file_client('file2') + dest_file = share_client.get_file_client("file2") file_attributes = NTFSAttributes(read_only=True) await dest_file.create_file(1024, file_attributes=file_attributes) @@ -3651,7 +3771,7 @@ async def test_rename_file_ignore_readonly(self, **kwargs): new_file = await source_file.rename_file(dest_file.file_name, overwrite=True, ignore_read_only=True) # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = await new_file.get_file_properties() assert props is not None @@ -3666,11 +3786,11 @@ async def test_rename_file_file_permission(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) file_permission_key = await share_client.create_permission_for_share(TEST_FILE_PERMISSIONS) - source_file = share_client.get_file_client('file1') + source_file = share_client.get_file_client("file1") await source_file.create_file(1024) # Act - new_file = await source_file.rename_file('file2', file_permission=TEST_FILE_PERMISSIONS) + new_file = await source_file.rename_file("file2", file_permission=TEST_FILE_PERMISSIONS) # Assert props = await new_file.get_file_properties() @@ -3687,14 +3807,14 @@ async def test_rename_file_preserve_permission(self, **kwargs): await self._setup_share(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_file = share_client.get_file_client('file1') + source_file = share_client.get_file_client("file1") await source_file.create_file(1024, file_permission=TEST_FILE_PERMISSIONS) source_props = await source_file.get_file_properties() source_permission_key = source_props.permission_key # Act - new_file = await source_file.rename_file('file2', file_permission='preserve') + new_file = await source_file.rename_file("file2", file_permission="preserve") # Assert props = await new_file.get_file_properties() @@ -3708,7 +3828,7 @@ async def test_rename_file_smb_properties(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file = await self._create_file(storage_account_name, storage_account_key, 'file1') + source_file = await self._create_file(storage_account_name, storage_account_key, "file1") file_attributes = NTFSAttributes(read_only=True, archive=True) file_creation_time = datetime(2022, 1, 26, 10, 9, 30, 500000) @@ -3717,16 +3837,17 @@ async def test_rename_file_smb_properties(self, **kwargs): # Act new_file = await source_file.rename_file( - 'file2', + "file2", 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 = 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 @@ -3738,13 +3859,11 @@ async def test_rename_file_content_type(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - source_file = await self._create_file(storage_account_name, storage_account_key, 'file1') - content_type = 'text/plain' + source_file = await self._create_file(storage_account_name, storage_account_key, "file1") + content_type = "text/plain" # Act - new_file = await source_file.rename_file( - 'file2', - content_type=content_type) + new_file = await source_file.rename_file("file2", content_type=content_type) # Assert props = await new_file.get_file_properties() @@ -3759,20 +3878,18 @@ async def test_rename_file_with_lease(self, **kwargs): self._setup(storage_account_name, storage_account_key) - source_file = await self._create_file(storage_account_name, storage_account_key, 'file1') - dest_file = await self._create_file(storage_account_name, storage_account_key, 'file2') - source_lease = await source_file.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') - dest_lease = await dest_file.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + source_file = await self._create_file(storage_account_name, storage_account_key, "file1") + dest_file = await self._create_file(storage_account_name, storage_account_key, "file2") + source_lease = await source_file.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") + dest_lease = await dest_file.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act new_file = await source_file.rename_file( - dest_file.file_name, - overwrite=True, - source_lease=source_lease, - destination_lease=dest_lease) + dest_file.file_name, overwrite=True, source_lease=source_lease, destination_lease=dest_lease + ) # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = await new_file.get_file_properties() assert props is not None @@ -3792,19 +3909,19 @@ async def test_rename_file_share_sas(self, **kwargs): share_client.share_name, share_client.credential.account_key, expiry=datetime.utcnow() + timedelta(hours=1), - permission=ShareSasPermissions(read=True, write=True)) + permission=ShareSasPermissions(read=True, write=True), + ) source_file = ShareFileClient( - self.account_url(storage_account_name, 'file'), - share_client.share_name, 'file1', - credential=token) + self.account_url(storage_account_name, "file"), share_client.share_name, "file1", credential=token + ) await source_file.create_file(1024) # Act - new_file = await source_file.rename_file('file2' + '?' + token) + new_file = await source_file.rename_file("file2" + "?" + token) # Assert - assert 'file2' == new_file.file_name + assert "file2" == new_file.file_name props = await new_file.get_file_properties() assert props is not None @@ -3822,7 +3939,7 @@ async def test_storage_account_audience_file_client(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key + credential=storage_account_key, ) await file_client.create_file(1024) @@ -3837,7 +3954,7 @@ async def test_storage_account_audience_file_client(self, **kwargs): file_path=file_name, credential=token_credential, token_intent=TEST_INTENT, - audience=f'https://{storage_account_name}.file.core.windows.net' + audience=f"https://{storage_account_name}.file.core.windows.net", ) # Assert @@ -3858,7 +3975,7 @@ async def test_bad_audience_file_client(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=file_name, - credential=storage_account_key + credential=storage_account_key, ) await file_client.create_file(1024) @@ -3873,7 +3990,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=f"https://badaudience.file.core.windows.net", ) # Assert @@ -3888,18 +4005,20 @@ async def test_file_permission_format(self, **kwargs): self._setup(storage_account_name, storage_account_key) await self._setup_share(storage_account_name, storage_account_key) share_client = self.fsc.get_share_client(self.share_name) - source_file = share_client.get_file_client('file1') - user_given_permission_sddl = ("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;;;" - "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL") - user_given_permission_binary = ("AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" - "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" - "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=") + source_file = share_client.get_file_client("file1") + user_given_permission_sddl = ( + "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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL" + ) + user_given_permission_binary = ( + "AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" + "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" + "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=" + ) await source_file.create_file( - 1024, - file_permission=user_given_permission_binary, - file_permission_format="binary" + 1024, file_permission=user_given_permission_binary, file_permission_format="binary" ) props = await source_file.get_file_properties() @@ -3907,28 +4026,22 @@ async def test_file_permission_format(self, **kwargs): assert props.permission_key is not None new_file = await source_file.rename_file( - 'file2', - file_permission=user_given_permission_binary, - file_permission_format="binary" + "file2", file_permission=user_given_permission_binary, file_permission_format="binary" ) props = await new_file.get_file_properties() assert props is not None assert props.permission_key is not None server_returned_permission = await share_client.get_permission_for_share( - props.permission_key, - file_permission_format="binary" + props.permission_key, file_permission_format="binary" ) assert server_returned_permission == user_given_permission_binary - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline' - ) + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") await new_file.set_http_headers( content_settings=content_settings, file_permission=user_given_permission_binary, - file_permission_format="binary" + file_permission_format="binary", ) props = await new_file.get_file_properties() assert props is not None @@ -3937,8 +4050,7 @@ async def test_file_permission_format(self, **kwargs): assert props.content_settings.content_disposition == content_settings.content_disposition server_returned_permission = await share_client.get_permission_for_share( - props.permission_key, - file_permission_format="sddl" + props.permission_key, file_permission_format="sddl" ) assert server_returned_permission == user_given_permission_sddl @@ -3946,17 +4058,15 @@ async def test_file_permission_format(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path='filecopy', - credential=storage_account_key + file_path="filecopy", + credential=storage_account_key, ) copy = await file_client.start_copy_from_url( - new_file.url, - file_permission=user_given_permission_binary, - file_permission_format="binary" + new_file.url, file_permission=user_given_permission_binary, file_permission_format="binary" ) assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None await new_file.delete_file() await file_client.delete_file() @@ -3975,7 +4085,7 @@ async def test_mock_transport_no_content_validation(self, **kwargs): file_path="filemocktransport", credential=storage_account_key, transport=transport, - retry_total=0 + retry_total=0, ) data = await file_client.download_file() @@ -4006,7 +4116,7 @@ async def test_mock_transport_with_content_validation(self, **kwargs): file_path="filemocktransport", credential=storage_account_key, transport=transport, - retry_total=0 + retry_total=0, ) data = b"Hello Async World!" 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 84e87748b23f..72295fca6ac0 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 @@ -18,15 +18,15 @@ # ------------------------------------------------------------------------------ SERVICES = { - ShareServiceClient: 'file', - ShareClient: 'file', - ShareDirectoryClient: 'file', - ShareFileClient: 'file', + ShareServiceClient: "file", + ShareClient: "file", + ShareDirectoryClient: "file", + ShareFileClient: "file", } -_CONNECTION_ENDPOINTS = {'file': 'FileEndpoint'} +_CONNECTION_ENDPOINTS = {"file": "FileEndpoint"} -_CONNECTION_ENDPOINTS_SECONDARY = {'file': 'FileSecondaryEndpoint'} +_CONNECTION_ENDPOINTS_SECONDARY = {"file": "FileSecondaryEndpoint"} class TestStorageFileClient(StorageRecordedTestCase): @@ -41,14 +41,25 @@ def _teardown(self, FILE_PATH): os.remove(FILE_PATH) except: pass + # --Helpers----------------------------------------------------------------- - def validate_standard_account_endpoints(self, service, service_type, protocol='https'): + def validate_standard_account_endpoints(self, service, service_type, protocol="https"): 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 - 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 + ) # --Direct Parameters Test Cases -------------------------------------------- @FileSharePreparer() @@ -61,12 +72,16 @@ def test_create_service_with_key(self, **kwargs): for client, url in SERVICES.items(): # Act service = client( - self.account_url(storage_account_name, "file"), credential=self.account_key, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + share_name="foo", + directory_path="bar", + file_path="baz", + ) # Assert self.validate_standard_account_endpoints(service, url) - assert service.scheme == 'https' + assert service.scheme == "https" @FileSharePreparer() def test_create_service_with_sas(self, **kwargs): @@ -78,8 +93,12 @@ def test_create_service_with_sas(self, **kwargs): for service_type in SERVICES: # Act service = service_type( - self.account_url(storage_account_name, "file"), credential=self.sas_token, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.sas_token, + share_name="foo", + directory_path="bar", + file_path="baz", + ) # Assert assert service is not None @@ -98,8 +117,13 @@ def test_create_service_with_token(self, **kwargs): # token credential is available for FileService token_credential = self.get_credential(ShareServiceClient) try: - service_type(self.account_url(storage_account_name, "file"), credential=token_credential, - share_name='foo', directory_path='bar', file_path='baz') + service_type( + self.account_url(storage_account_name, "file"), + credential=token_credential, + share_name="foo", + directory_path="bar", + file_path="baz", + ) except ValueError: pass @@ -109,20 +133,22 @@ def test_create_service_china(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - url = self.account_url(storage_account_name, "file").replace('core.windows.net', 'core.chinacloudapi.cn') + url = self.account_url(storage_account_name, "file").replace("core.windows.net", "core.chinacloudapi.cn") for service_type in SERVICES.items(): # Act service = service_type[0]( - url, credential=self.account_key, - share_name='foo', directory_path='bar', file_path='baz') + url, credential=self.account_key, 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 - 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): @@ -130,15 +156,16 @@ def test_create_service_protocol(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - url = self.account_url(storage_account_name, "file").replace('https', 'http') + url = self.account_url(storage_account_name, "file").replace("https", "http") for service_type in SERVICES.items(): # Act service = service_type[0]( - url, credential=self.account_key, share_name='foo', directory_path='bar', file_path='baz') + url, credential=self.account_key, share_name="foo", directory_path="bar", file_path="baz" + ) # Assert - self.validate_standard_account_endpoints(service, service_type[1], protocol='http') - assert service.scheme == 'http' + self.validate_standard_account_endpoints(service, service_type[1], protocol="http") + assert service.scheme == "http" @FileSharePreparer() def test_create_service_empty_key(self, **kwargs): @@ -151,9 +178,16 @@ 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): @@ -165,11 +199,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, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + share_name="foo", + directory_path="bar", + file_path="baz", + ) service = service_type[0]( - self.account_url(storage_account_name, "file"), credential=self.account_key, connection_timeout=22, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + connection_timeout=22, + share_name="foo", + directory_path="bar", + file_path="baz", + ) # Assert self.validate_standard_account_endpoints(service, service_type[1]) @@ -184,16 +227,17 @@ def test_create_service_with_connection_string_key(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};AccountKey={};'.format(self.account_name, self.account_key) + conn_string = "AccountName={};AccountKey={};".format(self.account_name, self.account_key) 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') + conn_string, share_name="foo", directory_path="bar", file_path="baz" + ) # Assert self.validate_standard_account_endpoints(service, service_type[1]) - assert service.scheme == 'https' + assert service.scheme == "https" @FileSharePreparer() def test_create_service_with_connection_string_sas(self, **kwargs): @@ -201,12 +245,13 @@ def test_create_service_with_connection_string_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};SharedAccessSignature={};'.format(self.account_name, self.sas_token) + conn_string = "AccountName={};SharedAccessSignature={};".format(self.account_name, self.sas_token) 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') + conn_string, share_name="foo", directory_path="bar", file_path="baz" + ) # Assert assert service is not None @@ -220,22 +265,28 @@ 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) + conn_string = ( + "AccountName={};AccountKey={};DefaultEndpointsProtocol=http;EndpointSuffix=core.chinacloudapi.cn;".format( + self.account_name, self.account_key + ) + ) 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') + 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 - 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' + 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() def test_create_service_with_connection_string_emulated(self, **kwargs): @@ -244,12 +295,13 @@ def test_create_service_with_connection_string_emulated(self, **kwargs): self._setup(storage_account_name, storage_account_key) for service_type in SERVICES.items(): - conn_string = 'UseDevelopmentStorage=true;' + conn_string = "UseDevelopmentStorage=true;" # Act with pytest.raises(ValueError): service_type[0].from_connection_string( - conn_string, share_name='foo', directory_path='bar', file_path='baz') + conn_string, share_name="foo", directory_path="bar", file_path="baz" + ) @FileSharePreparer() def test_create_service_with_connection_string_fails_if_secondary_without_primary(self, **kwargs): @@ -258,15 +310,17 @@ def test_create_service_with_connection_string_fails_if_secondary_without_primar for service_type in SERVICES.items(): self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};AccountKey={};{}=www.mydomain.com;'.format( - self.account_name, self.account_key, _CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1])) + conn_string = "AccountName={};AccountKey={};{}=www.mydomain.com;".format( + self.account_name, self.account_key, _CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1]) + ) # Act # Fails if primary excluded with pytest.raises(ValueError): service_type[0].from_connection_string( - conn_string, share_name='foo', directory_path='bar', file_path='baz') + conn_string, share_name="foo", directory_path="bar", file_path="baz" + ) @FileSharePreparer() def test_create_service_with_connection_string_succeeds_if_secondary_with_primary(self, **kwargs): @@ -275,22 +329,25 @@ def test_create_service_with_connection_string_succeeds_if_secondary_with_primar for service_type in SERVICES.items(): self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};AccountKey={};{}=www.mydomain.com;{}=www-sec.mydomain.com;'.format( - self.account_name, self.account_key, + conn_string = "AccountName={};AccountKey={};{}=www.mydomain.com;{}=www-sec.mydomain.com;".format( + self.account_name, + self.account_key, _CONNECTION_ENDPOINTS.get(service_type[1]), - _CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1])) + _CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1]), + ) # Act service = service_type[0].from_connection_string( - conn_string, share_name='foo', directory_path='bar', file_path='baz') + 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 - assert service.primary_hostname == 'www.mydomain.com' - assert service.secondary_hostname == 'www-sec.mydomain.com' + assert service.primary_hostname == "www.mydomain.com" + assert service.secondary_hostname == "www-sec.mydomain.com" @FileSharePreparer() def test_create_service_with_custom_account_endpoint_path(self, **kwargs): @@ -300,52 +357,60 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): self._setup(storage_account_name, storage_account_key) custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token for service_type in SERVICES.items(): - conn_string = 'DefaultEndpointsProtocol=http;AccountName={};AccountKey={};FileEndpoint={};'.format( - self.account_name, self.account_key, custom_account_url) + conn_string = "DefaultEndpointsProtocol=http;AccountName={};AccountKey={};FileEndpoint={};".format( + self.account_name, self.account_key, custom_account_url + ) # Act service = service_type[0].from_connection_string( - conn_string, share_name="foo", directory_path="bar", file_path="baz") + conn_string, share_name="foo", directory_path="bar", file_path="baz" + ) # Assert assert service.account_name == self.account_name assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key - assert service.primary_hostname == 'local-machine:11002/custom/account/path' - + 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 - assert service.primary_hostname == 'local-machine:11002/custom/account/path' - assert service.url.startswith('http://local-machine:11002/custom/account/path/?') + assert service.primary_hostname == "local-machine:11002/custom/account/path" + assert service.url.startswith("http://local-machine:11002/custom/account/path/?") service = ShareClient(account_url=custom_account_url, share_name="foo", snapshot="snap") assert service.account_name == None assert service.share_name == "foo" 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?sharesnapshot=snap&') + 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.primary_hostname == "local-machine:11002/custom/account/path" + 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="") + service = ShareDirectoryClient(account_url=custom_account_url, share_name="foo", directory_path="") assert service.account_name == None assert service.share_name == "foo" assert service.directory_path == "" assert service.snapshot == None 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?') + 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" @@ -353,8 +418,10 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): 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.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&" + ) service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="file") assert service.account_name == None @@ -364,23 +431,25 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.file_name == "file" assert service.snapshot == None 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/file?') + 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" + ) @FileSharePreparer() def test_client_request_id_echo(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) - request_id_header_name = 'x-ms-client-request-id' + request_id_header_name = "x-ms-client-request-id" service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key) # Act make the client request ID slightly different def callback(response): response.http_response.status_code = 200 - response.http_response.headers[request_id_header_name] += '1' + response.http_response.headers[request_id_header_name] += "1" # Assert the client request ID validation is working with pytest.raises(AzureError): @@ -404,8 +473,8 @@ def test_user_agent_default(self, **kwargs): service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key) def callback(response): - assert 'User-Agent' in response.http_request.headers - assert "azsdk-python-storage-file-share/{}".format(VERSION) in response.http_request.headers['User-Agent'] + assert "User-Agent" in response.http_request.headers + assert "azsdk-python-storage-file-share/{}".format(VERSION) in response.http_request.headers["User-Agent"] service.get_service_properties(raw_response_hook=callback) @@ -418,23 +487,26 @@ 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, user_agent=custom_app) + self.account_url(storage_account_name, "file"), credential=self.account_key, user_agent=custom_app + ) def callback1(response): - assert 'User-Agent' in response.http_request.headers - assert ("TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( - VERSION, - platform.python_version(), - platform.platform())) in response.http_request.headers['User-Agent'] + assert "User-Agent" in response.http_request.headers + assert ( + "TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( + VERSION, platform.python_version(), platform.platform() + ) + ) in response.http_request.headers["User-Agent"] service.get_service_properties(raw_response_hook=callback1) def callback2(response): - assert 'User-Agent' in response.http_request.headers - assert ("TestApp/v2.0 TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( - VERSION, - platform.python_version(), - platform.platform())) in response.http_request.headers['User-Agent'] + assert "User-Agent" in response.http_request.headers + assert ( + "TestApp/v2.0 TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( + VERSION, platform.python_version(), platform.platform() + ) + ) in response.http_request.headers["User-Agent"] service.get_service_properties(raw_response_hook=callback2, user_agent="TestApp/v2.0") @@ -448,13 +520,14 @@ def test_user_agent_append(self, **kwargs): service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key) def callback(response): - assert 'User-Agent' in response.http_request.headers - assert ("customer_user_agent azsdk-python-storage-file-share/{} Python/{} ({})".format( - VERSION, - platform.python_version(), - platform.platform())) in response.http_request.headers['User-Agent'] + assert "User-Agent" in response.http_request.headers + assert ( + "customer_user_agent azsdk-python-storage-file-share/{} Python/{} ({})".format( + VERSION, platform.python_version(), platform.platform() + ) + ) in response.http_request.headers["User-Agent"] - service.get_service_properties(raw_response_hook=callback, user_agent='customer_user_agent') + service.get_service_properties(raw_response_hook=callback, user_agent="customer_user_agent") @FileSharePreparer() def test_error_with_malformed_conn_str(self, **kwargs): @@ -467,11 +540,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") - - if conn_str in("", "foobar", "foo;bar;baz", ";"): + service = 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=;", "=", "=;=="): + elif conn_str in ("foobar=baz=foo", "foo=;bar=;", "=", "=;=="): assert e.value.args[0] == "Connection string missing required connection details." @FileSharePreparer() @@ -484,11 +559,16 @@ 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, share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + share_name="foo", + directory_path="bar", + file_path="baz", + ) # Assert with service: - assert hasattr(service, 'close') + assert hasattr(service, "close") service.close() @FileSharePreparer() @@ -501,6 +581,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, share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + share_name="foo", + directory_path="bar", + file_path="baz", + ) service.close() - 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 c3f86e1557f6..8a64c625eab3 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 @@ -18,15 +18,15 @@ # ------------------------------------------------------------------------------ SERVICES = { - ShareServiceClient: 'file', - ShareClient: 'file', - ShareDirectoryClient: 'file', - ShareFileClient: 'file', + ShareServiceClient: "file", + ShareClient: "file", + ShareDirectoryClient: "file", + ShareFileClient: "file", } -_CONNECTION_ENDPOINTS = {'file': 'FileEndpoint'} +_CONNECTION_ENDPOINTS = {"file": "FileEndpoint"} -_CONNECTION_ENDPOINTS_SECONDARY = {'file': 'FileSecondaryEndpoint'} +_CONNECTION_ENDPOINTS_SECONDARY = {"file": "FileSecondaryEndpoint"} class TestStorageFileClientAsync(AsyncStorageRecordedTestCase): @@ -42,14 +42,25 @@ def _teardown(self, FILE_PATH): os.remove(FILE_PATH) except: pass + # --Helpers----------------------------------------------------------------- - def validate_standard_account_endpoints(self, service, service_type, protocol='https'): + def validate_standard_account_endpoints(self, service, service_type, protocol="https"): 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 - 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 + ) # --Direct Parameters Test Cases -------------------------------------------- @FileSharePreparer() @@ -62,12 +73,16 @@ async def test_create_service_with_key(self, **kwargs): for client, url in SERVICES.items(): # Act service = client( - self.account_url(storage_account_name, "file"), credential=self.account_key, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + share_name="foo", + directory_path="bar", + file_path="baz", + ) # Assert self.validate_standard_account_endpoints(service, url) - assert service.scheme == 'https' + assert service.scheme == "https" @FileSharePreparer() async def test_create_service_with_sas(self, **kwargs): @@ -79,8 +94,12 @@ async def test_create_service_with_sas(self, **kwargs): for service_type in SERVICES: # Act service = service_type( - self.account_url(storage_account_name, "file"), credential=self.sas_token, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.sas_token, + share_name="foo", + directory_path="bar", + file_path="baz", + ) # Assert assert service is not None @@ -98,8 +117,13 @@ async def test_create_service_with_token(self, **kwargs): # Act # token credential is available for FileService try: - service_type(self.account_url(storage_account_name, "file"), credential=self.token_credential, - share_name='foo', directory_path='bar', file_path='baz') + service_type( + self.account_url(storage_account_name, "file"), + credential=self.token_credential, + share_name="foo", + directory_path="bar", + file_path="baz", + ) except ValueError: pass @@ -109,20 +133,22 @@ async def test_create_service_china(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - url = self.account_url(storage_account_name, "file").replace('core.windows.net', 'core.chinacloudapi.cn') + url = self.account_url(storage_account_name, "file").replace("core.windows.net", "core.chinacloudapi.cn") for service_type in SERVICES.items(): # Act service = service_type[0]( - url, credential=self.account_key, - share_name='foo', directory_path='bar', file_path='baz') + url, credential=self.account_key, 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 - 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): @@ -130,15 +156,16 @@ async def test_create_service_protocol(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - url = self.account_url(storage_account_name, "file").replace('https', 'http') + url = self.account_url(storage_account_name, "file").replace("https", "http") for service_type in SERVICES.items(): # Act service = service_type[0]( - url, credential=self.account_key, share_name='foo', directory_path='bar', file_path='baz') + url, credential=self.account_key, share_name="foo", directory_path="bar", file_path="baz" + ) # Assert - self.validate_standard_account_endpoints(service, service_type[1], protocol='http') - assert service.scheme == 'http' + self.validate_standard_account_endpoints(service, service_type[1], protocol="http") + assert service.scheme == "http" @FileSharePreparer() async def test_create_service_empty_key(self, **kwargs): @@ -151,9 +178,16 @@ 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): @@ -165,11 +199,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, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + share_name="foo", + directory_path="bar", + file_path="baz", + ) service = service_type[0]( - self.account_url(storage_account_name, "file"), credential=self.account_key, connection_timeout=22, - share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + connection_timeout=22, + share_name="foo", + directory_path="bar", + file_path="baz", + ) # Assert self.validate_standard_account_endpoints(service, service_type[1]) @@ -184,16 +227,17 @@ async def test_create_service_with_connection_string_key(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};AccountKey={};'.format(self.account_name, self.account_key) + conn_string = "AccountName={};AccountKey={};".format(self.account_name, self.account_key) 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') + conn_string, share_name="foo", directory_path="bar", file_path="baz" + ) # Assert self.validate_standard_account_endpoints(service, service_type[1]) - assert service.scheme == 'https' + assert service.scheme == "https" @FileSharePreparer() async def test_create_service_with_connection_string_sas(self, **kwargs): @@ -201,12 +245,13 @@ async def test_create_service_with_connection_string_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};SharedAccessSignature={};'.format(self.account_name, self.sas_token) + conn_string = "AccountName={};SharedAccessSignature={};".format(self.account_name, self.sas_token) 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') + conn_string, share_name="foo", directory_path="bar", file_path="baz" + ) # Assert assert service is not None @@ -220,21 +265,28 @@ 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) + conn_string = ( + "AccountName={};AccountKey={};DefaultEndpointsProtocol=http;EndpointSuffix=core.chinacloudapi.cn;".format( + self.account_name, self.account_key + ) + ) 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 - 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' + 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() async def test_create_service_with_connection_string_emulated(self, **kwargs): @@ -243,11 +295,13 @@ async def test_create_service_with_connection_string_emulated(self, **kwargs): self._setup(storage_account_name, storage_account_key) for service_type in SERVICES.items(): - conn_string = 'UseDevelopmentStorage=true;' + conn_string = "UseDevelopmentStorage=true;" # 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): @@ -256,15 +310,17 @@ async def test_create_service_with_connection_string_fails_if_secondary_without_ for service_type in SERVICES.items(): self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};AccountKey={};{}=www.mydomain.com;'.format( - self.account_name, self.account_key, _CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1])) + conn_string = "AccountName={};AccountKey={};{}=www.mydomain.com;".format( + self.account_name, self.account_key, _CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1]) + ) # Act # Fails if primary excluded with pytest.raises(ValueError): service_type[0].from_connection_string( - conn_string, share_name='foo', directory_path='bar', file_path='baz') + conn_string, share_name="foo", directory_path="bar", file_path="baz" + ) @FileSharePreparer() async def test_create_service_with_connection_string_succeeds_if_secondary_with_primary(self, **kwargs): @@ -273,22 +329,25 @@ async def test_create_service_with_connection_string_succeeds_if_secondary_with_ for service_type in SERVICES.items(): self._setup(storage_account_name, storage_account_key) - conn_string = 'AccountName={};AccountKey={};{}=www.mydomain.com;{}=www-sec.mydomain.com;'.format( - self.account_name, self.account_key, + conn_string = "AccountName={};AccountKey={};{}=www.mydomain.com;{}=www-sec.mydomain.com;".format( + self.account_name, + self.account_key, _CONNECTION_ENDPOINTS.get(service_type[1]), - _CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1])) + _CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1]), + ) # Act service = service_type[0].from_connection_string( - conn_string, share_name='foo', directory_path='bar', file_path='baz') + 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 - assert service.primary_hostname == 'www.mydomain.com' - assert service.secondary_hostname == 'www-sec.mydomain.com' + assert service.primary_hostname == "www.mydomain.com" + assert service.secondary_hostname == "www-sec.mydomain.com" @FileSharePreparer() async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): @@ -298,52 +357,60 @@ async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): self._setup(storage_account_name, storage_account_key) custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token for service_type in SERVICES.items(): - conn_string = 'DefaultEndpointsProtocol=http;AccountName={};AccountKey={};FileEndpoint={};'.format( - self.account_name, self.account_key, custom_account_url) + conn_string = "DefaultEndpointsProtocol=http;AccountName={};AccountKey={};FileEndpoint={};".format( + self.account_name, self.account_key, custom_account_url + ) # Act service = service_type[0].from_connection_string( - conn_string, share_name="foo", directory_path="bar", file_path="baz") + conn_string, share_name="foo", directory_path="bar", file_path="baz" + ) # Assert assert service.account_name == self.account_name assert service.credential.account_name == self.account_name assert service.credential.account_key == self.account_key - assert service.primary_hostname == 'local-machine:11002/custom/account/path' - + 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 - assert service.primary_hostname == 'local-machine:11002/custom/account/path' - assert service.url.startswith('http://local-machine:11002/custom/account/path/?') + assert service.primary_hostname == "local-machine:11002/custom/account/path" + assert service.url.startswith("http://local-machine:11002/custom/account/path/?") service = ShareClient(account_url=custom_account_url, share_name="foo", snapshot="snap") assert service.account_name == None assert service.share_name == "foo" 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?sharesnapshot=snap&') + 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.primary_hostname == "local-machine:11002/custom/account/path" + 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="") + service = ShareDirectoryClient(account_url=custom_account_url, share_name="foo", directory_path="") assert service.account_name == None assert service.share_name == "foo" assert service.directory_path == "" assert service.snapshot == None 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?') + 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" @@ -351,8 +418,10 @@ async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): 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.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&" + ) service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="file") assert service.account_name == None @@ -362,8 +431,8 @@ async def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.file_name == "file" assert service.snapshot == None 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/file?') + assert service.primary_hostname == "local-machine:11002/custom/account/path" + assert service.url.startswith("http://local-machine:11002/custom/account/path/foo/file?") @FileSharePreparer() @recorded_by_proxy_async @@ -375,8 +444,8 @@ async def test_user_agent_default(self, **kwargs): service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key) def callback(response): - assert 'User-Agent' in response.http_request.headers - assert "azsdk-python-storage-file-share/{}".format(VERSION) in response.http_request.headers['User-Agent'] + assert "User-Agent" in response.http_request.headers + assert "azsdk-python-storage-file-share/{}".format(VERSION) in response.http_request.headers["User-Agent"] await service.get_service_properties(raw_response_hook=callback) @@ -389,23 +458,26 @@ 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, user_agent=custom_app) + self.account_url(storage_account_name, "file"), credential=self.account_key, user_agent=custom_app + ) def callback1(response): - assert 'User-Agent' in response.http_request.headers - assert ("TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( - VERSION, - platform.python_version(), - platform.platform())) in response.http_request.headers['User-Agent'] + assert "User-Agent" in response.http_request.headers + assert ( + "TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( + VERSION, platform.python_version(), platform.platform() + ) + ) in response.http_request.headers["User-Agent"] await service.get_service_properties(raw_response_hook=callback1) def callback2(response): - assert 'User-Agent' in response.http_request.headers - assert ("TestApp/v2.0 TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( - VERSION, - platform.python_version(), - platform.platform())) in response.http_request.headers['User-Agent'] + assert "User-Agent" in response.http_request.headers + assert ( + "TestApp/v2.0 TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( + VERSION, platform.python_version(), platform.platform() + ) + ) in response.http_request.headers["User-Agent"] await service.get_service_properties(raw_response_hook=callback2, user_agent="TestApp/v2.0") @@ -419,13 +491,14 @@ async def test_user_agent_append(self, **kwargs): service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key) def callback(response): - assert 'User-Agent' in response.http_request.headers - assert ("customer_user_agent azsdk-python-storage-file-share/{} Python/{} ({})".format( - VERSION, - platform.python_version(), - platform.platform())) in response.http_request.headers['User-Agent'] + assert "User-Agent" in response.http_request.headers + assert ( + "customer_user_agent azsdk-python-storage-file-share/{} Python/{} ({})".format( + VERSION, platform.python_version(), platform.platform() + ) + ) in response.http_request.headers["User-Agent"] - await service.get_service_properties(raw_response_hook=callback, user_agent='customer_user_agent') + await service.get_service_properties(raw_response_hook=callback, user_agent="customer_user_agent") @FileSharePreparer() async def test_closing_pipeline_client(self, **kwargs): @@ -437,11 +510,16 @@ 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, share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + share_name="foo", + directory_path="bar", + file_path="baz", + ) # Assert async with service: - assert hasattr(service, 'close') + assert hasattr(service, "close") await service.close() @FileSharePreparer() @@ -454,7 +532,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, share_name='foo', directory_path='bar', file_path='baz') + self.account_url(storage_account_name, "file"), + credential=self.account_key, + 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 23f73f59e7f7..85eadb1f011f 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 @@ -14,7 +14,7 @@ ShareProtocolSettings, ShareServiceClient, ShareSmbSettings, - SmbMultichannel + SmbMultichannel, ) from devtools_testutils import recorded_by_proxy @@ -36,6 +36,7 @@ def _teardown(self, FILE_PATH): os.remove(FILE_PATH) except: pass + # --Helpers----------------------------------------------------------------- def _assert_metrics_equal(self, metrics1, metrics2): if metrics1 is None or metrics2 is None: @@ -81,14 +82,15 @@ def test_file_service_properties(self, **kwargs): # Act resp = self.fsc.set_service_properties( - hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[], protocol=protocol_properties1) + hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[], protocol=protocol_properties1 + ) # Assert assert resp is None props = self.fsc.get_service_properties() - self._assert_metrics_equal(props['hour_metrics'], Metrics()) - self._assert_metrics_equal(props['minute_metrics'], Metrics()) - self._assert_cors_equal(props['cors'], []) - assert props['protocol'].smb.multichannel.enabled == False + self._assert_metrics_equal(props["hour_metrics"], Metrics()) + self._assert_metrics_equal(props["minute_metrics"], Metrics()) + self._assert_cors_equal(props["cors"], []) + assert props["protocol"].smb.multichannel.enabled == False # Assert with pytest.raises(ValueError): ShareProtocolSettings(smb=ShareSmbSettings(multichannel=SmbMultichannel())) @@ -99,9 +101,10 @@ def test_file_service_properties(self, **kwargs): # Act self.fsc.set_service_properties( - hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[], protocol=protocol_properties2) + hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[], protocol=protocol_properties2 + ) props = self.fsc.get_service_properties() - assert props['protocol'].smb.multichannel.enabled == True + assert props["protocol"].smb.multichannel.enabled == True # --Test cases per feature --------------------------------------- @FileSharePreparer() @@ -118,7 +121,7 @@ def test_set_hour_metrics(self, **kwargs): # Assert received_props = self.fsc.get_service_properties() - self._assert_metrics_equal(received_props['hour_metrics'], hour_metrics) + self._assert_metrics_equal(received_props["hour_metrics"], hour_metrics) @FileSharePreparer() @recorded_by_proxy @@ -127,15 +130,16 @@ def test_set_minute_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - minute_metrics = Metrics(enabled=True, include_apis=True, - retention_policy=RetentionPolicy(enabled=True, days=5)) + minute_metrics = Metrics( + enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) + ) # Act self.fsc.set_service_properties(minute_metrics=minute_metrics) # Assert received_props = self.fsc.get_service_properties() - self._assert_metrics_equal(received_props['minute_metrics'], minute_metrics) + self._assert_metrics_equal(received_props["minute_metrics"], minute_metrics) @FileSharePreparer() @recorded_by_proxy @@ -144,10 +148,10 @@ def test_set_cors(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) + cors_rule1 = CorsRule(["www.xyz.com"], ["GET"]) - allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] - allowed_methods = ['GET', 'PUT'] + allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] + allowed_methods = ["GET", "PUT"] max_age_in_seconds = 500 exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] @@ -156,7 +160,8 @@ def test_set_cors(self, **kwargs): allowed_methods, max_age_in_seconds=max_age_in_seconds, exposed_headers=exposed_headers, - allowed_headers=allowed_headers) + allowed_headers=allowed_headers, + ) cors = [cors_rule1, cors_rule2] @@ -165,7 +170,7 @@ def test_set_cors(self, **kwargs): # Assert received_props = self.fsc.get_service_properties() - self._assert_cors_equal(received_props['cors'], cors) + self._assert_cors_equal(received_props["cors"], cors) # --Test cases for errors --------------------------------------- @FileSharePreparer() @@ -176,9 +181,7 @@ def test_retention_no_days(self, **kwargs): self._setup(storage_account_name, storage_account_key) # Assert - pytest.raises(ValueError, - RetentionPolicy, - True, None) + pytest.raises(ValueError, RetentionPolicy, True, None) @FileSharePreparer() @recorded_by_proxy @@ -189,13 +192,10 @@ def test_too_many_cors_rules(self, **kwargs): self._setup(storage_account_name, storage_account_key) cors = [] for i in range(0, 6): - cors.append(CorsRule(['www.xyz.com'], ['GET'])) + 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 eb74d804d7f3..526b2ce70f14 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 @@ -15,7 +15,7 @@ RetentionPolicy, ShareProtocolSettings, ShareSmbSettings, - SmbMultichannel + SmbMultichannel, ) from azure.storage.fileshare.aio import ShareServiceClient @@ -39,6 +39,7 @@ def _teardown(self, FILE_PATH): os.remove(FILE_PATH) except: pass + # --Helpers----------------------------------------------------------------- def _assert_metrics_equal(self, metrics1, metrics2): if metrics1 is None or metrics2 is None: @@ -83,15 +84,16 @@ async def test_file_service_properties(self, **kwargs): # Act resp = await self.fsc.set_service_properties( - hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[], protocol=protocol_properties1) + hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[], protocol=protocol_properties1 + ) # Assert assert resp is None props = await self.fsc.get_service_properties() - self._assert_metrics_equal(props['hour_metrics'], Metrics()) - self._assert_metrics_equal(props['minute_metrics'], Metrics()) - self._assert_cors_equal(props['cors'], []) - assert props['protocol'].smb.multichannel.enabled == False + self._assert_metrics_equal(props["hour_metrics"], Metrics()) + self._assert_metrics_equal(props["minute_metrics"], Metrics()) + self._assert_cors_equal(props["cors"], []) + assert props["protocol"].smb.multichannel.enabled == False # Assert with pytest.raises(ValueError): ShareProtocolSettings(smb=ShareSmbSettings(multichannel=SmbMultichannel())) @@ -102,9 +104,10 @@ async def test_file_service_properties(self, **kwargs): # Act await self.fsc.set_service_properties( - hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[], protocol=protocol_properties2) + hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[], protocol=protocol_properties2 + ) props = await self.fsc.get_service_properties() - assert props['protocol'].smb.multichannel.enabled == True + assert props["protocol"].smb.multichannel.enabled == True # --Test cases per feature --------------------------------------- @FileSharePreparer() @@ -121,7 +124,7 @@ async def test_set_hour_metrics(self, **kwargs): # Assert received_props = await self.fsc.get_service_properties() - self._assert_metrics_equal(received_props['hour_metrics'], hour_metrics) + self._assert_metrics_equal(received_props["hour_metrics"], hour_metrics) @FileSharePreparer() @recorded_by_proxy_async @@ -130,15 +133,16 @@ async def test_set_minute_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - minute_metrics = Metrics(enabled=True, include_apis=True, - retention_policy=RetentionPolicy(enabled=True, days=5)) + minute_metrics = Metrics( + enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) + ) # Act await self.fsc.set_service_properties(minute_metrics=minute_metrics) # Assert received_props = await self.fsc.get_service_properties() - self._assert_metrics_equal(received_props['minute_metrics'], minute_metrics) + self._assert_metrics_equal(received_props["minute_metrics"], minute_metrics) @FileSharePreparer() @recorded_by_proxy_async @@ -147,10 +151,10 @@ async def test_set_cors(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) + cors_rule1 = CorsRule(["www.xyz.com"], ["GET"]) - allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] - allowed_methods = ['GET', 'PUT'] + allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] + allowed_methods = ["GET", "PUT"] max_age_in_seconds = 500 exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] @@ -159,7 +163,8 @@ async def test_set_cors(self, **kwargs): allowed_methods, max_age_in_seconds=max_age_in_seconds, exposed_headers=exposed_headers, - allowed_headers=allowed_headers) + allowed_headers=allowed_headers, + ) cors = [cors_rule1, cors_rule2] @@ -168,7 +173,7 @@ async def test_set_cors(self, **kwargs): # Assert received_props = await self.fsc.get_service_properties() - self._assert_cors_equal(received_props['cors'], cors) + self._assert_cors_equal(received_props["cors"], cors) # --Test cases for errors --------------------------------------- @FileSharePreparer() @@ -180,7 +185,7 @@ async def test_too_many_cors_rules(self, **kwargs): self._setup(storage_account_name, storage_account_key) cors = [] for i in range(0, 6): - cors.append(CorsRule(['www.xyz.com'], ['GET'])) + cors.append(CorsRule(["www.xyz.com"], ["GET"])) # Assert with pytest.raises(HttpResponseError): 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 6e6fd20600df..375ee2e15a23 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 @@ -19,7 +19,7 @@ from test_helpers import ProgressTracker # ------------------------------------------------------------------------------ -TEST_FILE_PREFIX = 'file' +TEST_FILE_PREFIX = "file" # ------------------------------------------------------------------------------ @@ -35,27 +35,29 @@ def _setup(self, storage_account_name, storage_account_key): credential = storage_account_key self.fsc = ShareServiceClient( - url, credential=credential, + url, + credential=credential, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) - self.share_name = self.get_resource_name('utshare') - self.directory_name = self.get_resource_name('utdir') + self.share_name = self.get_resource_name("utshare") + self.directory_name = self.get_resource_name("utdir") if not self.is_playback(): share = self.fsc.create_share(self.share_name) share.create_directory(self.directory_name) - self.byte_file = self.get_resource_name('bytefile') + self.byte_file = self.get_resource_name("bytefile") self.byte_data = self.get_random_bytes(64 * 1024 + 5) if not self.is_playback(): - byte_file = self.directory_name + '/' + self.byte_file + byte_file = self.directory_name + "/" + self.byte_file file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=byte_file, - credential=credential + credential=credential, ) file_client.upload_file(self.byte_data) @@ -73,7 +75,7 @@ def write(self, data): def read(self, count): return self.wrapped_file.read(count) - + def seekable(self): return False @@ -86,15 +88,16 @@ 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"), - share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key, - max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + max_single_get_size=self.MAX_SINGLE_GET_SIZE, + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(file_data) # Act @@ -110,17 +113,18 @@ 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+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==" binary_data = base64.b64decode(base64_data) file_name = self._get_file_reference() file_client = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key, - max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + max_single_get_size=self.MAX_SINGLE_GET_SIZE, + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(binary_data) # Act @@ -136,15 +140,16 @@ def test_get_file_no_content(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_data = b'' + file_data = b"" file_name = self._get_file_reference() file_client = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key, - max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + max_single_get_size=self.MAX_SINGLE_GET_SIZE, + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(file_data) # Act @@ -166,10 +171,11 @@ def test_get_file_to_bytes(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act file_content = file_client.download_file(max_concurrency=2).readall() @@ -189,15 +195,17 @@ def test_get_file_to_bytes_with_progress(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -206,11 +214,7 @@ def callback(response): # Assert assert self.byte_data == file_content - self.assert_download_progress( - len(self.byte_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(self.byte_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy @@ -222,15 +226,17 @@ def test_get_file_to_bytes_non_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -239,11 +245,7 @@ def callback(response): # Assert assert self.byte_data == file_content - self.assert_download_progress( - len(self.byte_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(self.byte_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy @@ -257,16 +259,18 @@ def test_get_file_to_bytes_small(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(file_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -275,11 +279,7 @@ def callback(response): # Assert assert file_data == file_content - self.assert_download_progress( - len(file_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(file_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy @@ -292,11 +292,12 @@ def test_download_file_modified(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=38, - max_chunk_get_size=38) - data = b'hello world python storage test chunks' * 5 + max_chunk_get_size=38, + ) + data = b"hello world python storage test chunks" * 5 file_client.upload_file(data) resp = file_client.download_file() chunks = resp.chunks() @@ -320,10 +321,11 @@ def test_get_file_with_iter(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act chunk_size_list = [] @@ -352,10 +354,11 @@ def test_get_file_to_stream(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -378,15 +381,17 @@ def test_get_file_to_stream_with_progress(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -410,15 +415,17 @@ def test_get_file_to_stream_non_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -444,16 +451,18 @@ def test_get_file_to_stream_small(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(file_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -482,18 +491,20 @@ def test_get_file_to_stream_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -519,29 +530,34 @@ def test_get_file_to_stream_with_progress_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) # 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) @@ -562,29 +578,34 @@ def test_get_file_to_stream_non_parallel_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) # 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) @@ -604,8 +625,9 @@ def test_get_file_to_stream_small_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key) + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + ) file_client.upload_file(file_data) # Create a snapshot of the share and delete the file @@ -616,22 +638,26 @@ def test_get_file_to_stream_small_from_snapshot(self, **kwargs): snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) # 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) @@ -651,10 +677,11 @@ def test_ranged_get_file_to_path(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act end_range = self.MAX_SINGLE_GET_SIZE + 1024 @@ -664,7 +691,7 @@ def test_ranged_get_file_to_path(self, **kwargs): assert isinstance(bytes_read, int) temp_file.seek(0) actual = temp_file.read() - assert self.byte_data[1:end_range + 1] == actual + assert self.byte_data[1 : end_range + 1] == actual @pytest.mark.live_test_only @FileSharePreparer() @@ -678,10 +705,11 @@ def test_ranged_get_file_to_path_with_single_byte(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act end_range = self.MAX_SINGLE_GET_SIZE + 1024 @@ -701,15 +729,16 @@ def test_ranged_get_file_to_bytes_with_zero_byte(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_data = b'' + file_data = b"" file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(file_data) # Act @@ -732,15 +761,17 @@ def test_ranged_get_file_to_path_with_progress(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -750,20 +781,16 @@ def callback(response): with tempfile.TemporaryFile() as temp_file: length = end_range - start_range + 1 bytes_read = file_client.download_file( - offset=start_range, - length=length, - raw_response_hook=callback, - max_concurrency=2).readinto(temp_file) + offset=start_range, length=length, raw_response_hook=callback, max_concurrency=2 + ).readinto(temp_file) # Assert assert isinstance(bytes_read, int) temp_file.seek(0) actual = temp_file.read() - assert self.byte_data[start_range:end_range + 1] == actual + 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) + end_range - start_range + 1, self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress + ) @FileSharePreparer() @recorded_by_proxy @@ -775,10 +802,11 @@ def test_ranged_get_file_to_path_small(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -799,10 +827,11 @@ def test_ranged_get_file_to_path_non_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -828,10 +857,11 @@ def test_ranged_get_file_to_path_invalid_range_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(file_data) # Act @@ -852,7 +882,6 @@ def test_ranged_get_file_to_path_invalid_range_non_parallel(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_size = 1024 file_data = self.get_random_bytes(file_size) @@ -860,10 +889,11 @@ def test_ranged_get_file_to_path_invalid_range_non_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(file_data) # Act @@ -887,19 +917,20 @@ def test_get_file_to_text(self, **kwargs): # parallel tests introduce random order of requests, can only run live self._setup(storage_account_name, storage_account_key) - text_file = self.get_resource_name('textfile') + text_file = self.get_resource_name("textfile") text_data = self.get_random_text_data(self.MAX_SINGLE_GET_SIZE + 1) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + text_file, + file_path=self.directory_name + "/" + text_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(text_data) # Act - file_content = file_client.download_file(max_concurrency=2, encoding='utf-8').readall() + file_content = file_client.download_file(max_concurrency=2, encoding="utf-8").readall() # Assert assert text_data == file_content @@ -913,35 +944,36 @@ def test_get_file_to_text_with_progress(self, **kwargs): # parallel tests introduce random order of requests, can only run live self._setup(storage_account_name, storage_account_key) - text_file = self.get_resource_name('textfile') + text_file = self.get_resource_name("textfile") text_data = self.get_random_text_data(self.MAX_SINGLE_GET_SIZE + 1) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + text_file, + file_path=self.directory_name + "/" + text_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(text_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) # Act file_content = file_client.download_file( - raw_response_hook=callback, max_concurrency=2, encoding='utf-8').readall() + raw_response_hook=callback, max_concurrency=2, encoding="utf-8" + ).readall() # Assert assert text_data == file_content self.assert_download_progress( - len(text_data.encode('utf-8')), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + len(text_data.encode("utf-8")), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress + ) @FileSharePreparer() @recorded_by_proxy @@ -955,30 +987,29 @@ def test_get_file_to_text_non_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + text_file, + file_path=self.directory_name + "/" + text_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(text_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) # Act file_content = file_client.download_file( - raw_response_hook=callback, max_concurrency=1, encoding='utf-8').readall() + raw_response_hook=callback, max_concurrency=1, encoding="utf-8" + ).readall() # Assert assert text_data == file_content - self.assert_download_progress( - len(text_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(text_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy @@ -992,29 +1023,27 @@ def test_get_file_to_text_small(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(file_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) # Act - file_content = file_client.download_file(raw_response_hook=callback, encoding='utf-8').readall() + file_content = file_client.download_file(raw_response_hook=callback, encoding="utf-8").readall() # Assert assert file_data == file_content - self.assert_download_progress( - len(file_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(file_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy @@ -1023,20 +1052,21 @@ 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' - data = text.encode('utf-16') + text = "hello 啊齄丂狛狜 world" + data = text.encode("utf-16") file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(data) # Act - file_content = file_client.download_file(encoding='UTF-16').readall() + file_content = file_client.download_file(encoding="UTF-16").readall() # Assert assert text == file_content @@ -1048,35 +1078,33 @@ 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' - data = text.encode('utf-16') + text = "hello 啊齄丂狛狜 world" + data = text.encode("utf-16") file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(data) # Act progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) - file_content = file_client.download_file(raw_response_hook=callback, encoding='UTF-16').readall() + file_content = file_client.download_file(raw_response_hook=callback, encoding="UTF-16").readall() # Assert assert text == file_content - self.assert_download_progress( - len(data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy @@ -1088,10 +1116,11 @@ def test_get_file_non_seekable(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -1115,10 +1144,11 @@ def test_get_file_non_seekable_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -1140,18 +1170,20 @@ def test_get_file_non_seekable_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -1178,18 +1210,20 @@ def test_get_file_non_seekable_parallel_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -1210,16 +1244,18 @@ def test_get_file_exact_get_size(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(byte_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -1228,11 +1264,7 @@ def callback(response): # Assert assert byte_data == file_content.readall() - self.assert_download_progress( - len(byte_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(byte_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @pytest.mark.live_test_only @FileSharePreparer() @@ -1248,16 +1280,18 @@ def test_get_file_exact_chunk_size(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_client.upload_file(byte_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -1266,11 +1300,7 @@ def callback(response): # Assert assert byte_data == file_content.readall() - self.assert_download_progress( - len(byte_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(byte_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @pytest.mark.live_test_only @FileSharePreparer() @@ -1284,10 +1314,11 @@ def test_get_file_with_md5(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act file_content = file_client.download_file(validate_content=True) @@ -1307,10 +1338,11 @@ def test_get_file_range_with_md5(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_content = file_client.download_file(offset=0, length=1024, validate_content=True) @@ -1318,14 +1350,14 @@ def test_get_file_range_with_md5(self, **kwargs): assert file_content.properties.content_settings.content_md5 is None props = file_client.get_file_properties() - props.content_settings.content_md5 = b'MDAwMDAwMDA=' + props.content_settings.content_md5 = b"MDAwMDAwMDA=" file_client.set_http_headers(props.content_settings) # Act file_content = file_client.download_file(offset=0, length=1024, validate_content=True) # Assert - assert b'MDAwMDAwMDA=' == file_content.properties.content_settings.content_md5 + assert b"MDAwMDAwMDA=" == file_content.properties.content_settings.content_md5 @FileSharePreparer() @recorded_by_proxy @@ -1333,19 +1365,19 @@ def test_get_file_server_encryption(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_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act file_content = file_client.download_file(offset=0, length=1024, validate_content=True) - + # Assert assert file_content.properties.server_encrypted @@ -1355,15 +1387,15 @@ def test_get_file_properties_server_encryption(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_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act props = file_client.get_file_properties() @@ -1383,10 +1415,11 @@ def test_get_file_progress_single_get(self, **kwargs): file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key) + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + ) - data = b'a' * 512 + data = b"a" * 512 file.upload_file(data) progress = ProgressTracker(len(data), len(data)) @@ -1409,12 +1442,13 @@ def test_get_file_progress_chunked(self, **kwargs): file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=1024, - max_chunk_get_size=1024) + max_chunk_get_size=1024, + ) - data = b'a' * 5120 + data = b"a" * 5120 file.upload_file(data) progress = ProgressTracker(len(data), 1024) @@ -1438,12 +1472,13 @@ def test_get_file_progress_chunked_parallel(self, **kwargs): file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=1024, - max_chunk_get_size=1024) + max_chunk_get_size=1024, + ) - data = b'a' * 5120 + data = b"a" * 5120 file.upload_file(data) progress = ProgressTracker(len(data), 1024) @@ -1467,12 +1502,13 @@ def test_get_file_progress_range_readinto(self, **kwargs): file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=1024, - max_chunk_get_size=1024) + max_chunk_get_size=1024, + ) - data = b'a' * 5120 + data = b"a" * 5120 file.upload_file(data) length = 4096 @@ -1481,10 +1517,7 @@ def test_get_file_progress_range_readinto(self, **kwargs): # Act stream = file.download_file( - offset=512, - length=length, - max_concurrency=3, - progress_hook=progress.assert_progress + offset=512, length=length, max_concurrency=3, progress_hook=progress.assert_progress ) read = stream.readinto(result) @@ -1492,4 +1525,5 @@ def test_get_file_progress_range_readinto(self, **kwargs): progress.assert_complete() assert length == read + # ------------------------------------------------------------------------------ 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 840832914ac8..e999e5c38d29 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 @@ -20,7 +20,7 @@ from test_helpers_async import ProgressTracker # ------------------------------------------------------------------------------ -TEST_FILE_PREFIX = 'file' +TEST_FILE_PREFIX = "file" # ------------------------------------------------------------------------------ @@ -38,14 +38,15 @@ async def _setup(self, storage_account_name, storage_account_key): credential = storage_account_key self.fsc = ShareServiceClient( - url, credential=credential, + url, + credential=credential, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, ) - self.share_name = self.get_resource_name('utshare') - self.directory_name = self.get_resource_name('utdir') - self.byte_file = self.get_resource_name('bytefile') + self.share_name = self.get_resource_name("utshare") + self.directory_name = self.get_resource_name("utdir") + self.byte_file = self.get_resource_name("bytefile") self.byte_data = self.get_random_bytes(64 * 1024 + 5) if not self.is_playback(): try: @@ -53,12 +54,12 @@ async def _setup(self, storage_account_name, storage_account_key): await share.create_directory(self.directory_name) except: pass - byte_file = self.directory_name + '/' + self.byte_file + byte_file = self.directory_name + "/" + self.byte_file file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, file_path=byte_file, - credential=storage_account_key + credential=storage_account_key, ) try: await file_client.upload_file(self.byte_data) @@ -74,7 +75,7 @@ def write(self, data): def read(self, count): return self.wrapped_file.read(count) - + def seekable(self): return False @@ -88,15 +89,16 @@ 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"), - share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key, - max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + max_single_get_size=self.MAX_SINGLE_GET_SIZE, + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(file_data) # Act @@ -114,17 +116,18 @@ 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+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==" binary_data = base64.b64decode(base64_data) file_name = self._get_file_reference() file_client = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key, - max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + max_single_get_size=self.MAX_SINGLE_GET_SIZE, + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(binary_data) # Act @@ -142,15 +145,15 @@ async def test_get_file_no_content(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - file_data = b'' + file_data = b"" file_name = self._get_file_reference() file_client = ShareFileClient( - self.account_url(storage_account_name, "file"), - share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key, - max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + max_single_get_size=self.MAX_SINGLE_GET_SIZE, + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, ) await file_client.upload_file(file_data) @@ -175,10 +178,11 @@ async def test_get_file_to_bytes(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act file_output = await file_client.download_file(max_concurrency=2) @@ -200,15 +204,17 @@ async def test_get_file_to_bytes_with_progress(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -218,11 +224,7 @@ def callback(response): # Assert assert self.byte_data == file_content - self.assert_download_progress( - len(self.byte_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(self.byte_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy_async @@ -235,15 +237,17 @@ async def test_get_file_to_bytes_non_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -253,11 +257,7 @@ def callback(response): # Assert assert self.byte_data == file_content - self.assert_download_progress( - len(self.byte_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(self.byte_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy_async @@ -272,16 +272,18 @@ async def test_get_file_to_bytes_small(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(file_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -291,11 +293,7 @@ def callback(response): # Assert assert file_data == file_content - self.assert_download_progress( - len(file_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(file_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy_async @@ -308,11 +306,12 @@ async def test_download_file_modified(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=38, - max_chunk_get_size=38) - data = b'hello world python storage test chunks' * 5 + max_chunk_get_size=38, + ) + data = b"hello world python storage test chunks" * 5 await file_client.upload_file(data) resp = await file_client.download_file() chunks = resp.chunks() @@ -337,10 +336,11 @@ async def test_get_file_to_stream(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -367,10 +367,11 @@ async def test_get_file_with_iter(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act chunk_size_list = [] @@ -400,15 +401,17 @@ async def test_get_file_to_stream_with_progress(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -435,15 +438,17 @@ async def test_get_file_to_stream_non_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -472,16 +477,18 @@ async def test_get_file_to_stream_small(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(file_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -513,18 +520,20 @@ async def test_get_file_to_stream_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) await file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -553,23 +562,26 @@ async def test_get_file_to_stream_with_progress_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) await file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -599,23 +611,26 @@ async def test_get_file_to_stream_non_parallel_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) await file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -644,8 +659,9 @@ async def test_get_file_to_stream_small_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key) + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + ) await file_client.upload_file(file_data) # Create a snapshot of the share and delete the file @@ -656,16 +672,18 @@ async def test_get_file_to_stream_small_from_snapshot(self, **kwargs): snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -694,23 +712,24 @@ async def test_ranged_get_file_to_path(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act start = 4 end_range = self.MAX_SINGLE_GET_SIZE + 1024 with tempfile.TemporaryFile() as temp_file: - props = await file_client.download_file(offset=start, length=end_range-start+1, max_concurrency=2) + props = await file_client.download_file(offset=start, length=end_range - start + 1, max_concurrency=2) read_bytes = await props.readinto(temp_file) # Assert assert isinstance(read_bytes, int) temp_file.seek(0) actual = temp_file.read() - assert self.byte_data[start:end_range + 1] == actual + assert self.byte_data[start : end_range + 1] == actual @pytest.mark.live_test_only @FileSharePreparer() @@ -725,10 +744,11 @@ async def test_ranged_get_file_to_path_with_single_byte(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act end_range = self.MAX_SINGLE_GET_SIZE + 1024 @@ -751,15 +771,15 @@ async def test_ranged_get_file_to_bytes_with_zero_byte(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - file_data = b'' + file_data = b"" file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, ) await file_client.upload_file(file_data) @@ -786,15 +806,17 @@ async def test_ranged_get_file_to_path_with_progress(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -803,18 +825,18 @@ def callback(response): end_range = self.MAX_SINGLE_GET_SIZE + 1024 with tempfile.TemporaryFile() as temp_file: props = await file_client.download_file( - offset=start_range, - length=end_range - start_range + 1, - max_concurrency=2, - raw_response_hook=callback) + offset=start_range, length=end_range - start_range + 1, max_concurrency=2, raw_response_hook=callback + ) read_bytes = await props.readinto(temp_file) # Assert assert isinstance(read_bytes, int) 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) + 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 + ) @FileSharePreparer() @recorded_by_proxy_async @@ -827,10 +849,11 @@ async def test_ranged_get_file_to_path_small(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -854,10 +877,11 @@ async def test_ranged_get_file_to_path_non_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -886,10 +910,11 @@ async def test_ranged_get_file_to_path_invalid_range_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(file_data) # Act @@ -910,7 +935,6 @@ async def test_ranged_get_file_to_path_invalid_range_non_parallel(self, **kwargs storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - # Arrange await self._setup(storage_account_name, storage_account_key) file_size = 1024 @@ -919,17 +943,18 @@ async def test_ranged_get_file_to_path_invalid_range_non_parallel(self, **kwargs file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(file_data) # Act start = 4 end_range = 2 * self.MAX_SINGLE_GET_SIZE with tempfile.TemporaryFile() as temp_file: - props = await file_client.download_file(offset=start, length=end_range-start+1, max_concurrency=1) + props = await file_client.download_file(offset=start, length=end_range - start + 1, max_concurrency=1) read_bytes = await props.readinto(temp_file) # Assert @@ -948,19 +973,20 @@ async def test_get_file_to_text(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - text_file = self.get_resource_name('textfile') + text_file = self.get_resource_name("textfile") text_data = self.get_random_text_data(self.MAX_SINGLE_GET_SIZE + 1) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + text_file, + file_path=self.directory_name + "/" + text_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(text_data) # Act - file_content = await file_client.download_file(max_concurrency=2, encoding='utf-8') + file_content = await file_client.download_file(max_concurrency=2, encoding="utf-8") file_content = await file_content.readall() # Assert @@ -976,36 +1002,35 @@ async def test_get_file_to_text_with_progress(self, **kwargs): # Arrange await self._setup(storage_account_name, storage_account_key) - text_file = self.get_resource_name('textfile') + text_file = self.get_resource_name("textfile") text_data = self.get_random_text_data(self.MAX_SINGLE_GET_SIZE + 1) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + text_file, + file_path=self.directory_name + "/" + text_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(text_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) # Act - file_content = await file_client.download_file( - raw_response_hook=callback, max_concurrency=2, encoding='utf-8') + file_content = await file_client.download_file(raw_response_hook=callback, max_concurrency=2, encoding="utf-8") file_content = await file_content.readall() # Assert assert text_data == file_content self.assert_download_progress( - len(text_data.encode('utf-8')), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + len(text_data.encode("utf-8")), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress + ) @FileSharePreparer() @recorded_by_proxy_async @@ -1020,31 +1045,28 @@ async def test_get_file_to_text_non_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + text_file, + file_path=self.directory_name + "/" + text_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(text_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) # Act - file_content = await file_client.download_file( - raw_response_hook=callback, max_concurrency=1, encoding='utf-8') + file_content = await file_client.download_file(raw_response_hook=callback, max_concurrency=1, encoding="utf-8") file_content = await file_content.readall() # Assert assert text_data == file_content - self.assert_download_progress( - len(text_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(text_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy_async @@ -1059,30 +1081,28 @@ async def test_get_file_to_text_small(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(file_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) # Act - file_content = await file_client.download_file(raw_response_hook=callback, encoding='utf-8') + file_content = await file_client.download_file(raw_response_hook=callback, encoding="utf-8") file_content = await file_content.readall() # Assert assert file_data == file_content - self.assert_download_progress( - len(file_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(file_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy_async @@ -1092,20 +1112,21 @@ 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' - data = text.encode('utf-16') + text = "hello 啊齄丂狛狜 world" + data = text.encode("utf-16") file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(data) # Act - file_content = await file_client.download_file(encoding='UTF-16') + file_content = await file_client.download_file(encoding="UTF-16") file_content = await file_content.readall() # Assert @@ -1119,36 +1140,34 @@ 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' - data = text.encode('utf-16') + text = "hello 啊齄丂狛狜 world" + data = text.encode("utf-16") file_name = self._get_file_reference() file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(data) # Act progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) - file_content = await file_client.download_file(raw_response_hook=callback, encoding='UTF-16') + file_content = await file_client.download_file(raw_response_hook=callback, encoding="UTF-16") file_content = await file_content.readall() # Assert assert text == file_content - self.assert_download_progress( - len(data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @FileSharePreparer() @recorded_by_proxy_async @@ -1161,10 +1180,11 @@ async def test_get_file_non_seekable(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -1191,10 +1211,11 @@ async def test_get_file_non_seekable_parallel(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -1219,18 +1240,20 @@ async def test_get_file_non_seekable_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) await file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -1260,18 +1283,20 @@ async def test_get_file_non_seekable_parallel_from_snapshot(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, - credential=storage_account_key) + file_path=self.directory_name + "/" + self.byte_file, + credential=storage_account_key, + ) await file_client.delete_file() snapshot_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, snapshot=share_snapshot, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act with tempfile.TemporaryFile() as temp_file: @@ -1295,16 +1320,18 @@ async def test_get_file_exact_get_size(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(byte_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -1314,11 +1341,7 @@ def callback(response): # Assert assert byte_data == file_bytes - self.assert_download_progress( - len(byte_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(byte_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @pytest.mark.live_test_only @FileSharePreparer() @@ -1335,16 +1358,18 @@ async def test_get_file_exact_chunk_size(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) await file_client.upload_file(byte_data) progress = [] + def callback(response): - current = response.context['download_stream_current'] - total = response.context['data_stream_total'] + current = response.context["download_stream_current"] + total = response.context["data_stream_total"] if current is not None: progress.append((current, total)) @@ -1354,11 +1379,7 @@ def callback(response): # Assert assert byte_data == file_bytes - self.assert_download_progress( - len(byte_data), - self.MAX_CHUNK_GET_SIZE, - self.MAX_SINGLE_GET_SIZE, - progress) + self.assert_download_progress(len(byte_data), self.MAX_CHUNK_GET_SIZE, self.MAX_SINGLE_GET_SIZE, progress) @pytest.mark.live_test_only @FileSharePreparer() @@ -1373,10 +1394,11 @@ async def test_get_file_with_md5(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act file_content = await file_client.download_file(validate_content=True) @@ -1397,10 +1419,11 @@ async def test_get_file_range_with_md5(self, **kwargs): file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) file_content = await file_client.download_file(offset=0, length=1024, validate_content=True) @@ -1409,14 +1432,14 @@ async def test_get_file_range_with_md5(self, **kwargs): # Arrange props = await file_client.get_file_properties() - props.content_settings.content_md5 = b'MDAwMDAwMDA=' + props.content_settings.content_md5 = b"MDAwMDAwMDA=" await file_client.set_http_headers(props.content_settings) # Act file_content = await file_client.download_file(offset=0, length=1024, validate_content=True) # Assert - assert b'MDAwMDAwMDA=' == file_content.properties.content_settings.content_md5 + assert b"MDAwMDAwMDA=" == file_content.properties.content_settings.content_md5 @FileSharePreparer() @recorded_by_proxy_async @@ -1424,20 +1447,20 @@ async def test_get_file_server_encryption(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - - #Arrange + # Arrange await self._setup(storage_account_name, storage_account_key) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act file_content = await file_client.download_file(offset=0, length=1024, validate_content=True) - + # Assert assert file_content.properties.server_encrypted @@ -1447,16 +1470,16 @@ async def test_get_file_properties_server_encryption(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - # Arrange await self._setup(storage_account_name, storage_account_key) file_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + self.byte_file, + file_path=self.directory_name + "/" + self.byte_file, credential=storage_account_key, max_single_get_size=self.MAX_SINGLE_GET_SIZE, - max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) + max_chunk_get_size=self.MAX_CHUNK_GET_SIZE, + ) # Act props = await file_client.get_file_properties() @@ -1477,10 +1500,11 @@ async def test_get_file_progress_single_get(self, **kwargs): file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, - credential=storage_account_key) + file_path=self.directory_name + "/" + file_name, + credential=storage_account_key, + ) - data = b'a' * 512 + data = b"a" * 512 await file.upload_file(data) progress = ProgressTracker(len(data), len(data)) @@ -1504,12 +1528,13 @@ async def test_get_file_progress_chunked(self, **kwargs): file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=1024, - max_chunk_get_size=1024) + max_chunk_get_size=1024, + ) - data = b'a' * 5120 + data = b"a" * 5120 await file.upload_file(data) progress = ProgressTracker(len(data), 1024) @@ -1534,12 +1559,13 @@ async def test_get_file_progress_chunked_parallel(self, **kwargs): file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=1024, - max_chunk_get_size=1024) + max_chunk_get_size=1024, + ) - data = b'a' * 5120 + data = b"a" * 5120 await file.upload_file(data) progress = ProgressTracker(len(data), 1024) @@ -1564,12 +1590,13 @@ async def test_get_file_progress_range_readinto(self, **kwargs): file = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=self.share_name, - file_path=self.directory_name + '/' + file_name, + file_path=self.directory_name + "/" + file_name, credential=storage_account_key, max_single_get_size=1024, - max_chunk_get_size=1024) + max_chunk_get_size=1024, + ) - data = b'a' * 5120 + data = b"a" * 5120 await file.upload_file(data) length = 4096 @@ -1578,14 +1605,10 @@ async def test_get_file_progress_range_readinto(self, **kwargs): # Act stream = await file.download_file( - offset=512, - length=length, - max_concurrency=3, - progress_hook=progress.assert_progress + offset=512, length=length, max_concurrency=3, progress_hook=progress.assert_progress ) read = await stream.readinto(result) # Assert progress.assert_complete() assert length == read - 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 07ccb3095617..ec11c1806310 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_handle.py +++ b/sdk/storage/azure-storage-file-share/tests/test_handle.py @@ -13,7 +13,7 @@ from settings.testcase import FileSharePreparer # ------------------------------------------------------------------------------ -TEST_SHARE_NAME = 'test-share' +TEST_SHARE_NAME = "test-share" # ------------------------------------------------------------------------------ @@ -50,7 +50,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() @@ -107,10 +107,9 @@ def test_list_handles_with_marker(self, **kwargs): old_handle = handles[0] # Continue listing - remaining_handles = list(next( - root.list_handles(recursive=True).by_page( - continuation_token=handle_generator.continuation_token) - )) + remaining_handles = list( + next(root.list_handles(recursive=True).by_page(continuation_token=handle_generator.continuation_token)) + ) self._validate_handles(handles) # Make sure the old handle did not appear @@ -130,7 +129,7 @@ def test_list_handles_on_directory(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = self.fsc.get_share_client(TEST_SHARE_NAME) - dir = share.get_directory_client('testdir') + dir = share.get_directory_client("testdir") # Act handles = list(dir.list_handles(recursive=True)) @@ -156,7 +155,7 @@ def test_list_handles_on_file(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = self.fsc.get_share_client(TEST_SHARE_NAME) - client = share.get_file_client('testdir/test.txt') + client = share.get_file_client("testdir/test.txt") # Act handles = list(client.list_handles()) @@ -182,13 +181,13 @@ def test_close_single_handle(self, **kwargs): # Act with pytest.raises(ValueError): - root.close_handle('*') + root.close_handle("*") handles_info = root.close_handle(handles[0]) # Assert 1 handle has been closed - assert 1 == handles_info['closed_handles_count'] - assert handles_info['failed_handles_count'] == 0 + assert 1 == handles_info["closed_handles_count"] + assert handles_info["failed_handles_count"] == 0 @pytest.mark.playback_test_only @FileSharePreparer() @@ -210,8 +209,8 @@ def test_close_all_handle(self, **kwargs): handles_info = root.close_all_handles(recursive=True) # Assert at least 1 handle has been closed - assert handles_info['closed_handles_count'] > 1 - assert handles_info['failed_handles_count'] == 0 + assert handles_info["closed_handles_count"] > 1 + assert handles_info["failed_handles_count"] == 0 @pytest.mark.playback_test_only @FileSharePreparer() @@ -224,19 +223,19 @@ def test_list_handles_access_rights(self, **kwargs): # only run when recording, or playing back in CI self._setup(storage_account_name, storage_account_key) - share = self.fsc.get_share_client('mytestshare') - root = share.get_directory_client('testdir') - file_client = root.get_file_client('testfile.txt') + share = self.fsc.get_share_client("mytestshare") + root = share.get_directory_client("testdir") + file_client = root.get_file_client("testfile.txt") # Act handles = list(file_client.list_handles()) # Assert self._validate_handles(handles) - assert handles[0]['access_rights'][0] == 'Write' - assert handles[0]['client_name'] is not None + assert handles[0]["access_rights"][0] == "Write" + assert handles[0]["client_name"] is not None # ------------------------------------------------------------------------------ -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() 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 06c7592d444e..b7516c363b43 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 @@ -13,7 +13,7 @@ from settings.testcase import FileSharePreparer # ------------------------------------------------------------------------------ -TEST_SHARE_NAME = 'test-share' +TEST_SHARE_NAME = "test-share" # ------------------------------------------------------------------------------ @@ -61,13 +61,13 @@ async def test_close_single_handle(self, **kwargs): # Act with pytest.raises(ValueError): - await root.close_handle('*') + await root.close_handle("*") handles_info = await root.close_handle(handles[0]) # Assert 1 handle has been closed - assert 1 == handles_info['closed_handles_count'] - assert handles_info['failed_handles_count'] == 0 + assert 1 == handles_info["closed_handles_count"] + assert handles_info["failed_handles_count"] == 0 @pytest.mark.playback_test_only @FileSharePreparer() @@ -91,8 +91,8 @@ async def test_close_all_handle(self, **kwargs): handles_info = await root.close_all_handles(recursive=True) # Assert at least 1 handle has been closed - assert handles_info['closed_handles_count'] > 1 - assert handles_info['failed_handles_count'] == 0 + assert handles_info["closed_handles_count"] > 1 + assert handles_info["failed_handles_count"] == 0 @pytest.mark.playback_test_only @FileSharePreparer() @@ -105,9 +105,9 @@ async def test_list_handles_access_rights(self, **kwargs): # only run when recording, or playing back in CI self._setup(storage_account_name, storage_account_key) - share = self.fsc.get_share_client('mytestshare') - root = share.get_directory_client('testdir') - file_client = root.get_file_client('testfile.txt') + share = self.fsc.get_share_client("mytestshare") + root = share.get_directory_client("testdir") + file_client = root.get_file_client("testfile.txt") # Act handles = [] @@ -116,10 +116,10 @@ async def test_list_handles_access_rights(self, **kwargs): # Assert self._validate_handles(handles) - assert handles[0]['access_rights'][0] == 'Write' - assert handles[0]['client_name'] is not None + assert handles[0]["access_rights"][0] == "Write" + assert handles[0]["client_name"] is not None # ------------------------------------------------------------------------------ -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() 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..532d17c83bbc 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_helpers.py +++ b/sdk/storage/azure-storage-file-share/tests/test_helpers.py @@ -33,11 +33,7 @@ def assert_complete(self): class MockHttpClientResponse(Response): def __init__( - self, url: str, - body_bytes: bytes, - headers: Dict[str, Any], - status: int = 200, - reason: str = "OK" + self, url: str, body_bytes: bytes, headers: Dict[str, Any], status: int = 200, reason: str = "OK" ) -> None: super(MockHttpClientResponse).__init__() self._url = url @@ -57,8 +53,9 @@ class MockStorageTransport(HttpTransport): This transport returns legacy http response objects from azure core and is intended only to test our backwards compatibility support. """ + def send(self, request: HttpRequest, **kwargs: Any) -> RequestsTransportResponse: - if request.method == 'GET': + if request.method == "GET": # download_file headers = { "Content-Type": "application/octet-stream", @@ -75,9 +72,9 @@ def send(self, request: HttpRequest, **kwargs: Any) -> RequestsTransportResponse request.url, b"Hello World!", headers, - ) + ), ) - elif request.method == 'HEAD': + elif request.method == "HEAD": # get_file_properties rest_response = RequestsTransportResponse( request=request, @@ -88,9 +85,9 @@ def send(self, request: HttpRequest, **kwargs: Any) -> RequestsTransportResponse "Content-Type": "application/octet-stream", "Content-Length": "1024", }, - ) + ), ) - elif request.method == 'PUT': + elif request.method == "PUT": # upload_file rest_response = RequestsTransportResponse( request=request, @@ -101,10 +98,10 @@ def send(self, request: HttpRequest, **kwargs: Any) -> RequestsTransportResponse "Content-Length": "0", }, 201, - "Created" - ) + "Created", + ), ) - elif request.method == 'DELETE': + elif request.method == "DELETE": # delete_file rest_response = RequestsTransportResponse( request=request, @@ -115,8 +112,8 @@ def send(self, request: HttpRequest, **kwargs: Any) -> RequestsTransportResponse "Content-Length": "0", }, 202, - "Accepted" - ) + "Accepted", + ), ) else: raise ValueError("The request is not accepted as part of MockStorageTransport.") 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 48ca12c94dcc..5466e4ec472f 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 @@ -51,11 +51,7 @@ async def read(self, size: int = -1) -> bytes: class MockAioHttpClientResponse(ClientResponse): def __init__( - self, url: str, - body_bytes: bytes, - headers: Dict[str, Any], - status: int = 200, - reason: str = "OK" + self, url: str, body_bytes: bytes, headers: Dict[str, Any], status: int = 200, reason: str = "OK" ) -> None: super(MockAioHttpClientResponse).__init__() self._url = url @@ -69,11 +65,12 @@ def __init__( class MockStorageTransport(AsyncHttpTransport): """ - This transport returns legacy http response objects from azure core and is + This transport returns legacy http response objects from azure core and is intended only to test our backwards compatibility support. """ + async def send(self, request: HttpRequest, **kwargs: Any) -> AioHttpTransportResponse: - if request.method == 'GET': + if request.method == "GET": # download_file headers = { "Content-Type": "application/octet-stream", @@ -91,9 +88,9 @@ async def send(self, request: HttpRequest, **kwargs: Any) -> AioHttpTransportRes b"Hello Async World!", headers, ), - decompress=False + decompress=False, ) - elif request.method == 'HEAD': + elif request.method == "HEAD": # get_file_properties rest_response = AioHttpTransportResponse( request=request, @@ -105,9 +102,9 @@ async def send(self, request: HttpRequest, **kwargs: Any) -> AioHttpTransportRes "Content-Length": "1024", }, ), - decompress=False + decompress=False, ) - elif request.method == 'PUT': + elif request.method == "PUT": # upload_file rest_response = AioHttpTransportResponse( request=request, @@ -118,11 +115,11 @@ async def send(self, request: HttpRequest, **kwargs: Any) -> AioHttpTransportRes "Content-Length": "0", }, 201, - "Created" + "Created", ), - decompress=False + decompress=False, ) - elif request.method == 'DELETE': + elif request.method == "DELETE": # delete_file rest_response = AioHttpTransportResponse( request=request, @@ -133,9 +130,9 @@ async def send(self, request: HttpRequest, **kwargs: Any) -> AioHttpTransportRes "Content-Length": "0", }, 202, - "Accepted" + "Accepted", ), - decompress=False + decompress=False, ) else: raise ValueError("The request is not accepted as part of MockStorageTransport.") 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 55fa460202c1..a2c2d1b066ee 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_nfs.py +++ b/sdk/storage/azure-storage-file-share/tests/test_nfs.py @@ -11,7 +11,7 @@ ClientAuthenticationError, HttpResponseError, ResourceExistsError, - ResourceNotFoundError + ResourceNotFoundError, ) from azure.storage.fileshare import ( ContentSettings, @@ -19,16 +19,16 @@ DirectoryProperties, ShareFileClient, ShareDirectoryClient, - ShareServiceClient + ShareServiceClient, ) from devtools_testutils import recorded_by_proxy from devtools_testutils.storage import StorageRecordedTestCase from settings.testcase import FileSharePreparer -TEST_INTENT = 'backup' -TEST_FILE_PREFIX = 'file' -TEST_DIRECTORY_PREFIX = 'directory' +TEST_INTENT = "backup" +TEST_FILE_PREFIX = "file" +TEST_DIRECTORY_PREFIX = "directory" class TestStorageFileNFS(StorageRecordedTestCase): @@ -36,17 +36,15 @@ class TestStorageFileNFS(StorageRecordedTestCase): fsc: ShareServiceClient = None def _setup(self, storage_account_name: str): - self.account_url = self.account_url(storage_account_name, 'file') + self.account_url = self.account_url(storage_account_name, "file") self.credential = self.get_credential(ShareServiceClient) self.fsc = ShareServiceClient( - account_url=self.account_url, - credential=self.credential, - token_intent=TEST_INTENT + account_url=self.account_url, credential=self.credential, token_intent=TEST_INTENT ) - self.share_name = self.get_resource_name('utshare') + self.share_name = self.get_resource_name("utshare") if self.is_live: try: - self.fsc.create_share(self.share_name, protocols='NFS') + self.fsc.create_share(self.share_name, protocols="NFS") except: pass @@ -65,11 +63,12 @@ def _get_directory_name(self, prefix: str = TEST_DIRECTORY_PREFIX): return self.get_resource_name(prefix) def _assert_props( - self, props: Optional[Union[DirectoryProperties, FileProperties]], + self, + props: Optional[Union[DirectoryProperties, FileProperties]], owner: str, group: str, file_mode: str, - nfs_file_type: Optional[str] = None + nfs_file_type: Optional[str] = None, ) -> None: assert props is not None assert props.owner == owner @@ -85,8 +84,8 @@ def _assert_props( def _assert_copy(self, copy: Optional[Dict[str, Any]]) -> None: assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None # --Test cases for NFS ---------------------------------------------- @FileSharePreparer() @@ -96,24 +95,21 @@ def test_create_directory_and_set_directory_properties(self, **kwargs: Any): self._setup(premium_storage_file_account_name) - create_owner, create_group, create_file_mode = '345', '123', '7777' - set_owner, set_group, set_file_mode = '0', '0', '0755' + create_owner, create_group, create_file_mode = "345", "123", "7777" + set_owner, set_group, set_file_mode = "0", "0", "0755" share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url, - share_client.share_name, 'dir1', - credential=self.credential, - token_intent=TEST_INTENT + self.account_url, share_client.share_name, "dir1", credential=self.credential, token_intent=TEST_INTENT ) directory_client.create_directory(owner=create_owner, group=create_group, file_mode=create_file_mode) props = directory_client.get_directory_properties() - self._assert_props(props, create_owner, create_group, create_file_mode, 'Directory') + self._assert_props(props, create_owner, create_group, create_file_mode, "Directory") directory_client.set_http_headers(owner=set_owner, group=set_group, file_mode=set_file_mode) props = directory_client.get_directory_properties() - self._assert_props(props, set_owner, set_group, set_file_mode, 'Directory') + self._assert_props(props, set_owner, set_group, set_file_mode, "Directory") @FileSharePreparer() @recorded_by_proxy @@ -128,28 +124,22 @@ def test_create_file_and_set_file_properties(self, **kwargs: Any): share_name=self.share_name, file_path=file_name, credential=self.credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) - create_owner, create_group, create_file_mode = '345', '123', '7777' - set_owner, set_group, set_file_mode = '0', '0', '0644' - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline' - ) + create_owner, create_group, create_file_mode = "345", "123", "7777" + set_owner, set_group, set_file_mode = "0", "0", "0644" + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") file_client.create_file(1024, owner=create_owner, group=create_group, file_mode=create_file_mode) props = file_client.get_file_properties() - self._assert_props(props, create_owner, create_group, create_file_mode, 'Regular') + self._assert_props(props, create_owner, create_group, create_file_mode, "Regular") file_client.set_http_headers( - content_settings=content_settings, - owner=set_owner, - group=set_group, - file_mode=set_file_mode + content_settings=content_settings, owner=set_owner, group=set_group, file_mode=set_file_mode ) props = file_client.get_file_properties() - self._assert_props(props, set_owner, set_group, set_file_mode, 'Regular') + self._assert_props(props, set_owner, set_group, set_file_mode, "Regular") @FileSharePreparer() @recorded_by_proxy @@ -158,10 +148,10 @@ def test_download_and_copy_file(self, **kwargs: Any): self._setup(premium_storage_file_account_name) - default_owner, default_group, default_file_mode = '0', '0', '0664' - source_owner, source_group, source_file_mode = '999', '888', '0111' - override_owner, override_group, override_file_mode = '54321', '12345', '7777' - data = b'abcdefghijklmnop' * 32 + default_owner, default_group, default_file_mode = "0", "0", "0664" + source_owner, source_group, source_file_mode = "999", "888", "0111" + override_owner, override_group, override_file_mode = "54321", "12345", "7777" + data = b"abcdefghijklmnop" * 32 share_client = self.fsc.get_share_client(self.share_name) @@ -176,14 +166,12 @@ def test_download_and_copy_file(self, **kwargs: Any): new_client_source_copy = ShareFileClient( self.account_url, share_name=self.share_name, - file_path='newclientsourcecopy', + file_path="newclientsourcecopy", credential=self.credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) copy = new_client_source_copy.start_copy_from_url( - file_client.url, - file_mode_copy_mode='source', - owner_copy_mode='source' + file_client.url, file_mode_copy_mode="source", owner_copy_mode="source" ) self._assert_copy(copy) props = new_client_source_copy.get_file_properties() @@ -192,9 +180,9 @@ def test_download_and_copy_file(self, **kwargs: Any): new_client_default_copy = ShareFileClient( self.account_url, share_name=self.share_name, - file_path='newclientdefaultcopy', + file_path="newclientdefaultcopy", credential=self.credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) copy = new_client_default_copy.start_copy_from_url(file_client.url) self._assert_copy(copy) @@ -204,17 +192,17 @@ def test_download_and_copy_file(self, **kwargs: Any): new_client_override_copy = ShareFileClient( self.account_url, share_name=self.share_name, - file_path='newclientoverridecopy', + file_path="newclientoverridecopy", credential=self.credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) copy = new_client_override_copy.start_copy_from_url( file_client.url, owner=override_owner, group=override_group, file_mode=override_file_mode, - file_mode_copy_mode='override', - owner_copy_mode='override' + file_mode_copy_mode="override", + owner_copy_mode="override", ) self._assert_copy(copy) props = new_client_override_copy.get_file_properties() @@ -230,29 +218,29 @@ def test_create_hardlink(self, **kwargs: Any): share_client = self.fsc.get_share_client(self.share_name) directory_name = self._get_directory_name() directory_client = share_client.create_directory(directory_name) - source_file_name = self._get_file_name('file1') + source_file_name = self._get_file_name("file1") source_file_client = directory_client.get_file_client(source_file_name) source_file_client.create_file(size=1024) - hard_link_file_name = self._get_file_name('file2') + hard_link_file_name = self._get_file_name("file2") hard_link_file_client = directory_client.get_file_client(hard_link_file_name) resp = hard_link_file_client.create_hardlink(target=f"{directory_name}/{source_file_name}") assert resp is not None - assert resp['file_file_type'] == 'Regular' - assert resp['owner'] == '0' - assert resp['group'] == '0' - assert resp['mode'] == '0664' - assert resp['link_count'] == 2 + assert resp["file_file_type"] == "Regular" + assert resp["owner"] == "0" + assert resp["group"] == "0" + assert resp["mode"] == "0664" + assert resp["link_count"] == 2 - assert resp['file_creation_time'] is not None - assert resp['file_last_write_time'] is not None - assert resp['file_change_time'] is not None - assert resp['file_id'] is not None - assert resp['file_parent_id'] is not None + assert resp["file_creation_time"] is not None + assert resp["file_last_write_time"] is not None + assert resp["file_change_time"] is not None + assert resp["file_id"] is not None + assert resp["file_parent_id"] is not None - assert 'file_attributes' not in resp - assert 'file_response_key' not in resp + assert "file_attributes" not in resp + assert "file_response_key" not in resp @FileSharePreparer() @recorded_by_proxy @@ -264,15 +252,15 @@ def test_create_hardlink_error(self, **kwargs: Any): share_client = self.fsc.get_share_client(self.share_name) directory_name = self._get_directory_name() directory_client = share_client.get_directory_client(directory_name) - source_file_name = self._get_file_name('file1') + source_file_name = self._get_file_name("file1") source_file_client = directory_client.get_file_client(source_file_name) - hard_link_file_name = self._get_file_name('file2') + hard_link_file_name = self._get_file_name("file2") hard_link_file_client = directory_client.get_file_client(hard_link_file_name) with pytest.raises(ResourceNotFoundError) as e: hard_link_file_client.create_hardlink(target=f"{directory_name}/{source_file_name}") - assert 'ParentNotFound' in e.value.args[0] + assert "ParentNotFound" in e.value.args[0] @FileSharePreparer() @recorded_by_proxy @@ -284,37 +272,32 @@ def test_create_and_get_symlink(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_name = self._get_directory_name() directory_client = share_client.create_directory(directory_name) - source_file_name = self._get_file_name('file1') + source_file_name = self._get_file_name("file1") source_file_client = directory_client.get_file_client(source_file_name) source_file_client.create_file(size=1024) - symbolic_link_file_name = self._get_file_name('file2') + symbolic_link_file_name = self._get_file_name("file2") symbolic_link_file_client = directory_client.get_file_client(symbolic_link_file_name) metadata = {"test1": "foo", "test2": "bar"} owner, group = "345", "123" target = f"{directory_name}/{source_file_name}" - resp = symbolic_link_file_client.create_symlink( - target=target, - metadata=metadata, - owner=owner, - group=group - ) + resp = symbolic_link_file_client.create_symlink(target=target, metadata=metadata, owner=owner, group=group) assert resp is not None - assert resp['file_file_type'] == 'SymLink' - assert resp['owner'] == owner - assert resp['group'] == group - assert resp['file_creation_time'] is not None - assert resp['file_last_write_time'] is not None - assert resp['file_id'] is not None - assert resp['file_parent_id'] is not None - assert 'file_attributes' not in resp - assert 'file_permission_key' not in resp + assert resp["file_file_type"] == "SymLink" + assert resp["owner"] == owner + assert resp["group"] == group + assert resp["file_creation_time"] is not None + assert resp["file_last_write_time"] is not None + assert resp["file_id"] is not None + assert resp["file_parent_id"] is not None + assert "file_attributes" not in resp + assert "file_permission_key" not in resp resp = symbolic_link_file_client.get_symlink() assert resp is not None - assert resp['etag'] is not None - assert resp['last_modified'] is not None - assert unquote(resp['link_text']) == target + assert resp["etag"] is not None + assert resp["last_modified"] is not None + assert unquote(resp["link_text"]) == target @FileSharePreparer() @recorded_by_proxy @@ -326,16 +309,16 @@ def test_create_and_get_symlink_error(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_name = self._get_directory_name() directory_client = share_client.get_directory_client(directory_name) - source_file_name = self._get_file_name('file1') + source_file_name = self._get_file_name("file1") source_file_client = directory_client.get_file_client(source_file_name) - symbolic_link_file_name = self._get_file_name('file2') + symbolic_link_file_name = self._get_file_name("file2") symbolic_link_file_client = directory_client.get_file_client(symbolic_link_file_name) target = f"{directory_name}/{source_file_name}" with pytest.raises(ResourceNotFoundError) as e: symbolic_link_file_client.create_symlink(target=target) - assert 'ParentNotFound' in e.value.args[0] + assert "ParentNotFound" in e.value.args[0] with pytest.raises(ResourceNotFoundError) as e: symbolic_link_file_client.get_symlink() - assert 'ParentNotFound' in e.value.args[0] + assert "ParentNotFound" in e.value.args[0] 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 4d68bac26e4f..33810edb0d87 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 @@ -11,14 +11,9 @@ ClientAuthenticationError, HttpResponseError, ResourceExistsError, - ResourceNotFoundError -) -from azure.storage.fileshare import ( - ContentSettings, - DirectoryProperties, - FileProperties, - ShareServiceClient + ResourceNotFoundError, ) +from azure.storage.fileshare import ContentSettings, DirectoryProperties, FileProperties, ShareServiceClient from azure.storage.fileshare.aio import ShareServiceClient as AsyncShareServiceClient from azure.storage.fileshare.aio import ShareFileClient, ShareDirectoryClient @@ -27,9 +22,9 @@ from settings.testcase import FileSharePreparer -TEST_INTENT = 'backup' -TEST_FILE_PREFIX = 'file' -TEST_DIRECTORY_PREFIX = 'directory' +TEST_INTENT = "backup" +TEST_FILE_PREFIX = "file" +TEST_DIRECTORY_PREFIX = "directory" class TestStorageFileNFSAsync(AsyncStorageRecordedTestCase): @@ -37,23 +32,19 @@ class TestStorageFileNFSAsync(AsyncStorageRecordedTestCase): fsc: AsyncShareServiceClient = None async def _setup(self, storage_account_name: str): - self.account_url = self.account_url(storage_account_name, 'file') + self.account_url = self.account_url(storage_account_name, "file") self.credential = self.get_credential(AsyncShareServiceClient, is_async=True) self.fsc = AsyncShareServiceClient( - account_url=self.account_url, - credential=self.credential, - token_intent=TEST_INTENT + account_url=self.account_url, credential=self.credential, token_intent=TEST_INTENT ) - self.share_name = self.get_resource_name('utshare') + self.share_name = self.get_resource_name("utshare") async with AsyncShareServiceClient( - account_url=self.account_url, - credential=self.credential, - token_intent=TEST_INTENT + account_url=self.account_url, credential=self.credential, token_intent=TEST_INTENT ) as fsc: if self.is_live: try: - await fsc.create_share(self.share_name, protocols='NFS') + await fsc.create_share(self.share_name, protocols="NFS") except: pass @@ -63,7 +54,7 @@ def teardown_method(self): fsc = ShareServiceClient( account_url=self.account_url, credential=self.get_credential(ShareServiceClient), - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) fsc.delete_share(self.share_name) except: @@ -77,11 +68,12 @@ def _get_directory_name(self, prefix: str = TEST_DIRECTORY_PREFIX): return self.get_resource_name(prefix) def _assert_props( - self, props: Optional[Union[DirectoryProperties, FileProperties]], + self, + props: Optional[Union[DirectoryProperties, FileProperties]], owner: str, group: str, file_mode: str, - nfs_file_type: Optional[str] = None + nfs_file_type: Optional[str] = None, ) -> None: assert props is not None assert props.owner == owner @@ -97,8 +89,8 @@ def _assert_props( def _assert_copy(self, copy: Optional[Dict[str, Any]]) -> None: assert copy is not None - assert copy['copy_status'] == 'success' - assert copy['copy_id'] is not None + assert copy["copy_status"] == "success" + assert copy["copy_id"] is not None # --Test cases for NFS ---------------------------------------------- @FileSharePreparer() @@ -108,24 +100,21 @@ async def test_create_directory_and_set_directory_properties(self, **kwargs: Any await self._setup(premium_storage_file_account_name) - create_owner, create_group, create_file_mode = '345', '123', '7777' - set_owner, set_group, set_file_mode = '0', '0', '0755' + create_owner, create_group, create_file_mode = "345", "123", "7777" + set_owner, set_group, set_file_mode = "0", "0", "0755" share_client = self.fsc.get_share_client(self.share_name) directory_client = ShareDirectoryClient( - self.account_url, - share_client.share_name, 'dir1', - credential=self.credential, - token_intent=TEST_INTENT + self.account_url, share_client.share_name, "dir1", credential=self.credential, token_intent=TEST_INTENT ) await directory_client.create_directory(owner=create_owner, group=create_group, file_mode=create_file_mode) props = await directory_client.get_directory_properties() - self._assert_props(props, create_owner, create_group, create_file_mode, 'Directory') + self._assert_props(props, create_owner, create_group, create_file_mode, "Directory") await directory_client.set_http_headers(owner=set_owner, group=set_group, file_mode=set_file_mode) props = await directory_client.get_directory_properties() - self._assert_props(props, set_owner, set_group, set_file_mode, 'Directory') + self._assert_props(props, set_owner, set_group, set_file_mode, "Directory") @FileSharePreparer() @recorded_by_proxy_async @@ -140,28 +129,22 @@ async def test_create_file_and_set_file_properties(self, **kwargs: Any): share_name=self.share_name, file_path=file_name, credential=self.credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) - create_owner, create_group, create_file_mode = '345', '123', '7777' - set_owner, set_group, set_file_mode = '0', '0', '0644' - content_settings = ContentSettings( - content_language='spanish', - content_disposition='inline' - ) + create_owner, create_group, create_file_mode = "345", "123", "7777" + set_owner, set_group, set_file_mode = "0", "0", "0644" + content_settings = ContentSettings(content_language="spanish", content_disposition="inline") await file_client.create_file(1024, owner=create_owner, group=create_group, file_mode=create_file_mode) props = await file_client.get_file_properties() - self._assert_props(props, create_owner, create_group, create_file_mode, 'Regular') + self._assert_props(props, create_owner, create_group, create_file_mode, "Regular") await file_client.set_http_headers( - content_settings=content_settings, - owner=set_owner, - group=set_group, - file_mode=set_file_mode + content_settings=content_settings, owner=set_owner, group=set_group, file_mode=set_file_mode ) props = await file_client.get_file_properties() - self._assert_props(props, set_owner, set_group, set_file_mode, 'Regular') + self._assert_props(props, set_owner, set_group, set_file_mode, "Regular") @FileSharePreparer() @recorded_by_proxy_async @@ -170,10 +153,10 @@ async def test_download_and_copy_file(self, **kwargs: Any): await self._setup(premium_storage_file_account_name) - default_owner, default_group, default_file_mode = '0', '0', '0664' - source_owner, source_group, source_file_mode = '999', '888', '0111' - override_owner, override_group, override_file_mode = '54321', '12345', '7777' - data = b'abcdefghijklmnop' * 32 + default_owner, default_group, default_file_mode = "0", "0", "0664" + source_owner, source_group, source_file_mode = "999", "888", "0111" + override_owner, override_group, override_file_mode = "54321", "12345", "7777" + data = b"abcdefghijklmnop" * 32 share_client = self.fsc.get_share_client(self.share_name) @@ -188,14 +171,12 @@ async def test_download_and_copy_file(self, **kwargs: Any): new_client_source_copy = ShareFileClient( self.account_url, share_name=self.share_name, - file_path='newclientsourcecopy', + file_path="newclientsourcecopy", credential=self.credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) copy = await new_client_source_copy.start_copy_from_url( - file_client.url, - file_mode_copy_mode='source', - owner_copy_mode='source' + file_client.url, file_mode_copy_mode="source", owner_copy_mode="source" ) self._assert_copy(copy) props = await new_client_source_copy.get_file_properties() @@ -204,9 +185,9 @@ async def test_download_and_copy_file(self, **kwargs: Any): new_client_default_copy = ShareFileClient( self.account_url, share_name=self.share_name, - file_path='newclientdefaultcopy', + file_path="newclientdefaultcopy", credential=self.credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) copy = await new_client_default_copy.start_copy_from_url(file_client.url) self._assert_copy(copy) @@ -216,17 +197,17 @@ async def test_download_and_copy_file(self, **kwargs: Any): new_client_override_copy = ShareFileClient( self.account_url, share_name=self.share_name, - file_path='newclientoverridecopy', + file_path="newclientoverridecopy", credential=self.credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) copy = await new_client_override_copy.start_copy_from_url( file_client.url, owner=override_owner, group=override_group, file_mode=override_file_mode, - file_mode_copy_mode='override', - owner_copy_mode='override' + file_mode_copy_mode="override", + owner_copy_mode="override", ) self._assert_copy(copy) props = await new_client_override_copy.get_file_properties() @@ -242,29 +223,29 @@ async def test_create_hardlink(self, **kwargs: Any): share_client = self.fsc.get_share_client(self.share_name) directory_name = self._get_directory_name() directory_client = await share_client.create_directory(directory_name) - source_file_name = self._get_file_name('file1') + source_file_name = self._get_file_name("file1") source_file_client = directory_client.get_file_client(source_file_name) await source_file_client.create_file(size=1024) - hard_link_file_name = self._get_file_name('file2') + hard_link_file_name = self._get_file_name("file2") hard_link_file_client = directory_client.get_file_client(hard_link_file_name) resp = await hard_link_file_client.create_hardlink(target=f"{directory_name}/{source_file_name}") assert resp is not None - assert resp['file_file_type'] == 'Regular' - assert resp['owner'] == '0' - assert resp['group'] == '0' - assert resp['mode'] == '0664' - assert resp['link_count'] == 2 + assert resp["file_file_type"] == "Regular" + assert resp["owner"] == "0" + assert resp["group"] == "0" + assert resp["mode"] == "0664" + assert resp["link_count"] == 2 - assert resp['file_creation_time'] is not None - assert resp['file_last_write_time'] is not None - assert resp['file_change_time'] is not None - assert resp['file_id'] is not None - assert resp['file_parent_id'] is not None + assert resp["file_creation_time"] is not None + assert resp["file_last_write_time"] is not None + assert resp["file_change_time"] is not None + assert resp["file_id"] is not None + assert resp["file_parent_id"] is not None - assert 'file_attributes' not in resp - assert 'file_response_key' not in resp + assert "file_attributes" not in resp + assert "file_response_key" not in resp @FileSharePreparer() @recorded_by_proxy_async @@ -276,15 +257,15 @@ async def test_create_hardlink_error(self, **kwargs: Any): share_client = self.fsc.get_share_client(self.share_name) directory_name = self._get_directory_name() directory_client = share_client.get_directory_client(directory_name) - source_file_name = self._get_file_name('file1') + source_file_name = self._get_file_name("file1") source_file_client = directory_client.get_file_client(source_file_name) - hard_link_file_name = self._get_file_name('file2') + hard_link_file_name = self._get_file_name("file2") hard_link_file_client = directory_client.get_file_client(hard_link_file_name) with pytest.raises(ResourceNotFoundError) as e: await hard_link_file_client.create_hardlink(target=f"{directory_name}/{source_file_name}") - assert 'ParentNotFound' in e.value.args[0] + assert "ParentNotFound" in e.value.args[0] @FileSharePreparer() @recorded_by_proxy_async @@ -296,37 +277,34 @@ async def test_create_and_get_symlink(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_name = self._get_directory_name() directory_client = await share_client.create_directory(directory_name) - source_file_name = self._get_file_name('file1') + source_file_name = self._get_file_name("file1") source_file_client = directory_client.get_file_client(source_file_name) await source_file_client.create_file(size=1024) - symbolic_link_file_name = self._get_file_name('file2') + symbolic_link_file_name = self._get_file_name("file2") symbolic_link_file_client = directory_client.get_file_client(symbolic_link_file_name) metadata = {"test1": "foo", "test2": "bar"} owner, group = "345", "123" target = f"{directory_name}/{source_file_name}" resp = await symbolic_link_file_client.create_symlink( - target=target, - metadata=metadata, - owner=owner, - group=group + target=target, metadata=metadata, owner=owner, group=group ) assert resp is not None - assert resp['file_file_type'] == 'SymLink' - assert resp['owner'] == owner - assert resp['group'] == group - assert resp['file_creation_time'] is not None - assert resp['file_last_write_time'] is not None - assert resp['file_id'] is not None - assert resp['file_parent_id'] is not None - assert 'file_attributes' not in resp - assert 'file_permission_key' not in resp + assert resp["file_file_type"] == "SymLink" + assert resp["owner"] == owner + assert resp["group"] == group + assert resp["file_creation_time"] is not None + assert resp["file_last_write_time"] is not None + assert resp["file_id"] is not None + assert resp["file_parent_id"] is not None + assert "file_attributes" not in resp + assert "file_permission_key" not in resp resp = await symbolic_link_file_client.get_symlink() assert resp is not None - assert resp['etag'] is not None - assert resp['last_modified'] is not None - assert unquote(resp['link_text']) == target + assert resp["etag"] is not None + assert resp["last_modified"] is not None + assert unquote(resp["link_text"]) == target @FileSharePreparer() @recorded_by_proxy_async @@ -338,16 +316,16 @@ async def test_create_and_get_symlink_error(self, **kwargs): share_client = self.fsc.get_share_client(self.share_name) directory_name = self._get_directory_name() directory_client = share_client.get_directory_client(directory_name) - source_file_name = self._get_file_name('file1') + source_file_name = self._get_file_name("file1") source_file_client = directory_client.get_file_client(source_file_name) - symbolic_link_file_name = self._get_file_name('file2') + symbolic_link_file_name = self._get_file_name("file2") symbolic_link_file_client = directory_client.get_file_client(symbolic_link_file_name) target = f"{directory_name}/{source_file_name}" with pytest.raises(ResourceNotFoundError) as e: await symbolic_link_file_client.create_symlink(target=target) - assert 'ParentNotFound' in e.value.args[0] + assert "ParentNotFound" in e.value.args[0] with pytest.raises(ResourceNotFoundError) as e: await symbolic_link_file_client.get_symlink() - assert 'ParentNotFound' in e.value.args[0] + assert "ParentNotFound" in e.value.args[0] 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 c008a4205f61..03c6a739b196 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_share.py +++ b/sdk/storage/azure-storage-file-share/tests/test_share.py @@ -14,7 +14,7 @@ ClientAuthenticationError, HttpResponseError, ResourceExistsError, - ResourceNotFoundError + ResourceNotFoundError, ) from azure.core.pipeline.transport import RequestsTransport from azure.storage.fileshare import ( @@ -32,7 +32,7 @@ ShareRootSquash, ShareSasPermissions, ShareServiceClient, - StorageErrorCode + StorageErrorCode, ) from devtools_testutils import recorded_by_proxy @@ -40,10 +40,11 @@ from settings.testcase import FileSharePreparer # ------------------------------------------------------------------------------ -TEST_SHARE_PREFIX = 'share' +TEST_SHARE_PREFIX = "share" TEST_INTENT = "backup" # ------------------------------------------------------------------------------ + class TestStorageShare(StorageRecordedTestCase): def _setup(self, storage_account_name, storage_account_key): file_url = self.account_url(storage_account_name, "file") @@ -57,6 +58,7 @@ def _teardown(self, FILE_PATH): os.remove(FILE_PATH) except: pass + # --Helpers----------------------------------------------------------------- def _get_share_reference(self, prefix=TEST_SHARE_PREFIX): share_name = self.get_resource_name(prefix) @@ -75,7 +77,7 @@ 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): for l in self.fsc.list_shares(include_snapshots=True): try: @@ -85,11 +87,16 @@ 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" @@ -125,7 +132,7 @@ def test_create_share_with_oauth_fails(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=share_name, credential=token_credential, - file_request_intent=TEST_INTENT + file_request_intent=TEST_INTENT, ) @FileSharePreparer() @@ -143,9 +150,9 @@ def test_create_share_snapshot(self, **kwargs): # Assert assert created - assert snapshot['snapshot'] is not None - assert snapshot['etag'] is not None - assert snapshot['last_modified'] is not None + assert snapshot["snapshot"] is not None + assert snapshot["etag"] is not None + assert snapshot["last_modified"] is not None self._delete_shares(share.share_name) @FileSharePreparer() @@ -168,14 +175,14 @@ def test_create_snapshot_with_metadata(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=share.share_name, snapshot=snapshot, - credential=storage_account_key + credential=storage_account_key, ) snapshot_props = snapshot_client.get_share_properties() # Assert assert created - assert snapshot['snapshot'] is not None - assert snapshot['etag'] is not None - assert snapshot['last_modified'] is not None + assert snapshot["snapshot"] is not None + assert snapshot["etag"] is not None + assert snapshot["last_modified"] is not None assert share_props.metadata == metadata assert snapshot_props.metadata == metadata2 self._delete_shares(share.share_name) @@ -218,9 +225,9 @@ def test_lease_share_acquire_and_release(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') + share_client = self._create_share("test") # Act - lease = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") lease.release() # Assert @@ -241,11 +248,11 @@ def test_acquire_lease_on_sharesnapshot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=share.share_name, snapshot=snapshot, - credential=storage_account_key + credential=storage_account_key, ) - share_lease = share.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') - share_snapshot_lease = snapshot_client.acquire_lease(lease_id='44444444-3333-2222-1111-000000000000') + share_lease = share.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") + share_snapshot_lease = snapshot_client.acquire_lease(lease_id="44444444-3333-2222-1111-000000000000") # Assert with pytest.raises(HttpResponseError): @@ -254,9 +261,9 @@ def test_acquire_lease_on_sharesnapshot(self, **kwargs): with pytest.raises(HttpResponseError): snapshot_client.get_share_properties(lease=share_lease) - assert snapshot['snapshot'] is not None - assert snapshot['etag'] is not None - assert snapshot['last_modified'] is not None + assert snapshot["snapshot"] is not None + assert snapshot["etag"] is not None + assert snapshot["last_modified"] is not None assert share_lease is not None assert share_snapshot_lease is not None assert share_lease != share_snapshot_lease @@ -272,8 +279,8 @@ def test_lease_share_renew(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') - lease = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + share_client = self._create_share("test") + lease = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) self.sleep(10) lease_id_start = lease.id @@ -295,16 +302,16 @@ def test_lease_share_with_duration(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test1') + share_client = self._create_share("test1") # Act - lease = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + lease = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) # Assert with pytest.raises(HttpResponseError): - share_client.acquire_lease(lease_id='44444444-3333-2222-1111-000000000000') + share_client.acquire_lease(lease_id="44444444-3333-2222-1111-000000000000") self.sleep(17) - share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") @FileSharePreparer() @recorded_by_proxy @@ -313,10 +320,10 @@ def test_lease_share_twice(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') + share_client = self._create_share("test") # Act - lease = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + lease = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) # Assert lease2 = share_client.acquire_lease(lease_id=lease.id) @@ -329,10 +336,10 @@ def test_lease_share_with_proposed_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') + share_client = self._create_share("test") # Act - proposed_lease_id = '55e97f64-73e8-4390-838d-d9e84a374321' + proposed_lease_id = "55e97f64-73e8-4390-838d-d9e84a374321" lease = share_client.acquire_lease(lease_id=proposed_lease_id) # Assert @@ -345,11 +352,11 @@ def test_lease_share_change_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') + share_client = self._create_share("test") # Act - lease_id = '29e0b239-ecda-4f69-bfa3-95f6af91464c' - lease = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease_id = "29e0b239-ecda-4f69-bfa3-95f6af91464c" + lease = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") lease_id1 = lease.id lease.change(proposed_lease_id=lease_id) lease.renew() @@ -368,9 +375,9 @@ def test_set_share_metadata_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') - metadata = {'hello': 'world', 'number': '43'} - lease_id = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + share_client = self._create_share("test") + metadata = {"hello": "world", "number": "43"} + lease_id = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act share_client.set_share_metadata(metadata, lease=lease_id) @@ -386,10 +393,10 @@ def test_get_share_metadata_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') - metadata = {'hello': 'world', 'number': '43'} + share_client = self._create_share("test") + metadata = {"hello": "world", "number": "43"} share_client.set_share_metadata(metadata) - lease_id = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease_id = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act md = share_client.get_share_properties(lease=lease_id).metadata @@ -404,10 +411,10 @@ def test_get_share_properties_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') - metadata = {'hello': 'world', 'number': '43'} + share_client = self._create_share("test") + metadata = {"hello": "world", "number": "43"} share_client.set_share_metadata(metadata) - lease_id = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease_id = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act props = share_client.get_share_properties(lease=lease_id) @@ -416,9 +423,9 @@ def test_get_share_properties_with_lease_id(self, **kwargs): # Assert assert props is not None assert props.metadata == metadata - assert props.lease.duration == 'infinite' - assert props.lease.state == 'leased' - assert props.lease.status == 'locked' + assert props.lease.duration == "infinite" + assert props.lease.state == "leased" + assert props.lease.status == "locked" @FileSharePreparer() @recorded_by_proxy @@ -427,41 +434,39 @@ def test_get_share_acl_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') - lease_id = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + share_client = self._create_share("test") + lease_id = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act acl = share_client.get_share_access_policy(lease=lease_id) # Assert assert acl is not None - assert acl.get('public_access') is None + assert acl.get("public_access") is None @FileSharePreparer() @recorded_by_proxy def test_set_share_acl_with_lease_id(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - variables = kwargs.pop('variables', {}) + variables = kwargs.pop("variables", {}) self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') - lease_id = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + share_client = self._create_share("test") + lease_id = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act - expiry_time = self.get_datetime_variable(variables, 'expiry_time', datetime.utcnow() + timedelta(hours=1)) - start_time = self.get_datetime_variable(variables, 'start_time', datetime.utcnow()) - access_policy = AccessPolicy(permission=ShareSasPermissions(read=True), - expiry=expiry_time, - start=start_time) - signed_identifiers = {'testid': access_policy} + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow()) + access_policy = AccessPolicy(permission=ShareSasPermissions(read=True), expiry=expiry_time, start=start_time) + signed_identifiers = {"testid": access_policy} share_client.set_share_access_policy(signed_identifiers, lease=lease_id) # Assert acl = share_client.get_share_access_policy() assert acl is not None - assert acl.get('public_access') is None + assert acl.get("public_access") is None return variables @@ -472,10 +477,10 @@ def test_lease_share_break_period(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') + share_client = self._create_share("test") # Act - lease = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + lease = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) # Assert lease.break_lease(lease_break_period=5) @@ -490,8 +495,8 @@ def test_delete_share_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = self._create_share('test') - lease = share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + share_client = self._create_share("test") + lease = share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) # Assert with pytest.raises(HttpResponseError): @@ -554,7 +559,7 @@ def test_delete_snapshot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=share.share_name, snapshot=snapshot, - credential=storage_account_key + credential=storage_account_key, ) deleted = snapshot_client.delete_share() @@ -602,7 +607,7 @@ def test_create_share_with_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act client = self._get_share_reference() @@ -708,7 +713,7 @@ def test_share_snapshot_not_exists(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = self._create_share() - made_up_snapshot = '2017-07-19T06:53:46.0000000Z' + made_up_snapshot = "2017-07-19T06:53:46.0000000Z" # Act snapshot_client = self.fsc.get_share_client(share.share_name, snapshot=made_up_snapshot) @@ -725,7 +730,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): @@ -761,17 +766,17 @@ def test_list_shares_enable_snapshot_virtual_directory_access(self, **kwargs): 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 = self._create_share(protocols="NFS", headers={'x-ms-enable-snapshot-virtual-directory-access': "False"}) + share = self._create_share(protocols="NFS", headers={"x-ms-enable-snapshot-virtual-directory-access": "False"}) # Act list_props = list(self.fsc.list_shares()) share_props = share.get_share_properties() # Assert - assert list_props[0].protocols[0] == 'NFS' + assert list_props[0].protocols[0] == "NFS" assert list_props[0].enable_snapshot_virtual_directory_access is False - assert share_props.protocols[0] == 'NFS' + assert share_props.protocols[0] == "NFS" assert share_props.enable_snapshot_virtual_directory_access is False self._delete_shares() @@ -808,16 +813,16 @@ def test_list_shares_leased_share(self, **kwargs): share = self._create_share("test1") # Act - lease = share.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = share.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") resp = list(self.fsc.list_shares()) # Assert assert resp is not None assert len(resp) >= 1 assert resp[0] is not None - assert resp[0].lease.duration == 'infinite' - assert resp[0].lease.status == 'locked' - assert resp[0].lease.state == 'leased' + assert resp[0].lease.duration == "infinite" + assert resp[0].lease.status == "locked" + assert resp[0].lease.state == "leased" lease.release() self._delete_shares() @@ -828,7 +833,7 @@ def test_list_shares_with_snapshot(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share = self._create_share('random2') + share = self._create_share("random2") snapshot1 = share.create_snapshot() snapshot2 = share.create_snapshot() @@ -839,8 +844,8 @@ def test_list_shares_with_snapshot(self, **kwargs): all_shares = list(shares) assert len(all_shares) == 3 self.assertNamedItemInContainer(all_shares, share.share_name) - self.assertNamedItemInContainer(all_shares, snapshot1['snapshot']) - self.assertNamedItemInContainer(all_shares, snapshot2['snapshot']) + self.assertNamedItemInContainer(all_shares, snapshot1["snapshot"]) + self.assertNamedItemInContainer(all_shares, snapshot2["snapshot"]) share.delete_share(delete_snapshots=True) self._delete_shares() @@ -851,7 +856,7 @@ def test_delete_snapshots_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share = self._create_share('prefix') + share = self._create_share("prefix") share.create_snapshot() share.create_snapshot() @@ -865,15 +870,15 @@ def test_delete_snapshots_options(self, **kwargs): share.delete_share(delete_snapshots=True) # Test "include" - share = self._create_share('prefix2') + share = self._create_share("prefix2") share.create_snapshot() - share.delete_share(delete_snapshots='include') + share.delete_share(delete_snapshots="include") # Test "include-leased" - share = self._create_share('prefix3') - lease = share.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + share = self._create_share("prefix3") + lease = share.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") share.create_snapshot() - share.delete_share(delete_snapshots='include-leased', lease='00000000-1111-2222-3333-444444444444') + share.delete_share(delete_snapshots="include-leased", lease="00000000-1111-2222-3333-444444444444") @FileSharePreparer() @recorded_by_proxy @@ -882,8 +887,8 @@ def test_list_shares_with_prefix(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - self._create_share('othershare') - share = self._create_share('random2') + self._create_share("othershare") + share = self._create_share("random2") # Act shares = list(self.fsc.list_shares(name_starts_with=share.share_name)) @@ -902,7 +907,7 @@ def test_list_shares_with_include_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} share = self._get_share_reference() share.create_share(metadata=metadata) @@ -925,19 +930,20 @@ def test_list_shares_with_num_results_and_marker(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - prefix = 'listshare' + prefix = "listshare" share_names = [] for i in range(0, 4): share_names.append(self._create_share(prefix + str(i)).share_name) - #share_names.sort() + # share_names.sort() # Act generator1 = self.fsc.list_shares(prefix, results_per_page=2).by_page() shares1 = list(next(generator1)) - generator2 = self.fsc.list_shares( - prefix, results_per_page=2).by_page(continuation_token=generator1.continuation_token) + generator2 = self.fsc.list_shares(prefix, results_per_page=2).by_page( + continuation_token=generator1.continuation_token + ) shares2 = list(next(generator2)) # Assert @@ -993,7 +999,7 @@ def test_list_shares_account_sas_fails(self, **kwargs): storage_account_key, ResourceTypes(service=True), AccountSasPermissions(list=True), - datetime.utcnow() - timedelta(hours=1) + datetime.utcnow() - timedelta(hours=1), ) # Act @@ -1013,7 +1019,7 @@ def test_set_share_metadata(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = self._create_share() - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act share.set_share_metadata(metadata) @@ -1030,7 +1036,7 @@ def test_get_share_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act client = self._get_share_reference() @@ -1049,7 +1055,7 @@ def test_get_share_metadata_with_snapshot(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act client = self._get_share_reference() @@ -1135,9 +1141,9 @@ def test_set_share_properties_with_root_squash(self, **kwargs): # # Assert assert share1_props.root_squash == ShareRootSquash.no_root_squash - assert share1_props.protocols == ['NFS'] + assert share1_props.protocols == ["NFS"] assert share2_props.root_squash == ShareRootSquash.root_squash - assert share2_props.protocols == ['NFS'] + assert share2_props.protocols == ["NFS"] @pytest.mark.playback_test_only @FileSharePreparer() @@ -1234,7 +1240,7 @@ def test_delete_share_with_non_existing_share(self, **kwargs): deleted = client.delete_share() log_as_str = log_captured.getvalue() - assert 'ERROR' not in log_as_str + assert "ERROR" not in log_as_str self._delete_shares() @FileSharePreparer() @@ -1305,7 +1311,7 @@ def test_set_share_acl_with_empty_signed_identifiers(self, **kwargs): # Assert acl = share.get_share_access_policy() assert acl is not None - assert len(acl.get('signed_identifiers')) == 0 + assert len(acl.get("signed_identifiers")) == 0 self._delete_shares() @FileSharePreparer() @@ -1313,7 +1319,7 @@ def test_set_share_acl_with_empty_signed_identifiers(self, **kwargs): def test_set_share_acl_with_signed_identifiers(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - variables = kwargs.pop('variables', {}) + variables = kwargs.pop("variables", {}) self._setup(storage_account_name, storage_account_key) share = self._get_share_reference() @@ -1321,9 +1327,9 @@ def test_set_share_acl_with_signed_identifiers(self, **kwargs): # Act identifiers = {} - expiry_time = self.get_datetime_variable(variables, 'expiry_time', datetime.utcnow() + timedelta(hours=1)) - start_time = self.get_datetime_variable(variables, 'start_time', datetime.utcnow() - timedelta(minutes=1)) - identifiers['testid'] = AccessPolicy( + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(minutes=1)) + identifiers["testid"] = AccessPolicy( permission=ShareSasPermissions(write=True), expiry=expiry_time, start=start_time, @@ -1334,8 +1340,8 @@ def test_set_share_acl_with_signed_identifiers(self, **kwargs): # Assert acl = share.get_share_access_policy() assert acl is not None - assert len(acl['signed_identifiers']) == 1 - assert acl['signed_identifiers'][0].id == 'testid' + assert len(acl["signed_identifiers"]) == 1 + assert acl["signed_identifiers"][0].id == "testid" self._delete_shares() return variables @@ -1353,12 +1359,15 @@ def test_set_share_acl_too_many_ids(self, **kwargs): # Act identifiers = {} for i in range(0, 6): - identifiers['id{}'.format(i)] = AccessPolicy() + identifiers["id{}".format(i)] = AccessPolicy() # 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() @@ -1370,11 +1379,11 @@ def test_list_directories_and_files(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = self._create_share() dir0 = share.get_directory_client() - dir0.upload_file('file1', 'data1') - dir1 = share.get_directory_client('dir1') + dir0.upload_file("file1", "data1") + dir1 = share.get_directory_client("dir1") dir1.create_directory() - dir1.upload_file('file2', 'data2') - dir2 = share.get_directory_client('dir2') + dir1.upload_file("file2", "data2") + dir2 = share.get_directory_client("dir2") dir2.create_directory() # Act @@ -1384,9 +1393,9 @@ def test_list_directories_and_files(self, **kwargs): assert resp is not None assert len(resp) == 3 assert resp[0] is not None - self.assertNamedItemInContainer(resp, 'dir1') - self.assertNamedItemInContainer(resp, 'dir2') - self.assertNamedItemInContainer(resp, 'file1') + self.assertNamedItemInContainer(resp, "dir1") + self.assertNamedItemInContainer(resp, "dir2") + self.assertNamedItemInContainer(resp, "file1") self._delete_shares() @FileSharePreparer() @@ -1397,16 +1406,15 @@ def test_list_directories_and_files_with_snapshot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_name = self._create_share() - dir1 = share_name.get_directory_client('dir1') + dir1 = share_name.get_directory_client("dir1") dir1.create_directory() - dir2 = share_name.get_directory_client('dir2') + dir2 = share_name.get_directory_client("dir2") dir2.create_directory() snapshot1 = share_name.create_snapshot() - dir3 = share_name.get_directory_client('dir3') + dir3 = share_name.get_directory_client("dir3") dir3.create_directory() - file1 = share_name.get_file_client('file1') - file1.upload_file('data') - + file1 = share_name.get_file_client("file1") + file1.upload_file("data") # Act snapshot_client = self.fsc.get_share_client(share_name.share_name, snapshot=snapshot1) @@ -1416,8 +1424,8 @@ def test_list_directories_and_files_with_snapshot(self, **kwargs): assert resp is not None assert len(resp) == 2 assert resp[0] is not None - self.assertNamedItemInContainer(resp, 'dir1') - self.assertNamedItemInContainer(resp, 'dir2') + self.assertNamedItemInContainer(resp, "dir1") + self.assertNamedItemInContainer(resp, "dir2") self._delete_shares() @FileSharePreparer() @@ -1428,12 +1436,12 @@ def test_list_directories_and_files_with_num_results(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_name = self._create_share() - dir1 = share_name.create_directory('dir1') + dir1 = share_name.create_directory("dir1") root = share_name.get_directory_client() - root.upload_file('filea1', '1024') - root.upload_file('filea2', '1024') - root.upload_file('filea3', '1024') - root.upload_file('fileb1', '1024') + root.upload_file("filea1", "1024") + root.upload_file("filea2", "1024") + root.upload_file("filea3", "1024") + root.upload_file("fileb1", "1024") # Act result = share_name.list_directories_and_files(results_per_page=2).by_page() @@ -1442,8 +1450,8 @@ def test_list_directories_and_files_with_num_results(self, **kwargs): # Assert assert result is not None assert len(result) == 2 - self.assertNamedItemInContainer(result, 'dir1') - self.assertNamedItemInContainer(result, 'filea1') + self.assertNamedItemInContainer(result, "dir1") + self.assertNamedItemInContainer(result, "filea1") self._delete_shares() @FileSharePreparer() @@ -1454,29 +1462,29 @@ def test_list_directories_and_files_with_num_results_and_marker(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_name = self._create_share() - dir1 = share_name.get_directory_client('dir1') + dir1 = share_name.get_directory_client("dir1") dir1.create_directory() - dir1.upload_file('filea1', '1024') - dir1.upload_file('filea2', '1024') - dir1.upload_file('filea3', '1024') - dir1.upload_file('fileb1', '1024') + dir1.upload_file("filea1", "1024") + dir1.upload_file("filea2", "1024") + dir1.upload_file("filea3", "1024") + dir1.upload_file("fileb1", "1024") # Act - generator1 = share_name.list_directories_and_files( - 'dir1', results_per_page=2).by_page() + generator1 = share_name.list_directories_and_files("dir1", results_per_page=2).by_page() result1 = list(next(generator1)) - generator2 = share_name.list_directories_and_files( - 'dir1', results_per_page=2).by_page(continuation_token=generator1.continuation_token) + generator2 = share_name.list_directories_and_files("dir1", results_per_page=2).by_page( + continuation_token=generator1.continuation_token + ) result2 = list(next(generator2)) # Assert assert len(result1) == 2 assert len(result2) == 2 - self.assertNamedItemInContainer(result1, 'filea1') - self.assertNamedItemInContainer(result1, 'filea2') - self.assertNamedItemInContainer(result2, 'filea3') - self.assertNamedItemInContainer(result2, 'fileb1') + self.assertNamedItemInContainer(result1, "filea1") + self.assertNamedItemInContainer(result1, "filea2") + self.assertNamedItemInContainer(result2, "filea3") + self.assertNamedItemInContainer(result2, "fileb1") assert generator2.continuation_token == None self._delete_shares() @@ -1488,24 +1496,24 @@ def test_list_directories_and_files_with_prefix(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = self._create_share() - dir1 = share.create_directory('dir1') - share.create_directory('dir1/pref_dir3') - share.create_directory('dir2') + dir1 = share.create_directory("dir1") + share.create_directory("dir1/pref_dir3") + share.create_directory("dir2") root = share.get_directory_client() - root.upload_file('file1', '1024') - dir1.upload_file('pref_file2', '1025') - dir1.upload_file('file3', '1025') + root.upload_file("file1", "1024") + dir1.upload_file("pref_file2", "1025") + dir1.upload_file("file3", "1025") # Act - resp = list(share.list_directories_and_files('dir1', name_starts_with='pref')) + resp = list(share.list_directories_and_files("dir1", name_starts_with="pref")) # Assert assert resp is not None assert len(resp) == 2 assert resp[0] is not None - self.assertNamedItemInContainer(resp, 'pref_file2') - self.assertNamedItemInContainer(resp, 'pref_dir3') + self.assertNamedItemInContainer(resp, "pref_file2") + self.assertNamedItemInContainer(resp, "pref_dir3") self._delete_shares() @pytest.mark.live_test_only @@ -1515,9 +1523,9 @@ def test_shared_access_share(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_name = 'file1' - dir_name = 'dir1' - data = b'hello world' + file_name = "file1" + dir_name = "dir1" + data = b"hello world" share = self._create_share() dir1 = share.create_directory(dir_name) @@ -1534,7 +1542,7 @@ def test_shared_access_share(self, **kwargs): sas_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=share.share_name, - file_path=dir_name + '/' + file_name, + file_path=dir_name + "/" + file_name, credential=token, ) @@ -1554,9 +1562,11 @@ def test_create_permission_for_share(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - user_given_permission = "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;;;" \ - "S-1-5-21-397955417-626881126-188441444-3053964)" + user_given_permission = ( + "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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)" + ) share_client = self._create_share() permission_key = share_client.create_permission_for_share(user_given_permission) assert permission_key is not None @@ -1577,25 +1587,27 @@ def test_get_permission_format(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = self._create_share() - user_given_permission_sddl = ("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;;;" - "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL") - user_given_permission_binary = ("AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" - "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" - "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=") + user_given_permission_sddl = ( + "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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL" + ) + user_given_permission_binary = ( + "AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" + "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" + "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=" + ) permission_key = share_client.create_permission_for_share(user_given_permission_sddl) assert permission_key is not None server_returned_permission = share_client.get_permission_for_share( - permission_key, - file_permission_format="sddl" + permission_key, file_permission_format="sddl" ) assert server_returned_permission == user_given_permission_sddl server_returned_permission = share_client.get_permission_for_share( - permission_key, - file_permission_format="binary" + permission_key, file_permission_format="binary" ) assert server_returned_permission == user_given_permission_binary @@ -1629,15 +1641,15 @@ def test_delete_directory_from_share(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = self._create_share() - dir1 = share.create_directory('dir1') - share.create_directory('dir2') - share.create_directory('dir3') + dir1 = share.create_directory("dir1") + share.create_directory("dir2") + share.create_directory("dir3") # Act resp = list(share.list_directories_and_files()) assert len(resp) == 3 - share.delete_directory('dir3') + share.delete_directory("dir3") # Assert resp = list(share.list_directories_and_files()) @@ -1659,11 +1671,7 @@ def test_share_paid_bursting(self, **kwargs): # Act / Assert share = self._get_share_reference() - share.create_share( - paid_bursting_enabled=True, - paid_bursting_bandwidth_mibps=5000, - paid_bursting_iops=1000 - ) + share.create_share(paid_bursting_enabled=True, paid_bursting_bandwidth_mibps=5000, paid_bursting_iops=1000) share_props = share.get_share_properties() assert share_props.paid_bursting_enabled assert share_props.paid_bursting_bandwidth_mibps == 5000 @@ -1673,7 +1681,7 @@ def test_share_paid_bursting(self, **kwargs): root_squash="NoRootSquash", paid_bursting_enabled=True, paid_bursting_bandwidth_mibps=mibps, - paid_bursting_iops=iops + paid_bursting_iops=iops, ) share_props = share.get_share_properties() share_name = share_props.name @@ -1708,8 +1716,8 @@ def test_share_client_with_oauth(self, **kwargs): token_credential = self.get_credential(ShareClient) self._setup(storage_account_name, storage_account_key) - first_share = self._create_share('test1') - second_share = self._create_share('test2') + first_share = self._create_share("test1") + second_share = self._create_share("test2") share_names = {share.name for share in self.fsc.list_shares()} assert first_share.share_name in share_names @@ -1719,29 +1727,29 @@ def test_share_client_with_oauth(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=first_share.share_name, credential=token_credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) second_share_client = ShareClient( self.account_url(storage_account_name, "file"), share_name=second_share.share_name, credential=token_credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) first_share_props = first_share_client.get_share_properties() second_share_props = second_share_client.get_share_properties() assert first_share_props is not None assert first_share_props.name == first_share.share_name - assert first_share_props.access_tier == 'TransactionOptimized' + assert first_share_props.access_tier == "TransactionOptimized" assert second_share_props is not None assert second_share_props.name == second_share.share_name - assert second_share_props.access_tier == 'TransactionOptimized' + assert second_share_props.access_tier == "TransactionOptimized" - first_share_client.set_share_properties(access_tier='Hot') + first_share_client.set_share_properties(access_tier="Hot") first_share_props = first_share_client.get_share_properties() assert first_share_props is not None assert first_share_props.name == first_share.share_name - assert first_share_props.access_tier == 'Hot' + assert first_share_props.access_tier == "Hot" share_names = {share.name for share in self.fsc.list_shares()} assert first_share.share_name in share_names @@ -1759,25 +1767,22 @@ def test_share_lease_with_oauth(self, **kwargs): # Arrange self._setup(storage_account_name, storage_account_key) - share = self._create_share('test') + share = self._create_share("test") share_client = ShareClient( self.account_url(storage_account_name, "file"), share_name=share.share_name, credential=token_credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) # Act / Assert lease_duration = 60 - lease_id = '00000000-1111-2222-3333-444444444444' - lease = share_client.acquire_lease( - lease_id=lease_id, - lease_duration=lease_duration - ) + lease_id = "00000000-1111-2222-3333-444444444444" + lease = share_client.acquire_lease(lease_id=lease_id, lease_duration=lease_duration) props = share_client.get_share_properties(lease=lease) - assert props.lease.duration == 'fixed' - assert props.lease.state == 'leased' - assert props.lease.status == 'locked' + assert props.lease.duration == "fixed" + assert props.lease.state == "leased" + assert props.lease.status == "locked" lease.renew() assert lease.id == lease_id @@ -1795,9 +1800,9 @@ def test_create_share_access_tier_premium(self, **kwargs): self._setup(premium_storage_file_account_name, premium_storage_file_account_key) share = self._get_share_reference() - share.create_share(access_tier='Premium') + share.create_share(access_tier="Premium") props = share.get_share_properties() - assert props.access_tier == 'Premium' + assert props.access_tier == "Premium" finally: self._delete_shares() @@ -1812,9 +1817,9 @@ def test_set_share_properties_access_tier_premium(self, **kwargs): share = self._get_share_reference() share.create_share() - share.set_share_properties(access_tier='Premium') + share.set_share_properties(access_tier="Premium") props = share.get_share_properties() - assert props.access_tier == 'Premium' + assert props.access_tier == "Premium" finally: self._delete_shares() @@ -1842,11 +1847,7 @@ def test_provisioned_billing_v2(self, **kwargs): assert props.next_provisioned_iops_downgrade is not None assert props.next_provisioned_bandwidth_downgrade is not None - share.set_share_properties( - access_tier="Hot", - provisioned_iops=3000, - provisioned_bandwidth_mibps=125 - ) + share.set_share_properties(access_tier="Hot", provisioned_iops=3000, provisioned_bandwidth_mibps=125) shares = list(self.fsc.list_shares()) @@ -1862,6 +1863,7 @@ def test_provisioned_billing_v2(self, **kwargs): finally: self._delete_shares() + # ------------------------------------------------------------------------------ -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() 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 d6c3446d2181..caf5c47bc2af 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 @@ -13,7 +13,7 @@ ClientAuthenticationError, HttpResponseError, ResourceExistsError, - ResourceNotFoundError + ResourceNotFoundError, ) from azure.core.pipeline.transport import AioHttpTransport from azure.storage.fileshare import ( @@ -27,7 +27,7 @@ ShareRootSquash, ShareSasPermissions, ShareServiceClient, - StorageErrorCode + StorageErrorCode, ) from azure.storage.fileshare.aio import ShareClient, ShareFileClient, ShareServiceClient @@ -35,8 +35,9 @@ from devtools_testutils.storage import LogCaptured from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase from settings.testcase import FileSharePreparer + # ------------------------------------------------------------------------------ -TEST_SHARE_PREFIX = 'share' +TEST_SHARE_PREFIX = "share" TEST_INTENT = "backup" # ------------------------------------------------------------------------------ @@ -61,6 +62,7 @@ async def _delete_shares(self, prefix=TEST_SHARE_PREFIX): 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) @@ -109,7 +111,7 @@ async def test_create_share_with_oauth_fails(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=share_name, credential=token_credential, - file_request_intent=TEST_INTENT + file_request_intent=TEST_INTENT, ) @FileSharePreparer() @@ -127,12 +129,11 @@ async def test_create_share_snapshot(self, **kwargs): # Assert assert created - assert snapshot['snapshot'] is not None - assert snapshot['etag'] is not None - assert snapshot['last_modified'] is not None + assert snapshot["snapshot"] is not None + assert snapshot["etag"] is not None + assert snapshot["last_modified"] is not None await self._delete_shares(share.share_name) - @FileSharePreparer() @recorded_by_proxy_async async def test_create_snapshot_with_metadata(self, **kwargs): @@ -153,14 +154,14 @@ async def test_create_snapshot_with_metadata(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=share.share_name, snapshot=snapshot, - credential=storage_account_key + credential=storage_account_key, ) snapshot_props = await snapshot_client.get_share_properties() # Assert assert created - assert snapshot['snapshot'] is not None - assert snapshot['etag'] is not None - assert snapshot['last_modified'] is not None + assert snapshot["snapshot"] is not None + assert snapshot["etag"] is not None + assert snapshot["last_modified"] is not None assert share_props.metadata == metadata assert snapshot_props.metadata == metadata2 await self._delete_shares(share.share_name) @@ -206,9 +207,9 @@ async def test_lease_share_acquire_and_release(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') + share_client = await self._create_share("test") # Act - lease = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") await lease.release() # Assert @@ -229,11 +230,11 @@ async def test_acquire_lease_on_sharesnapshot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=share.share_name, snapshot=snapshot, - credential=storage_account_key + credential=storage_account_key, ) - share_lease = await share.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') - share_snapshot_lease = await snapshot_client.acquire_lease(lease_id='44444444-3333-2222-1111-000000000000') + share_lease = await share.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") + share_snapshot_lease = await snapshot_client.acquire_lease(lease_id="44444444-3333-2222-1111-000000000000") # Assert with pytest.raises(HttpResponseError): @@ -242,9 +243,9 @@ async def test_acquire_lease_on_sharesnapshot(self, **kwargs): with pytest.raises(HttpResponseError): await snapshot_client.get_share_properties(lease=share_lease) - assert snapshot['snapshot'] is not None - assert snapshot['etag'] is not None - assert snapshot['last_modified'] is not None + assert snapshot["snapshot"] is not None + assert snapshot["etag"] is not None + assert snapshot["last_modified"] is not None assert share_lease is not None assert share_snapshot_lease is not None assert share_lease != share_snapshot_lease @@ -260,8 +261,8 @@ async def test_lease_share_renew(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') - lease = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + share_client = await self._create_share("test") + lease = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) self.sleep(10) lease_id_start = lease.id @@ -283,16 +284,16 @@ async def test_lease_share_with_duration(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') + share_client = await self._create_share("test") # Act - lease = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + lease = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) # Assert with pytest.raises(HttpResponseError): - await share_client.acquire_lease(lease_id='44444444-3333-2222-1111-000000000000') + await share_client.acquire_lease(lease_id="44444444-3333-2222-1111-000000000000") self.sleep(17) - await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") @FileSharePreparer() @recorded_by_proxy_async @@ -301,10 +302,10 @@ async def test_lease_share_twice(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') + share_client = await self._create_share("test") # Act - lease = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + lease = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) # Assert lease2 = await share_client.acquire_lease(lease_id=lease.id) @@ -317,10 +318,10 @@ async def test_lease_share_with_proposed_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') + share_client = await self._create_share("test") # Act - proposed_lease_id = '55e97f64-73e8-4390-838d-d9e84a374321' + proposed_lease_id = "55e97f64-73e8-4390-838d-d9e84a374321" lease = await share_client.acquire_lease(lease_id=proposed_lease_id) # Assert @@ -333,11 +334,11 @@ async def test_lease_share_change_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') + share_client = await self._create_share("test") # Act - lease_id = '29e0b239-ecda-4f69-bfa3-95f6af91464c' - lease = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease_id = "29e0b239-ecda-4f69-bfa3-95f6af91464c" + lease = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") lease_id1 = lease.id await lease.change(proposed_lease_id=lease_id) await lease.renew() @@ -356,9 +357,9 @@ async def test_set_share_metadata_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test1') - metadata = {'hello': 'world', 'number': '43'} - lease_id = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + share_client = await self._create_share("test1") + metadata = {"hello": "world", "number": "43"} + lease_id = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act await share_client.set_share_metadata(metadata, lease=lease_id) @@ -375,10 +376,10 @@ async def test_get_share_metadata_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') - metadata = {'hello': 'world', 'number': '43'} + share_client = await self._create_share("test") + metadata = {"hello": "world", "number": "43"} await share_client.set_share_metadata(metadata) - lease_id = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease_id = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act props = await share_client.get_share_properties(lease=lease_id) @@ -394,10 +395,10 @@ async def test_get_share_properties_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') - metadata = {'hello': 'world', 'number': '43'} + share_client = await self._create_share("test") + metadata = {"hello": "world", "number": "43"} await share_client.set_share_metadata(metadata) - lease_id = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease_id = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act props = await share_client.get_share_properties(lease=lease_id) @@ -406,9 +407,9 @@ async def test_get_share_properties_with_lease_id(self, **kwargs): # Assert assert props is not None assert props.metadata == metadata - assert props.lease.duration == 'infinite' - assert props.lease.state == 'leased' - assert props.lease.status == 'locked' + assert props.lease.duration == "infinite" + assert props.lease.state == "leased" + assert props.lease.status == "locked" @FileSharePreparer() @recorded_by_proxy_async @@ -417,41 +418,39 @@ async def test_get_share_acl_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') - lease_id = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + share_client = await self._create_share("test") + lease_id = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act acl = await share_client.get_share_access_policy(lease=lease_id) # Assert assert acl is not None - assert acl.get('public_access') is None + assert acl.get("public_access") is None @FileSharePreparer() @recorded_by_proxy_async async def test_set_share_acl_with_lease_id(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - variables = kwargs.pop('variables', {}) + variables = kwargs.pop("variables", {}) self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') - lease_id = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + share_client = await self._create_share("test") + lease_id = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") # Act - expiry_time = self.get_datetime_variable(variables, 'expiry_time', datetime.utcnow() + timedelta(hours=1)) - start_time = self.get_datetime_variable(variables, 'start_time', datetime.utcnow()) - access_policy = AccessPolicy(permission=ShareSasPermissions(read=True), - expiry=expiry_time, - start=start_time) - signed_identifiers = {'testid': access_policy} + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow()) + access_policy = AccessPolicy(permission=ShareSasPermissions(read=True), expiry=expiry_time, start=start_time) + signed_identifiers = {"testid": access_policy} await share_client.set_share_access_policy(signed_identifiers, lease=lease_id) # Assert acl = await share_client.get_share_access_policy() assert acl is not None - assert acl.get('public_access') is None + assert acl.get("public_access") is None return variables @@ -462,10 +461,10 @@ async def test_lease_share_break_period(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') + share_client = await self._create_share("test") # Act - lease = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + lease = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) # Assert await lease.break_lease(lease_break_period=5) @@ -480,8 +479,8 @@ async def test_delete_share_with_lease_id(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share_client = await self._create_share('test') - lease = await share_client.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444', lease_duration=15) + share_client = await self._create_share("test") + lease = await share_client.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444", lease_duration=15) # Assert with pytest.raises(HttpResponseError): @@ -547,7 +546,7 @@ async def test_delete_snapshot(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=share.share_name, snapshot=snapshot, - credential=storage_account_key + credential=storage_account_key, ) deleted = await snapshot_client.delete_share() @@ -595,7 +594,7 @@ async def test_create_share_with_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act client = self._get_share_reference() @@ -701,7 +700,7 @@ async def test_share_snapshot_not_exists(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = await self._create_share() - made_up_snapshot = '2017-07-19T06:53:46.0000000Z' + made_up_snapshot = "2017-07-19T06:53:46.0000000Z" # Act snapshot_client = self.fsc.get_share_client(share.share_name, snapshot=made_up_snapshot) @@ -718,7 +717,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): @@ -756,7 +755,9 @@ 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 = [] @@ -765,10 +766,10 @@ async def test_list_shares_enable_snapshot_virtual_directory_access(self, **kwar share_props = await share.get_share_properties() # Assert - assert list_props[0].protocols[0] == 'NFS' + assert list_props[0].protocols[0] == "NFS" assert list_props[0].enable_snapshot_virtual_directory_access is False - assert share_props.protocols[0] == 'NFS' + assert share_props.protocols[0] == "NFS" assert share_props.enable_snapshot_virtual_directory_access is False await self._delete_shares() @@ -807,7 +808,7 @@ async def test_list_shares_leased_share(self, **kwargs): share = await self._create_share() # Act - lease = await share.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + lease = await share.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") resp = [] async for s in self.fsc.list_shares(): resp.append(s) @@ -816,9 +817,9 @@ async def test_list_shares_leased_share(self, **kwargs): assert resp is not None assert len(resp) >= 1 assert resp[0] is not None - assert resp[0].lease.duration == 'infinite' - assert resp[0].lease.status == 'locked' - assert resp[0].lease.state == 'leased' + assert resp[0].lease.duration == "infinite" + assert resp[0].lease.status == "locked" + assert resp[0].lease.state == "leased" await lease.release() await self._delete_shares() @@ -829,7 +830,7 @@ async def test_list_shares_with_snapshot(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share = await self._create_share('random3') + share = await self._create_share("random3") snapshot1 = await share.create_snapshot() snapshot2 = await share.create_snapshot() @@ -843,8 +844,8 @@ async def test_list_shares_with_snapshot(self, **kwargs): all_shares.append(s) assert len(all_shares) == 3 self.assertNamedItemInContainer(all_shares, share.share_name) - self.assertNamedItemInContainer(all_shares, snapshot1['snapshot']) - self.assertNamedItemInContainer(all_shares, snapshot2['snapshot']) + self.assertNamedItemInContainer(all_shares, snapshot1["snapshot"]) + self.assertNamedItemInContainer(all_shares, snapshot2["snapshot"]) await self._delete_shares(share.share_name) @FileSharePreparer() @@ -854,7 +855,7 @@ async def test_delete_snapshots_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - share = await self._create_share('prefix') + share = await self._create_share("prefix") await share.create_snapshot() await share.create_snapshot() @@ -868,15 +869,15 @@ async def test_delete_snapshots_options(self, **kwargs): await share.delete_share(delete_snapshots=True) # Test "include" - share = await self._create_share('prefix2') + share = await self._create_share("prefix2") await share.create_snapshot() - await share.delete_share(delete_snapshots='include') + await share.delete_share(delete_snapshots="include") # Test "include-leased" - share = await self._create_share('prefix3') - lease = await share.acquire_lease(lease_id='00000000-1111-2222-3333-444444444444') + share = await self._create_share("prefix3") + lease = await share.acquire_lease(lease_id="00000000-1111-2222-3333-444444444444") await share.create_snapshot() - await share.delete_share(delete_snapshots='include-leased', lease='00000000-1111-2222-3333-444444444444') + await share.delete_share(delete_snapshots="include-leased", lease="00000000-1111-2222-3333-444444444444") @FileSharePreparer() @recorded_by_proxy_async @@ -885,8 +886,8 @@ async def test_list_shares_with_prefix(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - await self._create_share('othershare') - share = await self._create_share('random4') + await self._create_share("othershare") + share = await self._create_share("random4") # Act shares = [] @@ -907,7 +908,7 @@ async def test_list_shares_with_include_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} share = self._get_share_reference() await share.create_share(metadata=metadata) @@ -932,7 +933,7 @@ async def test_list_shares_with_num_results_and_marker(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - prefix = 'listshare' + prefix = "listshare" share_names = [] for i in range(0, 4): share = await self._create_share(prefix + str(i)) @@ -945,8 +946,9 @@ async def test_list_shares_with_num_results_and_marker(self, **kwargs): shares1 = [] async for s in await generator1.__anext__(): shares1.append(s) - generator2 = self.fsc.list_shares( - prefix, results_per_page=2).by_page(continuation_token=generator1.continuation_token) + generator2 = self.fsc.list_shares(prefix, results_per_page=2).by_page( + continuation_token=generator1.continuation_token + ) shares2 = [] async for s in await generator2.__anext__(): shares2.append(s) @@ -1006,7 +1008,7 @@ async def test_list_shares_account_sas_fails(self, **kwargs): storage_account_key, ResourceTypes(service=True), AccountSasPermissions(list=True), - datetime.utcnow() - timedelta(hours=1) + datetime.utcnow() - timedelta(hours=1), ) # Act @@ -1020,7 +1022,6 @@ async def test_list_shares_account_sas_fails(self, **kwargs): assert e.value.error_code == StorageErrorCode.AUTHENTICATION_FAILED assert "authenticationerrordetail" in e.value.message - @FileSharePreparer() @recorded_by_proxy_async async def test_set_share_metadata(self, **kwargs): @@ -1029,7 +1030,7 @@ async def test_set_share_metadata(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = await self._create_share() - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act await share.set_share_metadata(metadata) @@ -1047,7 +1048,7 @@ async def test_get_share_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act client = self._get_share_reference() @@ -1066,7 +1067,7 @@ async def test_get_share_metadata_with_snapshot(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - metadata = {'hello': 'world', 'number': '42'} + metadata = {"hello": "world", "number": "42"} # Act client = self._get_share_reference() @@ -1256,7 +1257,7 @@ async def test_delete_share_with_non_existing_share(self, **kwargs): deleted = await client.delete_share() log_as_str = log_captured.getvalue() - assert 'ERROR' not in log_as_str + assert "ERROR" not in log_as_str await self._delete_shares(client.share_name) @FileSharePreparer() @@ -1327,7 +1328,7 @@ async def test_set_share_acl_with_empty_signed_identifiers(self, **kwargs): # Assert acl = await share.get_share_access_policy() assert acl is not None - assert len(acl.get('signed_identifiers')) == 0 + assert len(acl.get("signed_identifiers")) == 0 await self._delete_shares(share.share_name) @FileSharePreparer() @@ -1335,7 +1336,7 @@ async def test_set_share_acl_with_empty_signed_identifiers(self, **kwargs): async def test_set_share_acl_with_signed_identifiers(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - variables = kwargs.pop('variables', {}) + variables = kwargs.pop("variables", {}) self._setup(storage_account_name, storage_account_key) share = self._get_share_reference() @@ -1343,9 +1344,9 @@ async def test_set_share_acl_with_signed_identifiers(self, **kwargs): # Act identifiers = {} - expiry_time = self.get_datetime_variable(variables, 'expiry_time', datetime.utcnow() + timedelta(hours=1)) - start_time = self.get_datetime_variable(variables, 'start_time', datetime.utcnow() - timedelta(minutes=1)) - identifiers['testid'] = AccessPolicy( + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(minutes=1)) + identifiers["testid"] = AccessPolicy( permission=ShareSasPermissions(write=True), expiry=expiry_time, start=start_time, @@ -1356,8 +1357,8 @@ async def test_set_share_acl_with_signed_identifiers(self, **kwargs): # Assert acl = await share.get_share_access_policy() assert acl is not None - assert len(acl['signed_identifiers']) == 1 - assert acl['signed_identifiers'][0].id == 'testid' + assert len(acl["signed_identifiers"]) == 1 + assert acl["signed_identifiers"][0].id == "testid" await self._delete_shares(share.share_name) return variables @@ -1375,12 +1376,15 @@ async def test_set_share_acl_too_many_ids(self, **kwargs): # Act identifiers = {} for i in range(0, 6): - identifiers['id{}'.format(i)] = AccessPolicy() + identifiers["id{}".format(i)] = AccessPolicy() # 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() @@ -1392,11 +1396,11 @@ async def test_list_directories_and_files(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = await self._create_share() dir0 = share.get_directory_client() - await dir0.upload_file('file1', 'data1') - dir1 = share.get_directory_client('dir1') + await dir0.upload_file("file1", "data1") + dir1 = share.get_directory_client("dir1") await dir1.create_directory() - await dir1.upload_file('file2', 'data2') - dir2 = share.get_directory_client('dir2') + await dir1.upload_file("file2", "data2") + dir2 = share.get_directory_client("dir2") await dir2.create_directory() # Act @@ -1408,9 +1412,9 @@ async def test_list_directories_and_files(self, **kwargs): assert resp is not None assert len(resp) == 3 assert resp[0] is not None - self.assertNamedItemInContainer(resp, 'dir1') - self.assertNamedItemInContainer(resp, 'dir2') - self.assertNamedItemInContainer(resp, 'file1') + self.assertNamedItemInContainer(resp, "dir1") + self.assertNamedItemInContainer(resp, "dir2") + self.assertNamedItemInContainer(resp, "file1") await self._delete_shares(share) @FileSharePreparer() @@ -1421,16 +1425,15 @@ async def test_list_directories_and_files_with_snapshot(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_name = await self._create_share() - dir1 = share_name.get_directory_client('dir1') + dir1 = share_name.get_directory_client("dir1") await dir1.create_directory() - dir2 = share_name.get_directory_client('dir2') + dir2 = share_name.get_directory_client("dir2") await dir2.create_directory() snapshot1 = await share_name.create_snapshot() - dir3 = share_name.get_directory_client('dir3') + dir3 = share_name.get_directory_client("dir3") await dir3.create_directory() - file1 = share_name.get_file_client('file1') - await file1.upload_file('data') - + file1 = share_name.get_file_client("file1") + await file1.upload_file("data") # Act snapshot_client = self.fsc.get_share_client(share_name.share_name, snapshot=snapshot1) @@ -1442,8 +1445,8 @@ async def test_list_directories_and_files_with_snapshot(self, **kwargs): assert resp is not None assert len(resp) == 2 assert resp[0] is not None - self.assertNamedItemInContainer(resp, 'dir1') - self.assertNamedItemInContainer(resp, 'dir2') + self.assertNamedItemInContainer(resp, "dir1") + self.assertNamedItemInContainer(resp, "dir2") await self._delete_shares(share_name) @FileSharePreparer() @@ -1454,12 +1457,12 @@ async def test_list_directories_and_files_with_num_results(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_name = await self._create_share() - dir1 = await share_name.create_directory('dir1') + dir1 = await share_name.create_directory("dir1") root = share_name.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') + 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() @@ -1470,8 +1473,8 @@ async def test_list_directories_and_files_with_num_results(self, **kwargs): # Assert assert result is not None assert len(results) == 2 - self.assertNamedItemInContainer(results, 'dir1') - self.assertNamedItemInContainer(results, 'filea1') + self.assertNamedItemInContainer(results, "dir1") + self.assertNamedItemInContainer(results, "filea1") await self._delete_shares(share_name) @FileSharePreparer() @@ -1482,22 +1485,22 @@ async def test_list_directories_and_files_with_num_results_and_marker(self, **kw self._setup(storage_account_name, storage_account_key) share_name = await self._create_share() - dir1 = share_name.get_directory_client('dir1') + dir1 = share_name.get_directory_client("dir1") await dir1.create_directory() - await dir1.upload_file('filea1', '1024') - await dir1.upload_file('filea2', '1024') - await dir1.upload_file('filea3', '1024') - await dir1.upload_file('fileb1', '1024') + await dir1.upload_file("filea1", "1024") + await dir1.upload_file("filea2", "1024") + await dir1.upload_file("filea3", "1024") + await dir1.upload_file("fileb1", "1024") # Act - generator1 = share_name.list_directories_and_files( - 'dir1', results_per_page=2).by_page() + generator1 = share_name.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( - 'dir1', results_per_page=2).by_page(continuation_token=generator1.continuation_token) + generator2 = share_name.list_directories_and_files("dir1", results_per_page=2).by_page( + continuation_token=generator1.continuation_token + ) result2 = [] async for r in await generator2.__anext__(): result2.append(r) @@ -1505,10 +1508,10 @@ async def test_list_directories_and_files_with_num_results_and_marker(self, **kw # Assert assert len(result1) == 2 assert len(result2) == 2 - self.assertNamedItemInContainer(result1, 'filea1') - self.assertNamedItemInContainer(result1, 'filea2') - self.assertNamedItemInContainer(result2, 'filea3') - self.assertNamedItemInContainer(result2, 'fileb1') + self.assertNamedItemInContainer(result1, "filea1") + self.assertNamedItemInContainer(result1, "filea2") + self.assertNamedItemInContainer(result2, "filea3") + self.assertNamedItemInContainer(result2, "fileb1") assert generator2.continuation_token == None await self._delete_shares(share_name) @@ -1520,26 +1523,26 @@ async def test_list_directories_and_files_with_prefix(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = await self._create_share() - dir1 = await share.create_directory('dir1') - await share.create_directory('dir1/pref_dir3') - await share.create_directory('dir2') + dir1 = await share.create_directory("dir1") + await share.create_directory("dir1/pref_dir3") + await share.create_directory("dir2") root = share.get_directory_client() - await root.upload_file('file1', '1024') - await dir1.upload_file('pref_file2', '1025') - await dir1.upload_file('file3', '1025') + await root.upload_file("file1", "1024") + await dir1.upload_file("pref_file2", "1025") + await dir1.upload_file("file3", "1025") # Act resp = [] - async for d in share.list_directories_and_files('dir1', name_starts_with='pref'): + async for d in share.list_directories_and_files("dir1", name_starts_with="pref"): resp.append(d) # Assert assert resp is not None assert len(resp) == 2 assert resp[0] is not None - self.assertNamedItemInContainer(resp, 'pref_file2') - self.assertNamedItemInContainer(resp, 'pref_dir3') + self.assertNamedItemInContainer(resp, "pref_file2") + self.assertNamedItemInContainer(resp, "pref_dir3") await self._delete_shares(share) @pytest.mark.live_test_only @@ -1549,9 +1552,9 @@ async def test_shared_access_share(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - file_name = 'file1' - dir_name = 'dir1' - data = b'hello world' + file_name = "file1" + dir_name = "dir1" + data = b"hello world" share = await self._create_share() dir1 = await share.create_directory(dir_name) @@ -1567,7 +1570,7 @@ async def test_shared_access_share(self, **kwargs): sas_client = ShareFileClient( self.account_url(storage_account_name, "file"), share_name=share.share_name, - file_path=dir_name + '/' + file_name, + file_path=dir_name + "/" + file_name, credential=token, ) @@ -1586,9 +1589,11 @@ async def test_create_permission_for_share(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") self._setup(storage_account_name, storage_account_key) - user_given_permission = "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;;;" \ - "S-1-5-21-397955417-626881126-188441444-3053964)" + user_given_permission = ( + "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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)" + ) share_client = await self._create_share() permission_key = await share_client.create_permission_for_share(user_given_permission) assert permission_key is not None @@ -1610,25 +1615,27 @@ async def test_get_permission_format(self, **kwargs): self._setup(storage_account_name, storage_account_key) share_client = await self._create_share() - user_given_permission_sddl = ("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;;;" - "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL") - user_given_permission_binary = ("AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" - "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" - "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=") + user_given_permission_sddl = ( + "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;;;" + "S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL" + ) + user_given_permission_binary = ( + "AQAUhGwAAACIAAAAAAAAABQAAAACAFgAAwAAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHw" + "ABAgAAAAAABSAAAAAgAgAAAAAkAKkAEgABBQAAAAAABRUAAABZUbgXZnJdJWRjOwuMmS4AAQUA" + "AAAAAAUVAAAAoGXPfnhLm1/nfIdwr/1IAQEFAAAAAAAFFQAAAKBlz354S5tf53yHcAECAAA=" + ) permission_key = await share_client.create_permission_for_share(user_given_permission_sddl) assert permission_key is not None server_returned_permission = await share_client.get_permission_for_share( - permission_key, - file_permission_format="sddl" + permission_key, file_permission_format="sddl" ) assert server_returned_permission == user_given_permission_sddl server_returned_permission = await share_client.get_permission_for_share( - permission_key, - file_permission_format="binary" + permission_key, file_permission_format="binary" ) assert server_returned_permission == user_given_permission_binary @@ -1663,9 +1670,9 @@ async def test_delete_directory_from_share(self, **kwargs): self._setup(storage_account_name, storage_account_key) share = await self._create_share() - await share.create_directory('dir1') - await share.create_directory('dir2') - await share.create_directory('dir3') + await share.create_directory("dir1") + await share.create_directory("dir2") + await share.create_directory("dir3") # Act resp = [] @@ -1673,7 +1680,7 @@ async def test_delete_directory_from_share(self, **kwargs): resp.append(d) assert len(resp) == 3 - await share.delete_directory('dir3') + await share.delete_directory("dir3") # Assert resp = [] @@ -1697,9 +1704,7 @@ async def test_share_paid_bursting(self, **kwargs): # Act / Assert share = self._get_share_reference() await share.create_share( - paid_bursting_enabled=True, - paid_bursting_bandwidth_mibps=5000, - paid_bursting_iops=1000 + paid_bursting_enabled=True, paid_bursting_bandwidth_mibps=5000, paid_bursting_iops=1000 ) share_props = await share.get_share_properties() share_name = share_props.name @@ -1711,7 +1716,7 @@ async def test_share_paid_bursting(self, **kwargs): root_squash="NoRootSquash", paid_bursting_enabled=True, paid_bursting_bandwidth_mibps=mibps, - paid_bursting_iops=iops + paid_bursting_iops=iops, ) share_props = await share.get_share_properties() assert share_props.paid_bursting_enabled @@ -1741,8 +1746,8 @@ async def test_share_client_with_oauth(self, **kwargs): token_credential = self.get_credential(ShareClient, is_async=True) self._setup(storage_account_name, storage_account_key) - first_share = await self._create_share('test1') - second_share = await self._create_share('test2') + first_share = await self._create_share("test1") + second_share = await self._create_share("test2") share_names = [] async for share in self.fsc.list_shares(): @@ -1754,29 +1759,29 @@ async def test_share_client_with_oauth(self, **kwargs): self.account_url(storage_account_name, "file"), share_name=first_share.share_name, credential=token_credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) second_share_client = ShareClient( self.account_url(storage_account_name, "file"), share_name=second_share.share_name, credential=token_credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) first_share_props = await first_share_client.get_share_properties() second_share_props = await second_share_client.get_share_properties() assert first_share_props is not None assert first_share_props.name == first_share.share_name - assert first_share_props.access_tier == 'TransactionOptimized' + assert first_share_props.access_tier == "TransactionOptimized" assert second_share_props is not None assert second_share_props.name == second_share.share_name - assert second_share_props.access_tier == 'TransactionOptimized' + assert second_share_props.access_tier == "TransactionOptimized" - await first_share_client.set_share_properties(access_tier='Hot') + await first_share_client.set_share_properties(access_tier="Hot") first_share_props = await first_share_client.get_share_properties() assert first_share_props is not None assert first_share_props.name == first_share.share_name - assert first_share_props.access_tier == 'Hot' + assert first_share_props.access_tier == "Hot" share_names = [] async for share in self.fsc.list_shares(): @@ -1796,25 +1801,22 @@ async def test_share_lease_with_oauth(self, **kwargs): # Arrange self._setup(storage_account_name, storage_account_key) - share = await self._create_share('test') + share = await self._create_share("test") share_client = ShareClient( self.account_url(storage_account_name, "file"), share_name=share.share_name, credential=token_credential, - token_intent=TEST_INTENT + token_intent=TEST_INTENT, ) # Act / Assert lease_duration = 60 - lease_id = '00000000-1111-2222-3333-444444444444' - lease = await share_client.acquire_lease( - lease_id=lease_id, - lease_duration=lease_duration - ) + lease_id = "00000000-1111-2222-3333-444444444444" + lease = await share_client.acquire_lease(lease_id=lease_id, lease_duration=lease_duration) props = await share_client.get_share_properties(lease=lease) - assert props.lease.duration == 'fixed' - assert props.lease.state == 'leased' - assert props.lease.status == 'locked' + assert props.lease.duration == "fixed" + assert props.lease.state == "leased" + assert props.lease.status == "locked" await lease.renew() assert lease.id == lease_id @@ -1832,9 +1834,9 @@ async def test_create_share_access_tier_premium(self, **kwargs): self._setup(premium_storage_file_account_name, premium_storage_file_account_key) share = self._get_share_reference() - await share.create_share(access_tier='Premium') + await share.create_share(access_tier="Premium") props = await share.get_share_properties() - assert props.access_tier == 'Premium' + assert props.access_tier == "Premium" finally: await self._delete_shares() @@ -1849,9 +1851,9 @@ async def test_set_share_properties_access_tier_premium(self, **kwargs): share = self._get_share_reference() await share.create_share() - await share.set_share_properties(access_tier='Premium') + await share.set_share_properties(access_tier="Premium") props = await share.get_share_properties() - assert props.access_tier == 'Premium' + assert props.access_tier == "Premium" finally: await self._delete_shares() @@ -1879,11 +1881,7 @@ async def test_provisioned_billing_v2(self, **kwargs): assert props.next_provisioned_iops_downgrade is not None assert props.next_provisioned_bandwidth_downgrade is not None - await share.set_share_properties( - access_tier="Hot", - provisioned_iops=3000, - provisioned_bandwidth_mibps=125 - ) + await share.set_share_properties(access_tier="Hot", provisioned_iops=3000, provisioned_bandwidth_mibps=125) shares = [] async for share in self.fsc.list_shares():