diff --git a/sdk/tables/azure-data-tables/tests/recordings/test_table_batch.test_batch_sas_auth.yaml b/sdk/tables/azure-data-tables/tests/recordings/test_table_batch.test_batch_sas_auth.yaml new file mode 100644 index 000000000000..8257d38f947f --- /dev/null +++ b/sdk/tables/azure-data-tables/tests/recordings/test_table_batch.test_batch_sas_auth.yaml @@ -0,0 +1,242 @@ +interactions: +- request: + body: '{"TableName": "uttabled4f0e8f"}' + headers: + Accept: + - application/json;odata=minimalmetadata + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '31' + Content-Type: + - application/json;odata=nometadata + DataServiceVersion: + - '3.0' + Date: + - Fri, 05 Mar 2021 16:54:43 GMT + User-Agent: + - azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 05 Mar 2021 16:54:43 GMT + x-ms-version: + - '2019-02-02' + method: POST + uri: https://fake_table_account.table.core.windows.net/Tables + response: + body: + string: '{"odata.error":{"code":"TableAlreadyExists","message":{"lang":"en-US","value":"The + table specified already exists.\nRequestId:7fd90d5f-e002-003b-41e0-119f80000000\nTime:2021-03-05T16:54:43.1645315Z"}}}' + headers: + cache-control: + - no-cache + content-type: + - application/json;odata=minimalmetadata;streaming=true;charset=utf-8 + date: + - Fri, 05 Mar 2021 16:54:42 GMT + server: + - Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0 + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-ms-version: + - '2019-02-02' + status: + code: 409 + message: Conflict +- request: + body: "--batch_8e6535d9-ecdb-4f9f-8547-dfe348188540\r\nContent-Type: multipart/mixed;\ + \ boundary=changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\n\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 0\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c64afbf-7dd3-11eb-ab63-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"0\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 1\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c64afc0-7dd3-11eb-8299-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"1\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 2\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c64d743-7dd3-11eb-a56b-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"2\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 3\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c65083f-7dd3-11eb-88e4-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"3\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 4\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c650840-7dd3-11eb-8f93-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"4\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 5\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c650841-7dd3-11eb-a3d0-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"5\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 6\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c653e76-7dd3-11eb-9358-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"6\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 7\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c653e77-7dd3-11eb-a991-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"7\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 8\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c653e78-7dd3-11eb-9906-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"8\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6\r\ + \nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID:\ + \ 9\r\n\r\nPOST https://seankaneprim.table.core.windows.net/uttabled4f0e8f?st=2021-03-05T16%3A53%3A44Z&se=2021-03-05T17%3A54%3A44Z&sp=a&sv=2019-02-02&tn=uttabled4f0e8f&sig=TStgoQP%2FZDFaSw7JFX8lYcHHSbNXkWMaIejc8v7EGso%3D\ + \ HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nPrefer:\ + \ return-no-content\r\nContent-Type: application/json;odata=nometadata\r\nAccept:\ + \ application/json;odata=minimalmetadata\r\nContent-Length: 223\r\nx-ms-date:\ + \ Fri, 05 Mar 2021 16:54:44 GMT\r\nDate: Fri, 05 Mar 2021 16:54:44 GMT\r\nx-ms-client-request-id:\ + \ 7c653e79-7dd3-11eb-81dd-002b67128e4c\r\n\r\n{\"PartitionKey\": \"batch_inserts\"\ + , \"PartitionKey@odata.type\": \"Edm.String\", \"test\": true, \"test2\": \"\ + value\", \"test2@odata.type\": \"Edm.String\", \"test3\": 3, \"test4\": 1234567890,\ + \ \"RowKey\": \"9\", \"RowKey@odata.type\": \"Edm.String\"}\r\n--changeset_070b7ea2-9157-4ee4-8ce1-38b81ab0d4f6--\r\ + \n\r\n--batch_8e6535d9-ecdb-4f9f-8547-dfe348188540--\r\n" + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '9418' + Content-Type: + - multipart/mixed; boundary=batch_8e6535d9-ecdb-4f9f-8547-dfe348188540 + DataServiceVersion: + - '3.0' + Date: + - Fri, 05 Mar 2021 16:54:44 GMT + MaxDataServiceVersion: + - 3.0;NetFx + User-Agent: + - azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 05 Mar 2021 16:54:44 GMT + x-ms-version: + - '2019-02-02' + method: POST + uri: https://fake_table_account.table.core.windows.net/$batch + response: + body: + string: 'ResourceNotFoundThe specified resource does not exist. + + RequestId:b6ba23cc-3002-005a-7ce0-11bcc3000000 + + Time:2021-03-05T16:54:44.0091854Z' + headers: + content-length: + - '322' + content-type: + - application/xml + date: + - Fri, 05 Mar 2021 16:54:43 GMT + server: + - Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0 + x-ms-error-code: + - ResourceNotFound + x-ms-version: + - '2019-02-02' + status: + code: 404 + message: The specified resource does not exist. +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + Date: + - Fri, 05 Mar 2021 16:54:45 GMT + User-Agent: + - azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 05 Mar 2021 16:54:45 GMT + x-ms-version: + - '2019-02-02' + method: DELETE + uri: https://fake_table_account.table.core.windows.net/Tables('uttabled4f0e8f') + response: + body: + string: '' + headers: + cache-control: + - no-cache + content-length: + - '0' + date: + - Fri, 05 Mar 2021 16:54:43 GMT + server: + - Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0 + x-content-type-options: + - nosniff + x-ms-version: + - '2019-02-02' + status: + code: 204 + message: No Content +version: 1 diff --git a/sdk/tables/azure-data-tables/tests/test_table_batch.py b/sdk/tables/azure-data-tables/tests/test_table_batch.py index 87dba13a1a81..f0e90485bbbe 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_batch.py +++ b/sdk/tables/azure-data-tables/tests/test_table_batch.py @@ -8,7 +8,7 @@ import pytest -from datetime import datetime +from datetime import datetime, timedelta from dateutil.tz import tzutc import sys import uuid @@ -16,6 +16,7 @@ from devtools_testutils import AzureTestCase from azure.core import MatchConditions +from azure.core.credentials import AzureSasCredential from azure.core.exceptions import ( ResourceExistsError, ResourceNotFoundError, @@ -32,6 +33,9 @@ TableServiceClient, TableEntity, UpdateMode, + generate_table_sas, + TableSasPermissions, + TableClient ) from _shared.testcase import TableTestCase @@ -851,6 +855,58 @@ def test_new_delete_nonexistent_entity(self, tables_storage_account_name, tables finally: self._tear_down() + @pytest.mark.skipif(sys.version_info < (3, 0), reason="requires Python3") + @pytest.mark.live_test_only + @TablesPreparer() + def test_batch_sas_auth(self, tables_storage_account_name, tables_primary_storage_account_key): + # Arrange + self._set_up(tables_storage_account_name, tables_primary_storage_account_key) + try: + + token = generate_table_sas( + tables_storage_account_name, + tables_primary_storage_account_key, + self.table_name, + permission=TableSasPermissions(add=True, read=True, update=True, delete=True), + expiry=datetime.utcnow() + timedelta(hours=1), + start=datetime.utcnow() - timedelta(minutes=1), + ) + token = AzureSasCredential(token) + + # Act + service = TableServiceClient( + self.account_url(tables_storage_account_name, "table"), + credential=token, + ) + table = service.get_table_client(self.table_name) + + entity = TableEntity() + entity.PartitionKey = 'batch_inserts' + entity.test = EntityProperty(True) + entity.test2 = 'value' + entity.test3 = 3 + entity.test4 = EntityProperty(1234567890) + + batch = table.create_batch() + transaction_count = 0 + for i in range(10): + entity.RowKey = str(i) + batch.create_entity(entity) + transaction_count += 1 + transaction_result = table.send_batch(batch) + + assert transaction_result is not None + + total_entities = 0 + for e in table.list_entities(): + total_entities += 1 + + assert total_entities == transaction_count + finally: + self._tear_down() + + + class TestTableUnitTest(TableTestCase): #--Test cases for batch --------------------------------------------- diff --git a/sdk/tables/azure-data-tables/tests/test_table_batch_async.py b/sdk/tables/azure-data-tables/tests/test_table_batch_async.py index 85d85112644c..d47e003e108b 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_batch_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_batch_async.py @@ -9,13 +9,14 @@ import pytest import uuid -from datetime import datetime +from datetime import datetime, timedelta from dateutil.tz import tzutc import sys from devtools_testutils import AzureTestCase from azure.core import MatchConditions +from azure.core.credentials import AzureSasCredential from azure.core.exceptions import ( ResourceExistsError, ResourceNotFoundError, @@ -29,7 +30,9 @@ EntityProperty, EdmType, BatchTransactionResult, - BatchErrorException + BatchErrorException, + generate_table_sas, + TableSasPermissions ) from _shared.asynctestcase import AsyncTableTestCase @@ -762,3 +765,53 @@ async def test_new_delete_nonexistent_entity(self, tables_storage_account_name, finally: await self._tear_down() + + @pytest.mark.skipif(sys.version_info < (3, 0), reason="requires Python3") + @pytest.mark.live_test_only + @TablesPreparer() + async def test_batch_sas_auth(self, tables_storage_account_name, tables_primary_storage_account_key): + # Arrange + await self._set_up(tables_storage_account_name, tables_primary_storage_account_key) + try: + + token = generate_table_sas( + tables_storage_account_name, + tables_primary_storage_account_key, + self.table_name, + permission=TableSasPermissions(add=True, read=True, update=True, delete=True), + expiry=datetime.utcnow() + timedelta(hours=1), + start=datetime.utcnow() - timedelta(minutes=1), + ) + token = AzureSasCredential(token) + + # Act + service = TableServiceClient( + self.account_url(tables_storage_account_name, "table"), + credential=token, + ) + table = service.get_table_client(self.table_name) + + entity = TableEntity() + entity.PartitionKey = 'batch_inserts' + entity.test = EntityProperty(True) + entity.test2 = 'value' + entity.test3 = 3 + entity.test4 = EntityProperty(1234567890) + + batch = table.create_batch() + transaction_count = 0 + for i in range(10): + entity.RowKey = str(i) + batch.create_entity(entity) + transaction_count += 1 + transaction_result = await table.send_batch(batch) + + assert transaction_result is not None + + total_entities = 0 + async for e in table.list_entities(): + total_entities += 1 + + assert total_entities == transaction_count + finally: + await self._tear_down() \ No newline at end of file diff --git a/sdk/tables/azure-data-tables/tests/test_table_entity.py b/sdk/tables/azure-data-tables/tests/test_table_entity.py index c26e17ff3f47..0a322d59123f 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_entity.py +++ b/sdk/tables/azure-data-tables/tests/test_table_entity.py @@ -29,6 +29,7 @@ ) from azure.core import MatchConditions +from azure.core.credentials import AzureSasCredential from azure.core.exceptions import ( HttpResponseError, ResourceNotFoundError, @@ -1637,7 +1638,7 @@ def test_sas_query(self, tables_storage_account_name, tables_primary_storage_acc # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) entities = list(table.query_entities( @@ -1669,7 +1670,7 @@ def test_sas_add(self, tables_storage_account_name, tables_primary_storage_accou # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) @@ -1704,7 +1705,7 @@ def test_sas_add_inside_range(self, tables_storage_account_name, tables_primary_ # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) entity = self._create_random_entity_dict(u'test', u'test1') @@ -1737,7 +1738,7 @@ def test_sas_add_outside_range(self, tables_storage_account_name, tables_primary # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) with pytest.raises(HttpResponseError): @@ -1768,7 +1769,7 @@ def test_sas_update(self, tables_storage_account_name, tables_primary_storage_ac # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) updated_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) @@ -1801,7 +1802,7 @@ def test_sas_delete(self, tables_storage_account_name, tables_primary_storage_ac # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) table.delete_entity(entity.PartitionKey, entity.RowKey) @@ -1835,7 +1836,7 @@ def test_sas_upper_case_table_name(self, tables_storage_account_name, tables_pri # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) entities = list(table.query_entities( @@ -1875,7 +1876,7 @@ def test_sas_signed_identifier(self, tables_storage_account_name, tables_primary # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) entities = list(table.query_entities( diff --git a/sdk/tables/azure-data-tables/tests/test_table_entity_async.py b/sdk/tables/azure-data-tables/tests/test_table_entity_async.py index 96da2e34d5c7..22f714345f7c 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_entity_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_entity_async.py @@ -16,6 +16,7 @@ from devtools_testutils import AzureTestCase from azure.core import MatchConditions +from azure.core.credentials import AzureSasCredential from azure.core.exceptions import ( HttpResponseError, ResourceNotFoundError, @@ -1613,7 +1614,7 @@ async def test_sas_query(self, tables_storage_account_name, tables_primary_stora # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) entities = [] @@ -1647,7 +1648,7 @@ async def test_sas_add(self, tables_storage_account_name, tables_primary_storage # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) @@ -1682,7 +1683,7 @@ async def test_sas_add_inside_range(self, tables_storage_account_name, tables_pr # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) entity = self._create_random_entity_dict('test', 'test1') @@ -1715,7 +1716,7 @@ async def test_sas_add_outside_range(self, tables_storage_account_name, tables_p # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) with pytest.raises(HttpResponseError): @@ -1746,7 +1747,7 @@ async def test_sas_update(self, tables_storage_account_name, tables_primary_stor # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) updated_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) @@ -1781,7 +1782,7 @@ async def test_sas_delete(self, tables_storage_account_name, tables_primary_stor # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) await table.delete_entity(entity.PartitionKey, entity.RowKey) @@ -1815,7 +1816,7 @@ async def test_sas_upper_case_table_name(self, tables_storage_account_name, tabl # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) entities = [] @@ -1857,7 +1858,7 @@ async def test_sas_signed_identifier(self, tables_storage_account_name, tables_p # Act service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), - credential=token, + credential=AzureSasCredential(token), ) table = service.get_table_client(table_name=self.table_name) entities = []