diff --git a/sdk/tables/azure-data-tables/tests/_shared/asynctestcase.py b/sdk/tables/azure-data-tables/tests/_shared/asynctestcase.py index feabcbe3944b..b519d0976731 100644 --- a/sdk/tables/azure-data-tables/tests/_shared/asynctestcase.py +++ b/sdk/tables/azure-data-tables/tests/_shared/asynctestcase.py @@ -1,18 +1,35 @@ - # coding: utf-8 # ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +from __future__ import division +from datetime import datetime +from dateutil.tz import tzutc +import uuid + from azure.core.credentials import AccessToken +from azure.core.exceptions import ResourceExistsError +from azure.data.tables import ( + EntityProperty, + EdmType, + TableServiceClient, +) + +from devtools_testutils import is_live + +from .testcase import TableTestCase, SLEEP_DELAY + + +TEST_TABLE_PREFIX = "pytableasync" -from .testcase import TableTestCase class AsyncFakeTokenCredential(object): """Protocol for classes able to provide OAuth tokens. :param str scopes: Lets you specify the type of access needed. """ + def __init__(self): self.token = AccessToken("YOU SHALL NOT PASS", 0) @@ -21,6 +38,95 @@ async def get_token(self, *args): class AsyncTableTestCase(TableTestCase): - def generate_fake_token(self): return AsyncFakeTokenCredential() + + def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): + table_name = self.get_resource_name(prefix) + return table_name + + async def _create_table(self, ts, prefix=TEST_TABLE_PREFIX, table_list=None): + table_name = self._get_table_reference(prefix) + try: + table = await ts.create_table(table_name) + if table_list is not None: + table_list.append(table) + except ResourceExistsError: + table = ts.get_table_client(table_name) + return table + + async def _delete_all_tables(self, account_name, key): + client = TableServiceClient(self.account_url(account_name, "cosmos"), key) + async for table in client.list_tables(): + await client.delete_table(table.name) + + if self.is_live: + self.sleep(10) + + async def _tear_down(self): + if is_live(): + async for table in self.ts.list_tables(): + await self.ts.delete_table(table.name) + if self.ts._cosmos_endpoint: + self.sleep(SLEEP_DELAY) + self.test_tables = [] + await self.ts.close() + + async def _create_query_table(self, entity_count): + """ + Creates a table with the specified name and adds entities with the + default set of values. PartitionKey is set to 'MyPartition' and RowKey + is set to a unique counter value starting at 1 (as a string). + """ + table_name = self.get_resource_name("querytable") + table = await self.ts.create_table(table_name) + self.query_tables.append(table_name) + client = self.ts.get_table_client(table_name) + entity = self._create_random_entity_dict() + for i in range(1, entity_count + 1): + entity["RowKey"] = entity["RowKey"] + str(i) + await client.create_entity(entity=entity) + return client + + async def _insert_two_opposite_entities(self, pk=None, rk=None): + entity1 = self._create_random_entity_dict() + resp = await self.table.create_entity(entity1) + + partition, row = self._create_pk_rk(pk, rk) + properties = { + "PartitionKey": partition + u"1", + "RowKey": row + u"1", + "age": 49, + "sex": u"female", + "married": False, + "deceased": True, + "optional": None, + "ratio": 5.2, + "evenratio": 6.0, + "large": 39999011, + "Birthday": datetime(1993, 4, 1, tzinfo=tzutc()), + "birthday": datetime(1990, 4, 1, tzinfo=tzutc()), + "binary": b"binary-binary", + "other": EntityProperty(40, EdmType.INT32), + "clsid": uuid.UUID("c8da6455-213e-42d9-9b79-3f9149a57833"), + } + await self.table.create_entity(properties) + return entity1, resp + + async def _insert_random_entity(self, pk=None, rk=None): + entity = self._create_random_entity_dict(pk, rk) + metadata = await self.table.create_entity(entity=entity) + return entity, metadata["etag"] + + async def _set_up(self, account_name, account_key, url="table"): + account_url = self.account_url(account_name, url) + self.ts = TableServiceClient(account_url, account_key) + self.table_name = self.get_resource_name("uttable") + self.table = self.ts.get_table_client(self.table_name) + if self.is_live: + try: + await self.ts.create_table(table_name=self.table_name) + except ResourceExistsError: + pass + + self.query_tables = [] diff --git a/sdk/tables/azure-data-tables/tests/_shared/testcase.py b/sdk/tables/azure-data-tables/tests/_shared/testcase.py index 19ab9d6279f1..28be31dbce15 100644 --- a/sdk/tables/azure-data-tables/tests/_shared/testcase.py +++ b/sdk/tables/azure-data-tables/tests/_shared/testcase.py @@ -5,27 +5,37 @@ # license information. # -------------------------------------------------------------------------- from __future__ import division -from contextlib import contextmanager -import os +from base64 import b64encode from datetime import datetime, timedelta -import string -import logging +from dateutil.tz import tzutc +import uuid -import pytest - -from devtools_testutils import AzureTestCase from azure.core.credentials import AccessToken, AzureNamedKeyCredential -from azure.data.tables import generate_account_sas, AccountSasPermissions, ResourceTypes +from azure.core.exceptions import ResourceExistsError +from azure.data.tables import ( + generate_account_sas, + AccountSasPermissions, + ResourceTypes, + EntityProperty, + EdmType, + TableEntity, + TableAnalyticsLogging, + Metrics, + TableServiceClient, +) -LOGGING_FORMAT = '%(asctime)s %(name)-20s %(levelname)-5s %(message)s' +from devtools_testutils import is_live SLEEP_DELAY = 30 +TEST_TABLE_PREFIX = "pytablesync" + class FakeTokenCredential(object): """Protocol for classes able to provide OAuth tokens. :param str scopes: Lets you specify the type of access needed. """ + def __init__(self): self.token = AccessToken("YOU SHALL NOT PASS", 0) @@ -34,9 +44,14 @@ def get_token(self, *args): class TableTestCase(object): - def connection_string(self, account, key): - return "DefaultEndpointsProtocol=https;AccountName=" + account + ";AccountKey=" + str(key) + ";EndpointSuffix=core.windows.net" + return ( + "DefaultEndpointsProtocol=https;AccountName=" + + account + + ";AccountKey=" + + str(key) + + ";EndpointSuffix=core.windows.net" + ) def account_url(self, account, endpoint_type): """Return an url of storage account. @@ -49,28 +64,374 @@ def account_url(self, account, endpoint_type): return account.primary_endpoints.table.rstrip("/") if endpoint_type == "cosmos": return "https://{}.table.cosmos.azure.com".format(account.name) - else: - raise ValueError("Unknown storage type {}".format(storage_type)) - except AttributeError: # Didn't find "primary_endpoints" + except AttributeError: # Didn't find "primary_endpoints" if endpoint_type == "table": - return 'https://{}.{}.core.windows.net'.format(account, endpoint_type) + return "https://{}.{}.core.windows.net".format(account, endpoint_type) if endpoint_type == "cosmos": return "https://{}.table.cosmos.azure.com".format(account) def generate_sas_token(self): - fake_key = 'a'*30 + 'b'*30 - - return '?' + generate_account_sas( - credential = AzureNamedKeyCredential(name="fakename", key=fake_key), - resource_types = ResourceTypes(object=True), - permission = AccountSasPermissions(read=True,list=True), - start = datetime.now() - timedelta(hours = 24), - expiry = datetime.now() + timedelta(days = 8) + fake_key = "a" * 30 + "b" * 30 + + return "?" + generate_account_sas( + credential=AzureNamedKeyCredential(name="fakename", key=fake_key), + resource_types=ResourceTypes(object=True), + permission=AccountSasPermissions(read=True, list=True), + start=datetime.now() - timedelta(hours=24), + expiry=datetime.now() + timedelta(days=8), ) def generate_fake_token(self): return FakeTokenCredential() + def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): + table_name = self.get_resource_name(prefix) + return table_name + + def _create_table(self, ts, prefix=TEST_TABLE_PREFIX, table_list=None): + table_name = self._get_table_reference(prefix) + try: + table = ts.create_table(table_name) + if table_list is not None: + table_list.append(table) + except ResourceExistsError: + table = ts.get_table_client(table_name) + return table + + def _delete_all_tables(self, ts): + for table in ts.list_tables(): + ts.delete_table(table.name) + + def _create_pk_rk(self, pk, rk): + try: + pk = pk if pk is not None else self.get_resource_name("pk").decode("utf-8") + rk = rk if rk is not None else self.get_resource_name("rk").decode("utf-8") + except AttributeError: + pk = pk if pk is not None else self.get_resource_name("pk") + rk = rk if rk is not None else self.get_resource_name("rk") + return pk, rk + + def _create_random_base_entity_dict(self): + """ + Creates a dict-based entity with only pk and rk. + """ + partition, row = self._create_pk_rk(None, None) + return { + "PartitionKey": partition, + "RowKey": row, + } + + def _create_random_entity_dict(self, pk=None, rk=None): + """ + Creates a dictionary-based entity with fixed values, using all + of the supported data types. + """ + partition, row = self._create_pk_rk(pk, rk) + properties = { + "PartitionKey": partition, + "RowKey": row, + "age": 39, + "sex": u"male", + "married": True, + "deceased": False, + "optional": None, + "ratio": 3.1, + "evenratio": 3.0, + "large": 933311100, + "Birthday": datetime(1973, 10, 4, tzinfo=tzutc()), + "birthday": datetime(1970, 10, 4, tzinfo=tzutc()), + "binary": b"binary", + "other": EntityProperty(20, EdmType.INT32), + "clsid": uuid.UUID("c9da6455-213d-42c9-9a79-3e9149a57833"), + } + return TableEntity(**properties) + + def _create_updated_entity_dict(self, partition, row): + """ + Creates a dictionary-based entity with fixed values, with a + different set of values than the default entity. It + adds fields, changes field values, changes field types, + and removes fields when compared to the default entity. + """ + return { + "PartitionKey": partition, + "RowKey": row, + "age": u"abc", + "sex": u"female", + "sign": u"aquarius", + "birthday": datetime(1991, 10, 4, tzinfo=tzutc()), + } + + def _assert_default_entity(self, entity): + """ + Asserts that the entity passed in matches the default entity. + """ + assert entity["age"] == 39 + assert entity["sex"] == "male" + assert entity["married"] == True + assert entity["deceased"] == False + assert not "optional" in entity + assert entity["ratio"] == 3.1 + assert entity["evenratio"] == 3.0 + assert entity["large"] == 933311100 + assert entity["Birthday"] == datetime(1973, 10, 4, tzinfo=tzutc()) + assert entity["birthday"] == datetime(1970, 10, 4, tzinfo=tzutc()) + assert entity["binary"].value == b"binary" + assert entity["other"] == 20 + assert entity["clsid"] == uuid.UUID("c9da6455-213d-42c9-9a79-3e9149a57833") + assert entity.metadata["etag"] + assert entity.metadata["timestamp"] + + def _assert_default_entity_json_full_metadata(self, entity, headers=None): + """ + Asserts that the entity passed in matches the default entity. + """ + assert entity["age"] == 39 + assert entity["sex"] == "male" + assert entity["married"] == True + assert entity["deceased"] == False + assert not "optional" in entity + assert not "aquarius" in entity + assert entity["ratio"] == 3.1 + assert entity["evenratio"] == 3.0 + assert entity["large"] == 933311100 + assert entity["Birthday"] == datetime(1973, 10, 4, tzinfo=tzutc()) + assert entity["birthday"] == datetime(1970, 10, 4, tzinfo=tzutc()) + assert entity["binary"].value == b"binary" + assert entity["other"] == 20 + assert entity["clsid"] == uuid.UUID("c9da6455-213d-42c9-9a79-3e9149a57833") + assert entity.metadata["etag"] + assert entity.metadata["timestamp"] + + def _assert_default_entity_json_no_metadata(self, entity, headers=None): + """ + Asserts that the entity passed in matches the default entity. + """ + assert entity["age"] == 39 + assert entity["sex"] == "male" + assert entity["married"] == True + assert entity["deceased"] == False + assert not "optional" in entity + assert not "aquarius" in entity + assert entity["ratio"] == 3.1 + assert entity["evenratio"] == 3.0 + assert entity["large"] == 933311100 + assert entity["Birthday"].startswith("1973-10-04T00:00:00") + assert entity["birthday"].startswith("1970-10-04T00:00:00") + assert entity["Birthday"].endswith("00Z") + assert entity["birthday"].endswith("00Z") + assert entity["binary"] == b64encode(b"binary").decode("utf-8") + assert entity["other"] == 20 + assert entity["clsid"] == "c9da6455-213d-42c9-9a79-3e9149a57833" + assert entity.metadata["etag"] + assert entity.metadata["timestamp"] + + def _assert_updated_entity(self, entity): + """ + Asserts that the entity passed in matches the updated entity. + """ + assert entity["age"] == "abc" + assert entity["sex"] == "female" + assert not "married" in entity + assert not "deceased" in entity + assert entity["sign"] == "aquarius" + assert not "optional" in entity + assert not "ratio" in entity + assert not "evenratio" in entity + assert not "large" in entity + assert not "Birthday" in entity + assert entity["birthday"] == datetime(1991, 10, 4, tzinfo=tzutc()) + assert not "other" in entity + assert not "clsid" in entity + assert entity.metadata["etag"] + assert entity.metadata["timestamp"] + + def _assert_merged_entity(self, entity): + """ + Asserts that the entity passed in matches the default entity + merged with the updated entity. + """ + assert entity["age"] == "abc" + assert entity["sex"] == "female" + assert entity["sign"] == "aquarius" + assert entity["married"] == True + assert entity["deceased"] == False + assert entity["ratio"] == 3.1 + assert entity["evenratio"] == 3.0 + assert entity["large"] == 933311100 + assert entity["Birthday"] == datetime(1973, 10, 4, tzinfo=tzutc()) + assert entity["birthday"] == datetime(1991, 10, 4, tzinfo=tzutc()) + assert entity["other"] == 20 + assert isinstance(entity["clsid"], uuid.UUID) + assert str(entity["clsid"]) == "c9da6455-213d-42c9-9a79-3e9149a57833" + assert entity.metadata["etag"] + assert entity.metadata["timestamp"] + + def _assert_valid_metadata(self, metadata): + keys = metadata.keys() + assert "version" in keys + assert "date" in keys + assert "etag" in keys + assert len(keys) == 3 + + def _assert_valid_batch_transaction(self, transaction, length): + assert length == len(transaction) + + def _assert_properties_default(self, prop): + assert prop is not None + + self._assert_logging_equal(prop["analytics_logging"], TableAnalyticsLogging()) + self._assert_metrics_equal(prop["hour_metrics"], Metrics()) + self._assert_metrics_equal(prop["minute_metrics"], Metrics()) + self._assert_cors_equal(prop["cors"], list()) + + def _assert_logging_equal(self, log1, log2): + if log1 is None or log2 is None: + assert log1 == log2 + return + + assert log1.version == log2.version + assert log1.read == log2.read + assert log1.write == log2.write + assert log1.delete == log2.delete + self._assert_retention_equal(log1.retention_policy, log2.retention_policy) + + def _assert_delete_retention_policy_equal(self, policy1, policy2): + if policy1 is None or policy2 is None: + assert policy1 == policy2 + return + + assert policy1.enabled == policy2.enabled + assert policy1.days == policy2.days + + def _assert_static_website_equal(self, prop1, prop2): + if prop1 is None or prop2 is None: + assert prop1 == prop2 + return + + assert prop1.enabled == prop2.enabled + assert prop1.index_document == prop2.index_document + assert prop1.error_document404_path == prop2.error_document404_path + + def _assert_delete_retention_policy_not_equal(self, policy1, policy2): + if policy1 is None or policy2 is None: + assert policy1 != policy2 + return + + assert policy1.enabled == policy2.enabled and policy1.days == policy2.days + + def _assert_metrics_equal(self, metrics1, metrics2): + if metrics1 is None or metrics2 is None: + assert metrics1 == metrics2 + return + + assert metrics1.version == metrics2.version + assert metrics1.enabled == metrics2.enabled + assert metrics1.include_apis == metrics2.include_apis + self._assert_retention_equal(metrics1.retention_policy, metrics2.retention_policy) + + def _assert_cors_equal(self, cors1, cors2): + if cors1 is None or cors2 is None: + assert cors1 == cors2 + return + + assert len(cors1) == len(cors2) + + for i in range(0, len(cors1)): + rule1 = cors1[i] + rule2 = cors2[i] + assert len(rule1.allowed_origins) == len(rule2.allowed_origins) + assert len(rule1.allowed_methods) == len(rule2.allowed_methods) + assert rule1.max_age_in_seconds == rule2.max_age_in_seconds + assert len(rule1.exposed_headers) == len(rule2.exposed_headers) + assert len(rule1.allowed_headers) == len(rule2.allowed_headers) + + def _assert_retention_equal(self, ret1, ret2): + assert ret1.enabled == ret2.enabled + assert ret1.days == ret2.days + + def _tear_down(self): + if is_live(): + self._delete_all_tables(self.ts) + self.test_tables = [] + if self.ts._cosmos_endpoint: + self.sleep(SLEEP_DELAY) + self.ts.close() + + def _create_query_table(self, entity_count): + """ + Creates a table with the specified name and adds entities with the + default set of values. PartitionKey is set to 'MyPartition' and RowKey + is set to a unique counter value starting at 1 (as a string). + """ + table_name = self.get_resource_name("querytable") + table = self.ts.create_table(table_name) + self.query_tables.append(table_name) + client = self.ts.get_table_client(table_name) + entity = self._create_random_entity_dict() + for i in range(1, entity_count + 1): + entity["RowKey"] = entity["RowKey"] + str(i) + client.create_entity(entity) + return client + + def _insert_two_opposite_entities(self, pk=None, rk=None): + entity1 = self._create_random_entity_dict() + resp = self.table.create_entity(entity1) + + partition, row = self._create_pk_rk(pk, rk) + properties = { + "PartitionKey": partition + u"1", + "RowKey": row + u"1", + "age": 49, + "sex": u"female", + "married": False, + "deceased": True, + "optional": None, + "ratio": 5.2, + "evenratio": 6.0, + "large": 39999011, + "Birthday": datetime(1993, 4, 1, tzinfo=tzutc()), + "birthday": datetime(1990, 4, 1, tzinfo=tzutc()), + "binary": b"binary-binary", + "other": EntityProperty(40, EdmType.INT32), + "clsid": uuid.UUID("c8da6455-213e-42d9-9b79-3f9149a57833"), + } + self.table.create_entity(properties) + return entity1, resp + + def _insert_random_entity(self, pk=None, rk=None): + entity = self._create_random_entity_dict(pk, rk) + metadata = self.table.create_entity(entity) + return entity, metadata["etag"] + + def _set_up(self, account_name, account_key, url="table"): + self.table_name = self.get_resource_name("uttable") + self.ts = TableServiceClient( + self.account_url(account_name, url), credential=account_key, table_name=self.table_name + ) + self.table = self.ts.get_table_client(self.table_name) + if self.is_live: + try: + self.ts.create_table(self.table_name) + except ResourceExistsError: + pass + + self.query_tables = [] + + def _assert_stats_default(self, stats): + assert stats is not None + assert stats["geo_replication"] is not None + + assert stats["geo_replication"]["status"] == "live" + assert stats["geo_replication"]["last_sync_time"] is not None + + def _assert_stats_unavailable(self, stats): + assert stats is not None + assert stats["geo_replication"] is not None + + assert stats["geo_replication"]["status"] == "unavailable" + assert stats["geo_replication"]["last_sync_time"] is None + class ResponseCallback(object): def __init__(self, status=None, new_status=None): diff --git a/sdk/tables/azure-data-tables/tests/test_retry.py b/sdk/tables/azure-data-tables/tests/test_retry.py index a0b17ae09979..c5307e5391d4 100644 --- a/sdk/tables/azure-data-tables/tests/test_retry.py +++ b/sdk/tables/azure-data-tables/tests/test_retry.py @@ -3,32 +3,22 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import unittest import pytest from devtools_testutils import AzureTestCase - from azure.core.exceptions import ( HttpResponseError, ResourceExistsError, AzureError, - ClientAuthenticationError ) from azure.core.pipeline.policies import RetryMode -from azure.core.pipeline.transport import( - RequestsTransport -) - -from azure.data.tables import ( - TableServiceClient, - LocationMode -) +from azure.core.pipeline.transport import RequestsTransport +from azure.data.tables import TableServiceClient from _shared.testcase import ( TableTestCase, ResponseCallback, - RetryCounter ) from preparers import tables_decorator @@ -64,6 +54,7 @@ def _set_up(self, tables_storage_account_name, tables_primary_storage_account_ke self.query_tables = [] + # TODO: Figure out why this is needed by the "test_retry_on_socket_timeout" test def _tear_down(self, **kwargs): if self.is_live: try: diff --git a/sdk/tables/azure-data-tables/tests/test_retry_async.py b/sdk/tables/azure-data-tables/tests/test_retry_async.py index 728d44c1855f..e39316250681 100644 --- a/sdk/tables/azure-data-tables/tests/test_retry_async.py +++ b/sdk/tables/azure-data-tables/tests/test_retry_async.py @@ -13,7 +13,6 @@ HttpResponseError, ResourceExistsError, AzureError, - ResourceNotFoundError ) from azure.core.pipeline.policies import RetryMode from azure.core.pipeline.transport import( @@ -21,12 +20,10 @@ ) from azure.data.tables.aio import TableServiceClient -from azure.data.tables import LocationMode from _shared.asynctestcase import AsyncTableTestCase from _shared.testcase import ( ResponseCallback, - RetryCounter ) from async_preparers import tables_decorator_async @@ -63,22 +60,6 @@ async def _set_up(self, tables_storage_account_name, tables_primary_storage_acco self.query_tables = [] - async def _tear_down(self, **kwargs): - if self.is_live: - try: - await self.ts.delete_table(self.table_name, **kwargs) - except: - pass - - try: - for table_name in self.query_tables: - try: - await self.ts.delete_table(table_name, **kwargs) - except: - pass - except AttributeError: - pass - # --Test Cases -------------------------------------------- @tables_decorator_async async def test_retry_on_server_error_async(self, tables_storage_account_name, tables_primary_storage_account_key): diff --git a/sdk/tables/azure-data-tables/tests/test_table.py b/sdk/tables/azure-data-tables/tests/test_table.py index e64185ec5617..594a36e37984 100644 --- a/sdk/tables/azure-data-tables/tests/test_table.py +++ b/sdk/tables/azure-data-tables/tests/test_table.py @@ -6,10 +6,6 @@ # license information. # -------------------------------------------------------------------------- import pytest - -import sys -import locale -import os from datetime import datetime, timedelta from devtools_testutils import AzureTestCase @@ -17,8 +13,6 @@ from azure.data.tables import ( ResourceTypes, AccountSasPermissions, - TableSasPermissions, - CorsRule, RetentionPolicy, UpdateMode, AccessPolicy, @@ -29,60 +23,15 @@ generate_account_sas, ResourceTypes ) -from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential -from azure.core.pipeline import Pipeline -from azure.core.pipeline.policies import ( - HeadersPolicy, - ContentDecodePolicy, -) -from azure.core.exceptions import ( - HttpResponseError, - ResourceNotFoundError, - ResourceExistsError -) +from azure.core.credentials import AzureNamedKeyCredential +from azure.core.exceptions import ResourceExistsError -from _shared.testcase import TableTestCase +from _shared.testcase import TableTestCase, TEST_TABLE_PREFIX from preparers import tables_decorator, tables_decorator -# ------------------------------------------------------------------------------ - -TEST_TABLE_PREFIX = 'pytablesync' - # ------------------------------------------------------------------------------ class StorageTableTest(AzureTestCase, TableTestCase): - - # --Helpers----------------------------------------------------------------- - def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): - table_name = self.get_resource_name(prefix) - return table_name - - def _create_table(self, ts, prefix=TEST_TABLE_PREFIX, table_list=None): - table_name = self._get_table_reference(prefix) - try: - table = ts.create_table(table_name) - if table_list is not None: - table_list.append(table) - except ResourceExistsError: - table = ts.get_table_client(table_name) - return table - - def _delete_table(self, ts, table): - if table: - try: - ts.delete_table(table.table_name) - except ResourceNotFoundError: - pass - - def _delete_all_tables(self, ts): - for table in ts.list_tables(): - try: - ts.delete_table(table.name) - except ResourceNotFoundError: - pass - - # --Test cases for tables -------------------------------------------------- - @tables_decorator def test_create_properties(self, tables_storage_account_name, tables_primary_storage_account_key): # # Arrange @@ -477,7 +426,7 @@ def test_account_sas(self, tables_storage_account_name, tables_primary_storage_a assert entities[0]['text'] == u'hello' assert entities[1]['text'] == u'hello' finally: - self._delete_table(table=table, ts=tsc) + tsc.delete_table(table.table_name) class TestTablesUnitTest(TableTestCase): diff --git a/sdk/tables/azure-data-tables/tests/test_table_async.py b/sdk/tables/azure-data-tables/tests/test_table_async.py index 9e39f193645f..6d49baba67fb 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_async.py @@ -1,14 +1,11 @@ -import locale -import os -import sys from datetime import datetime, timedelta import pytest from devtools_testutils import AzureTestCase -from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential -from azure.core.exceptions import ResourceNotFoundError, ResourceExistsError +from azure.core.credentials import AzureNamedKeyCredential +from azure.core.exceptions import ResourceExistsError from azure.data.tables import ( AccessPolicy, TableSasPermissions, @@ -22,36 +19,8 @@ from _shared.asynctestcase import AsyncTableTestCase from async_preparers import tables_decorator_async -TEST_TABLE_PREFIX = 'pytableasync' - - -# ------------------------------------------------------------------------------ class TableTestAsync(AzureTestCase, AsyncTableTestCase): - # --Helpers----------------------------------------------------------------- - def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): - table_name = self.get_resource_name(prefix) - return table_name - - async def _create_table(self, ts, prefix=TEST_TABLE_PREFIX, table_list=None): - table_name = self._get_table_reference(prefix) - try: - table = await ts.create_table(table_name) - if table_list is not None: - table_list.append(table) - except ResourceExistsError: - table = ts.get_table_client(table_name) - return table - - async def _delete_table(self, ts, table): - if table is None: - return - try: - await ts.delete_table(table.table_name) - except ResourceNotFoundError: - pass - - # --Test cases for tables -------------------------------------------------- @tables_decorator_async async def test_create_table(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange @@ -297,7 +266,6 @@ async def test_set_table_acl_with_empty_signed_identifier(self, tables_storage_a assert acl['empty'].expiry is None assert acl['empty'].start is None finally: - # self._delete_table(table) await ts.delete_table(table.table_name) @tables_decorator_async @@ -386,7 +354,7 @@ async def test_account_sas(self, tables_storage_account_name, tables_primary_sto assert entities[0]['text'] == u'hello' assert entities[1]['text'] == u'hello' finally: - await self._delete_table(table=table, ts=tsc) + await tsc.delete_table(table.table_name) class TestTablesUnitTest(AsyncTableTestCase): 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 6fe8bf82407b..ff027b6a66c7 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_batch.py +++ b/sdk/tables/azure-data-tables/tests/test_table_batch.py @@ -9,17 +9,14 @@ import pytest from datetime import datetime, timedelta -from dateutil.tz import tzutc import os import sys -import uuid from devtools_testutils import AzureTestCase from azure.core import MatchConditions from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential from azure.core.exceptions import ( - ResourceExistsError, ResourceNotFoundError, ClientAuthenticationError ) @@ -46,135 +43,6 @@ #------------------------------------------------------------------------------ class StorageTableBatchTest(AzureTestCase, TableTestCase): - - def _set_up(self, tables_storage_account_name, tables_primary_storage_account_key): - self.ts = TableServiceClient(self.account_url(tables_storage_account_name, "table"), tables_primary_storage_account_key) - self.table_name = self.get_resource_name('uttable') - self.table = self.ts.get_table_client(self.table_name) - if self.is_live: - try: - self.ts.create_table(self.table_name) - except ResourceExistsError: - pass - - self.test_tables = [] - - def _tear_down(self): - if self.is_live: - try: - self.ts.delete_table(self.table_name) - except: - pass - - for table_name in self.test_tables: - try: - self.ts.delete_table(table_name) - except: - pass - - #--Helpers----------------------------------------------------------------- - - def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): - table_name = self.get_resource_name(prefix) - self.test_tables.append(table_name) - return self.ts.get_table_client(table_name) - - def _create_pk_rk(self, pk, rk): - try: - pk = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - rk = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - except AttributeError: - pk = pk if pk is not None else self.get_resource_name('pk') - rk = rk if rk is not None else self.get_resource_name('rk') - return pk, rk - - def _create_random_entity_dict(self, pk=None, rk=None): - """ - Creates a dictionary-based entity with fixed values, using all - of the supported data types. - """ - # partition = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - # row = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 39, - 'sex': u'male', - 'married': True, - 'deceased': False, - 'optional': None, - 'ratio': 3.1, - 'evenratio': 3.0, - 'large': 933311100, - 'Birthday': datetime(1973, 10, 4, tzinfo=tzutc()), - 'birthday': datetime(1970, 10, 4, tzinfo=tzutc()), - 'binary': b'binary', - 'other': EntityProperty(20, EdmType.INT32), - 'clsid': uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - } - return TableEntity(**properties) - - def _create_updated_entity_dict(self, partition, row): - ''' - Creates a dictionary-based entity with fixed values, with a - different set of values than the default entity. It - adds fields, changes field values, changes field types, - and removes fields when compared to the default entity. - ''' - return { - 'PartitionKey': partition, - 'RowKey': row, - 'age': u'abc', - 'sex': u'female', - 'sign': u'aquarius', - 'birthday': datetime(1991, 10, 4, tzinfo=tzutc()) - } - - def _assert_default_entity(self, entity): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_updated_entity(self, entity): - ''' - Asserts that the entity passed in matches the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert not "married" in entity - assert not "deceased" in entity - assert entity['sign'] == 'aquarius' - assert not "optional" in entity - assert not "ratio" in entity - assert not "evenratio" in entity - assert not "large" in entity - assert not "Birthday" in entity - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert not "other" in entity - assert not "clsid" in entity - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_valid_batch_transaction(self, transaction, length): - assert length == len(transaction) - - @pytest.mark.skipif(sys.version_info < (3, 0), reason="requires Python3") @tables_decorator def test_batch_single_insert(self, tables_storage_account_name, tables_primary_storage_account_key): @@ -616,7 +484,8 @@ def test_batch_reuse(self, tables_storage_account_name, tables_primary_storage_a # Arrange self._set_up(tables_storage_account_name, tables_primary_storage_account_key) try: - table2 = self._get_table_reference('table2') + table2_name = self._get_table_reference('table2') + table2 = self.ts.get_table_client(table2_name) table2.create_table() # Act 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 5be870c48547..14ff1cd74416 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,19 +9,15 @@ import pytest from datetime import datetime, timedelta -from dateutil.tz import tzutc import os import sys -import uuid from devtools_testutils import AzureTestCase from azure.core import MatchConditions from azure.core.credentials import AzureSasCredential from azure.core.exceptions import ( - ResourceExistsError, ResourceNotFoundError, - HttpResponseError, ClientAuthenticationError ) from azure.data.tables.aio import TableServiceClient @@ -40,141 +36,8 @@ from _shared.asynctestcase import AsyncTableTestCase from async_preparers import tables_decorator_async -#------------------------------------------------------------------------------ -TEST_TABLE_PREFIX = 'table' -#------------------------------------------------------------------------------ class StorageTableBatchTest(AzureTestCase, AsyncTableTestCase): - - async def _set_up(self, tables_storage_account_name, tables_primary_storage_account_key): - self.ts = TableServiceClient(self.account_url(tables_storage_account_name, "table"), tables_primary_storage_account_key) - self.table_name = self.get_resource_name('uttable') - self.table = self.ts.get_table_client(self.table_name) - if self.is_live: - try: - await self.ts.create_table(self.table_name) - except ResourceExistsError: - pass - - self.test_tables = [] - - async def _tear_down(self): - if self.is_live: - try: - await self.ts.delete_table(self.table_name) - except: - pass - - for table_name in self.test_tables: - try: - await self.ts.delete_table(table_name) - except: - pass - await self.table.close() - - #--Helpers----------------------------------------------------------------- - - def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): - table_name = self.get_resource_name(prefix) - self.test_tables.append(table_name) - return self.ts.get_table_client(table_name) - - def _create_pk_rk(self, pk, rk): - try: - pk = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - rk = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - except AttributeError: - pk = pk if pk is not None else self.get_resource_name('pk') - rk = rk if rk is not None else self.get_resource_name('rk') - return pk, rk - - def _create_random_entity_dict(self, pk=None, rk=None): - """ - Creates a dictionary-based entity with fixed values, using all - of the supported data types. - """ - # partition = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - # row = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 39, - 'sex': u'male', - 'married': True, - 'deceased': False, - 'optional': None, - 'ratio': 3.1, - 'evenratio': 3.0, - 'large': 933311100, - 'Birthday': datetime(1973, 10, 4, tzinfo=tzutc()), - 'birthday': datetime(1970, 10, 4, tzinfo=tzutc()), - 'binary': b'binary', - 'other': EntityProperty(20, EdmType.INT32), - 'clsid': uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - } - return TableEntity(**properties) - - def _create_updated_entity_dict(self, partition, row): - ''' - Creates a dictionary-based entity with fixed values, with a - different set of values than the default entity. It - adds fields, changes field values, changes field types, - and removes fields when compared to the default entity. - ''' - return { - 'PartitionKey': partition, - 'RowKey': row, - 'age': u'abc', - 'sex': u'female', - 'sign': u'aquarius', - 'birthday': datetime(1991, 10, 4, tzinfo=tzutc()) - } - - def _assert_default_entity(self, entity): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_updated_entity(self, entity): - ''' - Asserts that the entity passed in matches the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert not "married" in entity - assert not "deceased" in entity - assert entity['sign'] == 'aquarius' - assert not "optional" in entity - assert not "ratio" in entity - assert not "evenratio" in entity - assert not "large" in entity - assert not "Birthday" in entity - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert not "other" in entity - assert not "clsid" in entity - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_valid_batch_transaction(self, transaction, length): - assert length == len(transaction) - - #--Test cases for batch --------------------------------------------- @tables_decorator_async async def test_batch_single_insert(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange @@ -740,7 +603,6 @@ async def test_batch_sas_auth(self, tables_storage_account_name, tables_primary_ async def test_batch_request_too_large(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange await self._set_up(tables_storage_account_name, tables_primary_storage_account_key) - from azure.data.tables import RequestTooLargeError try: batch = [] diff --git a/sdk/tables/azure-data-tables/tests/test_table_batch_cosmos.py b/sdk/tables/azure-data-tables/tests/test_table_batch_cosmos.py index 0627bd8399a8..cbb1b630f5d8 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_batch_cosmos.py +++ b/sdk/tables/azure-data-tables/tests/test_table_batch_cosmos.py @@ -6,27 +6,21 @@ # license information. # -------------------------------------------------------------------------- from datetime import datetime -from dateutil.tz import tzutc import os import sys -import uuid import pytest from devtools_testutils import AzureTestCase from azure.core import MatchConditions -from azure.core.exceptions import ( - ResourceExistsError, - ResourceNotFoundError, -) +from azure.core.exceptions import ResourceNotFoundError from azure.data.tables import ( EdmType, TableEntity, EntityProperty, UpdateMode, TableTransactionError, - TableServiceClient, TableEntity, UpdateMode, TransactionOperation, @@ -41,141 +35,11 @@ #------------------------------------------------------------------------------ class StorageTableClientTest(AzureTestCase, TableTestCase): - - def _set_up(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - self.ts = TableServiceClient(self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) - self.table_name = self.get_resource_name('uttable') - self.table = self.ts.get_table_client(self.table_name) - if self.is_live: - try: - self.ts.create_table(self.table_name) - except ResourceExistsError: - pass - - self.test_tables = [] - - def _tear_down(self): - if self.is_live: - try: - self.ts.delete_table(self.table_name) - except: - pass - - for table_name in self.test_tables: - try: - self.ts.delete_table(table_name) - except: - pass - self.sleep(SLEEP_DELAY) - - #--Helpers----------------------------------------------------------------- - - def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): - table_name = self.get_resource_name(prefix) - self.test_tables.append(table_name) - return self.ts.get_table_client(table_name) - - def _create_pk_rk(self, pk, rk): - try: - pk = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - rk = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - except AttributeError: - pk = pk if pk is not None else self.get_resource_name('pk') - rk = rk if rk is not None else self.get_resource_name('rk') - return pk, rk - - def _create_random_entity_dict(self, pk=None, rk=None): - ''' - Creates a dictionary-based entity with fixed values, using all - of the supported data types. - ''' - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 39, - 'sex': u'male', - 'married': True, - 'deceased': False, - 'optional': None, - 'ratio': 3.1, - 'evenratio': 3.0, - 'large': 933311100, - 'Birthday': datetime(1973, 10, 4, tzinfo=tzutc()), - 'birthday': datetime(1970, 10, 4, tzinfo=tzutc()), - 'binary': b'binary', - 'other': EntityProperty(20, EdmType.INT32), - 'clsid': uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - } - return TableEntity(**properties) - - - def _create_updated_entity_dict(self, partition, row): - ''' - Creates a dictionary-based entity with fixed values, with a - different set of values than the default entity. It - adds fields, changes field values, changes field types, - and removes fields when compared to the default entity. - ''' - return { - 'PartitionKey': partition, - 'RowKey': row, - 'age': u'abc', - 'sex': u'female', - 'sign': u'aquarius', - 'birthday': datetime(1991, 10, 4, tzinfo=tzutc()) - } - - def _assert_default_entity(self, entity): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_updated_entity(self, entity): - ''' - Asserts that the entity passed in matches the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert not "married" in entity - assert not "deceased" in entity - assert entity['sign'] == 'aquarius' - assert not "optional" in entity - assert not "ratio" in entity - assert not "evenratio" in entity - assert not "large" in entity - assert not "Birthday" in entity - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert not "other" in entity - assert not "clsid" in entity - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - - #--Test cases for batch --------------------------------------------- - def _assert_valid_batch_transaction(self, transaction, length): - assert length == len(transaction) - @pytest.mark.skipif(sys.version_info < (3, 0), reason="requires Python3") @cosmos_decorator def test_batch_insert(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -205,7 +69,7 @@ def test_batch_insert(self, tables_cosmos_account_name, tables_primary_cosmos_ac @cosmos_decorator def test_batch_update(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -240,7 +104,7 @@ def test_batch_update(self, tables_cosmos_account_name, tables_primary_cosmos_ac @cosmos_decorator def test_batch_merge(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -279,7 +143,7 @@ def test_batch_merge(self, tables_cosmos_account_name, tables_primary_cosmos_acc @cosmos_decorator def test_batch_update_if_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() resp = self.table.create_entity(entity=entity) @@ -307,7 +171,7 @@ def test_batch_update_if_match(self, tables_cosmos_account_name, tables_primary_ @cosmos_decorator def test_batch_update_if_doesnt_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() self.table.create_entity(entity) @@ -333,7 +197,7 @@ def test_batch_update_if_doesnt_match(self, tables_cosmos_account_name, tables_p @cosmos_decorator def test_batch_insert_replace(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -363,7 +227,7 @@ def test_batch_insert_replace(self, tables_cosmos_account_name, tables_primary_c @cosmos_decorator def test_batch_insert_merge(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -393,7 +257,7 @@ def test_batch_insert_merge(self, tables_cosmos_account_name, tables_primary_cos @cosmos_decorator def test_batch_delete(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -425,7 +289,7 @@ def test_batch_delete(self, tables_cosmos_account_name, tables_primary_cosmos_ac @cosmos_decorator def test_batch_inserts(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -460,7 +324,7 @@ def test_batch_inserts(self, tables_cosmos_account_name, tables_primary_cosmos_a @cosmos_decorator def test_batch_all_operations_together(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -530,7 +394,7 @@ def test_batch_all_operations_together(self, tables_cosmos_account_name, tables_ @cosmos_decorator def test_batch_different_partition_operations_fail(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict('001', 'batch_negative_1') self.table.create_entity(entity) @@ -555,7 +419,7 @@ def test_batch_different_partition_operations_fail(self, tables_cosmos_account_n @cosmos_decorator def test_new_non_existent_table(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict('001', 'batch_negative_1') @@ -573,7 +437,7 @@ def test_new_non_existent_table(self, tables_cosmos_account_name, tables_primary @cosmos_decorator def test_new_delete_nonexistent_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict('001', 'batch_negative_1') @@ -588,7 +452,7 @@ def test_new_delete_nonexistent_entity(self, tables_cosmos_account_name, tables_ @cosmos_decorator def test_delete_batch_with_bad_kwarg(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict('001', 'batch_negative_1') self.table.create_entity(entity) @@ -615,7 +479,7 @@ def test_delete_batch_with_bad_kwarg(self, tables_cosmos_account_name, tables_pr @cosmos_decorator def test_batch_request_too_large(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: batch = [] entity = { diff --git a/sdk/tables/azure-data-tables/tests/test_table_batch_cosmos_async.py b/sdk/tables/azure-data-tables/tests/test_table_batch_cosmos_async.py index a80413e173f4..91695a6e4de0 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_batch_cosmos_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_batch_cosmos_async.py @@ -5,20 +5,15 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- - from datetime import datetime -from dateutil.tz import tzutc import os import sys -import uuid - import pytest from devtools_testutils import AzureTestCase from azure.core import MatchConditions from azure.core.exceptions import ( - ResourceExistsError, ResourceNotFoundError, HttpResponseError, ClientAuthenticationError @@ -34,7 +29,6 @@ ) from azure.data.tables.aio import TableServiceClient -from _shared.testcase import SLEEP_DELAY from _shared.asynctestcase import AsyncTableTestCase from async_preparers import cosmos_decorator_async @@ -43,141 +37,10 @@ #------------------------------------------------------------------------------ class StorageTableBatchTest(AzureTestCase, AsyncTableTestCase): - - async def _set_up(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - self.ts = TableServiceClient(self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) - self.table_name = self.get_resource_name('uttable') - self.table = self.ts.get_table_client(self.table_name) - if self.is_live: - try: - await self.ts.create_table(self.table_name) - except ResourceExistsError: - pass - self.test_tables = [self.table_name] - - async def _tear_down(self): - if self.is_live: - try: - await self.ts.delete_table(self.table_name) - except: - pass - - for table_name in self.test_tables: - try: - await self.ts.delete_table(table_name) - except: - pass - await self.table.close() - self.test_tables = [] - self.sleep(SLEEP_DELAY) - - #--Helpers----------------------------------------------------------------- - - def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): - table_name = self.get_resource_name(prefix) - self.test_tables.append(table_name) - return self.ts.get_table_client(table_name) - - def _create_pk_rk(self, pk, rk): - try: - pk = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - rk = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - except AttributeError: - pk = pk if pk is not None else self.get_resource_name('pk') - rk = rk if rk is not None else self.get_resource_name('rk') - return pk, rk - - def _create_random_entity_dict(self, pk=None, rk=None): - """ - Creates a dictionary-based entity with fixed values, using all - of the supported data types. - """ - # partition = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - # row = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 39, - 'sex': u'male', - 'married': True, - 'deceased': False, - 'optional': None, - 'ratio': 3.1, - 'evenratio': 3.0, - 'large': 933311100, - 'Birthday': datetime(1973, 10, 4, tzinfo=tzutc()), - 'birthday': datetime(1970, 10, 4, tzinfo=tzutc()), - 'binary': b'binary', - 'other': EntityProperty(20, EdmType.INT32), - 'clsid': uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - } - return TableEntity(**properties) - - def _create_updated_entity_dict(self, partition, row): - ''' - Creates a dictionary-based entity with fixed values, with a - different set of values than the default entity. It - adds fields, changes field values, changes field types, - and removes fields when compared to the default entity. - ''' - return { - 'PartitionKey': partition, - 'RowKey': row, - 'age': u'abc', - 'sex': u'female', - 'sign': u'aquarius', - 'birthday': datetime(1991, 10, 4, tzinfo=tzutc()) - } - - def _assert_default_entity(self, entity): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_updated_entity(self, entity): - ''' - Asserts that the entity passed in matches the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert not "married" in entity - assert not "deceased" in entity - assert entity['sign'] == 'aquarius' - assert not "optional" in entity - assert not "ratio" in entity - assert not "evenratio" in entity - assert not "large" in entity - assert not "Birthday" in entity - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert not "other" in entity - assert not "clsid" in entity - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_valid_batch_transaction(self, transaction, length): - assert length == len(transaction) - - #--Test cases for batch --------------------------------------------- @cosmos_decorator_async async def test_batch_single_insert(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -208,7 +71,7 @@ async def test_batch_single_insert(self, tables_cosmos_account_name, tables_prim @cosmos_decorator_async async def test_batch_single_update(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -243,7 +106,7 @@ async def test_batch_single_update(self, tables_cosmos_account_name, tables_prim @cosmos_decorator_async async def test_batch_update(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -277,7 +140,7 @@ async def test_batch_update(self, tables_cosmos_account_name, tables_primary_cos @cosmos_decorator_async async def test_batch_merge(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -315,7 +178,7 @@ async def test_batch_merge(self, tables_cosmos_account_name, tables_primary_cosm @cosmos_decorator_async async def test_batch_update_if_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() resp = await self.table.create_entity(entity=entity) @@ -342,7 +205,7 @@ async def test_batch_update_if_match(self, tables_cosmos_account_name, tables_pr @cosmos_decorator_async async def test_batch_update_if_doesnt_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() resp = await self.table.create_entity(entity) @@ -369,7 +232,7 @@ async def test_batch_update_if_doesnt_match(self, tables_cosmos_account_name, ta @cosmos_decorator_async async def test_batch_insert_replace(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -398,7 +261,7 @@ async def test_batch_insert_replace(self, tables_cosmos_account_name, tables_pri @cosmos_decorator_async async def test_batch_insert_merge(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -427,7 +290,7 @@ async def test_batch_insert_merge(self, tables_cosmos_account_name, tables_prima @cosmos_decorator_async async def test_batch_delete(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -458,7 +321,7 @@ async def test_batch_delete(self, tables_cosmos_account_name, tables_primary_cos @cosmos_decorator_async async def test_batch_inserts(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -495,7 +358,7 @@ async def test_batch_inserts(self, tables_cosmos_account_name, tables_primary_co @cosmos_decorator_async async def test_batch_all_operations_together(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act entity = TableEntity() @@ -567,7 +430,7 @@ async def test_batch_all_operations_together(self, tables_cosmos_account_name, t @cosmos_decorator_async async def test_batch_different_partition_operations_fail(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict('001', 'batch_negative_1') await self.table.create_entity(entity) @@ -592,7 +455,7 @@ async def test_batch_different_partition_operations_fail(self, tables_cosmos_acc @cosmos_decorator_async async def test_new_non_existent_table(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict('001', 'batch_negative_1') @@ -630,7 +493,7 @@ async def test_new_invalid_key(self, tables_cosmos_account_name, tables_primary_ @cosmos_decorator_async async def test_new_delete_nonexistent_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict('001', 'batch_negative_1') @@ -645,7 +508,7 @@ async def test_new_delete_nonexistent_entity(self, tables_cosmos_account_name, t @cosmos_decorator_async async def test_batch_request_too_large(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: batch = [] @@ -669,7 +532,7 @@ async def test_batch_request_too_large(self, tables_cosmos_account_name, tables_ @cosmos_decorator_async async def test_delete_batch_with_bad_kwarg(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict('001', 'batch_negative_1') await self.table.create_entity(entity) diff --git a/sdk/tables/azure-data-tables/tests/test_table_cosmos.py b/sdk/tables/azure-data-tables/tests/test_table_cosmos.py index 877b00b37700..1886f935189b 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_cosmos.py +++ b/sdk/tables/azure-data-tables/tests/test_table_cosmos.py @@ -6,42 +6,13 @@ # license information. # -------------------------------------------------------------------------- import pytest -import sys -import locale -import os from time import sleep -from datetime import ( - datetime, - timedelta, -) from devtools_testutils import AzureTestCase from azure.core.credentials import AzureNamedKeyCredential -from azure.core.exceptions import ( - HttpResponseError, - ResourceNotFoundError, - ResourceExistsError -) -from azure.core.pipeline import Pipeline -from azure.core.pipeline.policies import ( - HeadersPolicy, - ContentDecodePolicy, -) - -from azure.data.tables import ( - ResourceTypes, - AccountSasPermissions, - TableSasPermissions, - CorsRule, - RetentionPolicy, - UpdateMode, - AccessPolicy, - TableAnalyticsLogging, - Metrics, - TableServiceClient, - generate_account_sas -) +from azure.core.exceptions import ResourceExistsError +from azure.data.tables import TableServiceClient from _shared.testcase import TableTestCase, SLEEP_DELAY from preparers import cosmos_decorator @@ -52,38 +23,6 @@ class StorageTableTest(AzureTestCase, TableTestCase): - # --Helpers----------------------------------------------------------------- - def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): - table_name = self.get_resource_name(prefix) - return table_name - - def _create_table(self, ts, prefix=TEST_TABLE_PREFIX, table_list=None): - table_name = self._get_table_reference(prefix) - try: - table = ts.create_table(table_name) - if table_list is not None: - table_list.append(table) - except ResourceExistsError: - table = ts.get_table_client(table_name) - return table - - def _delete_table(self, ts, table): - if table is None: - return - try: - ts.delete_table(table.name) - except ResourceNotFoundError: - pass - - def _delete_all_tables(self, ts): - tables = ts.list_tables() - for table in tables: - try: - ts.delete_table(table.name) - except ResourceNotFoundError: - pass - - # --Test cases for tables -------------------------------------------------- @cosmos_decorator def test_create_table(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # # Arrange diff --git a/sdk/tables/azure-data-tables/tests/test_table_cosmos_async.py b/sdk/tables/azure-data-tables/tests/test_table_cosmos_async.py index 666fa22aa28a..e21702e96630 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_cosmos_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_cosmos_async.py @@ -1,7 +1,3 @@ -import locale -import os -import sys -from datetime import datetime, timedelta from time import sleep import pytest @@ -9,14 +5,7 @@ from devtools_testutils import AzureTestCase from azure.core.credentials import AzureNamedKeyCredential -from azure.core.exceptions import ResourceNotFoundError, ResourceExistsError, HttpResponseError -from azure.data.tables import ( - AccessPolicy, - TableSasPermissions, - ResourceTypes, - AccountSasPermissions, - generate_account_sas -) +from azure.core.exceptions import ResourceExistsError from azure.data.tables.aio import TableServiceClient from _shared.asynctestcase import AsyncTableTestCase @@ -28,38 +17,6 @@ # ------------------------------------------------------------------------------ class TableTestAsync(AzureTestCase, AsyncTableTestCase): - # --Helpers----------------------------------------------------------------- - def _get_table_reference(self, prefix=TEST_TABLE_PREFIX): - table_name = self.get_resource_name(prefix) - return table_name - - async def _delete_all_tables(self, account_name, key): - client = TableServiceClient(self.account_url(account_name, "cosmos"), key) - async for table in client.list_tables(): - await client.delete_table(table.name) - - if self.is_live: - self.sleep(10) - - async def _create_table(self, ts, prefix=TEST_TABLE_PREFIX, table_list=None): - table_name = self._get_table_reference(prefix) - try: - table = await ts.create_table(table_name) - if table_list is not None: - table_list.append(table) - except ResourceExistsError: - table = ts.get_table_client(table_name) - return table - - async def _delete_table(self, ts, table): - if table is None: - return - try: - await ts.delete_table(table.name) - except ResourceNotFoundError: - pass - - # --Test cases for tables -------------------------------------------------- @cosmos_decorator_async async def test_create_table(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange 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 e3c1441b2bf3..c9b96d2fe375 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_entity.py +++ b/sdk/tables/azure-data-tables/tests/test_table_entity.py @@ -7,12 +7,10 @@ # -------------------------------------------------------------------------- import pytest -from base64 import b64encode from datetime import datetime, timedelta from dateutil.tz import tzutc, tzoffset from enum import Enum from math import isnan -import uuid from devtools_testutils import AzureTestCase @@ -41,261 +39,6 @@ # ------------------------------------------------------------------------------ class StorageTableEntityTest(AzureTestCase, TableTestCase): - - def _set_up(self, tables_storage_account_name, tables_primary_storage_account_key, url='table'): - self.table_name = self.get_resource_name('uttable') - self.ts = TableServiceClient( - self.account_url(tables_storage_account_name, url), - credential=tables_primary_storage_account_key, - table_name = self.table_name - ) - self.table = self.ts.get_table_client(self.table_name) - if self.is_live: - try: - self.ts.create_table(self.table_name) - except ResourceExistsError: - pass - - self.query_tables = [] - - def _tear_down(self): - if self.is_live: - try: - self.ts.delete_table(self.table_name) - except: - pass - - try: - for table_name in self.query_tables: - try: - self.ts.delete_table(table_name) - except: - pass - except AttributeError: - pass - - # --Helpers----------------------------------------------------------------- - - def _create_query_table(self, entity_count): - """ - Creates a table with the specified name and adds entities with the - default set of values. PartitionKey is set to 'MyPartition' and RowKey - is set to a unique counter value starting at 1 (as a string). - """ - table_name = self.get_resource_name('querytable') - table = self.ts.create_table(table_name) - self.query_tables.append(table_name) - client = self.ts.get_table_client(table_name) - entity = self._create_random_entity_dict() - for i in range(1, entity_count + 1): - entity['RowKey'] = entity['RowKey'] + str(i) - client.create_entity(entity) - return client - - def _create_random_base_entity_dict(self): - """ - Creates a dict-based entity with only pk and rk. - """ - partition, row = self._create_pk_rk(None, None) - return { - 'PartitionKey': partition, - 'RowKey': row, - } - - def _create_pk_rk(self, pk, rk): - try: - pk = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - rk = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - except AttributeError: - pk = pk if pk is not None else self.get_resource_name('pk') - rk = rk if rk is not None else self.get_resource_name('rk') - return pk, rk - - def _insert_two_opposite_entities(self, pk=None, rk=None): - entity1 = self._create_random_entity_dict() - resp = self.table.create_entity(entity1) - - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition + u'1', - 'RowKey': row + u'1', - 'age': 49, - 'sex': u'female', - 'married': False, - 'deceased': True, - 'optional': None, - 'ratio': 5.2, - 'evenratio': 6.0, - 'large': 39999011, - 'Birthday': datetime(1993, 4, 1, tzinfo=tzutc()), - 'birthday': datetime(1990, 4, 1, tzinfo=tzutc()), - 'binary': b'binary-binary', - 'other': EntityProperty(40, EdmType.INT32), - 'clsid': uuid.UUID('c8da6455-213e-42d9-9b79-3f9149a57833') - } - self.table.create_entity(properties) - return entity1, resp - - def _create_random_entity_dict(self, pk=None, rk=None): - """ - Creates a dictionary-based entity with fixed values, using all - of the supported data types. - """ - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 39, - 'sex': u'male', - 'married': True, - 'deceased': False, - 'optional': None, - 'ratio': 3.1, - 'evenratio': 3.0, - 'large': 933311100, - 'Birthday': datetime(1973, 10, 4, tzinfo=tzutc()), - 'birthday': datetime(1970, 10, 4, tzinfo=tzutc()), - 'binary': b'binary', - 'other': EntityProperty(20, EdmType.INT32), - 'clsid': uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - } - return TableEntity(**properties) - - def _insert_random_entity(self, pk=None, rk=None): - entity = self._create_random_entity_dict(pk, rk) - metadata = self.table.create_entity(entity) - return entity, metadata['etag'] - - def _create_updated_entity_dict(self, partition, row): - """ - Creates a dictionary-based entity with fixed values, with a - different set of values than the default entity. It - adds fields, changes field values, changes field types, - and removes fields when compared to the default entity. - """ - return { - 'PartitionKey': partition, - 'RowKey': row, - 'age': u'abc', - 'sex': u'female', - 'sign': u'aquarius', - 'birthday': datetime(1991, 10, 4, tzinfo=tzutc()) - } - - def _assert_default_entity(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_default_entity_json_full_metadata(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_default_entity_json_no_metadata(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'].startswith('1973-10-04T00:00:00') - assert entity['birthday'].startswith('1970-10-04T00:00:00') - assert entity['Birthday'].endswith('00Z') - assert entity['birthday'].endswith('00Z') - assert entity['binary'] == b64encode(b'binary').decode('utf-8') - assert entity['other'] == 20 - assert entity['clsid'] == 'c9da6455-213d-42c9-9a79-3e9149a57833' - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_updated_entity(self, entity): - ''' - Asserts that the entity passed in matches the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert not "married" in entity - assert not "deceased" in entity - assert entity['sign'] == 'aquarius' - assert not "optional" in entity - assert not "ratio" in entity - assert not "evenratio" in entity - assert not "large" in entity - assert not "Birthday" in entity - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert not "other" in entity - assert not "clsid" in entity - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_merged_entity(self, entity): - ''' - Asserts that the entity passed in matches the default entity - merged with the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert entity['sign'] == 'aquarius' - assert entity['married'] == True - assert entity['deceased'] == False - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert entity['other'] == 20 - assert isinstance(entity['clsid'], uuid.UUID) - assert str(entity['clsid']) == 'c9da6455-213d-42c9-9a79-3e9149a57833' - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_valid_metadata(self, metadata): - keys = metadata.keys() - assert "version" in keys - assert "date" in keys - assert "etag" in keys - assert len(keys) == 3 - - # --Test cases for entities ------------------------------------------ @tables_decorator def test_url_encoding_at_symbol(self, tables_storage_account_name, tables_primary_storage_account_key): 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 204397b3d63e..fdd80cfc1515 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 @@ -7,11 +7,9 @@ # -------------------------------------------------------------------------- import pytest -from base64 import b64encode from datetime import datetime, timedelta from dateutil.tz import tzutc, tzoffset from math import isnan -import uuid from devtools_testutils import AzureTestCase @@ -38,258 +36,6 @@ from async_preparers import tables_decorator_async class StorageTableEntityTest(AzureTestCase, AsyncTableTestCase): - - async def _set_up(self, tables_storage_account_name, tables_primary_storage_account_key): - account_url = self.account_url(tables_storage_account_name, "table") - self.ts = TableServiceClient(account_url, tables_primary_storage_account_key) - self.table_name = self.get_resource_name('uttable') - self.table = self.ts.get_table_client(self.table_name) - if self.is_live: - try: - await self.ts.create_table(table_name=self.table_name) - except ResourceExistsError: - pass - - self.query_tables = [] - - async def _tear_down(self): - if self.is_live: - try: - await self.ts.delete_table(self.table_name) - except: - pass - - for table_name in self.query_tables: - try: - await self.ts.delete_table(table_name) - except: - pass - await self.ts.close() - - # --Helpers----------------------------------------------------------------- - async def _create_query_table(self, entity_count): - """ - Creates a table with the specified name and adds entities with the - default set of values. PartitionKey is set to 'MyPartition' and RowKey - is set to a unique counter value starting at 1 (as a string). - """ - table_name = self.get_resource_name('querytable') - table = await self.ts.create_table(table_name) - self.query_tables.append(table_name) - client = self.ts.get_table_client(table_name) - entity = self._create_random_entity_dict() - for i in range(1, entity_count + 1): - entity['RowKey'] = entity['RowKey'] + str(i) - await client.create_entity(entity=entity) - return client - - def _create_random_base_entity_dict(self): - """ - Creates a dict-based entity with only pk and rk. - """ - partition = self.get_resource_name('pk') - row = self.get_resource_name('rk') - return { - 'PartitionKey': partition, - 'RowKey': row, - } - - def _create_pk_rk(self, pk, rk): - try: - pk = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - rk = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - except AttributeError: - pk = pk if pk is not None else self.get_resource_name('pk') - rk = rk if rk is not None else self.get_resource_name('rk') - return pk, rk - - async def _insert_two_opposite_entities(self, pk=None, rk=None): - entity1 = self._create_random_entity_dict() - resp = await self.table.create_entity(entity1) - - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition + u'1', - 'RowKey': row + u'1', - 'age': 49, - 'sex': u'female', - 'married': False, - 'deceased': True, - 'optional': None, - 'ratio': 5.2, - 'evenratio': 6.0, - 'large': 39999011, - 'Birthday': datetime(1993, 4, 1, tzinfo=tzutc()), - 'birthday': datetime(1990, 4, 1, tzinfo=tzutc()), - 'binary': b'binary-binary', - 'other': EntityProperty(40, EdmType.INT32), - 'clsid': uuid.UUID('c8da6455-213e-42d9-9b79-3f9149a57833') - } - await self.table.create_entity(properties) - return entity1, resp - - def _create_random_entity_dict(self, pk=None, rk=None): - """ - Creates a dictionary-based entity with fixed values, using all - of the supported data types. - """ - partition = pk if pk is not None else self.get_resource_name('pk') - row = rk if rk is not None else self.get_resource_name('rk') - properties = { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 39, - 'sex': 'male', - 'married': True, - 'deceased': False, - 'optional': None, - 'ratio': 3.1, - 'evenratio': 3.0, - 'large': 933311100, - 'Birthday': datetime(1973, 10, 4, tzinfo=tzutc()), - 'birthday': datetime(1970, 10, 4, tzinfo=tzutc()), - 'binary': b'binary', - 'other': EntityProperty(20, EdmType.INT32), - 'clsid': uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - } - return TableEntity(**properties) - - async def _insert_random_entity(self, pk=None, rk=None): - entity = self._create_random_entity_dict(pk, rk) - metadata = await self.table.create_entity(entity=entity) - return entity, metadata['etag'] - - def _create_updated_entity_dict(self, partition, row): - """ - Creates a dictionary-based entity with fixed values, with a - different set of values than the default entity. It - adds fields, changes field values, changes field types, - and removes fields when compared to the default entity. - """ - return { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 'abc', - 'sex': 'female', - 'sign': 'aquarius', - 'birthday': datetime(1991, 10, 4, tzinfo=tzutc()) - } - - def _assert_default_entity(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_default_entity_json_full_metadata(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_default_entity_json_no_metadata(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'].startswith('1973-10-04T00:00:00') - assert entity['birthday'].startswith('1970-10-04T00:00:00') - assert entity['Birthday'].endswith('00Z') - assert entity['birthday'].endswith('00Z') - assert entity['binary'] == b64encode(b'binary').decode('utf-8') - assert entity['other'] == 20 - assert entity['clsid'] == 'c9da6455-213d-42c9-9a79-3e9149a57833' - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_updated_entity(self, entity): - ''' - Asserts that the entity passed in matches the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert not "married" in entity - assert not "deceased" in entity - assert entity['sign'] == 'aquarius' - assert not "optional" in entity - assert not "ratio" in entity - assert not "evenratio" in entity - assert not "large" in entity - assert not "Birthday" in entity - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert not "other" in entity - assert not "clsid" in entity - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_merged_entity(self, entity): - ''' - Asserts that the entity passed in matches the default entity - merged with the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert entity['sign'] == 'aquarius' - assert entity['married'] == True - assert entity['deceased'] == False - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert entity['other'] == 20 - assert isinstance(entity['clsid'], uuid.UUID) - assert str(entity['clsid']) == 'c9da6455-213d-42c9-9a79-3e9149a57833' - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_valid_metadata(self, metadata): - keys = metadata.keys() - assert "version" in keys - assert "date" in keys - assert "etag" in keys - assert len(keys) == 3 - - # --Test cases for entities ------------------------------------------ - @tables_decorator_async async def test_url_encoding_at_symbol(self, tables_storage_account_name, tables_primary_storage_account_key): diff --git a/sdk/tables/azure-data-tables/tests/test_table_entity_cosmos.py b/sdk/tables/azure-data-tables/tests/test_table_entity_cosmos.py index 4f57e354e3d9..458e2d264b09 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_entity_cosmos.py +++ b/sdk/tables/azure-data-tables/tests/test_table_entity_cosmos.py @@ -5,15 +5,11 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- - import pytest -from base64 import b64encode -from datetime import datetime, timedelta +from datetime import datetime from dateutil.tz import tzutc, tzoffset from math import isnan -from time import sleep -import uuid from devtools_testutils import AzureTestCase @@ -24,14 +20,9 @@ ResourceExistsError ) from azure.data.tables import ( - TableServiceClient, - TableClient, - generate_table_sas, TableEntity, EntityProperty, EdmType, - TableSasPermissions, - AccessPolicy, UpdateMode ) @@ -41,266 +32,10 @@ # ------------------------------------------------------------------------------ class StorageTableEntityTest(AzureTestCase, TableTestCase): - - def _set_up(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - self.ts = TableServiceClient(self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) - self.table_name = self.get_resource_name('uttable') - try: - self.table = self.ts.get_table_client(self.table_name) - except: - for table_entity in self.ts.list_tables(): - self.ts.delete_table(table_entity.table_name) - self.table = self.ts.get_table_client(self.table_name) - - if self.is_live: - try: - self.ts.create_table(self.table_name) - except ResourceExistsError: - pass - - self.query_tables = [] - - def _tear_down(self): - if self.is_live: - try: - self.ts.delete_table(self.table_name) - except: - pass - - for table_item in self.ts.list_tables(): - try: - self.ts.delete_table(table_item.table_name) - except: - pass - - # --Helpers----------------------------------------------------------------- - - def _create_query_table(self, entity_count): - """ - Creates a table with the specified name and adds entities with the - default set of values. PartitionKey is set to 'MyPartition' and RowKey - is set to a unique counter value starting at 1 (as a string). - """ - table_name = self.get_resource_name('querytable') - table = self.ts.create_table(table_name) - self.query_tables.append(table_name) - client = self.ts.get_table_client(table_name) - entity = self._create_random_entity_dict() - for i in range(1, entity_count + 1): - entity['RowKey'] = entity['RowKey'] + str(i) - client.create_entity(entity) - return client - - def _create_random_base_entity_dict(self): - """ - Creates a dict-based entity with only pk and rk. - """ - # partition = self.get_resource_name('pk') - # row = self.get_resource_name('rk') - partition, row = self._create_pk_rk(None, None) - return { - 'PartitionKey': partition, - 'RowKey': row, - } - - def _create_pk_rk(self, pk, rk): - try: - pk = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - rk = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - except AttributeError: - pk = pk if pk is not None else self.get_resource_name('pk') - rk = rk if rk is not None else self.get_resource_name('rk') - return pk, rk - - def _insert_two_opposite_entities(self, pk=None, rk=None): - entity1 = self._create_random_entity_dict() - resp = self.table.create_entity(entity1) - - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition + u'1', - 'RowKey': row + u'1', - 'age': 49, - 'sex': u'female', - 'married': False, - 'deceased': True, - 'optional': None, - 'ratio': 5.2, - 'evenratio': 6.0, - 'large': 39999011, - 'Birthday': datetime(1993, 4, 1, tzinfo=tzutc()), - 'birthday': datetime(1990, 4, 1, tzinfo=tzutc()), - 'binary': b'binary-binary', - 'other': EntityProperty(40, EdmType.INT32), - 'clsid': uuid.UUID('c8da6455-213e-42d9-9b79-3f9149a57833') - } - self.table.create_entity(properties) - return entity1, resp - - def _create_random_entity_dict(self, pk=None, rk=None): - """ - Creates a dictionary-based entity with fixed values, using all - of the supported data types. - """ - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 39, - 'sex': u'male', - 'married': True, - 'deceased': False, - 'optional': None, - 'ratio': 3.1, - 'evenratio': 3.0, - 'large': 933311100, - 'Birthday': datetime(1973, 10, 4, tzinfo=tzutc()), - 'birthday': datetime(1970, 10, 4, tzinfo=tzutc()), - 'binary': b'binary', - 'other': EntityProperty(20, EdmType.INT32), - 'clsid': uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - } - return TableEntity(**properties) - - def _insert_random_entity(self, pk=None, rk=None): - entity = self._create_random_entity_dict(pk, rk) - metadata = self.table.create_entity(entity) - return entity, metadata['etag'] - - def _create_updated_entity_dict(self, partition, row): - """ - Creates a dictionary-based entity with fixed values, with a - different set of values than the default entity. It - adds fields, changes field values, changes field types, - and removes fields when compared to the default entity. - """ - return { - 'PartitionKey': partition, - 'RowKey': row, - 'age': u'abc', - 'sex': u'female', - 'sign': u'aquarius', - 'birthday': datetime(1991, 10, 4, tzinfo=tzutc()) - } - - def _assert_default_entity(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_default_entity_json_full_metadata(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_default_entity_json_no_metadata(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'].startswith('1973-10-04T00:00:00') - assert entity['birthday'].startswith('1970-10-04T00:00:00') - assert entity['Birthday'].endswith('00Z') - assert entity['birthday'].endswith('00Z') - assert entity['binary'] == b64encode(b'binary').decode('utf-8') - assert entity['other'] == 20 - assert entity['clsid'] == 'c9da6455-213d-42c9-9a79-3e9149a57833' - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_updated_entity(self, entity): - ''' - Asserts that the entity passed in matches the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert not "married" in entity - assert not "deceased" in entity - assert entity['sign'] == 'aquarius' - assert not "optional" in entity - assert not "ratio" in entity - assert not "evenratio" in entity - assert not "large" in entity - assert not "Birthday" in entity - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert not "other" in entity - assert not "clsid" in entity - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_merged_entity(self, entity): - ''' - Asserts that the entity passed in matches the default entity - merged with the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert entity['sign'] == 'aquarius' - assert entity['married'] == True - assert entity['deceased'] == False - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert entity['other'] == 20 - assert isinstance(entity['clsid'], uuid.UUID) - assert str(entity['clsid']) == 'c9da6455-213d-42c9-9a79-3e9149a57833' - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_valid_metadata(self, metadata): - keys = metadata.keys() - assert "version" in keys - assert "date" in keys - assert "etag" in keys - assert len(keys) == 3 - - # --Test cases for entities ------------------------------------------ @cosmos_decorator def test_url_encoding_at_symbol(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = { u"PartitionKey": u"PK", @@ -331,12 +66,11 @@ def test_url_encoding_at_symbol(self, tables_cosmos_account_name, tables_primary assert count == 0 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_etag(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -349,12 +83,11 @@ def test_insert_etag(self, tables_cosmos_account_name, tables_primary_cosmos_acc assert entity1.metadata['timestamp'] finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_user_filter(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._insert_random_entity() @@ -370,12 +103,11 @@ def test_query_user_filter(self, tables_cosmos_account_name, tables_primary_cosm assert length == 1 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_user_filter_multiple_params(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -395,12 +127,11 @@ def test_query_user_filter_multiple_params(self, tables_cosmos_account_name, tab assert length == 1 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_user_filter_integers(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_two_opposite_entities() @@ -419,12 +150,11 @@ def test_query_user_filter_integers(self, tables_cosmos_account_name, tables_pri assert length == 1 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_user_filter_floats(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_two_opposite_entities() @@ -443,12 +173,11 @@ def test_query_user_filter_floats(self, tables_cosmos_account_name, tables_prima assert length == 1 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_user_filter_datetimes(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_two_opposite_entities() @@ -467,12 +196,11 @@ def test_query_user_filter_datetimes(self, tables_cosmos_account_name, tables_pr assert length == 1 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_user_filter_guids(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_two_opposite_entities() @@ -491,12 +219,11 @@ def test_query_user_filter_guids(self, tables_cosmos_account_name, tables_primar assert length == 1 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_user_filter_binary(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_two_opposite_entities() @@ -519,7 +246,7 @@ def test_query_user_filter_binary(self, tables_cosmos_account_name, tables_prima @cosmos_decorator def test_query_user_filter_int64(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_two_opposite_entities() large_entity = { @@ -548,7 +275,7 @@ def test_query_user_filter_int64(self, tables_cosmos_account_name, tables_primar @cosmos_decorator def test_query_invalid_filter(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: base_entity = { u"PartitionKey": u"pk", @@ -568,12 +295,11 @@ def test_query_invalid_filter(self, tables_cosmos_account_name, tables_primary_c finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_dictionary(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() @@ -584,12 +310,11 @@ def test_insert_entity_dictionary(self, tables_cosmos_account_name, tables_prima assert resp is not None finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_with_hook(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() @@ -605,12 +330,11 @@ def test_insert_entity_with_hook(self, tables_cosmos_account_name, tables_primar self._assert_default_entity(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_with_no_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() headers = {'Accept': 'application/json;odata=nometadata'} @@ -631,12 +355,11 @@ def test_insert_entity_with_no_metadata(self, tables_cosmos_account_name, tables self._assert_default_entity_json_no_metadata(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_with_full_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() headers = {'Accept': 'application/json;odata=fullmetadata'} @@ -657,12 +380,11 @@ def test_insert_entity_with_full_metadata(self, tables_cosmos_account_name, tabl self._assert_default_entity_json_full_metadata(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_conflict(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -675,13 +397,12 @@ def test_insert_entity_conflict(self, tables_cosmos_account_name, tables_primary finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_with_large_int32_value_throws(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act dict32 = self._create_random_base_entity_dict() @@ -696,13 +417,12 @@ def test_insert_entity_with_large_int32_value_throws(self, tables_cosmos_account self.table.create_entity(entity=dict32) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_with_large_int64_value_throws(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act dict64 = self._create_random_base_entity_dict() @@ -717,13 +437,12 @@ def test_insert_entity_with_large_int64_value_throws(self, tables_cosmos_account self.table.create_entity(entity=dict64) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_with_large_int_success(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act dict64 = self._create_random_base_entity_dict() @@ -744,12 +463,11 @@ def test_insert_entity_with_large_int_success(self, tables_cosmos_account_name, finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_missing_pk(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = {'RowKey': 'rk'} @@ -759,12 +477,11 @@ def test_insert_entity_missing_pk(self, tables_cosmos_account_name, tables_prima # Assert finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_empty_string_pk(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = {'RowKey': 'rk', 'PartitionKey': ''} @@ -776,12 +493,11 @@ def test_insert_entity_empty_string_pk(self, tables_cosmos_account_name, tables_ # assert resp is not None finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_missing_rk(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = {'PartitionKey': 'pk'} @@ -792,12 +508,11 @@ def test_insert_entity_missing_rk(self, tables_cosmos_account_name, tables_prima # Assert finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_entity_empty_string_rk(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = {'PartitionKey': 'pk', 'RowKey': ''} @@ -807,12 +522,11 @@ def test_insert_entity_empty_string_rk(self, tables_cosmos_account_name, tables_ finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_get_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -826,12 +540,11 @@ def test_get_entity(self, tables_cosmos_account_name, tables_primary_cosmos_acco self._assert_default_entity(resp) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_get_entity_with_select(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -847,12 +560,11 @@ def test_get_entity_with_select(self, tables_cosmos_account_name, tables_primary assert resp == {'age': 39, 'ratio': 3.1} finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_get_entity_with_hook(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -870,12 +582,11 @@ def test_get_entity_with_hook(self, tables_cosmos_account_name, tables_primary_c self._assert_default_entity(resp) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_get_entity_if_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = self._insert_random_entity() @@ -897,12 +608,11 @@ def test_get_entity_if_match(self, tables_cosmos_account_name, tables_primary_co ) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_get_entity_if_match_entity_bad_etag(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, old_etag = self._insert_random_entity() @@ -926,7 +636,7 @@ def test_get_entity_if_match_entity_bad_etag(self, tables_cosmos_account_name, t @cosmos_decorator def test_delete_entity_if_match_table_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = self._insert_random_entity() table_entity = TableEntity(**entity) @@ -949,7 +659,7 @@ def test_delete_entity_if_match_table_entity(self, tables_cosmos_account_name, t @cosmos_decorator def test_get_entity_full_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -965,12 +675,11 @@ def test_get_entity_full_metadata(self, tables_cosmos_account_name, tables_prima self._assert_default_entity_json_full_metadata(resp) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_get_entity_no_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -986,12 +695,11 @@ def test_get_entity_no_metadata(self, tables_cosmos_account_name, tables_primary self._assert_default_entity_json_no_metadata(resp) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_get_entity_not_existing(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() @@ -1003,12 +711,11 @@ def test_get_entity_not_existing(self, tables_cosmos_account_name, tables_primar # Assert finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_get_entity_with_special_doubles(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity.update({ @@ -1028,12 +735,11 @@ def test_get_entity_with_special_doubles(self, tables_cosmos_account_name, table assert isnan(resp['nan']) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_update_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1050,12 +756,11 @@ def test_update_entity(self, tables_cosmos_account_name, tables_primary_cosmos_a self._assert_updated_entity(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_update_entity_not_existing(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() @@ -1067,12 +772,11 @@ def test_update_entity_not_existing(self, tables_cosmos_account_name, tables_pri # Assert finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_update_entity_with_if_matches(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = self._insert_random_entity() @@ -1089,12 +793,11 @@ def test_update_entity_with_if_matches(self, tables_cosmos_account_name, tables_ self._assert_updated_entity(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_update_entity_with_if_doesnt_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1110,13 +813,12 @@ def test_update_entity_with_if_doesnt_match(self, tables_cosmos_account_name, ta # Assert finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_or_merge_entity_with_existing_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1130,13 +832,12 @@ def test_insert_or_merge_entity_with_existing_entity(self, tables_cosmos_account self._assert_merged_entity(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_or_merge_entity_with_non_existing_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() @@ -1151,13 +852,12 @@ def test_insert_or_merge_entity_with_non_existing_entity(self, tables_cosmos_acc self._assert_updated_entity(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_or_replace_entity_with_existing_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1171,13 +871,12 @@ def test_insert_or_replace_entity_with_existing_entity(self, tables_cosmos_accou self._assert_updated_entity(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_insert_or_replace_entity_with_non_existing_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() @@ -1192,12 +891,11 @@ def test_insert_or_replace_entity_with_non_existing_entity(self, tables_cosmos_a self._assert_updated_entity(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_merge_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1211,12 +909,11 @@ def test_merge_entity(self, tables_cosmos_account_name, tables_primary_cosmos_ac self._assert_merged_entity(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_merge_entity_not_existing(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() @@ -1228,12 +925,11 @@ def test_merge_entity_not_existing(self, tables_cosmos_account_name, tables_prim # Assert finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_merge_entity_with_if_matches(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = self._insert_random_entity() @@ -1251,12 +947,11 @@ def test_merge_entity_with_if_matches(self, tables_cosmos_account_name, tables_p self._assert_merged_entity(received_entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_merge_entity_with_if_doesnt_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1271,12 +966,11 @@ def test_merge_entity_with_if_doesnt_match(self, tables_cosmos_account_name, tab # Assert finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_delete_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1288,23 +982,21 @@ def test_delete_entity(self, tables_cosmos_account_name, tables_primary_cosmos_a self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_delete_entity_not_existing(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() self.table.delete_entity(entity['PartitionKey'], entity['RowKey']) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_delete_entity_with_if_matches(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = self._insert_random_entity() @@ -1321,12 +1013,11 @@ def test_delete_entity_with_if_matches(self, tables_cosmos_account_name, tables_ self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_delete_entity_with_if_doesnt_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1342,12 +1033,11 @@ def test_delete_entity_with_if_doesnt_match(self, tables_cosmos_account_name, ta # Assert finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_delete_entity_overloads(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1375,7 +1065,7 @@ def test_delete_entity_overloads(self, tables_cosmos_account_name, tables_primar @cosmos_decorator def test_delete_entity_overloads_kwargs(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() @@ -1403,7 +1093,7 @@ def test_delete_entity_overloads_kwargs(self, tables_cosmos_account_name, tables @cosmos_decorator def test_unicode_property_value(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity1 = entity.copy() @@ -1422,12 +1112,11 @@ def test_unicode_property_value(self, tables_cosmos_account_name, tables_primary assert entities[1]['Description'] == u'ꀕ' finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_unicode_property_name(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity1 = entity.copy() @@ -1447,7 +1136,6 @@ def test_unicode_property_name(self, tables_cosmos_account_name, tables_primary_ assert entities[1][u'啊齄丂狛狜'] == u'hello' finally: self._tear_down() - self.sleep(SLEEP_DELAY) @pytest.mark.skip("Bad Request: Cosmos cannot handle single quotes in a PK/RK (confirm)") @cosmos_decorator @@ -1456,7 +1144,7 @@ def test_operations_on_entity_with_partition_key_having_single_quote(self, table # Arrange partition_key_with_single_quote = "a''''b" row_key_with_single_quote = "a''''b" - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity(pk=partition_key_with_single_quote, rk=row_key_with_single_quote) @@ -1487,12 +1175,11 @@ def test_operations_on_entity_with_partition_key_having_single_quote(self, table assert resp is not None finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_empty_and_spaces_property_value(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity.update({ @@ -1525,12 +1212,11 @@ def test_empty_and_spaces_property_value(self, tables_cosmos_account_name, table assert resp['SpacesBeforeAndAfterUnicode'] == u' Text ' finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_none_property_value(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity.update({'NoneValue': None}) @@ -1544,12 +1230,11 @@ def test_none_property_value(self, tables_cosmos_account_name, tables_primary_co assert not hasattr(resp, 'NoneValue') finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_binary_property_value(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: binary_data = b'\x01\x02\x03\x04\x05\x06\x07\x08\t\n' entity = self._create_random_base_entity_dict() @@ -1564,12 +1249,11 @@ def test_binary_property_value(self, tables_cosmos_account_name, tables_primary_ assert resp['binary'].value == binary_data finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_timezone(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: local_tz = tzoffset('BRST', -10800) local_date = datetime(2003, 9, 27, 9, 52, 43, tzinfo=local_tz) @@ -1587,12 +1271,11 @@ def test_timezone(self, tables_cosmos_account_name, tables_primary_cosmos_accoun assert resp['date'].astimezone(local_tz) == local_date finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_entities(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table = self._create_query_table(2) @@ -1605,12 +1288,11 @@ def test_query_entities(self, tables_cosmos_account_name, tables_primary_cosmos_ self._assert_default_entity(entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_entities_each_page(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: base_entity = { "PartitionKey": u"pk", @@ -1646,12 +1328,11 @@ def test_query_entities_each_page(self, tables_cosmos_account_name, tables_prima finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_zero_entities(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table = self._create_query_table(0) @@ -1662,12 +1343,11 @@ def test_query_zero_entities(self, tables_cosmos_account_name, tables_primary_co assert len(entities) == 0 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_entities_full_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table = self._create_query_table(2) @@ -1680,12 +1360,11 @@ def test_query_entities_full_metadata(self, tables_cosmos_account_name, tables_p self._assert_default_entity_json_full_metadata(entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_entities_no_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table = self._create_query_table(2) @@ -1698,12 +1377,11 @@ def test_query_entities_no_metadata(self, tables_cosmos_account_name, tables_pri self._assert_default_entity_json_no_metadata(entity) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_entities_with_filter(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = self._insert_random_entity() entity2, _ = self._insert_random_entity(pk="foo" + entity['PartitionKey']) @@ -1719,12 +1397,11 @@ def test_query_entities_with_filter(self, tables_cosmos_account_name, tables_pri self._assert_default_entity(entities[0]) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_injection(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table_name = self.get_resource_name('querytable') table = self.ts.create_table_if_not_exists(table_name) @@ -1752,7 +1429,7 @@ def test_query_injection(self, tables_cosmos_account_name, tables_primary_cosmos @cosmos_decorator def test_query_special_chars(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table_name = self.get_resource_name('querytable') table = self.ts.create_table_if_not_exists(table_name) @@ -1793,7 +1470,7 @@ def test_query_special_chars(self, tables_cosmos_account_name, tables_primary_co @cosmos_decorator def test_query_entities_with_select(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table = self._create_query_table(2) @@ -1811,12 +1488,11 @@ def test_query_entities_with_select(self, tables_cosmos_account_name, tables_pri assert len(entities) == 2 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_entities_with_top(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table = self._create_query_table(3) # circular dependencies made this return a list not an item paged - problem when calling by page @@ -1827,12 +1503,11 @@ def test_query_entities_with_top(self, tables_cosmos_account_name, tables_primar assert len(entities) == 2 finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_query_entities_with_top_and_next(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table = self._create_query_table(5) @@ -1861,11 +1536,10 @@ def test_query_entities_with_top_and_next(self, tables_cosmos_account_name, tabl self._assert_default_entity(entities3[0]) finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_datetime_milliseconds(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() @@ -1882,11 +1556,10 @@ def test_datetime_milliseconds(self, tables_cosmos_account_name, tables_primary_ finally: self._tear_down() - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_datetime_str_passthrough(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") partition, row = self._create_pk_rk(None, None) dotnet_timestamp = "2013-08-22T01:12:06.2608595Z" diff --git a/sdk/tables/azure-data-tables/tests/test_table_entity_cosmos_async.py b/sdk/tables/azure-data-tables/tests/test_table_entity_cosmos_async.py index 4a539e40be72..0c1abda54cf1 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_entity_cosmos_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_entity_cosmos_async.py @@ -1,33 +1,23 @@ # coding: utf-8 - # ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- - import pytest -from base64 import b64encode -from datetime import datetime, timedelta +from datetime import datetime from dateutil.tz import tzutc, tzoffset from math import isnan -from time import sleep -import uuid from devtools_testutils import AzureTestCase from azure.data.tables import ( - generate_table_sas, TableEntity, EntityProperty, EdmType, - TableSasPermissions, - AccessPolicy, UpdateMode ) -from azure.data.tables.aio import TableServiceClient - from azure.core import MatchConditions from azure.core.exceptions import ( HttpResponseError, @@ -36,269 +26,16 @@ ) from _shared.asynctestcase import AsyncTableTestCase -from _shared.testcase import SLEEP_DELAY from async_preparers import cosmos_decorator_async # ------------------------------------------------------------------------------ # TODO: change to `with table_client as client:` to close sessions # ------------------------------------------------------------------------------ class StorageTableEntityTest(AzureTestCase, AsyncTableTestCase): - - async def _set_up(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - account_url = self.account_url(tables_cosmos_account_name, "cosmos") - self.ts = TableServiceClient(account_url, tables_primary_cosmos_account_key) - self.table_name = self.get_resource_name('uttable') - self.table = self.ts.get_table_client(self.table_name) - if self.is_live: - try: - await self.ts.create_table(table_name=self.table_name) - except ResourceExistsError: - pass - - self.query_tables = [] - - async def _tear_down(self): - if self.is_live: - async with self.ts as t: - try: - await t.delete_table(self.table_name) - except: - pass - - for table_name in self.query_tables: - try: - await t.delete_table(table_name) - except: - pass - self.sleep(SLEEP_DELAY) - - # --Helpers----------------------------------------------------------------- - async def _create_query_table(self, entity_count): - """ - Creates a table with the specified name and adds entities with the - default set of values. PartitionKey is set to 'MyPartition' and RowKey - is set to a unique counter value starting at 1 (as a string). - """ - table_name = self.get_resource_name('querytable') - table = await self.ts.create_table(table_name) - self.query_tables.append(table_name) - client = self.ts.get_table_client(table_name) - entity = self._create_random_entity_dict() - for i in range(1, entity_count + 1): - entity['RowKey'] = entity['RowKey'] + str(i) - await client.create_entity(entity=entity) - return client - - def _create_random_base_entity_dict(self): - """ - Creates a dict-based entity with only pk and rk. - """ - partition = self.get_resource_name('pk') - row = self.get_resource_name('rk') - return { - 'PartitionKey': partition, - 'RowKey': row, - } - - def _create_pk_rk(self, pk, rk): - try: - pk = pk if pk is not None else self.get_resource_name('pk').decode('utf-8') - rk = rk if rk is not None else self.get_resource_name('rk').decode('utf-8') - except AttributeError: - pk = pk if pk is not None else self.get_resource_name('pk') - rk = rk if rk is not None else self.get_resource_name('rk') - return pk, rk - - async def _insert_two_opposite_entities(self, pk=None, rk=None): - entity1 = self._create_random_entity_dict() - resp = await self.table.create_entity(entity1) - - partition, row = self._create_pk_rk(pk, rk) - properties = { - 'PartitionKey': partition + u'1', - 'RowKey': row + u'1', - 'age': 49, - 'sex': u'female', - 'married': False, - 'deceased': True, - 'optional': None, - 'ratio': 5.2, - 'evenratio': 6.0, - 'large': 39999011, - 'Birthday': datetime(1993, 4, 1, tzinfo=tzutc()), - 'birthday': datetime(1990, 4, 1, tzinfo=tzutc()), - 'binary': b'binary-binary', - 'other': EntityProperty(40, EdmType.INT32), - 'clsid': uuid.UUID('c8da6455-213e-42d9-9b79-3f9149a57833') - } - await self.table.create_entity(properties) - return entity1, resp - - def _create_random_entity_dict(self, pk=None, rk=None): - """ - Creates a dictionary-based entity with fixed values, using all - of the supported data types. - """ - partition = pk if pk is not None else self.get_resource_name('pk') - row = rk if rk is not None else self.get_resource_name('rk') - properties = { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 39, - 'sex': 'male', - 'married': True, - 'deceased': False, - 'optional': None, - 'ratio': 3.1, - 'evenratio': 3.0, - 'large': 933311100, - 'Birthday': datetime(1973, 10, 4, tzinfo=tzutc()), - 'birthday': datetime(1970, 10, 4, tzinfo=tzutc()), - 'binary': b'binary', - 'other': EntityProperty(20, EdmType.INT32), - 'clsid': uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - } - return TableEntity(**properties) - - async def _insert_random_entity(self, pk=None, rk=None): - entity = self._create_random_entity_dict(pk, rk) - metadata = await self.table.create_entity(entity=entity) - return entity, metadata['etag'] - - def _create_updated_entity_dict(self, partition, row): - """ - Creates a dictionary-based entity with fixed values, with a - different set of values than the default entity. It - adds fields, changes field values, changes field types, - and removes fields when compared to the default entity. - """ - return { - 'PartitionKey': partition, - 'RowKey': row, - 'age': 'abc', - 'sex': 'female', - 'sign': 'aquarius', - 'birthday': datetime(1991, 10, 4, tzinfo=tzutc()) - } - - def _assert_default_entity(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_default_entity_json_full_metadata(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1970, 10, 4, tzinfo=tzutc()) - assert entity['binary'].value == b'binary' - assert entity['other'] == 20 - assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_default_entity_json_no_metadata(self, entity, headers=None): - ''' - Asserts that the entity passed in matches the default entity. - ''' - assert entity['age'] == 39 - assert entity['sex'] == 'male' - assert entity['married'] == True - assert entity['deceased'] == False - assert not "optional" in entity - assert not "aquarius" in entity - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'].startswith('1973-10-04T00:00:00') - assert entity['birthday'].startswith('1970-10-04T00:00:00') - assert entity['Birthday'].endswith('00Z') - assert entity['birthday'].endswith('00Z') - assert entity['binary'] == b64encode(b'binary').decode('utf-8') - assert entity['other'] == 20 - assert entity['clsid'] == 'c9da6455-213d-42c9-9a79-3e9149a57833' - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_updated_entity(self, entity): - ''' - Asserts that the entity passed in matches the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert not "married" in entity - assert not "deceased" in entity - assert entity['sign'] == 'aquarius' - assert not "optional" in entity - assert not "ratio" in entity - assert not "evenratio" in entity - assert not "large" in entity - assert not "Birthday" in entity - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert not "other" in entity - assert not "clsid" in entity - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_merged_entity(self, entity): - ''' - Asserts that the entity passed in matches the default entity - merged with the updated entity. - ''' - assert entity['age'] == 'abc' - assert entity['sex'] == 'female' - assert entity['sign'] == 'aquarius' - assert entity['married'] == True - assert entity['deceased'] == False - assert entity['ratio'] == 3.1 - assert entity['evenratio'] == 3.0 - assert entity['large'] == 933311100 - assert entity['Birthday'] == datetime(1973, 10, 4, tzinfo=tzutc()) - assert entity['birthday'] == datetime(1991, 10, 4, tzinfo=tzutc()) - assert entity['other'] == 20 - assert isinstance(entity['clsid'], uuid.UUID) - assert str(entity['clsid']) == 'c9da6455-213d-42c9-9a79-3e9149a57833' - assert entity.metadata['etag'] - assert entity.metadata['timestamp'] - - def _assert_valid_metadata(self, metadata): - keys = metadata.keys() - assert "version" in keys - assert "date" in keys - assert "etag" in keys - assert len(keys) == 3 - - # --Test cases for entities ------------------------------------------ @cosmos_decorator_async async def test_url_encoding_at_symbol(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = { u"PartitionKey": u"PK", @@ -333,7 +70,7 @@ async def test_url_encoding_at_symbol(self, tables_cosmos_account_name, tables_p @cosmos_decorator_async async def test_insert_entity_dictionary(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() @@ -348,7 +85,7 @@ async def test_insert_entity_dictionary(self, tables_cosmos_account_name, tables @cosmos_decorator_async async def test_insert_entity_with_hook(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() @@ -367,7 +104,7 @@ async def test_insert_entity_with_hook(self, tables_cosmos_account_name, tables_ @cosmos_decorator_async async def test_insert_entity_with_no_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() headers = {'Accept': 'application/json;odata=nometadata'} @@ -393,7 +130,7 @@ async def test_insert_entity_with_no_metadata(self, tables_cosmos_account_name, async def test_insert_entity_with_full_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() headers = {'Accept': 'application/json;odata=fullmetadata'} @@ -418,7 +155,7 @@ async def test_insert_entity_with_full_metadata(self, tables_cosmos_account_name @cosmos_decorator_async async def test_insert_entity_conflict(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -434,7 +171,7 @@ async def test_insert_entity_conflict(self, tables_cosmos_account_name, tables_p async def test_insert_entity_with_large_int32_value_throws(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act dict32 = self._create_random_base_entity_dict() @@ -454,7 +191,7 @@ async def test_insert_entity_with_large_int32_value_throws(self, tables_cosmos_a async def test_insert_entity_with_large_int64_value_throws(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act dict64 = self._create_random_base_entity_dict() @@ -474,7 +211,7 @@ async def test_insert_entity_with_large_int64_value_throws(self, tables_cosmos_a async def test_insert_entity_with_large_int_success(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: # Act dict64 = self._create_random_base_entity_dict() @@ -499,7 +236,7 @@ async def test_insert_entity_with_large_int_success(self, tables_cosmos_account_ @cosmos_decorator_async async def test_insert_entity_missing_pk(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = {'RowKey': 'rk'} @@ -513,7 +250,7 @@ async def test_insert_entity_missing_pk(self, tables_cosmos_account_name, tables @cosmos_decorator_async async def test_insert_entity_empty_string_pk(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = {'RowKey': 'rk', 'PartitionKey': ''} @@ -526,7 +263,7 @@ async def test_insert_entity_empty_string_pk(self, tables_cosmos_account_name, t @cosmos_decorator_async async def test_insert_entity_missing_rk(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = {'PartitionKey': 'pk'} @@ -541,7 +278,7 @@ async def test_insert_entity_missing_rk(self, tables_cosmos_account_name, tables @cosmos_decorator_async async def test_insert_entity_empty_string_rk(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = {'PartitionKey': 'pk', 'RowKey': ''} @@ -555,7 +292,7 @@ async def test_insert_entity_empty_string_rk(self, tables_cosmos_account_name, t @cosmos_decorator_async async def test_get_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -573,7 +310,7 @@ async def test_get_entity(self, tables_cosmos_account_name, tables_primary_cosmo @cosmos_decorator_async async def test_get_entity_with_select(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -594,7 +331,7 @@ async def test_get_entity_with_select(self, tables_cosmos_account_name, tables_p @cosmos_decorator_async async def test_get_entity_with_hook(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -614,7 +351,7 @@ async def test_get_entity_with_hook(self, tables_cosmos_account_name, tables_pri @cosmos_decorator_async async def test_get_entity_if_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = await self._insert_random_entity() @@ -640,7 +377,7 @@ async def test_get_entity_if_match(self, tables_cosmos_account_name, tables_prim @cosmos_decorator_async async def test_get_entity_if_match_entity_bad_etag(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, old_etag = await self._insert_random_entity() @@ -664,7 +401,7 @@ async def test_get_entity_if_match_entity_bad_etag(self, tables_cosmos_account_n @cosmos_decorator_async async def test_delete_entity_if_match_table_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = await self._insert_random_entity() table_entity = TableEntity(**entity) @@ -688,7 +425,7 @@ async def test_delete_entity_if_match_table_entity(self, tables_cosmos_account_n @cosmos_decorator_async async def test_get_entity_full_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -708,7 +445,7 @@ async def test_get_entity_full_metadata(self, tables_cosmos_account_name, tables @cosmos_decorator_async async def test_get_entity_no_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -728,7 +465,7 @@ async def test_get_entity_no_metadata(self, tables_cosmos_account_name, tables_p @cosmos_decorator_async async def test_get_entity_not_existing(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() @@ -745,7 +482,7 @@ async def test_get_entity_not_existing(self, tables_cosmos_account_name, tables_ async def test_get_entity_with_special_doubles(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity.update({ @@ -769,7 +506,7 @@ async def test_get_entity_with_special_doubles(self, tables_cosmos_account_name, @cosmos_decorator_async async def test_update_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -791,7 +528,7 @@ async def test_update_entity(self, tables_cosmos_account_name, tables_primary_co @cosmos_decorator_async async def test_update_entity_not_existing(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() @@ -807,7 +544,7 @@ async def test_update_entity_not_existing(self, tables_cosmos_account_name, tabl @cosmos_decorator_async async def test_update_entity_with_if_matches(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = await self._insert_random_entity() @@ -830,7 +567,7 @@ async def test_update_entity_with_if_matches(self, tables_cosmos_account_name, t async def test_update_entity_with_if_doesnt_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -851,7 +588,7 @@ async def test_update_entity_with_if_doesnt_match(self, tables_cosmos_account_na async def test_insert_or_merge_entity_with_existing_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -870,7 +607,7 @@ async def test_insert_or_merge_entity_with_existing_entity(self, tables_cosmos_a async def test_insert_or_merge_entity_with_non_existing_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() @@ -888,7 +625,7 @@ async def test_insert_or_merge_entity_with_non_existing_entity(self, tables_cosm async def test_insert_or_replace_entity_with_existing_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -907,7 +644,7 @@ async def test_insert_or_replace_entity_with_existing_entity(self, tables_cosmos async def test_insert_or_replace_entity_with_non_existing_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() @@ -923,7 +660,7 @@ async def test_insert_or_replace_entity_with_non_existing_entity(self, tables_co @cosmos_decorator_async async def test_merge_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -940,7 +677,7 @@ async def test_merge_entity(self, tables_cosmos_account_name, tables_primary_cos @cosmos_decorator_async async def test_merge_entity_not_existing(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() @@ -956,7 +693,7 @@ async def test_merge_entity_not_existing(self, tables_cosmos_account_name, table @cosmos_decorator_async async def test_merge_entity_with_if_matches(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = await self._insert_random_entity() @@ -976,7 +713,7 @@ async def test_merge_entity_with_if_matches(self, tables_cosmos_account_name, ta async def test_merge_entity_with_if_doesnt_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -995,7 +732,7 @@ async def test_merge_entity_with_if_doesnt_match(self, tables_cosmos_account_nam @cosmos_decorator_async async def test_delete_entity(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -1009,7 +746,7 @@ async def test_delete_entity(self, tables_cosmos_account_name, tables_primary_co @cosmos_decorator_async async def test_delete_entity_not_existing(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() await self.table.delete_entity(entity['PartitionKey'], entity['RowKey']) @@ -1019,7 +756,7 @@ async def test_delete_entity_not_existing(self, tables_cosmos_account_name, tabl @cosmos_decorator_async async def test_delete_entity_with_if_matches(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, etag = await self._insert_random_entity() @@ -1039,7 +776,7 @@ async def test_delete_entity_with_if_matches(self, tables_cosmos_account_name, t async def test_delete_entity_with_if_doesnt_match(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -1057,7 +794,7 @@ async def test_delete_entity_with_if_doesnt_match(self, tables_cosmos_account_na @cosmos_decorator_async async def test_delete_entity_overloads(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -1086,7 +823,7 @@ async def test_delete_entity_overloads(self, tables_cosmos_account_name, tables_ @cosmos_decorator_async async def test_delete_entity_overloads_kwargs(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() @@ -1116,7 +853,7 @@ async def test_delete_entity_overloads_kwargs(self, tables_cosmos_account_name, async def test_unicode_property_value(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): ''' regression test for github issue #57''' # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity1 = entity.copy() @@ -1142,7 +879,7 @@ async def test_unicode_property_value(self, tables_cosmos_account_name, tables_p @cosmos_decorator_async async def test_unicode_property_name(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity1 = entity.copy() @@ -1171,7 +908,7 @@ async def test_operations_on_entity_with_partition_key_having_single_quote(self, # Arrange partition_key_with_single_quote = "a''''b" row_key_with_single_quote = "a''''b" - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity(pk=partition_key_with_single_quote, rk=row_key_with_single_quote) @@ -1197,7 +934,7 @@ async def test_operations_on_entity_with_partition_key_having_single_quote(self, async def test_empty_and_spaces_property_value(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity.update({ @@ -1235,7 +972,7 @@ async def test_empty_and_spaces_property_value(self, tables_cosmos_account_name, @cosmos_decorator_async async def test_none_property_value(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_base_entity_dict() entity.update({'NoneValue': None}) @@ -1253,7 +990,7 @@ async def test_none_property_value(self, tables_cosmos_account_name, tables_prim @cosmos_decorator_async async def test_binary_property_value(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: binary_data = b'\x01\x02\x03\x04\x05\x06\x07\x08\t\n' entity = self._create_random_base_entity_dict() @@ -1272,7 +1009,7 @@ async def test_binary_property_value(self, tables_cosmos_account_name, tables_pr @cosmos_decorator_async async def test_timezone(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: local_tz = tzoffset('BRST', -10800) local_date = datetime(2003, 9, 27, 9, 52, 43, tzinfo=local_tz) @@ -1294,7 +1031,7 @@ async def test_timezone(self, tables_cosmos_account_name, tables_primary_cosmos_ @cosmos_decorator_async async def test_query_entities(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: async with await self._create_query_table(2) as table: @@ -1313,7 +1050,7 @@ async def test_query_entities(self, tables_cosmos_account_name, tables_primary_c @cosmos_decorator_async async def test_query_entities_each_page(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: base_entity = { "PartitionKey": u"pk", @@ -1353,7 +1090,7 @@ async def test_query_entities_each_page(self, tables_cosmos_account_name, tables @cosmos_decorator_async async def test_query_user_filter(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = await self._insert_two_opposite_entities() @@ -1374,7 +1111,7 @@ async def test_query_user_filter(self, tables_cosmos_account_name, tables_primar @cosmos_decorator_async async def test_query_user_filter_multiple_params(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_two_opposite_entities() @@ -1398,7 +1135,7 @@ async def test_query_user_filter_multiple_params(self, tables_cosmos_account_nam @cosmos_decorator_async async def test_query_user_filter_integers(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_two_opposite_entities() @@ -1421,7 +1158,7 @@ async def test_query_user_filter_integers(self, tables_cosmos_account_name, tabl @cosmos_decorator_async async def test_query_user_filter_floats(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_two_opposite_entities() @@ -1444,7 +1181,7 @@ async def test_query_user_filter_floats(self, tables_cosmos_account_name, tables @cosmos_decorator_async async def test_query_user_filter_datetimes(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_two_opposite_entities() @@ -1467,7 +1204,7 @@ async def test_query_user_filter_datetimes(self, tables_cosmos_account_name, tab @cosmos_decorator_async async def test_query_user_filter_guids(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_two_opposite_entities() @@ -1490,7 +1227,7 @@ async def test_query_user_filter_guids(self, tables_cosmos_account_name, tables_ @cosmos_decorator_async async def test_query_user_filter_binary(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_two_opposite_entities() @@ -1513,7 +1250,7 @@ async def test_query_user_filter_binary(self, tables_cosmos_account_name, tables @cosmos_decorator_async async def test_query_user_filter_int64(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_two_opposite_entities() large_entity = { @@ -1543,7 +1280,7 @@ async def test_query_user_filter_int64(self, tables_cosmos_account_name, tables_ @cosmos_decorator_async async def test_query_zero_entities(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: async with await self._create_query_table(0) as table: @@ -1560,7 +1297,7 @@ async def test_query_zero_entities(self, tables_cosmos_account_name, tables_prim @cosmos_decorator_async async def test_query_entities_full_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: async with await self._create_query_table(2) as table: @@ -1579,7 +1316,7 @@ async def test_query_entities_full_metadata(self, tables_cosmos_account_name, ta @cosmos_decorator_async async def test_query_entities_no_metadata(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: async with await self._create_query_table(2) as table: @@ -1598,7 +1335,7 @@ async def test_query_entities_no_metadata(self, tables_cosmos_account_name, tabl @cosmos_decorator_async async def test_query_entities_with_filter(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity, _ = await self._insert_random_entity() entity2, _ = await self._insert_random_entity(pk="foo" + entity['PartitionKey']) @@ -1620,7 +1357,7 @@ async def test_query_entities_with_filter(self, tables_cosmos_account_name, tabl @cosmos_decorator_async async def test_query_injection_async(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table_name = self.get_resource_name('querytable') table = await self.ts.create_table_if_not_exists(table_name) @@ -1655,7 +1392,7 @@ async def test_query_injection_async(self, tables_cosmos_account_name, tables_pr @cosmos_decorator_async async def test_query_special_chars(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table_name = self.get_resource_name('querytable') table = await self.ts.create_table_if_not_exists(table_name) @@ -1713,7 +1450,7 @@ async def test_query_special_chars(self, tables_cosmos_account_name, tables_prim @cosmos_decorator_async async def test_query_invalid_filter(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: base_entity = { u"PartitionKey": u"pk", @@ -1734,7 +1471,7 @@ async def test_query_invalid_filter(self, tables_cosmos_account_name, tables_pri @cosmos_decorator_async async def test_query_entities_with_select(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: table = await self._create_query_table(2) @@ -1756,7 +1493,7 @@ async def test_query_entities_with_select(self, tables_cosmos_account_name, tabl @cosmos_decorator_async async def test_query_entities_with_top(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: async with await self._create_query_table(3) as table: @@ -1772,7 +1509,7 @@ async def test_query_entities_with_top(self, tables_cosmos_account_name, tables_ async def test_query_entities_with_top_and_next(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: async with await self._create_query_table(5) as table: @@ -1806,7 +1543,7 @@ async def test_query_entities_with_top_and_next(self, tables_cosmos_account_name @cosmos_decorator_async async def test_datetime_milliseconds(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") try: entity = self._create_random_entity_dict() @@ -1826,7 +1563,7 @@ async def test_datetime_milliseconds(self, tables_cosmos_account_name, tables_pr @cosmos_decorator_async async def test_datetime_str_passthrough(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): - await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) + await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key, url="cosmos") partition, row = self._create_pk_rk(None, None) dotnet_timestamp = "2013-08-22T01:12:06.2608595Z" diff --git a/sdk/tables/azure-data-tables/tests/test_table_service_properties.py b/sdk/tables/azure-data-tables/tests/test_table_service_properties.py index 961b573d39a6..9cf1c874104b 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_service_properties.py +++ b/sdk/tables/azure-data-tables/tests/test_table_service_properties.py @@ -26,81 +26,6 @@ class TableServicePropertiesTest(AzureTestCase, TableTestCase): - # --Helpers----------------------------------------------------------------- - def _assert_properties_default(self, prop): - assert prop is not None - - self._assert_logging_equal(prop['analytics_logging'], TableAnalyticsLogging()) - self._assert_metrics_equal(prop['hour_metrics'], Metrics()) - self._assert_metrics_equal(prop['minute_metrics'], Metrics()) - self._assert_cors_equal(prop['cors'], list()) - - def _assert_logging_equal(self, log1, log2): - if log1 is None or log2 is None: - assert log1 == log2 - return - - assert log1.version == log2.version - assert log1.read == log2.read - assert log1.write == log2.write - assert log1.delete == log2.delete - self._assert_retention_equal(log1.retention_policy, log2.retention_policy) - - def _assert_delete_retention_policy_equal(self, policy1, policy2): - if policy1 is None or policy2 is None: - assert policy1 == policy2 - return - - assert policy1.enabled == policy2.enabled - assert policy1.days == policy2.days - - def _assert_static_website_equal(self, prop1, prop2): - if prop1 is None or prop2 is None: - assert prop1 == prop2 - return - - assert prop1.enabled == prop2.enabled - assert prop1.index_document == prop2.index_document - assert prop1.error_document404_path == prop2.error_document404_path - - def _assert_delete_retention_policy_not_equal(self, policy1, policy2): - if policy1 is None or policy2 is None: - assert policy1 != policy2 - return - - assert (policy1.enabled == policy2.enabled and policy1.days == policy2.days) - - def _assert_metrics_equal(self, metrics1, metrics2): - if metrics1 is None or metrics2 is None: - assert metrics1 == metrics2 - return - - assert metrics1.version == metrics2.version - assert metrics1.enabled == metrics2.enabled - assert metrics1.include_apis == metrics2.include_apis - self._assert_retention_equal(metrics1.retention_policy, metrics2.retention_policy) - - def _assert_cors_equal(self, cors1, cors2): - if cors1 is None or cors2 is None: - assert cors1 == cors2 - return - - assert len(cors1) == len(cors2) - - for i in range(0, len(cors1)): - rule1 = cors1[i] - rule2 = cors2[i] - assert len(rule1.allowed_origins) == len(rule2.allowed_origins) - assert len(rule1.allowed_methods) == len(rule2.allowed_methods) - assert rule1.max_age_in_seconds == rule2.max_age_in_seconds - assert len(rule1.exposed_headers) == len(rule2.exposed_headers) - assert len(rule1.allowed_headers) == len(rule2.allowed_headers) - - def _assert_retention_equal(self, ret1, ret2): - assert ret1.enabled == ret2.enabled - assert ret1.days == ret2.days - - # --Test cases per service --------------------------------------- @tables_decorator def test_table_service_properties(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange diff --git a/sdk/tables/azure-data-tables/tests/test_table_service_properties_async.py b/sdk/tables/azure-data-tables/tests/test_table_service_properties_async.py index 64a52b976815..6c3501ea6ba6 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_service_properties_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_service_properties_async.py @@ -22,81 +22,6 @@ class TableServicePropertiesTest(AzureTestCase, TableTestCase): - # --Helpers----------------------------------------------------------------- - def _assert_properties_default(self, prop): - assert prop is not None - - self._assert_logging_equal(prop['analytics_logging'], TableAnalyticsLogging()) - self._assert_metrics_equal(prop['hour_metrics'], Metrics()) - self._assert_metrics_equal(prop['minute_metrics'], Metrics()) - self._assert_cors_equal(prop['cors'], list()) - - def _assert_logging_equal(self, log1, log2): - if log1 is None or log2 is None: - assert log1 == log2 - return - - assert log1.version == log2.version - assert log1.read == log2.read - assert log1.write == log2.write - assert log1.delete == log2.delete - self._assert_retention_equal(log1.retention_policy, log2.retention_policy) - - def _assert_delete_retention_policy_equal(self, policy1, policy2): - if policy1 is None or policy2 is None: - assert policy1 == policy2 - return - - assert policy1.enabled == policy2.enabled - assert policy1.days == policy2.days - - def _assert_static_website_equal(self, prop1, prop2): - if prop1 is None or prop2 is None: - assert prop1 == prop2 - return - - assert prop1.enabled == prop2.enabled - assert prop1.index_document == prop2.index_document - assert prop1.error_document404_path == prop2.error_document404_path - - def _assert_delete_retention_policy_not_equal(self, policy1, policy2): - if policy1 is None or policy2 is None: - assert policy1 != policy2 - return - - assert not (policy1.enabled == policy2.enabled and policy1.days == policy2.days) - - def _assert_metrics_equal(self, metrics1, metrics2): - if metrics1 is None or metrics2 is None: - assert metrics1 == metrics2 - return - - assert metrics1.version == metrics2.version - assert metrics1.enabled == metrics2.enabled - assert metrics1.include_apis == metrics2.include_apis - self._assert_retention_equal(metrics1.retention_policy, metrics2.retention_policy) - - def _assert_cors_equal(self, cors1, cors2): - if cors1 is None or cors2 is None: - assert cors1 == cors2 - return - - assert len(cors1) == len(cors2) - - for i in range(0, len(cors1)): - rule1 = cors1[i] - rule2 = cors2[i] - assert len(rule1.allowed_origins) == len(rule2.allowed_origins) - assert len(rule1.allowed_methods) == len(rule2.allowed_methods) - assert rule1.max_age_in_seconds == rule2.max_age_in_seconds - assert len(rule1.exposed_headers) == len(rule2.exposed_headers) - assert len(rule1.allowed_headers) == len(rule2.allowed_headers) - - def _assert_retention_equal(self, ret1, ret2): - assert ret1.enabled == ret2.enabled - assert ret1.days == ret2.days - - # --Test cases per service --------------------------------------- @tables_decorator_async async def test_table_service_properties_async(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange diff --git a/sdk/tables/azure-data-tables/tests/test_table_service_properties_cosmos.py b/sdk/tables/azure-data-tables/tests/test_table_service_properties_cosmos.py index 418f7e26d910..0a7c62d193fe 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_service_properties_cosmos.py +++ b/sdk/tables/azure-data-tables/tests/test_table_service_properties_cosmos.py @@ -5,7 +5,6 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import time import pytest from devtools_testutils import AzureTestCase @@ -14,7 +13,6 @@ from azure.data.tables import ( TableServiceClient, - TableAnalyticsLogging, Metrics, RetentionPolicy, CorsRule @@ -25,81 +23,6 @@ # ------------------------------------------------------------------------------ class TableServicePropertiesTest(AzureTestCase, TableTestCase): - # --Helpers----------------------------------------------------------------- - def _assert_properties_default(self, prop): - assert prop is not None - - self._assert_logging_equal(prop['analytics_logging'], TableAnalyticsLogging()) - self._assert_metrics_equal(prop['hour_metrics'], Metrics()) - self._assert_metrics_equal(prop['minute_metrics'], Metrics()) - self._assert_cors_equal(prop['cors'], list()) - - def _assert_logging_equal(self, log1, log2): - if log1 is None or log2 is None: - assert log1 == log2 - return - - assert log1.version == log2.version - assert log1.read == log2.read - assert log1.write == log2.write - assert log1.delete == log2.delete - self._assert_retention_equal(log1.retention_policy, log2.retention_policy) - - def _assert_delete_retention_policy_equal(self, policy1, policy2): - if policy1 is None or policy2 is None: - assert policy1 == policy2 - return - - assert policy1.enabled == policy2.enabled - assert policy1.days == policy2.days - - def _assert_static_website_equal(self, prop1, prop2): - if prop1 is None or prop2 is None: - assert prop1 == prop2 - return - - assert prop1.enabled == prop2.enabled - assert prop1.index_document == prop2.index_document - assert prop1.error_document404_path == prop2.error_document404_path - - def _assert_delete_retention_policy_not_equal(self, policy1, policy2): - if policy1 is None or policy2 is None: - assert policy1 != policy2 - return - - assert not (policy1.enabled == policy2.enabled and policy1.days == policy2.days) - - def _assert_metrics_equal(self, metrics1, metrics2): - if metrics1 is None or metrics2 is None: - assert metrics1 == metrics2 - return - - assert metrics1.version == metrics2.version - assert metrics1.enabled == metrics2.enabled - assert metrics1.include_apis == metrics2.include_apis - self._assert_retention_equal(metrics1.retention_policy, metrics2.retention_policy) - - def _assert_cors_equal(self, cors1, cors2): - if cors1 is None or cors2 is None: - assert cors1 == cors2 - return - - assert len(cors1) == len(cors2) - - for i in range(0, len(cors1)): - rule1 = cors1[i] - rule2 = cors2[i] - assert len(rule1.allowed_origins) == len(rule2.allowed_origins) - assert len(rule1.allowed_methods) == len(rule2.allowed_methods) - assert rule1.max_age_in_seconds == rule2.max_age_in_seconds - assert len(rule1.exposed_headers) == len(rule2.exposed_headers) - assert len(rule1.allowed_headers) == len(rule2.allowed_headers) - - def _assert_retention_equal(self, ret1, ret2): - assert ret1.enabled == ret2.enabled - assert ret1.days == ret2.days - - # --Test cases for errors --------------------------------------- @cosmos_decorator def test_too_many_cors_rules(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): tsc = TableServiceClient(self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) @@ -109,7 +32,6 @@ def test_too_many_cors_rules(self, tables_cosmos_account_name, tables_primary_co with pytest.raises(HttpResponseError): tsc.set_service_properties(None, None, None, cors) - self.sleep(SLEEP_DELAY) @cosmos_decorator def test_retention_too_long(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): @@ -118,7 +40,6 @@ def test_retention_too_long(self, tables_cosmos_account_name, tables_primary_cos with pytest.raises(HttpResponseError): tsc.set_service_properties(None, None, minute_metrics) - self.sleep(SLEEP_DELAY) class TestTableUnitTest(TableTestCase): diff --git a/sdk/tables/azure-data-tables/tests/test_table_service_properties_cosmos_async.py b/sdk/tables/azure-data-tables/tests/test_table_service_properties_cosmos_async.py index 13d6db99df0a..12232b333eda 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_service_properties_cosmos_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_service_properties_cosmos_async.py @@ -6,7 +6,6 @@ # license information. # -------------------------------------------------------------------------- import pytest -from time import sleep from devtools_testutils import AzureTestCase @@ -20,81 +19,6 @@ # ------------------------------------------------------------------------------ class TableServicePropertiesTest(AzureTestCase, AsyncTableTestCase): - # --Helpers----------------------------------------------------------------- - def _assert_properties_default(self, prop): - assert prop is not None - - self._assert_logging_equal(prop['analytics_logging'], TableAnalyticsLogging()) - self._assert_metrics_equal(prop['hour_metrics'], Metrics()) - self._assert_metrics_equal(prop['minute_metrics'], Metrics()) - self._assert_cors_equal(prop['cors'], list()) - - def _assert_logging_equal(self, log1, log2): - if log1 is None or log2 is None: - assert log1 == log2 - return - - assert log1.version == log2.version - assert log1.read == log2.read - assert log1.write == log2.write - assert log1.delete == log2.delete - self._assert_retention_equal(log1.retention_policy, log2.retention_policy) - - def _assert_delete_retention_policy_equal(self, policy1, policy2): - if policy1 is None or policy2 is None: - assert policy1 == policy2 - return - - assert policy1.enabled == policy2.enabled - assert policy1.days == policy2.days - - def _assert_static_website_equal(self, prop1, prop2): - if prop1 is None or prop2 is None: - assert prop1 == prop2 - return - - assert prop1.enabled == prop2.enabled - assert prop1.index_document == prop2.index_document - assert prop1.error_document404_path == prop2.error_document404_path - - def _assert_delete_retention_policy_not_equal(self, policy1, policy2): - if policy1 is None or policy2 is None: - assert policy1 != policy2 - return - - assert not (policy1.enabled == policy2.enabled) and (policy1.days == policy2.days) - - def _assert_metrics_equal(self, metrics1, metrics2): - if metrics1 is None or metrics2 is None: - assert metrics1 == metrics2 - return - - assert metrics1.version == metrics2.version - assert metrics1.enabled == metrics2.enabled - assert metrics1.include_apis == metrics2.include_apis - self._assert_retention_equal(metrics1.retention_policy, metrics2.retention_policy) - - def _assert_cors_equal(self, cors1, cors2): - if cors1 is None or cors2 is None: - assert cors1 == cors2 - return - - assert len(cors1) == len(cors2) - - for i in range(0, len(cors1)): - rule1 = cors1[i] - rule2 = cors2[i] - assert len(rule1.allowed_origins) == len(rule2.allowed_origins) - assert len(rule1.allowed_methods) == len(rule2.allowed_methods) - assert rule1.max_age_in_seconds == rule2.max_age_in_seconds - assert len(rule1.exposed_headers) == len(rule2.exposed_headers) - assert len(rule1.allowed_headers) == len(rule2.allowed_headers) - - def _assert_retention_equal(self, ret1, ret2): - assert ret1.enabled == ret2.enabled - assert ret1.days == ret2.days - - # --Test cases for errors --------------------------------------- @cosmos_decorator_async async def test_too_many_cors_rules_async(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange @@ -106,7 +30,6 @@ async def test_too_many_cors_rules_async(self, tables_cosmos_account_name, table # Assert with pytest.raises(HttpResponseError): await tsc.set_service_properties(None, None, None, cors) - self.sleep(SLEEP_DELAY) @cosmos_decorator_async async def test_retention_too_long_async(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): @@ -118,7 +41,6 @@ async def test_retention_too_long_async(self, tables_cosmos_account_name, tables # Assert with pytest.raises(HttpResponseError): await tsc.set_service_properties(None, None, minute_metrics) - self.sleep(SLEEP_DELAY) class TestTableUnitTest(AsyncTableTestCase): diff --git a/sdk/tables/azure-data-tables/tests/test_table_service_stats.py b/sdk/tables/azure-data-tables/tests/test_table_service_stats.py index 9995c4627a1c..5e0fd8f39d9a 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_service_stats.py +++ b/sdk/tables/azure-data-tables/tests/test_table_service_stats.py @@ -3,8 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import pytest - from devtools_testutils import AzureTestCase from azure.data.tables import TableServiceClient @@ -21,20 +19,6 @@ # --Test Class ----------------------------------------------------------------- class TableServiceStatsTest(AzureTestCase, TableTestCase): - # --Helpers----------------------------------------------------------------- - def _assert_stats_default(self, stats): - assert stats is not None - assert stats['geo_replication'] is not None - - assert stats['geo_replication']['status'] == 'live' - assert stats['geo_replication']['last_sync_time'] is not None - - def _assert_stats_unavailable(self, stats): - assert stats is not None - assert stats['geo_replication'] is not None - - assert stats['geo_replication']['status'] == 'unavailable' - assert stats['geo_replication']['last_sync_time'] is None @staticmethod def override_response_body_with_unavailable_status(response): @@ -43,7 +27,6 @@ def override_response_body_with_unavailable_status(response): @staticmethod def override_response_body_with_live_status(response): response.http_response.text = lambda _: SERVICE_LIVE_RESP_BODY - # response.http_response.text = lambda _: SERVICE_LIVE_RESP_BODY # --Test cases per service --------------------------------------- @tables_decorator diff --git a/sdk/tables/azure-data-tables/tests/test_table_service_stats_async.py b/sdk/tables/azure-data-tables/tests/test_table_service_stats_async.py index 3e794c8c82e5..23b0970d586c 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_service_stats_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_service_stats_async.py @@ -3,8 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -import pytest - from devtools_testutils import AzureTestCase from azure.data.tables.aio import TableServiceClient @@ -21,22 +19,7 @@ '> ' -# --Test Class ----------------------------------------------------------------- class TableServiceStatsTest(AzureTestCase, AsyncTableTestCase): - # --Helpers----------------------------------------------------------------- - def _assert_stats_default(self, stats): - assert stats is not None - assert stats['geo_replication'] is not None - - assert stats['geo_replication']['status'] == 'live' - assert stats['geo_replication']['last_sync_time'] is not None - - def _assert_stats_unavailable(self, stats): - assert stats is not None - assert stats['geo_replication'] is not None - - assert stats['geo_replication']['status'] == 'unavailable' - assert stats['geo_replication']['last_sync_time'] is None @staticmethod def override_response_body_with_unavailable_status(response): @@ -45,7 +28,6 @@ def override_response_body_with_unavailable_status(response): @staticmethod def override_response_body_with_live_status(response): response.http_response.text = lambda _: SERVICE_LIVE_RESP_BODY - # response.http_response.text = lambda _: SERVICE_LIVE_RESP_BODY # --Test cases per service --------------------------------------- @tables_decorator_async @@ -64,8 +46,7 @@ async def test_table_service_stats_when_unavailable(self, tables_storage_account tsc = TableServiceClient(self.account_url(tables_storage_account_name, "table"), tables_primary_storage_account_key) # Act - stats = await tsc.get_service_stats( - raw_response_hook=self.override_response_body_with_unavailable_status) + stats = await tsc.get_service_stats(raw_response_hook=self.override_response_body_with_unavailable_status) # Assert self._assert_stats_unavailable(stats) diff --git a/sdk/tables/azure-data-tables/tests/test_table_service_stats_cosmos.py b/sdk/tables/azure-data-tables/tests/test_table_service_stats_cosmos.py index 0f54f81704d4..d3239e2d207d 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_service_stats_cosmos.py +++ b/sdk/tables/azure-data-tables/tests/test_table_service_stats_cosmos.py @@ -22,20 +22,6 @@ # --Test Class ----------------------------------------------------------------- class TableServiceStatsTest(AzureTestCase, TableTestCase): - # --Helpers----------------------------------------------------------------- - def _assert_stats_default(self, stats): - assert stats is not None - assert stats['geo_replication'] is not None - - assert stats['geo_replication']['status'] == 'live' - assert stats['geo_replication']['last_sync_time'] is not None - - def _assert_stats_unavailable(self, stats): - assert stats is not None - assert stats['geo_replication'] is not None - - assert stats['geo_replication']['status'] == 'unavailable' - assert stats['geo_replication']['last_sync_time'] is None @staticmethod def override_response_body_with_unavailable_status(response): @@ -54,13 +40,9 @@ def test_table_service_stats_f(self, tables_cosmos_account_name, tables_primary_ stats = tsc.get_service_stats(raw_response_hook=self.override_response_body_with_live_status) self._assert_stats_default(stats) - self.sleep(SLEEP_DELAY) - @pytest.mark.skip("JSON is invalid for cosmos") @cosmos_decorator def test_table_service_stats_when_unavailable(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): tsc = TableServiceClient(self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) stats = tsc.get_service_stats(raw_response_hook=self.override_response_body_with_unavailable_status) self._assert_stats_unavailable(stats) - - self.sleep(SLEEP_DELAY) diff --git a/sdk/tables/azure-data-tables/tests/test_table_service_stats_cosmos_async.py b/sdk/tables/azure-data-tables/tests/test_table_service_stats_cosmos_async.py index ff6d4c7ae4d6..a0ad185fba99 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_service_stats_cosmos_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_service_stats_cosmos_async.py @@ -21,22 +21,7 @@ '>liveWed, 19 Jan 2021 22:28:43 GMT ' -# --Test Class ----------------------------------------------------------------- class TableServiceStatsTest(AzureTestCase, AsyncTableTestCase): - # --Helpers----------------------------------------------------------------- - def _assert_stats_default(self, stats): - assert stats is not None - assert stats['geo_replication'] is not None - - assert stats['geo_replication']['status'] == 'live' - assert stats['geo_replication']['last_sync_time'] is not None - - def _assert_stats_unavailable(self, stats): - assert stats is not None - assert stats['geo_replication'] is not None - - assert stats['geo_replication']['status'] == 'unavailable' - assert stats['geo_replication']['last_sync_time'] is None @staticmethod def override_response_body_with_unavailable_status(response): @@ -54,13 +39,9 @@ async def test_table_service_stats_f(self, tables_cosmos_account_name, tables_pr stats = await tsc.get_service_stats(raw_response_hook=self.override_response_body_with_live_status) self._assert_stats_default(stats) - self.sleep(SLEEP_DELAY) - @pytest.mark.skip("JSON is invalid for cosmos") @cosmos_decorator_async async def test_table_service_stats_when_unavailable(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): tsc = TableServiceClient(self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) stats = await tsc.get_service_stats(raw_response_hook=self.override_response_body_with_unavailable_status) self._assert_stats_unavailable(stats) - - self.sleep(SLEEP_DELAY)