diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.pyTestStorageFileClienttest_user_agent_append.json b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.pyTestStorageFileClienttest_user_agent_append.json new file mode 100644 index 000000000000..821053f356b2 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.pyTestStorageFileClienttest_user_agent_append.json @@ -0,0 +1,31 @@ +{ + "Entries": [ + { + "RequestUri": "https://storagename.file.core.windows.net/?restype=service\u0026comp=properties", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/xml", + "Accept-Encoding": "gzip, deflate", + "Connection": "keep-alive", + "User-Agent": "customer_user_agent azsdk-python-storage-file-share/12.10.0 Python/3.10.2 (Windows-10-10.0.19044-SP0)", + "x-ms-date": "Fri, 14 Oct 2022 19:15:45 GMT", + "x-ms-version": "2021-06-08" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/xml", + "Date": "Fri, 14 Oct 2022 19:15:44 GMT", + "Server": [ + "Windows-Azure-File/1.0", + "Microsoft-HTTPAPI/2.0" + ], + "Transfer-Encoding": "chunked", + "Vary": "Origin", + "x-ms-version": "2021-06-08" + }, + "ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceProperties\u003E\u003CHourMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/HourMetrics\u003E\u003CMinuteMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/MinuteMetrics\u003E\u003CCors\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders /\u003E\u003CExposedHeaders /\u003E\u003CMaxAgeInSeconds\u003E0\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET,PUT\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com,www.ab.com,www.bc.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders\u003Ex-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*\u003C/AllowedHeaders\u003E\u003CExposedHeaders\u003Ex-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*\u003C/ExposedHeaders\u003E\u003CMaxAgeInSeconds\u003E500\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003C/Cors\u003E\u003CProtocolSettings\u003E\u003CSMB\u003E\u003CMultichannel\u003E\u003CEnabled\u003Efalse\u003C/Enabled\u003E\u003C/Multichannel\u003E\u003C/SMB\u003E\u003C/ProtocolSettings\u003E\u003C/StorageServiceProperties\u003E" + } + ], + "Variables": {} +} diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.pyTestStorageFileClienttest_user_agent_custom.json b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.pyTestStorageFileClienttest_user_agent_custom.json new file mode 100644 index 000000000000..54631321740a --- /dev/null +++ b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.pyTestStorageFileClienttest_user_agent_custom.json @@ -0,0 +1,57 @@ +{ + "Entries": [ + { + "RequestUri": "https://storagename.file.core.windows.net/?restype=service\u0026comp=properties", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/xml", + "Accept-Encoding": "gzip, deflate", + "Connection": "keep-alive", + "User-Agent": "TestApp/v1.0 azsdk-python-storage-file-share/12.10.0 Python/3.10.2 (Windows-10-10.0.19044-SP0)", + "x-ms-date": "Fri, 14 Oct 2022 19:15:45 GMT", + "x-ms-version": "2021-06-08" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/xml", + "Date": "Fri, 14 Oct 2022 19:15:43 GMT", + "Server": [ + "Windows-Azure-File/1.0", + "Microsoft-HTTPAPI/2.0" + ], + "Transfer-Encoding": "chunked", + "Vary": "Origin", + "x-ms-version": "2021-06-08" + }, + "ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceProperties\u003E\u003CHourMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/HourMetrics\u003E\u003CMinuteMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/MinuteMetrics\u003E\u003CCors\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders /\u003E\u003CExposedHeaders /\u003E\u003CMaxAgeInSeconds\u003E0\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET,PUT\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com,www.ab.com,www.bc.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders\u003Ex-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*\u003C/AllowedHeaders\u003E\u003CExposedHeaders\u003Ex-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*\u003C/ExposedHeaders\u003E\u003CMaxAgeInSeconds\u003E500\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003C/Cors\u003E\u003CProtocolSettings\u003E\u003CSMB\u003E\u003CMultichannel\u003E\u003CEnabled\u003Efalse\u003C/Enabled\u003E\u003C/Multichannel\u003E\u003C/SMB\u003E\u003C/ProtocolSettings\u003E\u003C/StorageServiceProperties\u003E" + }, + { + "RequestUri": "https://storagename.file.core.windows.net/?restype=service\u0026comp=properties", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/xml", + "Accept-Encoding": "gzip, deflate", + "Connection": "keep-alive", + "User-Agent": "TestApp/v2.0 TestApp/v1.0 azsdk-python-storage-file-share/12.10.0 Python/3.10.2 (Windows-10-10.0.19044-SP0)", + "x-ms-date": "Fri, 14 Oct 2022 19:15:45 GMT", + "x-ms-version": "2021-06-08" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/xml", + "Date": "Fri, 14 Oct 2022 19:15:43 GMT", + "Server": [ + "Windows-Azure-File/1.0", + "Microsoft-HTTPAPI/2.0" + ], + "Transfer-Encoding": "chunked", + "Vary": "Origin", + "x-ms-version": "2021-06-08" + }, + "ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceProperties\u003E\u003CHourMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/HourMetrics\u003E\u003CMinuteMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/MinuteMetrics\u003E\u003CCors\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders /\u003E\u003CExposedHeaders /\u003E\u003CMaxAgeInSeconds\u003E0\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET,PUT\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com,www.ab.com,www.bc.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders\u003Ex-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*\u003C/AllowedHeaders\u003E\u003CExposedHeaders\u003Ex-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*\u003C/ExposedHeaders\u003E\u003CMaxAgeInSeconds\u003E500\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003C/Cors\u003E\u003CProtocolSettings\u003E\u003CSMB\u003E\u003CMultichannel\u003E\u003CEnabled\u003Efalse\u003C/Enabled\u003E\u003C/Multichannel\u003E\u003C/SMB\u003E\u003C/ProtocolSettings\u003E\u003C/StorageServiceProperties\u003E" + } + ], + "Variables": {} +} diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.pyTestStorageFileClienttest_user_agent_default.json b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.pyTestStorageFileClienttest_user_agent_default.json new file mode 100644 index 000000000000..4431dbe7a12b --- /dev/null +++ b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.pyTestStorageFileClienttest_user_agent_default.json @@ -0,0 +1,31 @@ +{ + "Entries": [ + { + "RequestUri": "https://storagename.file.core.windows.net/?restype=service\u0026comp=properties", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/xml", + "Accept-Encoding": "gzip, deflate", + "Connection": "keep-alive", + "User-Agent": "azsdk-python-storage-file-share/12.10.0 Python/3.10.2 (Windows-10-10.0.19044-SP0)", + "x-ms-date": "Fri, 14 Oct 2022 19:15:43 GMT", + "x-ms-version": "2021-06-08" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/xml", + "Date": "Fri, 14 Oct 2022 19:15:43 GMT", + "Server": [ + "Windows-Azure-File/1.0", + "Microsoft-HTTPAPI/2.0" + ], + "Transfer-Encoding": "chunked", + "Vary": "Origin", + "x-ms-version": "2021-06-08" + }, + "ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceProperties\u003E\u003CHourMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/HourMetrics\u003E\u003CMinuteMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/MinuteMetrics\u003E\u003CCors\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders /\u003E\u003CExposedHeaders /\u003E\u003CMaxAgeInSeconds\u003E0\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET,PUT\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com,www.ab.com,www.bc.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders\u003Ex-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*\u003C/AllowedHeaders\u003E\u003CExposedHeaders\u003Ex-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*\u003C/ExposedHeaders\u003E\u003CMaxAgeInSeconds\u003E500\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003C/Cors\u003E\u003CProtocolSettings\u003E\u003CSMB\u003E\u003CMultichannel\u003E\u003CEnabled\u003Efalse\u003C/Enabled\u003E\u003C/Multichannel\u003E\u003C/SMB\u003E\u003C/ProtocolSettings\u003E\u003C/StorageServiceProperties\u003E" + } + ], + "Variables": {} +} diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.test_user_agent_append.yaml b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.test_user_agent_append.yaml deleted file mode 100644 index e6ba0a348740..000000000000 --- a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.test_user_agent_append.yaml +++ /dev/null @@ -1,39 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/xml - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - User-Agent: - - customer_user_agent azsdk-python-storage-file-share/12.2.0 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-date: - - Fri, 18 Sep 2020 01:52:21 GMT - x-ms-version: - - '2020-02-10' - method: GET - uri: https://storagename.file.core.windows.net/?restype=service&comp=properties - response: - body: - string: "\uFEFF1.0truetruetrue51.0truetruetrue5GETwww.xyz.com0GET,PUTwww.xyz.com,www.ab.com,www.bc.comx-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*500false" - headers: - content-type: - - application/xml - date: - - Fri, 18 Sep 2020 01:52:21 GMT - server: - - Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 - transfer-encoding: - - chunked - vary: - - Origin - x-ms-version: - - '2020-02-10' - status: - code: 200 - message: OK -version: 1 diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.test_user_agent_custom.yaml b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.test_user_agent_custom.yaml deleted file mode 100644 index 96a432f8ee0b..000000000000 --- a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.test_user_agent_custom.yaml +++ /dev/null @@ -1,77 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/xml - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - User-Agent: - - TestApp/v1.0 azsdk-python-storage-file-share/12.2.0 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-date: - - Fri, 18 Sep 2020 01:52:23 GMT - x-ms-version: - - '2020-02-10' - method: GET - uri: https://storagename.file.core.windows.net/?restype=service&comp=properties - response: - body: - string: "\uFEFF1.0truetruetrue51.0truetruetrue5GETwww.xyz.com0GET,PUTwww.xyz.com,www.ab.com,www.bc.comx-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*500false" - headers: - content-type: - - application/xml - date: - - Fri, 18 Sep 2020 01:52:22 GMT - server: - - Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 - transfer-encoding: - - chunked - vary: - - Origin - x-ms-version: - - '2020-02-10' - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/xml - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - User-Agent: - - TestApp/v2.0 TestApp/v1.0 azsdk-python-storage-file-share/12.2.0 Python/3.8.5 - (Windows-10-10.0.19041-SP0) - x-ms-date: - - Fri, 18 Sep 2020 01:52:23 GMT - x-ms-version: - - '2020-02-10' - method: GET - uri: https://storagename.file.core.windows.net/?restype=service&comp=properties - response: - body: - string: "\uFEFF1.0truetruetrue51.0truetruetrue5GETwww.xyz.com0GET,PUTwww.xyz.com,www.ab.com,www.bc.comx-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*500false" - headers: - content-type: - - application/xml - date: - - Fri, 18 Sep 2020 01:52:22 GMT - server: - - Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 - transfer-encoding: - - chunked - vary: - - Origin - x-ms-version: - - '2020-02-10' - status: - code: 200 - message: OK -version: 1 diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.test_user_agent_default.yaml b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.test_user_agent_default.yaml deleted file mode 100644 index ddf36533263c..000000000000 --- a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client.test_user_agent_default.yaml +++ /dev/null @@ -1,39 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/xml - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - User-Agent: - - azsdk-python-storage-file-share/12.2.0 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-date: - - Fri, 18 Sep 2020 01:52:23 GMT - x-ms-version: - - '2020-02-10' - method: GET - uri: https://storagename.file.core.windows.net/?restype=service&comp=properties - response: - body: - string: "\uFEFF1.0truetruetrue51.0truetruetrue5GETwww.xyz.com0GET,PUTwww.xyz.com,www.ab.com,www.bc.comx-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*500false" - headers: - content-type: - - application/xml - date: - - Fri, 18 Sep 2020 01:52:22 GMT - server: - - Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 - transfer-encoding: - - chunked - vary: - - Origin - x-ms-version: - - '2020-02-10' - status: - code: 200 - message: OK -version: 1 diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.pyTestStorageFileClientAsynctest_user_agent_append.json b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.pyTestStorageFileClientAsynctest_user_agent_append.json new file mode 100644 index 000000000000..269daee61240 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.pyTestStorageFileClientAsynctest_user_agent_append.json @@ -0,0 +1,30 @@ +{ + "Entries": [ + { + "RequestUri": "https://storagename.file.core.windows.net/?restype=service\u0026comp=properties", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/xml", + "Accept-Encoding": "gzip, deflate", + "User-Agent": "customer_user_agent azsdk-python-storage-file-share/12.10.0 Python/3.10.2 (Windows-10-10.0.19044-SP0)", + "x-ms-date": "Fri, 14 Oct 2022 19:17:44 GMT", + "x-ms-version": "2021-06-08" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/xml", + "Date": "Fri, 14 Oct 2022 19:17:43 GMT", + "Server": [ + "Windows-Azure-File/1.0", + "Microsoft-HTTPAPI/2.0" + ], + "Transfer-Encoding": "chunked", + "Vary": "Origin", + "x-ms-version": "2021-06-08" + }, + "ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceProperties\u003E\u003CHourMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/HourMetrics\u003E\u003CMinuteMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/MinuteMetrics\u003E\u003CCors\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders /\u003E\u003CExposedHeaders /\u003E\u003CMaxAgeInSeconds\u003E0\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET,PUT\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com,www.ab.com,www.bc.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders\u003Ex-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*\u003C/AllowedHeaders\u003E\u003CExposedHeaders\u003Ex-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*\u003C/ExposedHeaders\u003E\u003CMaxAgeInSeconds\u003E500\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003C/Cors\u003E\u003CProtocolSettings\u003E\u003CSMB\u003E\u003CMultichannel\u003E\u003CEnabled\u003Efalse\u003C/Enabled\u003E\u003C/Multichannel\u003E\u003C/SMB\u003E\u003C/ProtocolSettings\u003E\u003C/StorageServiceProperties\u003E" + } + ], + "Variables": {} +} diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.pyTestStorageFileClientAsynctest_user_agent_custom.json b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.pyTestStorageFileClientAsynctest_user_agent_custom.json new file mode 100644 index 000000000000..f42d4f557ce5 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.pyTestStorageFileClientAsynctest_user_agent_custom.json @@ -0,0 +1,55 @@ +{ + "Entries": [ + { + "RequestUri": "https://storagename.file.core.windows.net/?restype=service\u0026comp=properties", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/xml", + "Accept-Encoding": "gzip, deflate", + "User-Agent": "TestApp/v1.0 azsdk-python-storage-file-share/12.10.0 Python/3.10.2 (Windows-10-10.0.19044-SP0)", + "x-ms-date": "Fri, 14 Oct 2022 19:17:44 GMT", + "x-ms-version": "2021-06-08" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/xml", + "Date": "Fri, 14 Oct 2022 19:17:42 GMT", + "Server": [ + "Windows-Azure-File/1.0", + "Microsoft-HTTPAPI/2.0" + ], + "Transfer-Encoding": "chunked", + "Vary": "Origin", + "x-ms-version": "2021-06-08" + }, + "ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceProperties\u003E\u003CHourMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/HourMetrics\u003E\u003CMinuteMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/MinuteMetrics\u003E\u003CCors\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders /\u003E\u003CExposedHeaders /\u003E\u003CMaxAgeInSeconds\u003E0\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET,PUT\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com,www.ab.com,www.bc.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders\u003Ex-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*\u003C/AllowedHeaders\u003E\u003CExposedHeaders\u003Ex-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*\u003C/ExposedHeaders\u003E\u003CMaxAgeInSeconds\u003E500\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003C/Cors\u003E\u003CProtocolSettings\u003E\u003CSMB\u003E\u003CMultichannel\u003E\u003CEnabled\u003Efalse\u003C/Enabled\u003E\u003C/Multichannel\u003E\u003C/SMB\u003E\u003C/ProtocolSettings\u003E\u003C/StorageServiceProperties\u003E" + }, + { + "RequestUri": "https://storagename.file.core.windows.net/?restype=service\u0026comp=properties", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/xml", + "Accept-Encoding": "gzip, deflate", + "User-Agent": "TestApp/v2.0 TestApp/v1.0 azsdk-python-storage-file-share/12.10.0 Python/3.10.2 (Windows-10-10.0.19044-SP0)", + "x-ms-date": "Fri, 14 Oct 2022 19:17:44 GMT", + "x-ms-version": "2021-06-08" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/xml", + "Date": "Fri, 14 Oct 2022 19:17:42 GMT", + "Server": [ + "Windows-Azure-File/1.0", + "Microsoft-HTTPAPI/2.0" + ], + "Transfer-Encoding": "chunked", + "Vary": "Origin", + "x-ms-version": "2021-06-08" + }, + "ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceProperties\u003E\u003CHourMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/HourMetrics\u003E\u003CMinuteMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/MinuteMetrics\u003E\u003CCors\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders /\u003E\u003CExposedHeaders /\u003E\u003CMaxAgeInSeconds\u003E0\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET,PUT\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com,www.ab.com,www.bc.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders\u003Ex-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*\u003C/AllowedHeaders\u003E\u003CExposedHeaders\u003Ex-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*\u003C/ExposedHeaders\u003E\u003CMaxAgeInSeconds\u003E500\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003C/Cors\u003E\u003CProtocolSettings\u003E\u003CSMB\u003E\u003CMultichannel\u003E\u003CEnabled\u003Efalse\u003C/Enabled\u003E\u003C/Multichannel\u003E\u003C/SMB\u003E\u003C/ProtocolSettings\u003E\u003C/StorageServiceProperties\u003E" + } + ], + "Variables": {} +} diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.pyTestStorageFileClientAsynctest_user_agent_default.json b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.pyTestStorageFileClientAsynctest_user_agent_default.json new file mode 100644 index 000000000000..8f644582a831 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.pyTestStorageFileClientAsynctest_user_agent_default.json @@ -0,0 +1,30 @@ +{ + "Entries": [ + { + "RequestUri": "https://storagename.file.core.windows.net/?restype=service\u0026comp=properties", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/xml", + "Accept-Encoding": "gzip, deflate", + "User-Agent": "azsdk-python-storage-file-share/12.10.0 Python/3.10.2 (Windows-10-10.0.19044-SP0)", + "x-ms-date": "Fri, 14 Oct 2022 19:17:43 GMT", + "x-ms-version": "2021-06-08" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Content-Type": "application/xml", + "Date": "Fri, 14 Oct 2022 19:17:42 GMT", + "Server": [ + "Windows-Azure-File/1.0", + "Microsoft-HTTPAPI/2.0" + ], + "Transfer-Encoding": "chunked", + "Vary": "Origin", + "x-ms-version": "2021-06-08" + }, + "ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceProperties\u003E\u003CHourMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/HourMetrics\u003E\u003CMinuteMetrics\u003E\u003CVersion\u003E1.0\u003C/Version\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CIncludeAPIs\u003Etrue\u003C/IncludeAPIs\u003E\u003CRetentionPolicy\u003E\u003CEnabled\u003Etrue\u003C/Enabled\u003E\u003CDays\u003E5\u003C/Days\u003E\u003C/RetentionPolicy\u003E\u003C/MinuteMetrics\u003E\u003CCors\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders /\u003E\u003CExposedHeaders /\u003E\u003CMaxAgeInSeconds\u003E0\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003CCorsRule\u003E\u003CAllowedMethods\u003EGET,PUT\u003C/AllowedMethods\u003E\u003CAllowedOrigins\u003Ewww.xyz.com,www.ab.com,www.bc.com\u003C/AllowedOrigins\u003E\u003CAllowedHeaders\u003Ex-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*\u003C/AllowedHeaders\u003E\u003CExposedHeaders\u003Ex-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*\u003C/ExposedHeaders\u003E\u003CMaxAgeInSeconds\u003E500\u003C/MaxAgeInSeconds\u003E\u003C/CorsRule\u003E\u003C/Cors\u003E\u003CProtocolSettings\u003E\u003CSMB\u003E\u003CMultichannel\u003E\u003CEnabled\u003Efalse\u003C/Enabled\u003E\u003C/Multichannel\u003E\u003C/SMB\u003E\u003C/ProtocolSettings\u003E\u003C/StorageServiceProperties\u003E" + } + ], + "Variables": {} +} diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.test_user_agent_append_async.yaml b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.test_user_agent_append_async.yaml deleted file mode 100644 index 90ab35cec905..000000000000 --- a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.test_user_agent_append_async.yaml +++ /dev/null @@ -1,30 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/xml - User-Agent: - - customer_user_agent azsdk-python-storage-file-share/12.2.0 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-date: - - Fri, 18 Sep 2020 01:52:39 GMT - x-ms-version: - - '2020-02-10' - method: GET - uri: https://storagename.file.core.windows.net/?restype=service&comp=properties - response: - body: - string: "\uFEFF1.0truetruetrue51.0truetruetrue5GETwww.xyz.com0GET,PUTwww.xyz.com,www.ab.com,www.bc.comx-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*500false" - headers: - content-type: application/xml - date: Fri, 18 Sep 2020 01:52:38 GMT - server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 - transfer-encoding: chunked - vary: Origin - x-ms-version: '2020-02-10' - status: - code: 200 - message: OK - url: https://seanmcccanary3.file.core.windows.net/?restype=service&comp=properties -version: 1 diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.test_user_agent_custom_async.yaml b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.test_user_agent_custom_async.yaml deleted file mode 100644 index 0e248ab1a26b..000000000000 --- a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.test_user_agent_custom_async.yaml +++ /dev/null @@ -1,59 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/xml - User-Agent: - - TestApp/v1.0 azsdk-python-storage-file-share/12.2.0 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-date: - - Fri, 18 Sep 2020 01:52:40 GMT - x-ms-version: - - '2020-02-10' - method: GET - uri: https://storagename.file.core.windows.net/?restype=service&comp=properties - response: - body: - string: "\uFEFF1.0truetruetrue51.0truetruetrue5GETwww.xyz.com0GET,PUTwww.xyz.com,www.ab.com,www.bc.comx-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*500false" - headers: - content-type: application/xml - date: Fri, 18 Sep 2020 01:52:38 GMT - server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 - transfer-encoding: chunked - vary: Origin - x-ms-version: '2020-02-10' - status: - code: 200 - message: OK - url: https://seanmcccanary3.file.core.windows.net/?restype=service&comp=properties -- request: - body: null - headers: - Accept: - - application/xml - User-Agent: - - TestApp/v2.0 TestApp/v1.0 azsdk-python-storage-file-share/12.2.0 Python/3.8.5 - (Windows-10-10.0.19041-SP0) - x-ms-date: - - Fri, 18 Sep 2020 01:52:40 GMT - x-ms-version: - - '2020-02-10' - method: GET - uri: https://storagename.file.core.windows.net/?restype=service&comp=properties - response: - body: - string: "\uFEFF1.0truetruetrue51.0truetruetrue5GETwww.xyz.com0GET,PUTwww.xyz.com,www.ab.com,www.bc.comx-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*500false" - headers: - content-type: application/xml - date: Fri, 18 Sep 2020 01:52:39 GMT - server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 - transfer-encoding: chunked - vary: Origin - x-ms-version: '2020-02-10' - status: - code: 200 - message: OK - url: https://seanmcccanary3.file.core.windows.net/?restype=service&comp=properties -version: 1 diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.test_user_agent_default_async.yaml b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.test_user_agent_default_async.yaml deleted file mode 100644 index 035d8432b964..000000000000 --- a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_client_async.test_user_agent_default_async.yaml +++ /dev/null @@ -1,30 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/xml - User-Agent: - - azsdk-python-storage-file-share/12.2.0 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-date: - - Fri, 18 Sep 2020 01:52:40 GMT - x-ms-version: - - '2020-02-10' - method: GET - uri: https://storagename.file.core.windows.net/?restype=service&comp=properties - response: - body: - string: "\uFEFF1.0truetruetrue51.0truetruetrue5GETwww.xyz.com0GET,PUTwww.xyz.com,www.ab.com,www.bc.comx-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*500false" - headers: - content-type: application/xml - date: Fri, 18 Sep 2020 01:52:39 GMT - server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 - transfer-encoding: chunked - vary: Origin - x-ms-version: '2020-02-10' - status: - code: 200 - message: OK - url: https://seanmcccanary3.file.core.windows.net/?restype=service&comp=properties -version: 1 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 e2d690b33232..45bcfc4d86e2 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 @@ -3,20 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import unittest +import os import platform -import pytest +import pytest from azure.core.exceptions import AzureError -from azure.storage.fileshare import ( - VERSION, - ShareServiceClient, - ShareClient, - ShareDirectoryClient, - ShareFileClient) -from devtools_testutils.storage import StorageTestCase +from azure.storage.fileshare import ShareClient, ShareDirectoryClient, ShareFileClient, ShareServiceClient, VERSION + +from devtools_testutils import recorded_by_proxy +from devtools_testutils.storage import StorageRecordedTestCase +from devtools_testutils.storage.testcase import generate_sas_token from settings.testcase import FileSharePreparer -#from azure.storage.common import TokenCredential + # ------------------------------------------------------------------------------ SERVICES = { @@ -30,11 +28,12 @@ _CONNECTION_ENDPOINTS_SECONDARY = {'file': 'FileSecondaryEndpoint'} -class StorageFileClientTest(StorageTestCase): + +class TestStorageFileClient(StorageRecordedTestCase): def _setup(self, storage_account_name, storage_account_key): self.account_name = storage_account_name self.account_key = storage_account_key - self.sas_token = self.generate_sas_token() + self.sas_token = generate_sas_token() def _teardown(self, FILE_PATH): if os.path.isfile(FILE_PATH): @@ -44,18 +43,19 @@ def _teardown(self, FILE_PATH): pass # --Helpers----------------------------------------------------------------- def validate_standard_account_endpoints(self, service, service_type, protocol='https'): - self.assertIsNotNone(service) - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertTrue(service.primary_endpoint.startswith('{}://{}.{}.core.windows.net/'.format( - protocol, self.account_name, service_type))) - self.assertTrue(service.secondary_endpoint.startswith('{}://{}-secondary.{}.core.windows.net/'.format( - protocol, self.account_name, service_type))) + 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 # --Direct Parameters Test Cases -------------------------------------------- @FileSharePreparer() - def test_create_service_with_key(self, storage_account_name, storage_account_key): + def test_create_service_with_key(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) for client, url in SERVICES.items(): @@ -66,10 +66,13 @@ def test_create_service_with_key(self, storage_account_name, storage_account_key # Assert self.validate_standard_account_endpoints(service, url) - self.assertEqual(service.scheme, 'https') + assert service.scheme == 'https' @FileSharePreparer() - def test_create_service_with_sas(self, storage_account_name, storage_account_key): + def test_create_service_with_sas(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) for service_type in SERVICES: @@ -79,24 +82,30 @@ def test_create_service_with_sas(self, storage_account_name, storage_account_key share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertIsNone(service.credential) - self.assertEqual(service.account_name, self.account_name) - self.assertTrue(service.url.endswith(self.sas_token)) + assert service is not None + assert service.credential is None + assert service.account_name == self.account_name + assert service.url.endswith(self.sas_token) @FileSharePreparer() - def test_create_service_with_token(self, storage_account_name, storage_account_key): + def test_create_service_with_token(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) for service_type in SERVICES: # Act # token credential is not available for FileService token_credential = self.generate_oauth_token() - with self.assertRaises(ValueError): + with pytest.raises(ValueError): service_type(self.account_url(storage_account_name, "file"), credential=token_credential, share_name='foo', directory_path='bar', file_path='baz') @FileSharePreparer() - def test_create_service_china(self, storage_account_name, storage_account_key): + def test_create_service_china(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) url = self.account_url(storage_account_name, "file").replace('core.windows.net', 'core.chinacloudapi.cn') for service_type in SERVICES.items(): @@ -106,17 +115,18 @@ def test_create_service_china(self, storage_account_name, storage_account_key): share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertEqual(service.primary_hostname, '{}.{}.core.chinacloudapi.cn'.format( - self.account_name, service_type[1])) - self.assertEqual(service.secondary_hostname, - '{}-secondary.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1])) + 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]) @FileSharePreparer() - def test_create_service_protocol(self, storage_account_name, storage_account_key): + def test_create_service_protocol(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) url = self.account_url(storage_account_name, "file").replace('https', 'http') for service_type in SERVICES.items(): @@ -126,25 +136,28 @@ def test_create_service_protocol(self, storage_account_name, storage_account_key # Assert self.validate_standard_account_endpoints(service, service_type[1], protocol='http') - self.assertEqual(service.scheme, 'http') - + assert service.scheme == 'http' @FileSharePreparer() - def test_create_service_empty_key(self, storage_account_name, storage_account_key): + def test_create_service_empty_key(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) for service_type in SERVICES: # Act # Passing an empty key to create account should fail. - with self.assertRaises(ValueError) as e: + 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.assertEqual( - str(e.exception), - '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, storage_account_name, storage_account_key): + def test_create_service_with_socket_timeout(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) for service_type in SERVICES.items(): @@ -164,7 +177,10 @@ def test_create_service_with_socket_timeout(self, storage_account_name, storage_ # --Connection String Test Cases -------------------------------------------- @FileSharePreparer() - def test_create_service_with_connection_string_key(self, storage_account_name, storage_account_key): + def test_create_service_with_connection_string_key(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) conn_string = 'AccountName={};AccountKey={};'.format(self.account_name, self.account_key) @@ -175,10 +191,13 @@ def test_create_service_with_connection_string_key(self, storage_account_name, s # Assert self.validate_standard_account_endpoints(service, service_type[1]) - self.assertEqual(service.scheme, 'https') + assert service.scheme == 'https' @FileSharePreparer() - def test_create_service_with_connection_string_sas(self, storage_account_name, storage_account_key): + def test_create_service_with_connection_string_sas(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) conn_string = 'AccountName={};SharedAccessSignature={};'.format(self.account_name, self.sas_token) @@ -188,13 +207,16 @@ def test_create_service_with_connection_string_sas(self, storage_account_name, s conn_string, share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertIsNone(service.credential) - self.assertEqual(service.account_name, self.account_name) - self.assertTrue(service.url.endswith(self.sas_token)) + assert service is not None + assert service.credential is None + assert service.account_name == self.account_name + assert service.url.endswith(self.sas_token) @FileSharePreparer() - def test_create_service_with_connection_string_endpoint_protocol(self, storage_account_name, storage_account_key): + def test_create_service_with_connection_string_endpoint_protocol(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) conn_string = 'AccountName={};AccountKey={};DefaultEndpointsProtocol=http;EndpointSuffix=core.chinacloudapi.cn;'.format( self.account_name, self.account_key) @@ -205,28 +227,33 @@ def test_create_service_with_connection_string_endpoint_protocol(self, storage_a conn_string, share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertEqual(service.primary_hostname, '{}.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1])) - self.assertEqual(service.secondary_hostname, - '{}-secondary.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1])) - self.assertEqual(service.scheme, 'http') + 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' @FileSharePreparer() - def test_create_service_with_connection_string_emulated(self, storage_account_name, storage_account_key): + def test_create_service_with_connection_string_emulated(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) for service_type in SERVICES.items(): conn_string = 'UseDevelopmentStorage=true;' # Act - with self.assertRaises(ValueError): + with pytest.raises(ValueError): service_type[0].from_connection_string( 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, storage_account_name, storage_account_key): + def test_create_service_with_connection_string_fails_if_secondary_without_primary(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + storage_account_key = kwargs.pop("storage_account_key") + for service_type in SERVICES.items(): self._setup(storage_account_name, storage_account_key) conn_string = 'AccountName={};AccountKey={};{}=www.mydomain.com;'.format( @@ -235,12 +262,15 @@ def test_create_service_with_connection_string_fails_if_secondary_without_primar # Act # Fails if primary excluded - with self.assertRaises(ValueError): + with pytest.raises(ValueError): service_type[0].from_connection_string( 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, storage_account_name, storage_account_key): + def test_create_service_with_connection_string_succeeds_if_secondary_with_primary(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + storage_account_key = kwargs.pop("storage_account_key") + 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( @@ -253,15 +283,18 @@ def test_create_service_with_connection_string_succeeds_if_secondary_with_primar conn_string, share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertEqual(service.primary_hostname, 'www.mydomain.com') - self.assertEqual(service.secondary_hostname, 'www-sec.mydomain.com') + 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' @FileSharePreparer() - def test_create_service_with_custom_account_endpoint_path(self, storage_account_name, storage_account_key): + def test_create_service_with_custom_account_endpoint_path(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) custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token for service_type in SERVICES.items(): @@ -273,71 +306,70 @@ def test_create_service_with_custom_account_endpoint_path(self, storage_account_ conn_string, share_name="foo", directory_path="bar", file_path="baz") # Assert - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') + 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' service = ShareServiceClient(account_url=custom_account_url) - self.assertEqual(service.account_name, None) - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/?')) + 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/?') service = ShareClient(account_url=custom_account_url, share_name="foo", snapshot="snap") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.snapshot, "snap") - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo?sharesnapshot=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&') service = ShareDirectoryClient(account_url=custom_account_url, share_name='foo', directory_path="bar/baz", snapshot="snap") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.directory_path, "bar/baz") - self.assertEqual(service.snapshot, "snap") - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo/bar%2Fbaz?sharesnapshot=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&') service = ShareDirectoryClient(account_url=custom_account_url, share_name='foo', directory_path="") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.directory_path, "") - self.assertEqual(service.snapshot, None) - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo?')) + 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?') service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="bar/baz/file", snapshot="snap") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.directory_path, "bar/baz") - self.assertEqual(service.file_path, ["bar", "baz", "file"]) - self.assertEqual(service.file_name, "file") - self.assertEqual(service.snapshot, "snap") - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo/bar/baz/file?sharesnapshot=snap&')) + assert service.account_name == None + assert service.share_name == "foo" + assert service.directory_path == "bar/baz" + assert service.file_path, ["bar", "baz" == "file"] + assert service.file_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&') service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="file") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.directory_path, "") - self.assertEqual(service.file_path, ["file"]) - self.assertEqual(service.file_name, "file") - self.assertEqual(service.snapshot, None) - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo/file?')) - + assert service.account_name == None + assert service.share_name == "foo" + assert service.directory_path == "" + assert service.file_path == ["file"] + 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?') + + @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, storage_account_name, storage_account_key): - # client request id is different for every request, so it will never match the recorded one - pytest.skip("Issue tracked here: https://github.com/Azure/azure-sdk-for-python/issues/8098") - if not self.is_live: - return + 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' @@ -349,7 +381,7 @@ def callback(response): response.http_response.headers[request_id_header_name] += '1' # Assert the client request ID validation is working - with self.assertRaises(AzureError): + with pytest.raises(AzureError): service.get_service_properties(raw_response_hook=callback) # Act remove the echoed client request ID @@ -361,25 +393,33 @@ def callback(response): service.get_service_properties(raw_response_hook=callback) @FileSharePreparer() - def test_user_agent_default(self, storage_account_name, storage_account_key): + @recorded_by_proxy + def test_user_agent_default(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) service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key) def callback(response): - self.assertTrue('User-Agent' in response.http_request.headers) + 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) @FileSharePreparer() - def test_user_agent_custom(self, storage_account_name, storage_account_key): + @recorded_by_proxy + def test_user_agent_custom(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) custom_app = "TestApp/v1.0" service = ShareServiceClient( self.account_url(storage_account_name, "file"), credential=self.account_key, user_agent=custom_app) def callback1(response): - self.assertTrue('User-Agent' in response.http_request.headers) + assert 'User-Agent' in response.http_request.headers assert ("TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( VERSION, platform.python_version(), @@ -388,7 +428,7 @@ def callback1(response): service.get_service_properties(raw_response_hook=callback1) def callback2(response): - self.assertTrue('User-Agent' in response.http_request.headers) + 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(), @@ -397,12 +437,16 @@ def callback2(response): service.get_service_properties(raw_response_hook=callback2, user_agent="TestApp/v2.0") @FileSharePreparer() - def test_user_agent_append(self, storage_account_name, storage_account_key): + @recorded_by_proxy + def test_user_agent_append(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) service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key) def callback(response): - self.assertTrue('User-Agent' in response.http_request.headers) + assert 'User-Agent' in response.http_request.headers assert ("customer_user_agent azsdk-python-storage-file-share/{} Python/{} ({})".format( VERSION, platform.python_version(), @@ -411,24 +455,28 @@ def callback(response): service.get_service_properties(raw_response_hook=callback, user_agent='customer_user_agent') @FileSharePreparer() - def test_error_with_malformed_conn_str(self, storage_account_name, storage_account_key): + def test_error_with_malformed_conn_str(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) for conn_str in ["", "foobar", "foobar=baz=foo", "foo;bar;baz", "foo=;bar=;", "=", ";", "=;=="]: for service_type in SERVICES.items(): # Act - with self.assertRaises(ValueError) as e: + 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", ";"): - self.assertEqual( - str(e.exception), "Connection string is either blank or malformed.") + assert e.value.args[0] == "Connection string is either blank or malformed." elif conn_str in ("foobar=baz=foo" , "foo=;bar=;", "=", "=;=="): - self.assertEqual( - str(e.exception), "Connection string missing required connection details.") + assert e.value.args[0] == "Connection string missing required connection details." @FileSharePreparer() - def test_closing_pipeline_client(self, storage_account_name, storage_account_key): + def test_closing_pipeline_client(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) for client, url in SERVICES.items(): @@ -442,7 +490,10 @@ def test_closing_pipeline_client(self, storage_account_name, storage_account_key service.close() @FileSharePreparer() - def test_closing_pipeline_client_simple(self, storage_account_name, storage_account_key): + def test_closing_pipeline_client_simple(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) for client, url in SERVICES.items(): 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 ca6542185558..4c8bb65ec4ad 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 @@ -3,20 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import unittest +import os import platform -import asyncio -from azure.core.pipeline.transport import AioHttpTransport -from multidict import CIMultiDict, CIMultiDictProxy + +import pytest from azure.storage.fileshare import VERSION -from azure.storage.fileshare.aio import ( - ShareServiceClient, - ShareClient, - ShareDirectoryClient, - ShareFileClient) +from azure.storage.fileshare.aio import ShareClient, ShareDirectoryClient, ShareFileClient, ShareServiceClient +from devtools_testutils.aio import recorded_by_proxy_async +from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase +from devtools_testutils.storage.testcase import generate_sas_token from settings.testcase import FileSharePreparer -from devtools_testutils.storage.aio import AsyncStorageTestCase + # ------------------------------------------------------------------------------ SERVICES = { @@ -31,22 +29,11 @@ _CONNECTION_ENDPOINTS_SECONDARY = {'file': 'FileSecondaryEndpoint'} -class AiohttpTestTransport(AioHttpTransport): - """Workaround to vcrpy bug: https://github.com/kevin1024/vcrpy/pull/461 - """ - async def send(self, request, **config): - response = await super(AiohttpTestTransport, self).send(request, **config) - if not isinstance(response.headers, CIMultiDictProxy): - response.headers = CIMultiDictProxy(CIMultiDict(response.internal_response.headers)) - response.content_type = response.headers.get("content-type") - return response - - -class StorageFileClientTest(AsyncStorageTestCase): +class TestStorageFileClientAsync(AsyncStorageRecordedTestCase): def _setup(self, storage_account_name, storage_account_key): self.account_name = storage_account_name self.account_key = storage_account_key - self.sas_token = self.generate_sas_token() + self.sas_token = generate_sas_token() self.token_credential = self.generate_oauth_token() def _teardown(self, FILE_PATH): @@ -57,18 +44,19 @@ def _teardown(self, FILE_PATH): pass # --Helpers----------------------------------------------------------------- def validate_standard_account_endpoints(self, service, service_type, protocol='https'): - self.assertIsNotNone(service) - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertTrue(service.primary_endpoint.startswith('{}://{}.{}.core.windows.net/'.format( - protocol, self.account_name, service_type))) - self.assertTrue(service.secondary_endpoint.startswith('{}://{}-secondary.{}.core.windows.net/'.format( - protocol, self.account_name, service_type))) + 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 # --Direct Parameters Test Cases -------------------------------------------- @FileSharePreparer() - def test_create_service_with_key_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_key(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) for client, url in SERVICES.items(): @@ -79,10 +67,13 @@ def test_create_service_with_key_async(self, storage_account_name, storage_accou # Assert self.validate_standard_account_endpoints(service, url) - self.assertEqual(service.scheme, 'https') + assert service.scheme == 'https' @FileSharePreparer() - def test_create_service_with_sas_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_sas(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) for service_type in SERVICES: @@ -92,23 +83,29 @@ def test_create_service_with_sas_async(self, storage_account_name, storage_accou share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertIsNone(service.credential) - self.assertEqual(service.account_name, self.account_name) - self.assertTrue(service.url.endswith(self.sas_token)) + assert service is not None + assert service.credential is None + assert service.account_name == self.account_name + assert service.url.endswith(self.sas_token) @FileSharePreparer() - def test_create_service_with_token_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_token(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) for service_type in SERVICES: # Act # token credential is not available for FileService - with self.assertRaises(ValueError): + with pytest.raises(ValueError): service_type(self.account_url(storage_account_name, "file"), credential=self.token_credential, share_name='foo', directory_path='bar', file_path='baz') @FileSharePreparer() - def test_create_service_china_async(self, storage_account_name, storage_account_key): + async def test_create_service_china(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) url = self.account_url(storage_account_name, "file").replace('core.windows.net', 'core.chinacloudapi.cn') for service_type in SERVICES.items(): @@ -118,16 +115,18 @@ def test_create_service_china_async(self, storage_account_name, storage_account_ share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertEqual(service.primary_hostname, '{}.{}.core.chinacloudapi.cn'.format( - self.account_name, service_type[1])) - self.assertEqual(service.secondary_hostname, - '{}-secondary.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1])) + 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]) + @FileSharePreparer() - def test_create_service_protocol_async(self, storage_account_name, storage_account_key): + async def test_create_service_protocol(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) url = self.account_url(storage_account_name, "file").replace('https', 'http') for service_type in SERVICES.items(): @@ -137,24 +136,28 @@ def test_create_service_protocol_async(self, storage_account_name, storage_accou # Assert self.validate_standard_account_endpoints(service, service_type[1], protocol='http') - self.assertEqual(service.scheme, 'http') + assert service.scheme == 'http' @FileSharePreparer() - def test_create_service_empty_key_async(self, storage_account_name, storage_account_key): + async def test_create_service_empty_key(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) for service_type in SERVICES: # Act # Passing an empty key to create account should fail. - with self.assertRaises(ValueError) as e: + 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.assertEqual( - str(e.exception), - '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_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_socket_timeout(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) for service_type in SERVICES.items(): @@ -174,7 +177,10 @@ def test_create_service_with_socket_timeout_async(self, storage_account_name, st # --Connection String Test Cases -------------------------------------------- @FileSharePreparer() - def test_create_service_with_connection_string_key_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_connection_string_key(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) conn_string = 'AccountName={};AccountKey={};'.format(self.account_name, self.account_key) @@ -185,58 +191,67 @@ def test_create_service_with_connection_string_key_async(self, storage_account_n # Assert self.validate_standard_account_endpoints(service, service_type[1]) - self.assertEqual(service.scheme, 'https') + assert service.scheme == 'https' @FileSharePreparer() - def test_create_service_with_connection_string_sas_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_connection_string_sas(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) 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', transport=AiohttpTestTransport()) + conn_string, share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertIsNone(service.credential) - self.assertEqual(service.account_name, self.account_name) - self.assertTrue(service.url.endswith(self.sas_token)) + assert service is not None + assert service.credential is None + assert service.account_name == self.account_name + assert service.url.endswith(self.sas_token) @FileSharePreparer() - def test_create_service_with_connection_string_endpoint_protocol_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_connection_string_endpoint_protocol(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) 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', transport=AiohttpTestTransport()) + service = service_type[0].from_connection_string(conn_string, share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertEqual(service.primary_hostname, '{}.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1])) - self.assertEqual(service.secondary_hostname, - '{}-secondary.{}.core.chinacloudapi.cn'.format(self.account_name, service_type[1])) - self.assertEqual(service.scheme, 'http') + 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' @FileSharePreparer() - def test_create_service_with_connection_string_emulated_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_connection_string_emulated(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) for service_type in SERVICES.items(): conn_string = 'UseDevelopmentStorage=true;' # Act - with self.assertRaises(ValueError): - service_type[0].from_connection_string( - conn_string, share_name='foo', directory_path='bar', file_path='baz', transport=AiohttpTestTransport()) + with pytest.raises(ValueError): + service_type[0].from_connection_string(conn_string, share_name='foo', directory_path='bar', file_path='baz') @FileSharePreparer() - def test_create_service_with_connection_string_fails_if_secondary_without_primary_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_connection_string_fails_if_secondary_without_primary(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + storage_account_key = kwargs.pop("storage_account_key") + for service_type in SERVICES.items(): self._setup(storage_account_name, storage_account_key) conn_string = 'AccountName={};AccountKey={};{}=www.mydomain.com;'.format( @@ -245,12 +260,15 @@ def test_create_service_with_connection_string_fails_if_secondary_without_primar # Act # Fails if primary excluded - with self.assertRaises(ValueError): + with pytest.raises(ValueError): service_type[0].from_connection_string( conn_string, share_name='foo', directory_path='bar', file_path='baz') @FileSharePreparer() - def test_create_service_with_connection_string_succeeds_if_secondary_with_primary_async(self, storage_account_name, storage_account_key): + async def test_create_service_with_connection_string_succeeds_if_secondary_with_primary(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + storage_account_key = kwargs.pop("storage_account_key") + 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( @@ -263,15 +281,18 @@ def test_create_service_with_connection_string_succeeds_if_secondary_with_primar conn_string, share_name='foo', directory_path='bar', file_path='baz') # Assert - self.assertIsNotNone(service) - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertEqual(service.primary_hostname, 'www.mydomain.com') - self.assertEqual(service.secondary_hostname, 'www-sec.mydomain.com') + 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' @FileSharePreparer() - def test_create_service_with_custom_account_endpoint_path(self, storage_account_name, storage_account_key): + async def test_create_service_with_custom_account_endpoint_path(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) custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token for service_type in SERVICES.items(): @@ -283,87 +304,93 @@ def test_create_service_with_custom_account_endpoint_path(self, storage_account_ conn_string, share_name="foo", directory_path="bar", file_path="baz") # Assert - self.assertEqual(service.account_name, self.account_name) - self.assertEqual(service.credential.account_name, self.account_name) - self.assertEqual(service.credential.account_key, self.account_key) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') + 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' service = ShareServiceClient(account_url=custom_account_url) - self.assertEqual(service.account_name, None) - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/?')) + 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/?') service = ShareClient(account_url=custom_account_url, share_name="foo", snapshot="snap") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.snapshot, "snap") - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo?sharesnapshot=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&') service = ShareDirectoryClient(account_url=custom_account_url, share_name='foo', directory_path="bar/baz", snapshot="snap") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.directory_path, "bar/baz") - self.assertEqual(service.snapshot, "snap") - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo/bar%2Fbaz?sharesnapshot=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&') service = ShareDirectoryClient(account_url=custom_account_url, share_name='foo', directory_path="") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.directory_path, "") - self.assertEqual(service.snapshot, None) - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo?')) + 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?') service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="bar/baz/file", snapshot="snap") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.directory_path, "bar/baz") - self.assertEqual(service.file_path, ["bar", "baz", "file"]) - self.assertEqual(service.file_name, "file") - self.assertEqual(service.snapshot, "snap") - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo/bar/baz/file?sharesnapshot=snap&')) + assert service.account_name == None + assert service.share_name == "foo" + assert service.directory_path == "bar/baz" + assert service.file_path, ["bar", "baz" == "file"] + assert service.file_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&') service = ShareFileClient(account_url=custom_account_url, share_name="foo", file_path="file") - self.assertEqual(service.account_name, None) - self.assertEqual(service.share_name, "foo") - self.assertEqual(service.directory_path, "") - self.assertEqual(service.file_path, ["file"]) - self.assertEqual(service.file_name, "file") - self.assertEqual(service.snapshot, None) - self.assertEqual(service.credential, None) - self.assertEqual(service.primary_hostname, 'local-machine:11002/custom/account/path') - self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path/foo/file?')) + assert service.account_name == None + assert service.share_name == "foo" + assert service.directory_path == "" + assert service.file_path == ["file"] + 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?') @FileSharePreparer() - @AsyncStorageTestCase.await_prepared_test - async def test_user_agent_default_async(self, storage_account_name, storage_account_key): + @recorded_by_proxy_async + async def test_user_agent_default(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) - service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key, transport=AiohttpTestTransport()) + service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key) def callback(response): - self.assertTrue('User-Agent' in response.http_request.headers) + 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) @FileSharePreparer() - @AsyncStorageTestCase.await_prepared_test - async def test_user_agent_custom_async(self, storage_account_name, storage_account_key): + @recorded_by_proxy_async + async def test_user_agent_custom(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) custom_app = "TestApp/v1.0" service = ShareServiceClient( - self.account_url(storage_account_name, "file"), credential=self.account_key, user_agent=custom_app, transport=AiohttpTestTransport()) + self.account_url(storage_account_name, "file"), credential=self.account_key, user_agent=custom_app) def callback1(response): - self.assertTrue('User-Agent' in response.http_request.headers) + assert 'User-Agent' in response.http_request.headers assert ("TestApp/v1.0 azsdk-python-storage-file-share/{} Python/{} ({})".format( VERSION, platform.python_version(), @@ -372,7 +399,7 @@ def callback1(response): await service.get_service_properties(raw_response_hook=callback1) def callback2(response): - self.assertTrue('User-Agent' in response.http_request.headers) + 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(), @@ -381,13 +408,16 @@ def callback2(response): await service.get_service_properties(raw_response_hook=callback2, user_agent="TestApp/v2.0") @FileSharePreparer() - @AsyncStorageTestCase.await_prepared_test - async def test_user_agent_append_async(self, storage_account_name, storage_account_key): + @recorded_by_proxy_async + async def test_user_agent_append(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) - service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key, transport=AiohttpTestTransport()) + service = ShareServiceClient(self.account_url(storage_account_name, "file"), credential=self.account_key) def callback(response): - self.assertTrue('User-Agent' in response.http_request.headers) + assert 'User-Agent' in response.http_request.headers assert ("customer_user_agent azsdk-python-storage-file-share/{} Python/{} ({})".format( VERSION, platform.python_version(), @@ -395,10 +425,11 @@ def callback(response): await service.get_service_properties(raw_response_hook=callback, user_agent='customer_user_agent') - @FileSharePreparer() - @AsyncStorageTestCase.await_prepared_test - async def test_closing_pipeline_client_async(self, storage_account_name, storage_account_key): + async def test_closing_pipeline_client(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) for client, url in SERVICES.items(): @@ -412,8 +443,10 @@ async def test_closing_pipeline_client_async(self, storage_account_name, storage await service.close() @FileSharePreparer() - @AsyncStorageTestCase.await_prepared_test - async def test_closing_pipeline_client_simple_async(self, storage_account_name, storage_account_key): + async def test_closing_pipeline_client_simple(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) for client, url in SERVICES.items():