Skip to content

Commit 5b0b727

Browse files
author
Yalin Li
authored
Add batch tests (Azure#31788)
1 parent e857bd3 commit 5b0b727

File tree

6 files changed

+108
-3
lines changed

6 files changed

+108
-3
lines changed

sdk/tables/azure-data-tables/tests/test_table_batch.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from azure.core import MatchConditions
1515
from azure.core.pipeline.policies import HTTPPolicy
1616
from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential
17-
from azure.core.exceptions import ResourceNotFoundError, ClientAuthenticationError
17+
from azure.core.exceptions import ResourceNotFoundError, ClientAuthenticationError, HttpResponseError
1818
from azure.data.tables import (
1919
EdmType,
2020
EntityProperty,
@@ -965,6 +965,30 @@ def test_batch_with_specialchar_partitionkey(self, tables_storage_account_name,
965965
finally:
966966
self._tear_down()
967967

968+
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
969+
@pytest.mark.live_test_only
970+
@tables_decorator
971+
@recorded_by_proxy
972+
def test_client_with_url_ends_with_table_name(
973+
self, tables_storage_account_name, tables_primary_storage_account_key
974+
):
975+
url = self.account_url(tables_storage_account_name, "table")
976+
table_name = self.get_resource_name("mytable")
977+
invalid_url = url + "/" + table_name
978+
entity = {"PartitionKey": "test-partition", "RowKey": "test-key", "name": "test-name"}
979+
980+
valid_tc = TableClient(url, table_name, credential=tables_primary_storage_account_key)
981+
valid_tc.create_table()
982+
983+
tc = TableClient(invalid_url, table_name, credential=tables_primary_storage_account_key)
984+
with pytest.raises(HttpResponseError) as ex:
985+
tc.submit_transaction([("upsert", entity)])
986+
assert "None of the provided media types are supported" in str(ex.value)
987+
assert ex.value.error_code == "MediaTypeNotSupported"
988+
assert ex.value.status_code == 415
989+
990+
valid_tc.delete_table()
991+
968992

969993
class RequestCorrect(Exception):
970994
pass

sdk/tables/azure-data-tables/tests/test_table_batch_async.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from azure.core import MatchConditions
1818
from azure.core.pipeline.policies import AsyncHTTPPolicy
1919
from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential
20-
from azure.core.exceptions import ResourceNotFoundError, ClientAuthenticationError
20+
from azure.core.exceptions import ResourceNotFoundError, ClientAuthenticationError, HttpResponseError
2121
from azure.data.tables.aio import TableServiceClient, TableClient
2222
from azure.data.tables import (
2323
TableEntity,
@@ -889,6 +889,32 @@ async def generate_entities(count):
889889
finally:
890890
await self._tear_down()
891891

892+
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
893+
@pytest.mark.live_test_only
894+
@tables_decorator_async
895+
@recorded_by_proxy_async
896+
async def test_client_with_url_ends_with_table_name(
897+
self, tables_storage_account_name, tables_primary_storage_account_key
898+
):
899+
url = self.account_url(tables_storage_account_name, "table")
900+
table_name = self.get_resource_name("mytable")
901+
invalid_url = url + "/" + table_name
902+
entity = {"PartitionKey": "test-partition", "RowKey": "test-key", "name": "test-name"}
903+
904+
valid_tc = TableClient(url, table_name, credential=tables_primary_storage_account_key)
905+
await valid_tc.create_table()
906+
907+
tc = TableClient(invalid_url, table_name, credential=tables_primary_storage_account_key)
908+
with pytest.raises(HttpResponseError) as ex:
909+
await tc.submit_transaction([("upsert", entity)])
910+
assert "None of the provided media types are supported" in str(ex.value)
911+
assert ex.value.error_code == "MediaTypeNotSupported"
912+
assert ex.value.status_code == 415
913+
914+
await valid_tc.delete_table()
915+
await valid_tc.close()
916+
await tc.close()
917+
892918

893919
class RequestCorrect(Exception):
894920
pass

sdk/tables/azure-data-tables/tests/test_table_batch_cosmos.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from azure.core import MatchConditions
1515
from azure.core.credentials import AzureSasCredential
16-
from azure.core.exceptions import ResourceNotFoundError
16+
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError
1717
from azure.data.tables import (
1818
EdmType,
1919
EntityProperty,
@@ -690,6 +690,28 @@ def test_batch_with_specialchar_partitionkey(self, tables_cosmos_account_name, t
690690
finally:
691691
self._tear_down()
692692

693+
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
694+
@pytest.mark.live_test_only
695+
@cosmos_decorator
696+
@recorded_by_proxy
697+
def test_client_with_url_ends_with_table_name(self, tables_cosmos_account_name, tables_primary_cosmos_account_key):
698+
url = self.account_url(tables_cosmos_account_name, "cosmos")
699+
table_name = self.get_resource_name("mytable")
700+
invalid_url = url + "/" + table_name
701+
entity = {"PartitionKey": "test-partition", "RowKey": "test-key", "name": "test-name"}
702+
703+
valid_tc = TableClient(url, table_name, credential=tables_primary_cosmos_account_key)
704+
valid_tc.create_table()
705+
706+
tc = TableClient(invalid_url, table_name, credential=tables_primary_cosmos_account_key)
707+
with pytest.raises(HttpResponseError) as ex:
708+
tc.submit_transaction([("upsert", entity)])
709+
assert "Request url is invalid" in str(ex.value)
710+
assert ex.value.error_code == "InvalidInput"
711+
assert ex.value.status_code == 400
712+
713+
valid_tc.delete_table()
714+
693715

694716
class TestBatchCosmosUnitTests(TableTestCase):
695717
tables_cosmos_account_name = "fake_cosmos_account"

sdk/tables/azure-data-tables/tests/test_table_batch_cosmos_async.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from azure.core.exceptions import (
1818
ResourceNotFoundError,
1919
ClientAuthenticationError,
20+
HttpResponseError,
2021
)
2122
from azure.data.tables.aio import TableServiceClient, TableClient
2223
from azure.data.tables import (
@@ -796,6 +797,32 @@ async def generate_entities(count):
796797
finally:
797798
await self._tear_down()
798799

800+
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
801+
@pytest.mark.live_test_only
802+
@cosmos_decorator_async
803+
@recorded_by_proxy_async
804+
async def test_client_with_url_ends_with_table_name(
805+
self, tables_cosmos_account_name, tables_primary_cosmos_account_key
806+
):
807+
url = self.account_url(tables_cosmos_account_name, "cosmos")
808+
table_name = self.get_resource_name("mytable")
809+
invalid_url = url + "/" + table_name
810+
entity = {"PartitionKey": "test-partition", "RowKey": "test-key", "name": "test-name"}
811+
812+
valid_tc = TableClient(url, table_name, credential=tables_primary_cosmos_account_key)
813+
await valid_tc.create_table()
814+
815+
tc = TableClient(invalid_url, table_name, credential=tables_primary_cosmos_account_key)
816+
with pytest.raises(HttpResponseError) as ex:
817+
await tc.submit_transaction([("upsert", entity)])
818+
assert "Request url is invalid" in str(ex.value)
819+
assert ex.value.error_code == "InvalidInput"
820+
assert ex.value.status_code == 400
821+
822+
await valid_tc.delete_table()
823+
await valid_tc.close()
824+
await tc.close()
825+
799826

800827
class TestBatchCosmosAsyncUnitTests(AsyncTableTestCase):
801828
tables_cosmos_account_name = "fake_cosmos_account"

sdk/tables/azure-data-tables/tests/test_table_client_async.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ async def test_client_with_url_ends_with_table_name(
191191
assert ("URI does not match number of key properties for the resource") in str(exc.value)
192192
assert ("Please check your account URL.") in str(exc.value)
193193
await valid_tc.delete_table()
194+
await valid_tc.close()
195+
await tc.close()
196+
await tc2.close()
194197

195198
@tables_decorator_async
196199
@recorded_by_proxy_async

sdk/tables/azure-data-tables/tests/test_table_cosmos_async.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,6 @@ async def test_client_with_url_ends_with_table_name(
276276
assert ("Request url is invalid") in str(exc.value)
277277
assert ("Please check your account URL.") in str(exc.value)
278278
await valid_tc.delete_table()
279+
await valid_tc.close()
280+
await tc.close()
281+
await tc2.close()

0 commit comments

Comments
 (0)