diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3efc8ea7bc47..b1ff2a9e0396 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -119,7 +119,7 @@ /sdk/translation/ @kristapratico @mohamedshabanofficial # PRLabel: %Tables -/sdk/tables/ @seankane-msft +/sdk/tables/ @annatisch @YalinLi0312 # PRLabel: %Media /sdk/media/ @naiteeks @bennage @giakas diff --git a/sdk/tables/azure-data-tables/CHANGELOG.md b/sdk/tables/azure-data-tables/CHANGELOG.md index 77b2ca167eae..284c5b4577ce 100644 --- a/sdk/tables/azure-data-tables/CHANGELOG.md +++ b/sdk/tables/azure-data-tables/CHANGELOG.md @@ -8,6 +8,8 @@ ### Bugs Fixed +- Resolved bug where strings couldn't be used instead of enum value for entity Update Mode (#20247). + ### Other Changes - Bumped dependency on `msrest` to `>=0.6.21` diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_table_batch.py b/sdk/tables/azure-data-tables/azure/data/tables/_table_batch.py index 89fe84b1117a..83071a71dec0 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_table_batch.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_table_batch.py @@ -261,7 +261,7 @@ def update( partition_key = temp["PartitionKey"] row_key = temp["RowKey"] temp = _add_entity_properties(temp) - if mode is UpdateMode.REPLACE: + if mode == UpdateMode.REPLACE: self._batch_update_entity( table=self.table_name, partition_key=partition_key, @@ -270,7 +270,7 @@ def update( table_entity_properties=temp, **kwargs ) - elif mode is UpdateMode.MERGE: + elif mode == UpdateMode.MERGE: self._batch_merge_entity( table=self.table_name, partition_key=partition_key, @@ -279,6 +279,8 @@ def update( table_entity_properties=temp, **kwargs ) + else: + raise ValueError("Mode type '{}' is not supported.".format(mode)) def _batch_update_entity( self, @@ -668,7 +670,7 @@ def upsert( row_key = temp["RowKey"] temp = _add_entity_properties(temp) - if mode is UpdateMode.MERGE: + if mode == UpdateMode.MERGE: self._batch_merge_entity( table=self.table_name, partition_key=partition_key, @@ -676,7 +678,7 @@ def upsert( table_entity_properties=temp, **kwargs ) - elif mode is UpdateMode.REPLACE: + elif mode == UpdateMode.REPLACE: self._batch_update_entity( table=self.table_name, partition_key=partition_key, @@ -684,3 +686,5 @@ def upsert( table_entity_properties=temp, **kwargs ) + else: + raise ValueError("Mode type '{}' is not supported.".format(mode)) diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_table_client.py b/sdk/tables/azure-data-tables/azure/data/tables/_table_client.py index 14e9e437f461..4821acfc4664 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_table_client.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_table_client.py @@ -466,7 +466,7 @@ def update_entity( try: metadata = None content = None - if mode is UpdateMode.REPLACE: + if mode == UpdateMode.REPLACE: metadata, content = self._client.table.update_entity( # type: ignore table=self.table_name, partition_key=partition_key, @@ -476,7 +476,7 @@ def update_entity( cls=kwargs.pop("cls", _return_headers_and_deserialized), **kwargs ) - elif mode is UpdateMode.MERGE: + elif mode == UpdateMode.MERGE: metadata, content = self._client.table.merge_entity( # type: ignore table=self.table_name, partition_key=partition_key, @@ -487,7 +487,7 @@ def update_entity( **kwargs ) else: - raise ValueError("Mode type is not supported") + raise ValueError("Mode type '{}' is not supported.".format(mode)) except HttpResponseError as error: _process_table_error(error) return _trim_service_metadata(metadata, content=content) # type: ignore @@ -654,7 +654,7 @@ def upsert_entity( try: metadata = None content = None - if mode is UpdateMode.MERGE: + if mode == UpdateMode.MERGE: metadata, content = self._client.table.merge_entity( # type: ignore table=self.table_name, partition_key=partition_key, @@ -663,7 +663,7 @@ def upsert_entity( cls=kwargs.pop("cls", _return_headers_and_deserialized), **kwargs ) - elif mode is UpdateMode.REPLACE: + elif mode == UpdateMode.REPLACE: metadata, content = self._client.table.update_entity( # type: ignore table=self.table_name, partition_key=partition_key, diff --git a/sdk/tables/azure-data-tables/azure/data/tables/aio/_table_batch_async.py b/sdk/tables/azure-data-tables/azure/data/tables/aio/_table_batch_async.py index 4c8e590cdafa..c6a319ddaff9 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/aio/_table_batch_async.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/aio/_table_batch_async.py @@ -233,7 +233,7 @@ def update( partition_key = temp["PartitionKey"] row_key = temp["RowKey"] temp = _add_entity_properties(temp) - if mode is UpdateMode.REPLACE: + if mode == UpdateMode.REPLACE: self._batch_update_entity( table=self.table_name, partition_key=partition_key, @@ -242,7 +242,7 @@ def update( table_entity_properties=temp, **kwargs ) - elif mode is UpdateMode.MERGE: + elif mode == UpdateMode.MERGE: self._batch_merge_entity( table=self.table_name, partition_key=partition_key, @@ -251,6 +251,8 @@ def update( table_entity_properties=temp, **kwargs ) + else: + raise ValueError("Mode type '{}' is not supported.".format(mode)) def _batch_update_entity( self, @@ -631,7 +633,7 @@ def upsert( row_key = temp["RowKey"] temp = _add_entity_properties(temp) - if mode is UpdateMode.MERGE: + if mode == UpdateMode.MERGE: self._batch_merge_entity( table=self.table_name, partition_key=partition_key, @@ -639,7 +641,7 @@ def upsert( table_entity_properties=temp, **kwargs ) - elif mode is UpdateMode.REPLACE: + elif mode == UpdateMode.REPLACE: self._batch_update_entity( table=self.table_name, partition_key=partition_key, @@ -647,3 +649,5 @@ def upsert( table_entity_properties=temp, **kwargs ) + else: + raise ValueError("Mode type '{}' is not supported.".format(mode)) diff --git a/sdk/tables/azure-data-tables/azure/data/tables/aio/_table_client_async.py b/sdk/tables/azure-data-tables/azure/data/tables/aio/_table_client_async.py index 4513b657d9ef..a2b2964d4e29 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/aio/_table_client_async.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/aio/_table_client_async.py @@ -448,7 +448,7 @@ async def update_entity( try: metadata = None content = None - if mode is UpdateMode.REPLACE: + if mode == UpdateMode.REPLACE: metadata, content = await self._client.table.update_entity( # type: ignore table=self.table_name, partition_key=partition_key, @@ -458,7 +458,7 @@ async def update_entity( cls=kwargs.pop("cls", _return_headers_and_deserialized), **kwargs ) - elif mode is UpdateMode.MERGE: + elif mode == UpdateMode.MERGE: metadata, content = await self._client.table.merge_entity( # type: ignore table=self.table_name, partition_key=partition_key, @@ -469,7 +469,7 @@ async def update_entity( **kwargs ) else: - raise ValueError("Mode type is not supported") + raise ValueError("Mode type '{}' is not supported.".format(mode)) except HttpResponseError as error: _process_table_error(error) return _trim_service_metadata(metadata, content=content) # type: ignore @@ -632,7 +632,7 @@ async def upsert_entity( try: metadata = None content = None - if mode is UpdateMode.MERGE: + if mode == UpdateMode.MERGE: metadata, content = await self._client.table.merge_entity( # type: ignore table=self.table_name, partition_key=partition_key, @@ -641,7 +641,7 @@ async def upsert_entity( cls=kwargs.pop("cls", _return_headers_and_deserialized), **kwargs ) - elif mode is UpdateMode.REPLACE: + elif mode == UpdateMode.REPLACE: metadata, content = await self._client.table.update_entity( # type: ignore table=self.table_name, partition_key=partition_key, diff --git a/sdk/tables/azure-data-tables/tests/recordings/test_table_batch.test_batch_with_mode.yaml b/sdk/tables/azure-data-tables/tests/recordings/test_table_batch.test_batch_with_mode.yaml new file mode 100644 index 000000000000..5d32714639bf --- /dev/null +++ b/sdk/tables/azure-data-tables/tests/recordings/test_table_batch.test_batch_with_mode.yaml @@ -0,0 +1,292 @@ +interactions: +- request: + body: '{"TableName": "uttable1ca30ef7"}' + headers: + Accept: + - application/json;odata=minimalmetadata + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '32' + Content-Type: + - application/json;odata=nometadata + DataServiceVersion: + - '3.0' + Date: + - Fri, 13 Aug 2021 15:51:32 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:32 GMT + x-ms-version: + - '2019-02-02' + method: POST + uri: https://fake_table_account.table.core.windows.net/Tables + response: + body: + string: '{"odata.metadata":"https://fake_table_account.table.core.windows.net/$metadata#Tables/@Element","TableName":"uttable1ca30ef7"}' + headers: + cache-control: + - no-cache + content-type: + - application/json;odata=minimalmetadata;streaming=true;charset=utf-8 + date: + - Fri, 13 Aug 2021 15:51:32 GMT + location: + - https://fake_table_account.table.core.windows.net/Tables('uttable1ca30ef7') + 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: 201 + message: Created +- request: + body: '{"TableName": "table21ca30ef7"}' + 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, 13 Aug 2021 15:51:32 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:32 GMT + x-ms-version: + - '2019-02-02' + method: POST + uri: https://fake_table_account.table.core.windows.net/Tables + response: + body: + string: '{"odata.metadata":"https://fake_table_account.table.core.windows.net/$metadata#Tables/@Element","TableName":"table21ca30ef7"}' + headers: + cache-control: + - no-cache + content-type: + - application/json;odata=minimalmetadata;streaming=true;charset=utf-8 + date: + - Fri, 13 Aug 2021 15:51:32 GMT + location: + - https://fake_table_account.table.core.windows.net/Tables('table21ca30ef7') + 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: 201 + message: Created +- request: + body: "--batch_736b8e4d-b1b6-4cee-8285-06891044a4f0\r\nContent-Type: multipart/mixed; + boundary=changeset_82fbf594-7f1c-4890-ab65-bddeb3232afb\r\n\r\n--changeset_82fbf594-7f1c-4890-ab65-bddeb3232afb\r\nContent-Type: + application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 0\r\n\r\nPATCH + https://pytestremote.table.core.windows.net/uttable1ca30ef7(PartitionKey='pk001',RowKey='rk001') + HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nContent-Type: + application/json\r\nAccept: application/json\r\nContent-Length: 231\r\nx-ms-date: + Fri, 13 Aug 2021 15:51:32 GMT\r\nDate: Fri, 13 Aug 2021 15:51:32 GMT\r\n\r\n{\"PartitionKey\": + \"pk001\", \"PartitionKey@odata.type\": \"Edm.String\", \"RowKey\": \"rk001\", + \"RowKey@odata.type\": \"Edm.String\", \"Value\": 1, \"day\": \"Monday\", \"day@odata.type\": + \"Edm.String\", \"float\": 1.001, \"float@odata.type\": \"Edm.Double\"}\r\n--changeset_82fbf594-7f1c-4890-ab65-bddeb3232afb\r\nContent-Type: + application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 1\r\n\r\nPUT + https://pytestremote.table.core.windows.net/uttable1ca30ef7(PartitionKey='pk001',RowKey='rk002') + HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nContent-Type: + application/json\r\nAccept: application/json\r\nContent-Length: 231\r\nx-ms-date: + Fri, 13 Aug 2021 15:51:32 GMT\r\nDate: Fri, 13 Aug 2021 15:51:32 GMT\r\n\r\n{\"PartitionKey\": + \"pk001\", \"PartitionKey@odata.type\": \"Edm.String\", \"RowKey\": \"rk002\", + \"RowKey@odata.type\": \"Edm.String\", \"Value\": 1, \"day\": \"Monday\", \"day@odata.type\": + \"Edm.String\", \"float\": 1.001, \"float@odata.type\": \"Edm.Double\"}\r\n--changeset_82fbf594-7f1c-4890-ab65-bddeb3232afb--\r\n\r\n--batch_736b8e4d-b1b6-4cee-8285-06891044a4f0--\r\n" + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '1618' + Content-Type: + - multipart/mixed; boundary=batch_736b8e4d-b1b6-4cee-8285-06891044a4f0 + DataServiceVersion: + - '3.0' + Date: + - Fri, 13 Aug 2021 15:51:32 GMT + MaxDataServiceVersion: + - 3.0;NetFx + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:32 GMT + x-ms-version: + - '2019-02-02' + method: POST + uri: https://fake_table_account.table.core.windows.net/$batch + response: + body: + string: "--batchresponse_402b5216-258f-466f-8036-4d5da49543d2\r\nContent-Type: + multipart/mixed; boundary=changesetresponse_d8a05621-36ea-459c-be11-193ddd020a77\r\n\r\n--changesetresponse_d8a05621-36ea-459c-be11-193ddd020a77\r\nContent-Type: + application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nHTTP/1.1 204 + No Content\r\nX-Content-Type-Options: nosniff\r\nCache-Control: no-cache\r\nDataServiceVersion: + 1.0;\r\nETag: W/\"datetime'2021-08-13T15%3A51%3A32.9675797Z'\"\r\n\r\n\r\n--changesetresponse_d8a05621-36ea-459c-be11-193ddd020a77\r\nContent-Type: + application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nHTTP/1.1 204 + No Content\r\nX-Content-Type-Options: nosniff\r\nCache-Control: no-cache\r\nDataServiceVersion: + 1.0;\r\nETag: W/\"datetime'2021-08-13T15%3A51%3A32.9685804Z'\"\r\n\r\n\r\n--changesetresponse_d8a05621-36ea-459c-be11-193ddd020a77--\r\n--batchresponse_402b5216-258f-466f-8036-4d5da49543d2--\r\n" + headers: + cache-control: + - no-cache + content-type: + - multipart/mixed; boundary=batchresponse_402b5216-258f-466f-8036-4d5da49543d2 + date: + - Fri, 13 Aug 2021 15:51:32 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: 202 + message: Accepted +- request: + body: null + headers: + Accept: + - application/json;odata=minimalmetadata + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + DataServiceVersion: + - '3.0' + Date: + - Fri, 13 Aug 2021 15:51:32 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:32 GMT + x-ms-version: + - '2019-02-02' + method: GET + uri: https://fake_table_account.table.core.windows.net/Tables + response: + body: + string: '{"odata.metadata":"https://fake_table_account.table.core.windows.net/$metadata#Tables","value":[{"TableName":"table21ca30ef7"},{"TableName":"uttable1ca30ef7"}]}' + headers: + cache-control: + - no-cache + content-type: + - application/json;odata=minimalmetadata;streaming=true;charset=utf-8 + date: + - Fri, 13 Aug 2021 15:51:33 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: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + Date: + - Fri, 13 Aug 2021 15:51:33 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:33 GMT + x-ms-version: + - '2019-02-02' + method: DELETE + uri: https://fake_table_account.table.core.windows.net/Tables('table21ca30ef7') + response: + body: + string: '' + headers: + cache-control: + - no-cache + content-length: + - '0' + date: + - Fri, 13 Aug 2021 15:51:33 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 +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + Date: + - Fri, 13 Aug 2021 15:51:33 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:33 GMT + x-ms-version: + - '2019-02-02' + method: DELETE + uri: https://fake_table_account.table.core.windows.net/Tables('uttable1ca30ef7') + response: + body: + string: '' + headers: + cache-control: + - no-cache + content-length: + - '0' + date: + - Fri, 13 Aug 2021 15:51:33 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/recordings/test_table_batch_async.test_batch_with_mode.yaml b/sdk/tables/azure-data-tables/tests/recordings/test_table_batch_async.test_batch_with_mode.yaml new file mode 100644 index 000000000000..4af38339577d --- /dev/null +++ b/sdk/tables/azure-data-tables/tests/recordings/test_table_batch_async.test_batch_with_mode.yaml @@ -0,0 +1,228 @@ +interactions: +- request: + body: '{"TableName": "uttable80af1174"}' + headers: + Accept: + - application/json;odata=minimalmetadata + Content-Length: + - '32' + Content-Type: + - application/json;odata=nometadata + DataServiceVersion: + - '3.0' + Date: + - Fri, 13 Aug 2021 15:51:43 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:43 GMT + x-ms-version: + - '2019-02-02' + method: POST + uri: https://fake_table_account.table.core.windows.net/Tables + response: + body: + string: '{"odata.metadata":"https://fake_table_account.table.core.windows.net/$metadata#Tables/@Element","TableName":"uttable80af1174"}' + headers: + cache-control: no-cache + content-type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8 + date: Fri, 13 Aug 2021 15:51:42 GMT + location: https://fake_table_account.table.core.windows.net/Tables('uttable80af1174') + 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: 201 + message: Created + url: https://pytestremote.table.core.windows.net/Tables +- request: + body: '{"TableName": "table280af1174"}' + headers: + Accept: + - application/json;odata=minimalmetadata + Content-Length: + - '31' + Content-Type: + - application/json;odata=nometadata + DataServiceVersion: + - '3.0' + Date: + - Fri, 13 Aug 2021 15:51:43 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:43 GMT + x-ms-version: + - '2019-02-02' + method: POST + uri: https://fake_table_account.table.core.windows.net/Tables + response: + body: + string: '{"odata.metadata":"https://fake_table_account.table.core.windows.net/$metadata#Tables/@Element","TableName":"table280af1174"}' + headers: + cache-control: no-cache + content-type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8 + date: Fri, 13 Aug 2021 15:51:42 GMT + location: https://fake_table_account.table.core.windows.net/Tables('table280af1174') + 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: 201 + message: Created + url: https://pytestremote.table.core.windows.net/Tables +- request: + body: "--batch_331ceef8-6b4f-44f3-af14-1d89bd5141c3\r\nContent-Type: multipart/mixed; + boundary=changeset_5af4fc18-4d1a-41d2-8c20-f3402d9a61a4\r\n\r\n--changeset_5af4fc18-4d1a-41d2-8c20-f3402d9a61a4\r\nContent-Type: + application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 0\r\n\r\nPATCH + https://pytestremote.table.core.windows.net/uttable80af1174(PartitionKey='pk001',RowKey='rk001') + HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nContent-Type: + application/json\r\nAccept: application/json\r\nContent-Length: 231\r\nx-ms-date: + Fri, 13 Aug 2021 15:51:43 GMT\r\nDate: Fri, 13 Aug 2021 15:51:43 GMT\r\n\r\n{\"PartitionKey\": + \"pk001\", \"PartitionKey@odata.type\": \"Edm.String\", \"RowKey\": \"rk001\", + \"RowKey@odata.type\": \"Edm.String\", \"Value\": 1, \"day\": \"Monday\", \"day@odata.type\": + \"Edm.String\", \"float\": 1.001, \"float@odata.type\": \"Edm.Double\"}\r\n--changeset_5af4fc18-4d1a-41d2-8c20-f3402d9a61a4\r\nContent-Type: + application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 1\r\n\r\nPUT + https://pytestremote.table.core.windows.net/uttable80af1174(PartitionKey='pk001',RowKey='rk002') + HTTP/1.1\r\nx-ms-version: 2019-02-02\r\nDataServiceVersion: 3.0\r\nContent-Type: + application/json\r\nAccept: application/json\r\nContent-Length: 231\r\nx-ms-date: + Fri, 13 Aug 2021 15:51:43 GMT\r\nDate: Fri, 13 Aug 2021 15:51:43 GMT\r\n\r\n{\"PartitionKey\": + \"pk001\", \"PartitionKey@odata.type\": \"Edm.String\", \"RowKey\": \"rk002\", + \"RowKey@odata.type\": \"Edm.String\", \"Value\": 1, \"day\": \"Monday\", \"day@odata.type\": + \"Edm.String\", \"float\": 1.001, \"float@odata.type\": \"Edm.Double\"}\r\n--changeset_5af4fc18-4d1a-41d2-8c20-f3402d9a61a4--\r\n\r\n--batch_331ceef8-6b4f-44f3-af14-1d89bd5141c3--\r\n" + headers: + Accept: + - application/json + Content-Length: + - '1618' + Content-Type: + - multipart/mixed; boundary=batch_331ceef8-6b4f-44f3-af14-1d89bd5141c3 + DataServiceVersion: + - '3.0' + Date: + - Fri, 13 Aug 2021 15:51:43 GMT + MaxDataServiceVersion: + - 3.0;NetFx + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:43 GMT + x-ms-version: + - '2019-02-02' + method: POST + uri: https://fake_table_account.table.core.windows.net/$batch + response: + body: + string: "--batchresponse_694a648a-8c87-4a80-a302-b426b5e31170\r\nContent-Type: + multipart/mixed; boundary=changesetresponse_a8badf0a-0c7d-4ff0-ac6b-0e6970a9541a\r\n\r\n--changesetresponse_a8badf0a-0c7d-4ff0-ac6b-0e6970a9541a\r\nContent-Type: + application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nHTTP/1.1 204 + No Content\r\nX-Content-Type-Options: nosniff\r\nCache-Control: no-cache\r\nDataServiceVersion: + 1.0;\r\nETag: W/\"datetime'2021-08-13T15%3A51%3A43.6900767Z'\"\r\n\r\n\r\n--changesetresponse_a8badf0a-0c7d-4ff0-ac6b-0e6970a9541a\r\nContent-Type: + application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nHTTP/1.1 204 + No Content\r\nX-Content-Type-Options: nosniff\r\nCache-Control: no-cache\r\nDataServiceVersion: + 1.0;\r\nETag: W/\"datetime'2021-08-13T15%3A51%3A43.6900767Z'\"\r\n\r\n\r\n--changesetresponse_a8badf0a-0c7d-4ff0-ac6b-0e6970a9541a--\r\n--batchresponse_694a648a-8c87-4a80-a302-b426b5e31170--\r\n" + headers: + cache-control: no-cache + content-type: multipart/mixed; boundary=batchresponse_694a648a-8c87-4a80-a302-b426b5e31170 + date: Fri, 13 Aug 2021 15:51:43 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: 202 + message: Accepted + url: https://pytestremote.table.core.windows.net/$batch +- request: + body: null + headers: + Accept: + - application/json;odata=minimalmetadata + DataServiceVersion: + - '3.0' + Date: + - Fri, 13 Aug 2021 15:51:43 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:43 GMT + x-ms-version: + - '2019-02-02' + method: GET + uri: https://fake_table_account.table.core.windows.net/Tables + response: + body: + string: '{"odata.metadata":"https://fake_table_account.table.core.windows.net/$metadata#Tables","value":[{"TableName":"table280af1174"},{"TableName":"uttable80af1174"}]}' + headers: + cache-control: no-cache + content-type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8 + date: Fri, 13 Aug 2021 15:51:43 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: 200 + message: OK + url: https://pytestremote.table.core.windows.net/Tables +- request: + body: null + headers: + Accept: + - application/json + Date: + - Fri, 13 Aug 2021 15:51:43 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:43 GMT + x-ms-version: + - '2019-02-02' + method: DELETE + uri: https://fake_table_account.table.core.windows.net/Tables('table280af1174') + response: + body: + string: '' + headers: + cache-control: no-cache + content-length: '0' + date: Fri, 13 Aug 2021 15:51: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 + url: https://pytestremote.table.core.windows.net/Tables('table280af1174') +- request: + body: null + headers: + Accept: + - application/json + Date: + - Fri, 13 Aug 2021 15:51:43 GMT + User-Agent: + - azsdk-python-data-tables/12.1.1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + x-ms-date: + - Fri, 13 Aug 2021 15:51:43 GMT + x-ms-version: + - '2019-02-02' + method: DELETE + uri: https://fake_table_account.table.core.windows.net/Tables('uttable80af1174') + response: + body: + string: '' + headers: + cache-control: no-cache + content-length: '0' + date: Fri, 13 Aug 2021 15:51: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 + url: https://pytestremote.table.core.windows.net/Tables('uttable80af1174') +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 fca3e2ae0489..7d4a0f9806c4 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_batch.py +++ b/sdk/tables/azure-data-tables/tests/test_table_batch.py @@ -768,3 +768,47 @@ def test_batch_request_too_large(self, tables_storage_account_name, tables_prima finally: self._tear_down() + + @pytest.mark.skipif(sys.version_info < (3, 0), reason="requires Python3") + @tables_decorator + def test_batch_with_mode(self, tables_storage_account_name, tables_primary_storage_account_key): + # Arrange + self._set_up(tables_storage_account_name, tables_primary_storage_account_key) + try: + table2_name = self._get_table_reference('table2') + table2 = self.ts.get_table_client(table2_name) + table2.create_table() + + # Act + entity1 = { + "PartitionKey": "pk001", + "RowKey": "rk001", + "Value": 1, + "day": "Monday", + "float": 1.001 + } + entity2 = { + "PartitionKey": "pk001", + "RowKey": "rk002", + "Value": 1, + "day": "Monday", + "float": 1.001 + } + + + batch = [ + ("upsert", entity1, {"mode": "merge"}), + ("upsert", entity2, {"mode": "replace"}) + ] + + resp = self.table.submit_transaction(batch) + assert len(resp) == 2 + + with pytest.raises(ValueError): + batch = [ + ("upsert", entity1, {"mode": "foo"}), + ("upsert", entity2, {"mode": "bar"}) + ] + self.table.submit_transaction(batch) + finally: + self._tear_down() 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 b965d26d487c..4cfc025c55fa 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 @@ -648,3 +648,47 @@ async def test_delete_batch_with_bad_kwarg(self, tables_storage_account_name, ta finally: await self._tear_down() + @pytest.mark.skipif(sys.version_info < (3, 0), reason="requires Python3") + @tables_decorator_async + async def test_batch_with_mode(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: + table2_name = self._get_table_reference('table2') + table2 = self.ts.get_table_client(table2_name) + await table2.create_table() + + # Act + entity1 = { + "PartitionKey": "pk001", + "RowKey": "rk001", + "Value": 1, + "day": "Monday", + "float": 1.001 + } + entity2 = { + "PartitionKey": "pk001", + "RowKey": "rk002", + "Value": 1, + "day": "Monday", + "float": 1.001 + } + + + batch = [ + ("upsert", entity1, {"mode": "merge"}), + ("upsert", entity2, {"mode": "replace"}) + ] + + resp = await self.table.submit_transaction(batch) + assert len(resp) == 2 + + with pytest.raises(ValueError): + batch = [ + ("upsert", entity1, {"mode": "foo"}), + ("upsert", entity2, {"mode": "bar"}) + ] + await self.table.submit_transaction(batch) + + finally: + await self._tear_down()