diff --git a/sdk/tables/azure-data-tables/CHANGELOG.md b/sdk/tables/azure-data-tables/CHANGELOG.md index dda256295dd7..8f69a1d3a20f 100644 --- a/sdk/tables/azure-data-tables/CHANGELOG.md +++ b/sdk/tables/azure-data-tables/CHANGELOG.md @@ -2,6 +2,8 @@ ## 12.0.0b7 (Unreleased) **Breaking** +* The `TableEntity` object now acts exclusively like a dictionary, and no longer supports key access via attributes. +* Metadata of an entity is now accessed via `TableEntity.metadata` attribute rather than a method. * Removed explicit `LinearRetry` and `ExponentialRetry` in favor of keyword parameter. * Renamed `filter` parameter in query APIs to `query_filter`. * The `location_mode` attribute on clients is now read-only. This has been added as a keyword parameter to the constructor. diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_base_client.py b/sdk/tables/azure-data-tables/azure/data/tables/_base_client.py index ed64fb1fe34b..f5984ccdf4dc 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_base_client.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_base_client.py @@ -372,6 +372,8 @@ def parse_connection_str(conn_str, credential, keyword_args): } except KeyError: credential = conn_settings.get("sharedaccesssignature") + # if "sharedaccesssignature" in conn_settings: + # credential = AzureSasCredential(conn_settings['sharedaccesssignature']) primary = conn_settings.get("tableendpoint") secondary = conn_settings.get("tablesecondaryendpoint") diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py b/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py index 0e02f1ce7490..ecb2d5e0d12a 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py @@ -198,9 +198,6 @@ def _convert_to_entity(entry_element): # Timestamp is a known property timestamp = properties.pop("Timestamp", None) - if timestamp: - # entity['Timestamp'] = _from_entity_datetime(timestamp) - entity["Timestamp"] = timestamp for name, value in properties.items(): mtype = edmtypes.get(name) @@ -237,9 +234,8 @@ def _convert_to_entity(entry_element): etag = odata.get("etag") if timestamp and not etag: etag = "W/\"datetime'" + url_quote(timestamp) + "'\"" - entity["etag"] = etag - entity._set_metadata() # pylint: disable=protected-access + entity._metadata = {'etag': etag, 'timestamp': timestamp} # pylint: disable=protected-access return entity diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_entity.py b/sdk/tables/azure-data-tables/azure/data/tables/_entity.py index 9df5e5e32d6b..824fa35d10b9 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_entity.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_entity.py @@ -6,65 +6,23 @@ from enum import Enum from typing import Any, Dict, Union, NamedTuple -from ._error import _ERROR_ATTRIBUTE_MISSING - class TableEntity(dict): """ - An entity object. Can be accessed as a dict or as an obj. The attributes of - the entity will be created dynamically. For example, the following are both - valid:: - TableEntity = TableEntity() - TableEntity.a = 'b' - TableEntity['x'] = 'y' + An Entity dictionary with additional metadata """ + _metadata = None - def _set_metadata(self): - if "Timestamp" in self.keys(): - self._metadata = { # pylint: disable=attribute-defined-outside-init - "etag": self.pop("etag"), - "timestamp": self.pop("Timestamp"), - } - else: - self._metadata = {"etag": self.pop("etag")} # pylint: disable=attribute-defined-outside-init - + @property def metadata(self): - # type: (...) -> Dict[str,Any] + # type: () -> Dict[str, Any] """Resets metadata to be a part of the entity :return Dict of entity metadata :rtype Dict[str, Any] """ return self._metadata - def __getattr__(self, name): - """ - :param name:name of entity entry - :type name: str - :return: TableEntity dictionary - :rtype: Dict[str,str] - """ - try: - return self[name] - except KeyError: - raise AttributeError(_ERROR_ATTRIBUTE_MISSING.format("TableEntity", name)) - - __setattr__ = dict.__setitem__ - - def __delattr__(self, name): - """ - :param name:name of entity entry - :type name: str - """ - try: - if name is not None: - del self[name] - except KeyError: - raise AttributeError(_ERROR_ATTRIBUTE_MISSING.format("TableEntity", name)) - - def __dir__(self): - return dir({}) + list(self.keys()) - class EdmType(str, Enum): """ diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_error.py b/sdk/tables/azure-data-tables/azure/data/tables/_error.py index 0688da50962e..cda8cd05a1b2 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_error.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_error.py @@ -33,10 +33,8 @@ def _to_str(value): return _str(value) if value is not None else None -_ERROR_ATTRIBUTE_MISSING = "'{0}' object has no attribute '{1}'" _ERROR_TYPE_NOT_SUPPORTED = "Type not supported when sending data to the service: {0}." _ERROR_VALUE_TOO_LARGE = "{0} is too large to be cast to type {1}." -_ERROR_ATTRIBUTE_MISSING = "'{0}' object has no attribute '{1}'" _ERROR_UNKNOWN = "Unknown error ({0})" _ERROR_VALUE_NONE = "{0} should not be None." _ERROR_UNKNOWN_KEY_WRAP_ALGORITHM = "Unknown key wrap algorithm." diff --git a/sdk/tables/azure-data-tables/samples/async_samples/sample_update_upsert_merge_entities_async.py b/sdk/tables/azure-data-tables/samples/async_samples/sample_update_upsert_merge_entities_async.py index e27e87404f18..193bccf7c917 100644 --- a/sdk/tables/azure-data-tables/samples/async_samples/sample_update_upsert_merge_entities_async.py +++ b/sdk/tables/azure-data-tables/samples/async_samples/sample_update_upsert_merge_entities_async.py @@ -64,8 +64,10 @@ async def create_and_get_entities(self): # [START get_entity] # Get Entity by partition and row key - got_entity = await table.get_entity(partition_key=my_entity['PartitionKey'], - row_key=my_entity['RowKey']) + got_entity = await table.get_entity( + partition_key=my_entity['PartitionKey'], + row_key=my_entity['RowKey'] + ) print("Received entity: {}".format(got_entity)) # [END get_entity] @@ -127,28 +129,28 @@ async def update_entities(self): print("Inserted entity: {}".format(insert_entity)) # Try merge, and merge since already in table - created.text = "NewMarker" + created['text'] = "NewMarker" merged_entity = await table.upsert_entity(mode=UpdateMode.MERGE, entity=entity) print("Merged entity: {}".format(merged_entity)) # [END upsert_entity] # [START update_entity] # Update the entity - created.text = "NewMarker" + created['text'] = "NewMarker" await table.update_entity(mode=UpdateMode.REPLACE, entity=created) # Get the replaced entity replaced = await table.get_entity( - partition_key=created.PartitionKey, row_key=created.RowKey) + partition_key=created['PartitionKey'], row_key=created['RowKey']) print("Replaced entity: {}".format(replaced)) # Merge the entity - replaced.color = "Blue" + replaced['color'] = "Blue" await table.update_entity(mode=UpdateMode.MERGE, entity=replaced) # Get the merged entity merged = await table.get_entity( - partition_key=replaced.PartitionKey, row_key=replaced.RowKey) + partition_key=replaced['PartitionKey'], row_key=replaced['RowKey']) print("Merged entity: {}".format(merged)) # [END update_entity] diff --git a/sdk/tables/azure-data-tables/samples/sample_update_upsert_merge_entities.py b/sdk/tables/azure-data-tables/samples/sample_update_upsert_merge_entities.py index a8df0bf82d36..83ab9442aa7a 100644 --- a/sdk/tables/azure-data-tables/samples/sample_update_upsert_merge_entities.py +++ b/sdk/tables/azure-data-tables/samples/sample_update_upsert_merge_entities.py @@ -63,8 +63,10 @@ def create_and_get_entities(self): # [START get_entity] # Get Entity by partition and row key - got_entity = table.get_entity(partition_key=my_entity['PartitionKey'], - row_key=my_entity['RowKey']) + got_entity = table.get_entity( + partition_key=my_entity['PartitionKey'], + row_key=my_entity['RowKey'] + ) print("Received entity: {}".format(got_entity)) # [END get_entity] @@ -122,28 +124,28 @@ def update_entities(self): print("Inserted entity: {}".format(insert_entity)) # Try merge, and merge since already in table - created.text = "NewMarker" + created['text'] = "NewMarker" merged_entity = table.upsert_entity(mode=UpdateMode.MERGE, entity=entity) print("Merged entity: {}".format(merged_entity)) # [END upsert_entity] # [START update_entity] # Update the entity - created.text = "NewMarker" + created['text'] = "NewMarker" table.update_entity(mode=UpdateMode.REPLACE, entity=created) # Get the replaced entity replaced = table.get_entity( - partition_key=created.PartitionKey, row_key=created.RowKey) + partition_key=created['PartitionKey'], row_key=created['RowKey']) print("Replaced entity: {}".format(replaced)) # Merge the entity - replaced.color = "Blue" + replaced['color'] = "Blue" table.update_entity(mode=UpdateMode.MERGE, entity=replaced) # Get the merged entity merged = table.get_entity( - partition_key=replaced.PartitionKey, row_key=replaced.RowKey) + partition_key=replaced['PartitionKey'], row_key=replaced['RowKey']) print("Merged entity: {}".format(merged)) # [END update_entity] diff --git a/sdk/tables/azure-data-tables/tests/test_table.py b/sdk/tables/azure-data-tables/tests/test_table.py index 90cce3deb7ba..1a4401132907 100644 --- a/sdk/tables/azure-data-tables/tests/test_table.py +++ b/sdk/tables/azure-data-tables/tests/test_table.py @@ -473,8 +473,8 @@ def test_account_sas(self, tables_storage_account_name, tables_primary_storage_a # Assert assert len(entities) == 2 - assert entities[0].text == u'hello' - assert entities[1].text == u'hello' + assert entities[0]['text'] == u'hello' + assert entities[1]['text'] == u'hello' finally: self._delete_table(table=table, ts=tsc) @@ -529,4 +529,4 @@ def test_azurite_url(self): assert tsc.url == "https://127.0.0.1:10002/my_account" assert tsc.location_mode == "primary" assert tsc.credential.account_key == self.tables_primary_storage_account_key - assert tsc.credential.account_name == "my_account" \ No newline at end of file + assert tsc.credential.account_name == "my_account" 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 9b3f38225f29..d09a85635675 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_async.py @@ -387,8 +387,8 @@ async def test_account_sas(self, tables_storage_account_name, tables_primary_sto # Assert assert len(entities) == 2 - assert entities[0].text == u'hello' - assert entities[1].text == u'hello' + assert entities[0]['text'] == u'hello' + assert entities[1]['text'] == u'hello' finally: await self._delete_table(table=table, ts=tsc) 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 1aa18cfbecef..400e12d1ebc5 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_batch.py +++ b/sdk/tables/azure-data-tables/tests/test_table_batch.py @@ -148,26 +148,28 @@ def _assert_default_entity(self, entity): assert entity['binary'].value == b'binary' assert entity['other'] == 20 assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert '_metadata' in entity + 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 hasattr(entity, "married") - assert not hasattr(entity, "deceased") - assert entity.sign == 'aquarius' - assert not hasattr(entity, "optional") - assert not hasattr(entity, "ratio") - assert not hasattr(entity, "evenratio") - assert not hasattr(entity, "large") - assert not hasattr(entity, "Birthday") - assert entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()) - assert not hasattr(entity, "other") - assert not hasattr(entity, "clsid") - assert entity['_metadata']['etag'] is not None + 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) @@ -181,13 +183,13 @@ def test_batch_single_insert(self, tables_storage_account_name, tables_primary_s try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('create', entity)] transaction_result = self.table.submit_transaction(batch) @@ -196,11 +198,11 @@ def test_batch_single_insert(self, tables_storage_account_name, tables_primary_s self._assert_valid_batch_transaction(transaction_result, 1) assert 'etag' in transaction_result[0] - e = self.table.get_entity(row_key=entity.RowKey, partition_key=entity.PartitionKey) - assert e.test == entity.test.value - assert e.test2 == entity.test2 - assert e.test3 == entity.test3 - assert e.test4 == entity.test4.value + e = self.table.get_entity(row_key=entity['RowKey'], partition_key=entity['PartitionKey']) + assert e['test'] == entity['test'].value + assert e['test2'] == entity['test2'] + assert e['test3'] == entity['test3'] + assert e['test4'] == entity['test4'].value finally: self._tear_down() @@ -212,19 +214,19 @@ def test_batch_single_update(self, tables_storage_account_name, tables_primary_s try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() resp = self.table.create_entity(entity) assert resp is not None - entity.test3 = 5 - entity.test5 = datetime.utcnow() + entity['test3'] = 5 + entity['test5'] = datetime.utcnow() batch = [('update', entity, {'mode':UpdateMode.MERGE})] transaction_result = self.table.submit_transaction(batch) @@ -232,10 +234,10 @@ def test_batch_single_update(self, tables_storage_account_name, tables_primary_s # Assert self._assert_valid_batch_transaction(transaction_result, 1) assert 'etag' in transaction_result[0] - result = self.table.get_entity(row_key=entity.RowKey, partition_key=entity.PartitionKey) - assert result.PartitionKey == u'001' - assert result.RowKey == u'batch_insert' - assert result.test3 == 5 + result = self.table.get_entity(row_key=entity['RowKey'], partition_key=entity['PartitionKey']) + assert result['PartitionKey'] == u'001' + assert result['RowKey'] == u'batch_insert' + assert result['test3'] == 5 finally: self._tear_down() @@ -247,19 +249,19 @@ def test_batch_update(self, tables_storage_account_name, tables_primary_storage_ try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_update' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() - entity.test6 = (2 ** 40, "Edm.Int64") + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_update' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() + entity['test6'] = (2 ** 40, "Edm.Int64") self.table.create_entity(entity) entity = self.table.get_entity(u'001', u'batch_update') - assert 3 == entity.test3 - entity.test2 = u'value1' + assert 3 == entity['test3'] + entity['test2'] = u'value1' batch = [('update', entity)] transaction_result = self.table.submit_transaction(batch) @@ -270,9 +272,9 @@ def test_batch_update(self, tables_storage_account_name, tables_primary_storage_ result = self.table.get_entity('001', 'batch_update') - assert 'value1' == result.test2 - assert entity.PartitionKey == u'001' - assert entity.RowKey == u'batch_update' + assert 'value1' == result['test2'] + assert entity['PartitionKey'] == u'001' + assert entity['RowKey'] == u'batch_update' finally: self._tear_down() @@ -284,21 +286,21 @@ def test_batch_merge(self, tables_storage_account_name, tables_primary_storage_a try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_merge' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_merge' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() self.table.create_entity(entity) resp_entity = self.table.get_entity(partition_key=u'001', row_key=u'batch_merge') - assert 3 == entity.test3 + assert 3 == entity['test3'] entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_merge' - entity.test2 = u'value1' + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_merge' + entity['test2'] = u'value1' batch = [('update', entity, {'mode': UpdateMode.MERGE})] transaction_result = self.table.submit_transaction(batch) @@ -308,10 +310,10 @@ def test_batch_merge(self, tables_storage_account_name, tables_primary_storage_a assert 'etag' in transaction_result[0] resp_entity = self.table.get_entity(partition_key=u'001', row_key=u'batch_merge') - assert entity.test2 == resp_entity.test2 - assert 1234567890 == resp_entity.test4 - assert entity.PartitionKey == resp_entity.PartitionKey - assert entity.RowKey == resp_entity.RowKey + assert entity['test2'] == resp_entity['test2'] + assert 1234567890 == resp_entity['test4'] + assert entity['PartitionKey'] == resp_entity['PartitionKey'] + assert entity['RowKey'] == resp_entity['RowKey'] finally: self._tear_down() @@ -377,16 +379,16 @@ def test_batch_single_op_if_doesnt_match(self, tables_storage_account_name, tabl try: # Act entity = TableEntity() - entity.PartitionKey = 'batch_inserts' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) + entity['PartitionKey'] = 'batch_inserts' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) batch = [] transaction_count = 0 for i in range(10): - entity.RowKey = str(i) + entity['RowKey'] = str(i) batch.append(('create', entity.copy())) transaction_count += 1 @@ -419,13 +421,13 @@ def test_batch_insert_replace(self, tables_storage_account_name, tables_primary_ try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert_replace' - entity.test = True - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert_replace' + entity['test'] = True + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('upsert', entity, {'mode': UpdateMode.REPLACE})] transaction_result = self.table.submit_transaction(batch) @@ -436,8 +438,8 @@ def test_batch_insert_replace(self, tables_storage_account_name, tables_primary_ entity = self.table.get_entity('001', 'batch_insert_replace') assert entity is not None - assert 'value' == entity.test2 - assert 1234567890 == entity.test4 + assert 'value' == entity['test2'] + assert 1234567890 == entity['test4'] finally: self._tear_down() @@ -449,13 +451,13 @@ def test_batch_insert_merge(self, tables_storage_account_name, tables_primary_st try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert_merge' - entity.test = True - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert_merge' + entity['test'] = True + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('upsert', entity, {'mode': UpdateMode.MERGE})] transaction_result = self.table.submit_transaction(batch) @@ -466,8 +468,8 @@ def test_batch_insert_merge(self, tables_storage_account_name, tables_primary_st entity = self.table.get_entity('001', 'batch_insert_merge') assert entity is not None - assert 'value' == entity.test2 - assert 1234567890 == entity.test4 + assert 'value' == entity['test2'] + assert 1234567890 == entity['test4'] finally: self._tear_down() @@ -479,17 +481,17 @@ def test_batch_delete(self, tables_storage_account_name, tables_primary_storage_ try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_delete' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_delete' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() self.table.create_entity(entity) entity = self.table.get_entity(partition_key=u'001', row_key=u'batch_delete') - assert 3 == entity.test3 + assert 3 == entity['test3'] batch = [('delete', entity)] transaction_result = self.table.submit_transaction(batch) @@ -499,7 +501,7 @@ def test_batch_delete(self, tables_storage_account_name, tables_primary_storage_ assert 'etag' not in transaction_result[0] with pytest.raises(ResourceNotFoundError): - entity = self.table.get_entity(partition_key=entity.PartitionKey, row_key=entity.RowKey) + entity = self.table.get_entity(partition_key=entity['PartitionKey'], row_key=entity['RowKey']) finally: self._tear_down() @@ -511,16 +513,16 @@ def test_batch_inserts(self, tables_storage_account_name, tables_primary_storage try: # Act entity = TableEntity() - entity.PartitionKey = 'batch_inserts' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) + entity['PartitionKey'] = 'batch_inserts' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) transaction_count = 0 batch = [] for i in range(100): - entity.RowKey = str(i) + entity['RowKey'] = str(i) batch.append(('create', entity.copy())) transaction_count += 1 transaction_result = self.table.submit_transaction(batch) @@ -546,47 +548,48 @@ def test_batch_all_operations_together(self, tables_storage_account_name, tables try: # Act entity = TableEntity() - entity.PartitionKey = '003' - entity.RowKey = 'batch_all_operations_together-1' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '003' + entity['RowKey'] = 'batch_all_operations_together-1' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() + self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-2' + entity['RowKey'] = 'batch_all_operations_together-2' self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-3' + entity['RowKey'] = 'batch_all_operations_together-3' self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-4' + entity['RowKey'] = 'batch_all_operations_together-4' self.table.create_entity(entity) transaction_count = 0 batch = [] - entity.RowKey = 'batch_all_operations_together' + entity['RowKey'] = 'batch_all_operations_together' batch.append((TransactionOperation.CREATE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-1' + entity['RowKey'] = 'batch_all_operations_together-1' batch.append((TransactionOperation.DELETE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-2' - entity.test3 = 10 + entity['RowKey'] = 'batch_all_operations_together-2' + entity['test3'] = 10 batch.append((TransactionOperation.UPDATE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-3' - entity.test3 = 100 + entity['RowKey'] = 'batch_all_operations_together-3' + entity['test3'] = 100 batch.append((TransactionOperation.UPDATE, entity.copy(), {'mode': UpdateMode.REPLACE})) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-4' - entity.test3 = 10 + entity['RowKey'] = 'batch_all_operations_together-4' + entity['test3'] = 10 batch.append((TransactionOperation.UPSERT, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-5' + entity['RowKey'] = 'batch_all_operations_together-5' batch.append((TransactionOperation.UPSERT, entity.copy(), {'mode': UpdateMode.REPLACE})) transaction_count += 1 @@ -618,21 +621,21 @@ def test_batch_reuse(self, tables_storage_account_name, tables_primary_storage_a # Act entity = TableEntity() - entity.PartitionKey = '003' - entity.RowKey = 'batch_all_operations_together-1' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '003' + entity['RowKey'] = 'batch_all_operations_together-1' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [] batch.append(('upsert', entity.copy())) - entity.RowKey = 'batch_all_operations_together-2' + entity['RowKey'] = 'batch_all_operations_together-2' batch.append(('upsert', entity.copy())) - entity.RowKey = 'batch_all_operations_together-3' + entity['RowKey'] = 'batch_all_operations_together-3' batch.append(('upsert', entity.copy())) - entity.RowKey = 'batch_all_operations_together-4' + entity['RowKey'] = 'batch_all_operations_together-4' batch.append(('upsert', entity.copy())) resp1 = self.table.submit_transaction(batch) @@ -712,8 +715,8 @@ def test_batch_too_many_ops(self, tables_storage_account_name, tables_primary_st batch = [] for i in range(0, 101): entity = TableEntity() - entity.PartitionKey = 'large' - entity.RowKey = 'item{0}'.format(i) + entity['PartitionKey'] = 'large' + entity['RowKey'] = 'item{0}'.format(i) batch.append(('create', entity.copy())) self.table.submit_transaction(batch) @@ -814,16 +817,16 @@ def test_batch_sas_auth(self, tables_storage_account_name, tables_primary_storag table = service.get_table_client(self.table_name) entity = TableEntity() - entity.PartitionKey = 'batch_inserts' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) + entity['PartitionKey'] = 'batch_inserts' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) batch = [] transaction_count = 0 for i in range(10): - entity.RowKey = str(i) + entity['RowKey'] = str(i) batch.append(('create', entity.copy())) transaction_count += 1 transaction_result = table.submit_transaction(batch) diff --git a/sdk/tables/azure-data-tables/tests/test_table_batch_async.py b/sdk/tables/azure-data-tables/tests/test_table_batch_async.py index 876b4ec9fe3d..0e9505447067 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 @@ -148,26 +148,28 @@ def _assert_default_entity(self, entity): assert entity['binary'].value == b'binary' assert entity['other'] == 20 assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert '_metadata' in entity + 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 hasattr(entity, "married") - assert not hasattr(entity, "deceased") - assert entity.sign == 'aquarius' - assert not hasattr(entity, "optional") - assert not hasattr(entity, "ratio") - assert not hasattr(entity, "evenratio") - assert not hasattr(entity, "large") - assert not hasattr(entity, "Birthday") - assert entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()) - assert not hasattr(entity, "other") - assert not hasattr(entity, "clsid") - assert entity['_metadata']['etag'] is not None + 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) @@ -180,13 +182,13 @@ async def test_batch_single_insert(self, tables_storage_account_name, tables_pri try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('create', entity)] transaction_result = await self.table.submit_transaction(batch) @@ -195,11 +197,11 @@ async def test_batch_single_insert(self, tables_storage_account_name, tables_pri self._assert_valid_batch_transaction(transaction_result, 1) assert 'etag' in transaction_result[0] - e = await self.table.get_entity(row_key=entity.RowKey, partition_key=entity.PartitionKey) - assert e.test == entity.test.value - assert e.test2 == entity.test2 - assert e.test3 == entity.test3 - assert e.test4 == entity.test4.value + e = await self.table.get_entity(row_key=entity['RowKey'], partition_key=entity['PartitionKey']) + assert e['test'] == entity['test'].value + assert e['test2'] == entity['test2'] + assert e['test3'] == entity['test3'] + assert e['test4'] == entity['test4'].value finally: await self._tear_down() @@ -210,19 +212,19 @@ async def test_batch_single_update(self, tables_storage_account_name, tables_pri try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() resp = await self.table.create_entity(entity) assert resp is not None - entity.test3 = 5 - entity.test5 = datetime.utcnow() + entity['test3'] = 5 + entity['test5'] = datetime.utcnow() batch = [('update', entity, {'mode':UpdateMode.MERGE})] transaction_result = await self.table.submit_transaction(batch) @@ -231,10 +233,10 @@ async def test_batch_single_update(self, tables_storage_account_name, tables_pri self._assert_valid_batch_transaction(transaction_result, 1) assert 'etag' in transaction_result[0] - result = await self.table.get_entity(row_key=entity.RowKey, partition_key=entity.PartitionKey) - assert result.PartitionKey == u'001' - assert result.RowKey == u'batch_insert' - assert result.test3 == 5 + result = await self.table.get_entity(row_key=entity['RowKey'], partition_key=entity['PartitionKey']) + assert result['PartitionKey'] == u'001' + assert result['RowKey'] == u'batch_insert' + assert result['test3'] == 5 finally: await self._tear_down() @@ -245,18 +247,18 @@ async def test_batch_update(self, tables_storage_account_name, tables_primary_st try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_update' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_update' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() await self.table.create_entity(entity) entity = await self.table.get_entity(u'001', u'batch_update') - assert 3 == entity.test3 - entity.test2 = u'value1' + assert 3 == entity['test3'] + entity['test2'] = u'value1' batch = [('update', entity)] transaction_result = await self.table.submit_transaction(batch) @@ -266,9 +268,9 @@ async def test_batch_update(self, tables_storage_account_name, tables_primary_st assert 'etag' in transaction_result[0] result = await self.table.get_entity('001', 'batch_update') - assert 'value1' == result.test2 - assert entity.PartitionKey == u'001' - assert entity.RowKey == u'batch_update' + assert 'value1' == result['test2'] + assert entity['PartitionKey'] == u'001' + assert entity['RowKey'] == u'batch_update' finally: await self._tear_down() @@ -279,21 +281,21 @@ async def test_batch_merge(self, tables_storage_account_name, tables_primary_sto try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_merge' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_merge' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() await self.table.create_entity(entity) resp_entity = await self.table.get_entity(partition_key=u'001', row_key=u'batch_merge') - assert 3 == entity.test3 + assert 3 == entity['test3'] entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_merge' - entity.test2 = u'value1' + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_merge' + entity['test2'] = u'value1' batch = [('update', entity, {'mode': UpdateMode.MERGE})] transaction_result = await self.table.submit_transaction(batch) @@ -303,10 +305,10 @@ async def test_batch_merge(self, tables_storage_account_name, tables_primary_sto assert 'etag' in transaction_result[0] resp_entity = await self.table.get_entity(partition_key=u'001', row_key=u'batch_merge') - assert entity.test2 == resp_entity.test2 - assert 1234567890 == resp_entity.test4 - assert entity.PartitionKey == resp_entity.PartitionKey - assert entity.RowKey == resp_entity.RowKey + assert entity['test2'] == resp_entity['test2'] + assert 1234567890 == resp_entity['test4'] + assert entity['PartitionKey'] == resp_entity['PartitionKey'] + assert entity['RowKey'] == resp_entity['RowKey'] finally: await self._tear_down() @@ -370,13 +372,13 @@ async def test_batch_insert_replace(self, tables_storage_account_name, tables_pr try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert_replace' - entity.test = True - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert_replace' + entity['test'] = True + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('upsert', entity, {'mode': UpdateMode.REPLACE})] transaction_result = await self.table.submit_transaction(batch) @@ -387,8 +389,8 @@ async def test_batch_insert_replace(self, tables_storage_account_name, tables_pr entity = await self.table.get_entity('001', 'batch_insert_replace') assert entity is not None - assert 'value' == entity.test2 - assert 1234567890 == entity.test4 + assert 'value' == entity['test2'] + assert 1234567890 == entity['test4'] finally: await self._tear_down() @@ -399,13 +401,13 @@ async def test_batch_insert_merge(self, tables_storage_account_name, tables_prim try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert_merge' - entity.test = True - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert_merge' + entity['test'] = True + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('upsert', entity, {'mode':UpdateMode.MERGE})] transaction_result = await self.table.submit_transaction(batch) @@ -416,8 +418,8 @@ async def test_batch_insert_merge(self, tables_storage_account_name, tables_prim entity = await self.table.get_entity('001', 'batch_insert_merge') assert entity is not None - assert 'value' == entity.test2 - assert 1234567890 == entity.test4 + assert 'value' == entity['test2'] + assert 1234567890 == entity['test4'] finally: await self._tear_down() @@ -428,17 +430,17 @@ async def test_batch_delete(self, tables_storage_account_name, tables_primary_st try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_delete' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_delete' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() await self.table.create_entity(entity) entity = await self.table.get_entity(partition_key=u'001', row_key=u'batch_delete') - assert 3 == entity.test3 + assert 3 == entity['test3'] batch = [('delete', entity)] transaction_result = await self.table.submit_transaction(batch) @@ -448,7 +450,7 @@ async def test_batch_delete(self, tables_storage_account_name, tables_primary_st assert 'etag' not in transaction_result[0] with pytest.raises(ResourceNotFoundError): - entity = await self.table.get_entity(partition_key=entity.PartitionKey, row_key=entity.RowKey) + entity = await self.table.get_entity(partition_key=entity['PartitionKey'], row_key=entity['RowKey']) finally: await self._tear_down() @@ -459,16 +461,16 @@ async def test_batch_inserts(self, tables_storage_account_name, tables_primary_s try: # Act entity = TableEntity() - entity.PartitionKey = 'batch_inserts' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) + entity['PartitionKey'] = 'batch_inserts' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) transaction_count = 0 batch = [] for i in range(100): - entity.RowKey = str(i) + entity['RowKey'] = str(i) batch.append(('create', entity.copy())) transaction_count += 1 transaction_result = await self.table.submit_transaction(batch) @@ -496,48 +498,49 @@ async def test_batch_all_operations_together(self, tables_storage_account_name, try: # Act entity = TableEntity() - entity.PartitionKey = '003' - entity.RowKey = 'batch_all_operations_together-1' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '003' + entity['RowKey'] = 'batch_all_operations_together-1' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() + await self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-2' + entity['RowKey'] = 'batch_all_operations_together-2' await self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-3' + entity['RowKey'] = 'batch_all_operations_together-3' await self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-4' + entity['RowKey'] = 'batch_all_operations_together-4' await self.table.create_entity(entity) transaction_count = 0 batch = [] - entity.RowKey = 'batch_all_operations_together' + entity['RowKey'] = 'batch_all_operations_together' batch.append((TransactionOperation.CREATE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-1' + entity['RowKey'] = 'batch_all_operations_together-1' batch.append((TransactionOperation.DELETE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-2' - entity.test3 = 10 + entity['RowKey'] = 'batch_all_operations_together-2' + entity['test3'] = 10 batch.append((TransactionOperation.UPDATE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-3' - entity.test3 = 100 + entity['RowKey'] = 'batch_all_operations_together-3' + entity['test3'] = 100 batch.append((TransactionOperation.UPDATE, entity.copy(), {'mode': UpdateMode.REPLACE})) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-4' - entity.test3 = 10 + entity['RowKey'] = 'batch_all_operations_together-4' + entity['test3'] = 10 batch.append((TransactionOperation.UPSERT, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-5' + entity['RowKey'] = 'batch_all_operations_together-5' batch.append((TransactionOperation.UPSERT, entity.copy(), {'mode': UpdateMode.REPLACE})) transaction_count += 1 @@ -623,8 +626,8 @@ async def test_batch_too_many_ops(self, tables_storage_account_name, tables_prim batch = [] for i in range(0, 101): entity = TableEntity() - entity.PartitionKey = 'large' - entity.RowKey = 'item{0}'.format(i) + entity['PartitionKey'] = 'large' + entity['RowKey'] = 'item{0}'.format(i) batch.append(('create', entity.copy())) await self.table.submit_transaction(batch) @@ -707,16 +710,16 @@ async def test_batch_sas_auth(self, tables_storage_account_name, tables_primary_ table = service.get_table_client(self.table_name) entity = TableEntity() - entity.PartitionKey = 'batch_inserts' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) + entity['PartitionKey'] = 'batch_inserts' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) batch = [] transaction_count = 0 for i in range(10): - entity.RowKey = str(i) + entity['RowKey'] = str(i) batch.append(('create', entity.copy())) transaction_count += 1 transaction_result = await table.submit_transaction(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 47bd008db449..068166391de0 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 @@ -143,26 +143,29 @@ def _assert_default_entity(self, entity): assert entity['binary'].value == b'binary' assert entity['other'] == 20 assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert '_metadata' in entity + 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 hasattr(entity, "married") - assert not hasattr(entity, "deceased") - assert entity.sign == 'aquarius' - assert not hasattr(entity, "optional") - assert not hasattr(entity, "ratio") - assert not hasattr(entity, "evenratio") - assert not hasattr(entity, "large") - assert not hasattr(entity, "Birthday") - assert entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()) - assert not hasattr(entity, "other") - assert not hasattr(entity, "clsid") - assert entity['_metadata']['etag'] is not None + 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): @@ -176,13 +179,13 @@ def test_batch_insert(self, tables_cosmos_account_name, tables_primary_cosmos_ac try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert_replace' - entity.test = True - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert_replace' + entity['test'] = True + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('upsert', entity)] transaction_result = self.table.submit_transaction(batch) @@ -193,8 +196,8 @@ def test_batch_insert(self, tables_cosmos_account_name, tables_primary_cosmos_ac entity = self.table.get_entity('001', 'batch_insert_replace') assert entity is not None - assert 'value' == entity.test2 - assert 1234567890 == entity.test4 + assert 'value' == entity['test2'] + assert 1234567890 == entity['test4'] finally: self._tear_down() @@ -206,18 +209,18 @@ def test_batch_update(self, tables_cosmos_account_name, tables_primary_cosmos_ac try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_update' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_update' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() self.table.create_entity(entity) entity = self.table.get_entity(u'001', u'batch_update') - assert 3 == entity.test3 - entity.test2 = u'value1' + assert 3 == entity['test3'] + entity['test2'] = u'value1' batch = [('update', entity)] transaction_result = self.table.submit_transaction(batch) @@ -227,9 +230,9 @@ def test_batch_update(self, tables_cosmos_account_name, tables_primary_cosmos_ac assert 'etag' in transaction_result[0] result = self.table.get_entity('001', 'batch_update') - assert 'value1' == result.test2 - assert entity.PartitionKey == u'001' - assert entity.RowKey == u'batch_update' + assert 'value1' == result['test2'] + assert entity['PartitionKey'] == u'001' + assert entity['RowKey'] == u'batch_update' finally: self._tear_down() @@ -241,21 +244,21 @@ def test_batch_merge(self, tables_cosmos_account_name, tables_primary_cosmos_acc try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_merge' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_merge' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() self.table.create_entity(entity) resp_entity = self.table.get_entity(partition_key=u'001', row_key=u'batch_merge') - assert 3 == entity.test3 + assert 3 == entity['test3'] entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_merge' - entity.test2 = u'value1' + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_merge' + entity['test2'] = u'value1' batch = [('update', entity, {'mode': UpdateMode.MERGE})] transaction_result = self.table.submit_transaction(batch) @@ -265,10 +268,10 @@ def test_batch_merge(self, tables_cosmos_account_name, tables_primary_cosmos_acc assert 'etag' in transaction_result[0] resp_entity = self.table.get_entity(partition_key=u'001', row_key=u'batch_merge') - assert entity.test2 == resp_entity.test2 - assert 1234567890 == resp_entity.test4 - assert entity.PartitionKey == resp_entity.PartitionKey - assert entity.RowKey == resp_entity.RowKey + assert entity['test2'] == resp_entity['test2'] + assert 1234567890 == resp_entity['test4'] + assert entity['PartitionKey'] == resp_entity['PartitionKey'] + assert entity['RowKey'] == resp_entity['RowKey'] finally: self._tear_down() @@ -334,13 +337,13 @@ def test_batch_insert_replace(self, tables_cosmos_account_name, tables_primary_c try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert_replace' - entity.test = True - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert_replace' + entity['test'] = True + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('upsert', entity, {'mode': UpdateMode.REPLACE})] transaction_result = self.table.submit_transaction(batch) @@ -351,8 +354,8 @@ def test_batch_insert_replace(self, tables_cosmos_account_name, tables_primary_c entity = self.table.get_entity('001', 'batch_insert_replace') assert entity is not None - assert 'value' == entity.test2 - assert 1234567890 == entity.test4 + assert 'value' == entity['test2'] + assert 1234567890 == entity['test4'] finally: self._tear_down() @@ -364,13 +367,13 @@ def test_batch_insert_merge(self, tables_cosmos_account_name, tables_primary_cos try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert_merge' - entity.test = True - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert_merge' + entity['test'] = True + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('upsert', entity, {'mode': UpdateMode.MERGE})] transaction_result = self.table.submit_transaction(batch) @@ -381,8 +384,8 @@ def test_batch_insert_merge(self, tables_cosmos_account_name, tables_primary_cos entity = self.table.get_entity('001', 'batch_insert_merge') assert entity is not None - assert 'value' == entity.test2 - assert 1234567890 == entity.test4 + assert 'value' == entity['test2'] + assert 1234567890 == entity['test4'] finally: self._tear_down() @@ -394,17 +397,17 @@ def test_batch_delete(self, tables_cosmos_account_name, tables_primary_cosmos_ac try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_delete' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_delete' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() self.table.create_entity(entity) entity = self.table.get_entity(partition_key=u'001', row_key=u'batch_delete') - assert 3 == entity.test3 + assert 3 == entity['test3'] batch = [('delete', entity)] transaction_result = self.table.submit_transaction(batch) @@ -414,7 +417,7 @@ def test_batch_delete(self, tables_cosmos_account_name, tables_primary_cosmos_ac assert 'etag' not in transaction_result[0] with pytest.raises(ResourceNotFoundError): - entity = self.table.get_entity(partition_key=entity.PartitionKey, row_key=entity.RowKey) + entity = self.table.get_entity(partition_key=entity['PartitionKey'], row_key=entity['RowKey']) finally: self._tear_down() @@ -426,16 +429,16 @@ def test_batch_inserts(self, tables_cosmos_account_name, tables_primary_cosmos_a try: # Act entity = TableEntity() - entity.PartitionKey = 'batch_inserts' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) + entity['PartitionKey'] = 'batch_inserts' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) transaction_count = 0 batch = [] for i in range(100): - entity.RowKey = str(i) + entity['RowKey'] = str(i) batch.append(('create', entity.copy())) transaction_count += 1 transaction_result = self.table.submit_transaction(batch) @@ -461,47 +464,48 @@ def test_batch_all_operations_together(self, tables_cosmos_account_name, tables_ try: # Act entity = TableEntity() - entity.PartitionKey = '003' - entity.RowKey = 'batch_all_operations_together-1' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '003' + entity['RowKey'] = 'batch_all_operations_together-1' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() + self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-2' + entity['RowKey'] = 'batch_all_operations_together-2' self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-3' + entity['RowKey'] = 'batch_all_operations_together-3' self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-4' + entity['RowKey'] = 'batch_all_operations_together-4' self.table.create_entity(entity) transaction_count = 0 batch = [] - entity.RowKey = 'batch_all_operations_together' + entity['RowKey'] = 'batch_all_operations_together' batch.append((TransactionOperation.CREATE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-1' + entity['RowKey'] = 'batch_all_operations_together-1' batch.append((TransactionOperation.DELETE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-2' - entity.test3 = 10 + entity['RowKey'] = 'batch_all_operations_together-2' + entity['test3'] = 10 batch.append((TransactionOperation.UPDATE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-3' - entity.test3 = 100 + entity['RowKey'] = 'batch_all_operations_together-3' + entity['test3'] = 100 batch.append((TransactionOperation.UPDATE, entity.copy(), {'mode': UpdateMode.REPLACE})) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-4' - entity.test3 = 10 + entity['RowKey'] = 'batch_all_operations_together-4' + entity['test3'] = 10 batch.append((TransactionOperation.UPSERT, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-5' + entity['RowKey'] = 'batch_all_operations_together-5' batch.append((TransactionOperation.UPSERT, entity.copy(), {'mode': UpdateMode.REPLACE})) transaction_count += 1 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 bb068b342ea4..c62702d02b23 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 @@ -147,26 +147,28 @@ def _assert_default_entity(self, entity): assert entity['binary'].value == b'binary' assert entity['other'] == 20 assert entity['clsid'] == uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833') - assert '_metadata' in entity + 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 hasattr(entity, "married") - assert not hasattr(entity, "deceased") - assert entity.sign == 'aquarius' - assert not hasattr(entity, "optional") - assert not hasattr(entity, "ratio") - assert not hasattr(entity, "evenratio") - assert not hasattr(entity, "large") - assert not hasattr(entity, "Birthday") - assert entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()) - assert not hasattr(entity, "other") - assert not hasattr(entity, "clsid") - assert entity['_metadata']['etag'] is not None + 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) @@ -179,13 +181,13 @@ async def test_batch_single_insert(self, tables_cosmos_account_name, tables_prim try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('create', entity)] transaction_result = await self.table.submit_transaction(batch) @@ -194,11 +196,11 @@ async def test_batch_single_insert(self, tables_cosmos_account_name, tables_prim self._assert_valid_batch_transaction(transaction_result, 1) assert 'etag' in transaction_result[0] - e = await self.table.get_entity(row_key=entity.RowKey, partition_key=entity.PartitionKey) - assert e.test == entity.test.value - assert e.test2 == entity.test2 - assert e.test3 == entity.test3 - assert e.test4 == entity.test4.value + e = await self.table.get_entity(row_key=entity['RowKey'], partition_key=entity['PartitionKey']) + assert e['test'] == entity['test'].value + assert e['test2'] == entity['test2'] + assert e['test3'] == entity['test3'] + assert e['test4'] == entity['test4'].value finally: await self._tear_down() @@ -210,19 +212,19 @@ async def test_batch_single_update(self, tables_cosmos_account_name, tables_prim try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() resp = await self.table.create_entity(entity) assert resp is not None - entity.test3 = 5 - entity.test5 = datetime.utcnow() + entity['test3'] = 5 + entity['test5'] = datetime.utcnow() batch = [('update', entity, {'mode':UpdateMode.MERGE})] transaction_result = await self.table.submit_transaction(batch) @@ -231,10 +233,10 @@ async def test_batch_single_update(self, tables_cosmos_account_name, tables_prim self._assert_valid_batch_transaction(transaction_result, 1) assert 'etag' in transaction_result[0] - result = await self.table.get_entity(row_key=entity.RowKey, partition_key=entity.PartitionKey) - assert result.PartitionKey == u'001' - assert result.RowKey == u'batch_insert' - assert result.test3 == 5 + result = await self.table.get_entity(row_key=entity['RowKey'], partition_key=entity['PartitionKey']) + assert result['PartitionKey'] == u'001' + assert result['RowKey'] == u'batch_insert' + assert result['test3'] == 5 finally: await self._tear_down() @@ -245,18 +247,18 @@ async def test_batch_update(self, tables_cosmos_account_name, tables_primary_cos try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_update' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_update' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() await self.table.create_entity(entity) entity = await self.table.get_entity(u'001', u'batch_update') - assert 3 == entity.test3 - entity.test2 = u'value1' + assert 3 == entity['test3'] + entity['test2'] = u'value1' batch = [('update', entity)] transaction_result = await self.table.submit_transaction(batch) @@ -266,9 +268,9 @@ async def test_batch_update(self, tables_cosmos_account_name, tables_primary_cos assert 'etag' in transaction_result[0] result = await self.table.get_entity('001', 'batch_update') - assert 'value1' == result.test2 - assert entity.PartitionKey == u'001' - assert entity.RowKey == u'batch_update' + assert 'value1' == result['test2'] + assert entity['PartitionKey'] == u'001' + assert entity['RowKey'] == u'batch_update' finally: await self._tear_down() @@ -279,21 +281,21 @@ async def test_batch_merge(self, tables_cosmos_account_name, tables_primary_cosm try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_merge' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_merge' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() await self.table.create_entity(entity) resp_entity = await self.table.get_entity(partition_key=u'001', row_key=u'batch_merge') - assert 3 == entity.test3 + assert 3 == entity['test3'] entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_merge' - entity.test2 = u'value1' + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_merge' + entity['test2'] = u'value1' batch = [('update', entity, {'mode': UpdateMode.MERGE})] transaction_result = await self.table.submit_transaction(batch) @@ -303,10 +305,10 @@ async def test_batch_merge(self, tables_cosmos_account_name, tables_primary_cosm assert 'etag' in transaction_result[0] resp_entity = await self.table.get_entity(partition_key=u'001', row_key=u'batch_merge') - assert entity.test2 == resp_entity.test2 - assert 1234567890 == resp_entity.test4 - assert entity.PartitionKey == resp_entity.PartitionKey - assert entity.RowKey == resp_entity.RowKey + assert entity['test2'] == resp_entity['test2'] + assert 1234567890 == resp_entity['test4'] + assert entity['PartitionKey'] == resp_entity['PartitionKey'] + assert entity['RowKey'] == resp_entity['RowKey'] finally: await self._tear_down() @@ -371,13 +373,13 @@ async def test_batch_insert_replace(self, tables_cosmos_account_name, tables_pri try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert_replace' - entity.test = True - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert_replace' + entity['test'] = True + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('upsert', entity, {'mode': UpdateMode.REPLACE})] transaction_result = await self.table.submit_transaction(batch) @@ -388,8 +390,8 @@ async def test_batch_insert_replace(self, tables_cosmos_account_name, tables_pri entity = await self.table.get_entity('001', 'batch_insert_replace') assert entity is not None - assert 'value' == entity.test2 - assert 1234567890 == entity.test4 + assert 'value' == entity['test2'] + assert 1234567890 == entity['test4'] finally: await self._tear_down() @@ -400,13 +402,13 @@ async def test_batch_insert_merge(self, tables_cosmos_account_name, tables_prima try: # Act entity = TableEntity() - entity.PartitionKey = '001' - entity.RowKey = 'batch_insert_merge' - entity.test = True - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '001' + entity['RowKey'] = 'batch_insert_merge' + entity['test'] = True + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() batch = [('upsert', entity, {'mode':UpdateMode.MERGE})] transaction_result = await self.table.submit_transaction(batch) @@ -417,8 +419,8 @@ async def test_batch_insert_merge(self, tables_cosmos_account_name, tables_prima entity = await self.table.get_entity('001', 'batch_insert_merge') assert entity is not None - assert 'value' == entity.test2 - assert 1234567890 == entity.test4 + assert 'value' == entity['test2'] + assert 1234567890 == entity['test4'] finally: await self._tear_down() @@ -429,17 +431,17 @@ async def test_batch_delete(self, tables_cosmos_account_name, tables_primary_cos try: # Act entity = TableEntity() - entity.PartitionKey = u'001' - entity.RowKey = u'batch_delete' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = u'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = u'001' + entity['RowKey'] = u'batch_delete' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = u'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() await self.table.create_entity(entity) entity = await self.table.get_entity(partition_key=u'001', row_key=u'batch_delete') - assert 3 == entity.test3 + assert 3 == entity['test3'] batch = [('delete', entity)] transaction_result = await self.table.submit_transaction(batch) @@ -449,7 +451,7 @@ async def test_batch_delete(self, tables_cosmos_account_name, tables_primary_cos assert 'etag' not in transaction_result[0] with pytest.raises(ResourceNotFoundError): - entity = await self.table.get_entity(partition_key=entity.PartitionKey, row_key=entity.RowKey) + entity = await self.table.get_entity(partition_key=entity['PartitionKey'], row_key=entity['RowKey']) finally: await self._tear_down() @@ -460,16 +462,16 @@ async def test_batch_inserts(self, tables_cosmos_account_name, tables_primary_co try: # Act entity = TableEntity() - entity.PartitionKey = 'batch_inserts' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) + entity['PartitionKey'] = 'batch_inserts' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) transaction_count = 0 batch = [] for i in range(10): - entity.RowKey = str(i) + entity['RowKey'] = str(i) batch.append(('create', entity.copy())) transaction_count += 1 transaction_result = await self.table.submit_transaction(batch) @@ -497,48 +499,49 @@ async def test_batch_all_operations_together(self, tables_cosmos_account_name, t try: # Act entity = TableEntity() - entity.PartitionKey = '003' - entity.RowKey = 'batch_all_operations_together-1' - entity.test = EntityProperty(True, EdmType.BOOLEAN) - entity.test2 = 'value' - entity.test3 = 3 - entity.test4 = EntityProperty(1234567890, EdmType.INT32) - entity.test5 = datetime.utcnow() + entity['PartitionKey'] = '003' + entity['RowKey'] = 'batch_all_operations_together-1' + entity['test'] = EntityProperty(True, EdmType.BOOLEAN) + entity['test2'] = 'value' + entity['test3'] = 3 + entity['test4'] = EntityProperty(1234567890, EdmType.INT32) + entity['test5'] = datetime.utcnow() + await self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-2' + entity['RowKey'] = 'batch_all_operations_together-2' await self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-3' + entity['RowKey'] = 'batch_all_operations_together-3' await self.table.create_entity(entity) - entity.RowKey = 'batch_all_operations_together-4' + entity['RowKey'] = 'batch_all_operations_together-4' await self.table.create_entity(entity) transaction_count = 0 batch = [] - entity.RowKey = 'batch_all_operations_together' + entity['RowKey'] = 'batch_all_operations_together' batch.append((TransactionOperation.CREATE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-1' + entity['RowKey'] = 'batch_all_operations_together-1' batch.append((TransactionOperation.DELETE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-2' - entity.test3 = 10 + entity['RowKey'] = 'batch_all_operations_together-2' + entity['test3'] = 10 batch.append((TransactionOperation.UPDATE, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-3' - entity.test3 = 100 + entity['RowKey'] = 'batch_all_operations_together-3' + entity['test3'] = 100 batch.append((TransactionOperation.UPDATE, entity.copy(), {'mode': UpdateMode.REPLACE})) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-4' - entity.test3 = 10 + entity['RowKey'] = 'batch_all_operations_together-4' + entity['test3'] = 10 batch.append((TransactionOperation.UPSERT, entity.copy())) transaction_count += 1 - entity.RowKey = 'batch_all_operations_together-5' + entity['RowKey'] = 'batch_all_operations_together-5' batch.append((TransactionOperation.UPSERT, entity.copy(), {'mode': UpdateMode.REPLACE})) transaction_count += 1 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 2ce101aa2bbd..ecee18445d37 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_entity.py +++ b/sdk/tables/azure-data-tables/tests/test_table_entity.py @@ -135,8 +135,7 @@ def _insert_two_opposite_entities(self, pk=None, rk=None): 'other': EntityProperty(40, EdmType.INT32), 'clsid': uuid.UUID('c8da6455-213e-42d9-9b79-3f9149a57833') } - entity = TableEntity(**properties) - self.table.create_entity(entity) + self.table.create_entity(properties) return entity1, resp def _create_random_entity_dict(self, pk=None, rk=None): @@ -203,6 +202,8 @@ def _assert_default_entity(self, entity, headers=None): 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): ''' @@ -222,6 +223,8 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None): 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): ''' @@ -243,43 +246,49 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None): 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 hasattr(entity, "married") - assert not hasattr(entity, "deceased") - assert entity.sign == 'aquarius' - assert not hasattr(entity, "optional") - assert not hasattr(entity, "ratio") - assert not hasattr(entity, "evenratio") - assert not hasattr(entity, "large") - assert not hasattr(entity, "Birthday") - assert entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()) - assert not hasattr(entity, "other") - assert not hasattr(entity, "clsid") + 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['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() @@ -309,11 +318,11 @@ def test_url_encoding_at_symbol(self, tables_storage_account_name, tables_primar entities = self.table.query_entities(f) count = 0 for e in entities: - assert e.PartitionKey == entity[u"PartitionKey"] - assert e.RowKey == entity[u"RowKey"] - assert e.Value == entity[u"Value"] + assert e[u'PartitionKey'] == entity[u"PartitionKey"] + assert e[u'RowKey'] == entity[u"RowKey"] + assert e[u'Value'] == entity[u"Value"] count += 1 - self.table.delete_entity(e.PartitionKey, e.RowKey) + self.table.delete_entity(e[u'PartitionKey'], e[u'RowKey']) assert count == 1 @@ -332,12 +341,14 @@ def test_insert_etag(self, tables_storage_account_name, tables_primary_storage_a entity, _ = self._insert_random_entity() - entity1 = self.table.get_entity(row_key=entity.RowKey, partition_key=entity.PartitionKey) + entity1 = self.table.get_entity(row_key=entity['RowKey'], partition_key=entity['PartitionKey']) - with pytest.raises(AttributeError): - etag = entity1.etag + assert 'etag' not in entity1 + assert 'timestamp' not in entity1 + assert entity1.metadata + assert entity1.metadata['etag'] + assert entity1.metadata['timestamp'] - assert entity1.metadata() is not None finally: self._tear_down() @@ -825,19 +836,19 @@ class Color(Enum): YELLOW = 3 pk, rk = self._create_pk_rk(None, None) - entity = TableEntity() - entity.PartitionKey = pk - entity.RowKey = rk - entity.test1 = Color.YELLOW - entity.test2 = Color.BLUE - entity.test3 = Color.RED - + entity = TableEntity( + PartitionKey=pk, + RowKey=rk, + test1=Color.YELLOW, + test2=Color.BLUE, + test3=Color.RED + ) self.table.create_entity(entity=entity) resp_entity = self.table.get_entity(partition_key=pk, row_key=rk) - assert str(entity.test1) == resp_entity.test1 - assert str(entity.test2) == resp_entity.test2 - assert str(entity.test3) == resp_entity.test3 + assert str(entity['test1']) == resp_entity['test1'] + assert str(entity['test2']) == resp_entity['test2'] + assert str(entity['test3']) == resp_entity['test3'] finally: self._tear_down() @@ -919,13 +930,13 @@ def test_get_entity_full_metadata(self, tables_storage_account_name, tables_prim # Act resp = self.table.get_entity( - entity.PartitionKey, - entity.RowKey, + entity['PartitionKey'], + entity['RowKey'], headers={'accept': 'application/json;odata=fullmetadata'}) # Assert - assert resp.PartitionKey == entity.PartitionKey - assert resp.RowKey == entity.RowKey + assert resp['PartitionKey'] == entity['PartitionKey'] + assert resp['RowKey'] == entity['RowKey'] self._assert_default_entity_json_full_metadata(resp) finally: self._tear_down() @@ -939,13 +950,13 @@ def test_get_entity_no_metadata(self, tables_storage_account_name, tables_primar # Act resp = self.table.get_entity( - partition_key=entity.PartitionKey, - row_key=entity.RowKey, + partition_key=entity['PartitionKey'], + row_key=entity['RowKey'], headers={'accept': 'application/json;odata=nometadata'}) # Assert - assert resp.PartitionKey == entity.PartitionKey - assert resp.RowKey == entity.RowKey + assert resp['PartitionKey'] == entity['PartitionKey'] + assert resp['RowKey'] == entity['RowKey'] self._assert_default_entity_json_no_metadata(resp) finally: self._tear_down() @@ -959,8 +970,8 @@ def test_get_entity_not_existing(self, tables_storage_account_name, tables_prima # Act with pytest.raises(ResourceNotFoundError): - self.table.get_entity(partition_key=entity.PartitionKey, - row_key=entity.RowKey) + self.table.get_entity(partition_key=entity['PartitionKey'], + row_key=entity['RowKey']) # Assert finally: @@ -984,9 +995,9 @@ def test_get_entity_with_special_doubles(self, tables_storage_account_name, tabl row_key=entity['RowKey']) # Assert - assert received_entity.inf == float('inf') - assert received_entity.negativeinf == float('-inf') - assert isnan(received_entity.nan) + assert received_entity['inf'] == float('inf') + assert received_entity['negativeinf'] == float('-inf') + assert isnan(received_entity['nan']) finally: self._tear_down() @@ -998,14 +1009,14 @@ def test_update_entity(self, tables_storage_account_name, tables_primary_storage entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity[u'PartitionKey'], entity[u'RowKey']) resp = self.table.update_entity(mode=UpdateMode.REPLACE, entity=sent_entity) # Assert # assert resp - received_entity = self.table.get_entity(partition_key=entity.PartitionKey, - row_key=entity.RowKey) + received_entity = self.table.get_entity(partition_key=entity[u'PartitionKey'], + row_key=entity[u'RowKey']) with pytest.raises(KeyError): del received_entity['property_that_does_not_exist'] @@ -1038,7 +1049,7 @@ def test_update_entity_with_if_matches(self, tables_storage_account_name, tables entity, etag = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity[u'PartitionKey'], entity[u'RowKey']) resp = self.table.update_entity( mode=UpdateMode.REPLACE, entity=sent_entity, etag=etag, @@ -1046,7 +1057,7 @@ def test_update_entity_with_if_matches(self, tables_storage_account_name, tables # Assert self._assert_valid_metadata(resp) - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity[u'PartitionKey'], entity[u'RowKey']) self._assert_updated_entity(received_entity) finally: self._tear_down() @@ -1058,7 +1069,7 @@ def test_update_entity_with_if_doesnt_match(self, tables_storage_account_name, t try: entity, _ = self._insert_random_entity() - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity[u'PartitionKey'], entity[u'RowKey']) with pytest.raises(HttpResponseError): self.table.update_entity( mode=UpdateMode.REPLACE, @@ -1078,12 +1089,12 @@ def test_insert_or_merge_entity_with_existing_entity(self, tables_storage_accoun entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.upsert_entity(mode=UpdateMode.MERGE, entity=sent_entity) # Assert self._assert_valid_metadata(resp) - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_merged_entity(received_entity) finally: self._tear_down() @@ -1117,12 +1128,12 @@ def test_insert_or_replace_entity_with_existing_entity(self, tables_storage_acco entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.upsert_entity(mode=UpdateMode.REPLACE, entity=sent_entity) # Assert self._assert_valid_metadata(resp) - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) finally: self._tear_down() @@ -1155,12 +1166,12 @@ def test_merge_entity(self, tables_storage_account_name, tables_primary_storage_ entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity) # Assert self._assert_valid_metadata(resp) - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_merged_entity(received_entity) finally: self._tear_down() @@ -1189,7 +1200,7 @@ def test_merge_entity_with_if_matches(self, tables_storage_account_name, tables_ entity, etag = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.update_entity( mode=UpdateMode.MERGE, entity=sent_entity, @@ -1198,7 +1209,7 @@ def test_merge_entity_with_if_matches(self, tables_storage_account_name, tables_ # Assert self._assert_valid_metadata(resp) - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_merged_entity(received_entity) finally: self._tear_down() @@ -1211,7 +1222,7 @@ def test_merge_entity_with_if_doesnt_match(self, tables_storage_account_name, ta entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) with pytest.raises(HttpResponseError): self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity, @@ -1230,12 +1241,12 @@ def test_delete_entity(self, tables_storage_account_name, tables_primary_storage entity, _ = self._insert_random_entity() # Act - resp = self.table.delete_entity(partition_key=entity.PartitionKey, row_key=entity.RowKey) + resp = self.table.delete_entity(partition_key=entity['PartitionKey'], row_key=entity['RowKey']) # Assert assert resp is None with pytest.raises(ResourceNotFoundError): - self.table.get_entity(entity.PartitionKey, entity.RowKey) + self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: self._tear_down() @@ -1262,13 +1273,13 @@ def test_delete_entity_with_if_matches(self, tables_storage_account_name, tables entity, etag = self._insert_random_entity() # Act - resp = self.table.delete_entity(entity.PartitionKey, entity.RowKey, etag=etag, + resp = self.table.delete_entity(entity['PartitionKey'], entity['RowKey'], etag=etag, match_condition=MatchConditions.IfNotModified) # Assert assert resp is None with pytest.raises(ResourceNotFoundError): - self.table.get_entity(entity.PartitionKey, entity.RowKey) + self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: self._tear_down() @@ -1282,7 +1293,7 @@ def test_delete_entity_with_if_doesnt_match(self, tables_storage_account_name, t # Act with pytest.raises(HttpResponseError): self.table.delete_entity( - entity.PartitionKey, entity.RowKey, + entity['PartitionKey'], entity['RowKey'], etag=u'W/"datetime\'2012-06-15T22%3A51%3A44.9662825Z\'"', match_condition=MatchConditions.IfNotModified) @@ -1309,8 +1320,8 @@ def test_unicode_property_value(self, tables_storage_account_name, tables_primar # Assert assert len(entities) == 2 - assert entities[0].Description == u'ꀕ' - assert entities[1].Description == u'ꀕ' + assert entities[0]['Description'] == u'ꀕ' + assert entities[1]['Description'] == u'ꀕ' finally: self._tear_down() @@ -1348,13 +1359,13 @@ def test_operations_on_entity_with_partition_key_having_single_quote(self, table entity, _ = self._insert_random_entity(pk=partition_key_with_single_quote, rk=row_key_with_single_quote) # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.upsert_entity(mode=UpdateMode.MERGE, entity=sent_entity) # Assert self._assert_valid_metadata(resp) # row key here only has 2 quotes - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) # Act @@ -1363,12 +1374,12 @@ def test_operations_on_entity_with_partition_key_having_single_quote(self, table # Assert self._assert_valid_metadata(resp) - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) assert received_entity['newField'] == 'newFieldValue' # Act - resp = self.table.delete_entity(entity.PartitionKey, entity.RowKey) + resp = self.table.delete_entity(entity['PartitionKey'], entity['RowKey']) # Assert assert resp is None @@ -1400,16 +1411,16 @@ def test_empty_and_spaces_property_value(self, tables_storage_account_name, tabl # Assert assert resp is not None - assert resp.EmptyByte.value == b'' - assert resp.EmptyUnicode == u'' - assert resp.SpacesOnlyByte.value == b' ' - assert resp.SpacesOnlyUnicode == u' ' - assert resp.SpacesBeforeByte.value == b' Text' - assert resp.SpacesBeforeUnicode == u' Text' - assert resp.SpacesAfterByte.value == b'Text ' - assert resp.SpacesAfterUnicode == u'Text ' - assert resp.SpacesBeforeAndAfterByte.value == b' Text ' - assert resp.SpacesBeforeAndAfterUnicode == u' Text ' + assert resp['EmptyByte'].value == b'' + assert resp['EmptyUnicode'] == u'' + assert resp['SpacesOnlyByte'].value == b' ' + assert resp['SpacesOnlyUnicode'] == u' ' + assert resp['SpacesBeforeByte'].value == b' Text' + assert resp['SpacesBeforeUnicode'] == u' Text' + assert resp['SpacesAfterByte'].value == b'Text ' + assert resp['SpacesAfterUnicode'] == u'Text ' + assert resp['SpacesBeforeAndAfterByte'].value == b' Text ' + assert resp['SpacesBeforeAndAfterUnicode'] == u' Text ' finally: self._tear_down() @@ -1446,7 +1457,7 @@ def test_binary_property_value(self, tables_storage_account_name, tables_primary # Assert assert resp is not None - assert resp.binary.value == binary_data + assert resp['binary'].value == binary_data finally: self._tear_down() @@ -1467,8 +1478,8 @@ def test_timezone(self, tables_storage_account_name, tables_primary_storage_acco # Assert assert resp is not None # times are not equal because request is made after - # assert resp.date.astimezone(tzutc()) == local_date.astimezone(tzutc()) - assert resp.date.astimezone(local_tz) == local_date + assert resp['date'].astimezone(tzutc()) == local_date.astimezone(tzutc()) + assert resp['date'].astimezone(local_tz) == local_date finally: self._tear_down() @@ -1584,17 +1595,17 @@ def test_query_entities_with_filter(self, tables_storage_account_name, tables_pr self._set_up(tables_storage_account_name, tables_primary_storage_account_key) try: entity, _ = self._insert_random_entity() - entity2, _ = self._insert_random_entity(pk="foo" + entity.PartitionKey) - entity3, _ = self._insert_random_entity(pk="bar" + entity.PartitionKey) + entity2, _ = self._insert_random_entity(pk="foo" + entity['PartitionKey']) + entity3, _ = self._insert_random_entity(pk="bar" + entity['PartitionKey']) # Act entities = list(self.table.query_entities( - "PartitionKey eq '{}'".format(entity.PartitionKey), + "PartitionKey eq '{}'".format(entity['PartitionKey']), results_per_page=1)) # Assert assert len(entities) == 1 - assert entity.PartitionKey == entities[0].PartitionKey + assert entity['PartitionKey'] == entities[0]['PartitionKey'] self._assert_default_entity(entities[0]) finally: self._tear_down() @@ -1679,11 +1690,11 @@ def test_query_entities_with_select(self, tables_storage_account_name, tables_pr # Assert assert len(entities) == 2 - assert entities[0].age == 39 - assert entities[0].sex == 'male' - assert not hasattr(entities[0], "birthday") - assert not hasattr(entities[0], "married") - assert not hasattr(entities[0], "deceased") + assert entities[0]['age'] == 39 + assert entities[0]['sex'] == 'male' + assert not "birthday" in entities[0] + assert not "married" in entities[0] + assert not "deceased" in entities[0] finally: self._tear_down() @@ -1898,11 +1909,11 @@ def test_sas_update(self, tables_storage_account_name, tables_primary_storage_ac credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) - updated_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + updated_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = table.update_entity(mode=UpdateMode.REPLACE, entity=updated_entity) # Assert - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) assert resp is not None self._assert_updated_entity(received_entity) finally: @@ -1931,11 +1942,11 @@ def test_sas_delete(self, tables_storage_account_name, tables_primary_storage_ac credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) - table.delete_entity(entity.PartitionKey, entity.RowKey) + table.delete_entity(entity['PartitionKey'], entity['RowKey']) # Assert with pytest.raises(ResourceNotFoundError): - self.table.get_entity(entity.PartitionKey, entity.RowKey) + self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: self._tear_down() @@ -1973,7 +1984,7 @@ def test_sas_upper_case_table_name(self, tables_storage_account_name, tables_pri ) table = service.get_table_client(self.table_name) entities = list(table.query_entities( - "PartitionKey eq '{}'".format(entity.PartitionKey))) + "PartitionKey eq '{}'".format(entity['PartitionKey']))) # Assert assert len(entities) == 1 @@ -2013,7 +2024,7 @@ def test_sas_signed_identifier(self, tables_storage_account_name, tables_primary ) table = service.get_table_client(self.table_name) entities = list(table.query_entities( - "PartitionKey eq '{}'".format(entity.PartitionKey))) + "PartitionKey eq '{}'".format(entity['PartitionKey']))) # Assert assert len(entities) == 1 @@ -2057,15 +2068,15 @@ def test_datetime_str_passthrough(self, tables_storage_account_name, tables_prim self.table.create_entity(entity) received = self.table.get_entity(partition, row) assert isinstance(received['datetime1'], datetime) - assert received.datetime1.tables_service_value == dotnet_timestamp + assert received['datetime1'].tables_service_value == dotnet_timestamp - received['datetime2'] = received.datetime1.replace(year=2020) + received['datetime2'] = received['datetime1'].replace(year=2020) assert received['datetime2'].tables_service_value == "" self.table.update_entity(received) updated = self.table.get_entity(partition, row) assert isinstance(updated['datetime1'], datetime) assert isinstance(updated['datetime2'], datetime) - assert updated.datetime1.tables_service_value == dotnet_timestamp + assert updated['datetime1'].tables_service_value == dotnet_timestamp finally: self._tear_down() 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 39f9c8248d7c..80c71dc24583 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 @@ -125,8 +125,7 @@ async def _insert_two_opposite_entities(self, pk=None, rk=None): 'other': EntityProperty(40, EdmType.INT32), 'clsid': uuid.UUID('c8da6455-213e-42d9-9b79-3f9149a57833') } - entity = TableEntity(**properties) - await self.table.create_entity(entity) + await self.table.create_entity(properties) return entity1, resp def _create_random_entity_dict(self, pk=None, rk=None): @@ -194,6 +193,8 @@ def _assert_default_entity(self, entity, headers=None): 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): ''' @@ -213,6 +214,8 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None): 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): ''' @@ -234,43 +237,49 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None): 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 hasattr(entity, "married") - assert not hasattr(entity, "deceased") - assert entity.sign == 'aquarius' - assert not hasattr(entity, "optional") - assert not hasattr(entity, "ratio") - assert not hasattr(entity, "evenratio") - assert not hasattr(entity, "large") - assert not hasattr(entity, "Birthday") - assert entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()) - assert not hasattr(entity, "other") - assert not hasattr(entity, "clsid") + 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['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() @@ -299,10 +308,10 @@ async def test_url_encoding_at_symbol(self, tables_storage_account_name, tables_ count = 0 async for e in entities: - assert e.PartitionKey == entity[u"PartitionKey"] - assert e.RowKey == entity[u"RowKey"] - assert e.Value == entity[u"Value"] - await self.table.delete_entity(e.PartitionKey, e.RowKey) + assert e['PartitionKey'] == entity[u"PartitionKey"] + assert e['RowKey'] == entity[u"RowKey"] + assert e['Value'] == entity[u"Value"] + await self.table.delete_entity(e['PartitionKey'], e['RowKey']) count += 1 assert count == 1 @@ -646,13 +655,13 @@ async def test_get_entity_full_metadata(self, tables_storage_account_name, table # Act resp = await self.table.get_entity( - entity.PartitionKey, - entity.RowKey, + entity['PartitionKey'], + entity['RowKey'], headers={'accept': 'application/json;odata=fullmetadata'}) # Assert - assert resp.PartitionKey == entity.PartitionKey - assert resp.RowKey == entity.RowKey + assert resp['PartitionKey'] == entity['PartitionKey'] + assert resp['RowKey'] == entity['RowKey'] self._assert_default_entity_json_full_metadata(resp) finally: await self._tear_down() @@ -666,13 +675,13 @@ async def test_get_entity_no_metadata(self, tables_storage_account_name, tables_ # Act resp = await self.table.get_entity( - partition_key=entity.PartitionKey, - row_key=entity.RowKey, + partition_key=entity['PartitionKey'], + row_key=entity['RowKey'], headers={'accept': 'application/json;odata=nometadata'}) # Assert - assert resp.PartitionKey == entity.PartitionKey - assert resp.RowKey == entity.RowKey + assert resp['PartitionKey'] == entity['PartitionKey'] + assert resp['RowKey'] == entity['RowKey'] self._assert_default_entity_json_no_metadata(resp) finally: await self._tear_down() @@ -686,8 +695,8 @@ async def test_get_entity_not_existing(self, tables_storage_account_name, tables # Act with pytest.raises(ResourceNotFoundError): - await self.table.get_entity(partition_key=entity.PartitionKey, - row_key=entity.RowKey) + await self.table.get_entity(partition_key=entity['PartitionKey'], + row_key=entity['RowKey']) # Assert finally: @@ -712,9 +721,9 @@ async def test_get_entity_with_special_doubles(self, tables_storage_account_name row_key=entity['RowKey']) # Assert - assert resp.inf == float('inf') - assert resp.negativeinf == float('-inf') - assert isnan(resp.nan) + assert resp['inf'] == float('inf') + assert resp['negativeinf'] == float('-inf') + assert isnan(resp['nan']) finally: await self._tear_down() @@ -726,14 +735,14 @@ async def test_update_entity(self, tables_storage_account_name, tables_primary_s entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.update_entity(mode=UpdateMode.REPLACE, entity=sent_entity) # Assert received_entity = await self.table.get_entity( - partition_key=entity.PartitionKey, - row_key=entity.RowKey) + partition_key=entity['PartitionKey'], + row_key=entity['RowKey']) self._assert_valid_metadata(resp) self._assert_updated_entity(received_entity) @@ -764,15 +773,15 @@ async def test_update_entity_with_if_matches(self, tables_storage_account_name, entity, etag = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.update_entity( mode=UpdateMode.REPLACE, entity=sent_entity, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_valid_metadata(resp) self._assert_updated_entity(received_entity) finally: @@ -787,7 +796,7 @@ async def test_update_entity_with_if_doesnt_match(self, tables_storage_account_n entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) with pytest.raises(HttpResponseError): await self.table.update_entity( mode=UpdateMode.REPLACE, @@ -808,12 +817,12 @@ async def test_insert_or_merge_entity_with_existing_entity(self, tables_storage_ entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.upsert_entity(mode=UpdateMode.MERGE, entity=sent_entity) # Assert - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_valid_metadata(resp) self._assert_merged_entity(received_entity) finally: @@ -848,12 +857,12 @@ async def test_insert_or_replace_entity_with_existing_entity(self, tables_storag entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.upsert_entity(mode=UpdateMode.REPLACE, entity=sent_entity) # Assert - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_valid_metadata(resp) self._assert_updated_entity(received_entity) finally: @@ -887,12 +896,12 @@ async def test_merge_entity(self, tables_storage_account_name, tables_primary_st entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity) # Assert - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_valid_metadata(resp) self._assert_merged_entity(received_entity) finally: @@ -922,14 +931,14 @@ async def test_merge_entity_with_if_matches(self, tables_storage_account_name, t entity, etag = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_valid_metadata(resp) self._assert_merged_entity(received_entity) finally: @@ -944,7 +953,7 @@ async def test_merge_entity_with_if_doesnt_match(self, tables_storage_account_na entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) with pytest.raises(HttpResponseError): await self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity, @@ -963,12 +972,12 @@ async def test_delete_entity(self, tables_storage_account_name, tables_primary_s entity, _ = await self._insert_random_entity() # Act - resp = await self.table.delete_entity(partition_key=entity.PartitionKey, row_key=entity.RowKey) + resp = await self.table.delete_entity(partition_key=entity['PartitionKey'], row_key=entity['RowKey']) # Assert assert resp is None with pytest.raises(ResourceNotFoundError): - await self.table.get_entity(entity.PartitionKey, entity.RowKey) + await self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: await self._tear_down() @@ -995,13 +1004,13 @@ async def test_delete_entity_with_if_matches(self, tables_storage_account_name, entity, etag = await self._insert_random_entity() # Act - resp = await self.table.delete_entity(entity.PartitionKey, entity.RowKey, etag=etag, + resp = await self.table.delete_entity(entity['PartitionKey'], entity['RowKey'], etag=etag, match_condition=MatchConditions.IfNotModified) # Assert assert resp is None with pytest.raises(ResourceNotFoundError): - await self.table.get_entity(entity.PartitionKey, entity.RowKey) + await self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: await self._tear_down() @@ -1016,7 +1025,7 @@ async def test_delete_entity_with_if_doesnt_match(self, tables_storage_account_n # Act with pytest.raises(HttpResponseError): await self.table.delete_entity( - entity.PartitionKey, entity.RowKey, + entity['PartitionKey'], entity['RowKey'], etag=u'W/"datetime\'2012-06-15T22%3A51%3A44.9662825Z\'"', match_condition=MatchConditions.IfNotModified) @@ -1046,8 +1055,8 @@ async def test_unicode_property_value(self, tables_storage_account_name, tables_ # Assert assert len(entities) == 2 - assert entities[0].Description == u'ꀕ' - assert entities[1].Description == u'ꀕ' + assert entities[0]['Description'] == u'ꀕ' + assert entities[1]['Description'] == u'ꀕ' finally: await self._tear_down() @@ -1086,18 +1095,18 @@ async def test_operations_on_entity_with_partition_key_having_single_quote(self, entity, _ = await self._insert_random_entity(pk=partition_key_with_single_quote, rk=row_key_with_single_quote) - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.upsert_entity(mode=UpdateMode.MERGE, entity=sent_entity) self._assert_valid_metadata(resp) - received_entity = await self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) sent_entity['newField'] = u'newFieldValue' resp = await self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity) self._assert_valid_metadata(resp) - received_entity = await self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) assert received_entity['newField'] == 'newFieldValue' finally: @@ -1129,16 +1138,16 @@ async def test_empty_and_spaces_property_value(self, tables_storage_account_name # Assert assert resp is not None - assert resp.EmptyByte == '' - assert resp.EmptyUnicode == u'' - assert resp.SpacesOnlyByte == ' ' - assert resp.SpacesOnlyUnicode == u' ' - assert resp.SpacesBeforeByte == ' Text' - assert resp.SpacesBeforeUnicode == u' Text' - assert resp.SpacesAfterByte == 'Text ' - assert resp.SpacesAfterUnicode == u'Text ' - assert resp.SpacesBeforeAndAfterByte == ' Text ' - assert resp.SpacesBeforeAndAfterUnicode == u' Text ' + assert resp['EmptyByte'] == '' + assert resp['EmptyUnicode'] == u'' + assert resp['SpacesOnlyByte'] == ' ' + assert resp['SpacesOnlyUnicode'] == u' ' + assert resp['SpacesBeforeByte'] == ' Text' + assert resp['SpacesBeforeUnicode'] == u' Text' + assert resp['SpacesAfterByte'] == 'Text ' + assert resp['SpacesAfterUnicode'] == u'Text ' + assert resp['SpacesBeforeAndAfterByte'] == ' Text ' + assert resp['SpacesBeforeAndAfterUnicode'] == u' Text ' finally: await self._tear_down() @@ -1175,7 +1184,7 @@ async def test_binary_property_value(self, tables_storage_account_name, tables_p # Assert assert resp is not None - assert resp.binary.value == binary_data + assert resp['binary'].value == binary_data finally: await self._tear_down() @@ -1196,8 +1205,8 @@ async def test_timezone(self, tables_storage_account_name, tables_primary_storag # Assert assert resp is not None # times are not equal because request is made after - # assert resp.date.astimezone(tzutc()) == local_date.astimezone(tzutc()) - # assert resp.date.astimezone(local_tz) == local_date + assert resp['date'].astimezone(tzutc()) == local_date.astimezone(tzutc()) + assert resp['date'].astimezone(local_tz) == local_date finally: await self._tear_down() @@ -1605,18 +1614,18 @@ async def test_query_entities_with_filter(self, tables_storage_account_name, tab await self._set_up(tables_storage_account_name, tables_primary_storage_account_key) try: entity, _ = await self._insert_random_entity() - entity2, _ = await self._insert_random_entity(pk="foo" + entity.PartitionKey) - entity3, _ = await self._insert_random_entity(pk="bar" + entity.PartitionKey) + entity2, _ = await self._insert_random_entity(pk="foo" + entity['PartitionKey']) + entity3, _ = await self._insert_random_entity(pk="bar" + entity['PartitionKey']) # Act entities = [] async for t in self.table.query_entities( - "PartitionKey eq '{}'".format(entity.PartitionKey)): + "PartitionKey eq '{}'".format(entity['PartitionKey'])): entities.append(t) # Assert assert len(entities) == 1 - assert entity.PartitionKey == entities[0].PartitionKey + assert entity['PartitionKey'] == entities[0]['PartitionKey'] self._assert_default_entity(entities[0]) finally: await self._tear_down() @@ -1657,11 +1666,11 @@ async def test_query_entities_with_select(self, tables_storage_account_name, tab # Assert assert len(entities) == 2 - assert entities[0].age == 39 - assert entities[0].sex == 'male' - assert not hasattr(entities[0], "birthday") - assert not hasattr(entities[0], "married") - assert not hasattr(entities[0], "deceased") + assert entities[0]['age'] == 39 + assert entities[0]['sex'] == 'male' + assert not "birthday" in entities[0] + assert not "married" in entities[0] + assert not "deceased" in entities[0] finally: await self._tear_down() @@ -1876,10 +1885,10 @@ async def test_sas_update(self, tables_storage_account_name, tables_primary_stor credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) - updated_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + updated_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await table.update_entity(mode=UpdateMode.REPLACE, entity=updated_entity) - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) # Assert self._assert_updated_entity(received_entity) @@ -1911,11 +1920,11 @@ async def test_sas_delete(self, tables_storage_account_name, tables_primary_stor credential=AzureSasCredential(token), ) table = service.get_table_client(self.table_name) - await table.delete_entity(entity.PartitionKey, entity.RowKey) + await table.delete_entity(entity['PartitionKey'], entity['RowKey']) # Assert with pytest.raises(ResourceNotFoundError): - await self.table.get_entity(entity.PartitionKey, entity.RowKey) + await self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: await self._tear_down() @@ -1989,7 +1998,7 @@ async def test_sas_signed_identifier(self, tables_storage_account_name, tables_p table = service.get_table_client(table_name=self.table_name) entities = [] async for t in table.query_entities( - "PartitionKey eq '{}'".format(entity.PartitionKey)): + "PartitionKey eq '{}'".format(entity['PartitionKey'])): entities.append(t) # Assert @@ -2033,15 +2042,15 @@ async def test_datetime_str_passthrough(self, tables_storage_account_name, table await self.table.create_entity(entity) received = await self.table.get_entity(partition, row) assert isinstance(received['datetime1'], datetime) - assert received.datetime1.tables_service_value == dotnet_timestamp + assert received['datetime1'].tables_service_value == dotnet_timestamp - received['datetime2'] = received.datetime1.replace(year=2020) + received['datetime2'] = received['datetime1'].replace(year=2020) assert received['datetime2'].tables_service_value == "" await self.table.update_entity(received) updated = await self.table.get_entity(partition, row) assert isinstance(updated['datetime1'], datetime) assert isinstance(updated['datetime2'], datetime) - assert updated.datetime1.tables_service_value == dotnet_timestamp + assert updated['datetime1'].tables_service_value == dotnet_timestamp finally: await self._tear_down() \ No newline at end of file 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 f68049f7487b..c1b22c73508d 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 @@ -134,8 +134,7 @@ def _insert_two_opposite_entities(self, pk=None, rk=None): 'other': EntityProperty(40, EdmType.INT32), 'clsid': uuid.UUID('c8da6455-213e-42d9-9b79-3f9149a57833') } - entity = TableEntity(**properties) - self.table.create_entity(entity) + self.table.create_entity(properties) return entity1, resp def _create_random_entity_dict(self, pk=None, rk=None): @@ -202,6 +201,8 @@ def _assert_default_entity(self, entity, headers=None): 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): ''' @@ -221,6 +222,8 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None): 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): ''' @@ -242,44 +245,49 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None): 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 hasattr(entity, "married") - assert not hasattr(entity, "deceased") - assert entity.sign == 'aquarius' - assert not hasattr(entity, "optional") - assert not hasattr(entity, "ratio") - assert not hasattr(entity, "evenratio") - assert not hasattr(entity, "large") - assert not hasattr(entity, "Birthday") - assert entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()) - assert not hasattr(entity, "other") - assert not hasattr(entity, "clsid") + 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.sign == 'aquarius' - 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['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() @@ -309,11 +317,11 @@ def test_url_encoding_at_symbol(self, tables_cosmos_account_name, tables_primary entities = self.table.query_entities(f) count = 0 for e in entities: - assert e.PartitionKey == entity[u"PartitionKey"] - assert e.RowKey == entity[u"RowKey"] - assert e.Value == entity[u"Value"] + assert e['PartitionKey'] == entity[u"PartitionKey"] + assert e['RowKey'] == entity[u"RowKey"] + assert e['Value'] == entity[u"Value"] count += 1 - self.table.delete_entity(e.PartitionKey, e.RowKey) + self.table.delete_entity(e['PartitionKey'], e['RowKey']) assert count == 1 @@ -332,12 +340,13 @@ def test_insert_etag(self, tables_cosmos_account_name, tables_primary_cosmos_acc try: entity, _ = self._insert_random_entity() - entity1 = self.table.get_entity(row_key=entity.RowKey, partition_key=entity.PartitionKey) - - with pytest.raises(AttributeError): - etag = entity1.etag + entity1 = self.table.get_entity(row_key=entity['RowKey'], partition_key=entity['PartitionKey']) - assert entity1.metadata() is not None + assert 'etag' not in entity1 + assert 'timestamp' not in entity1 + assert entity1.metadata + assert entity1.metadata['etag'] + assert entity1.metadata['timestamp'] finally: self._tear_down() self.sleep(SLEEP_DELAY) @@ -876,13 +885,13 @@ def test_get_entity_full_metadata(self, tables_cosmos_account_name, tables_prima # Act resp = self.table.get_entity( - entity.PartitionKey, - entity.RowKey, + entity['PartitionKey'], + entity['RowKey'], headers={'accept': 'application/json;odata=fullmetadata'}) # Assert - assert resp.PartitionKey == entity.PartitionKey - assert resp.RowKey == entity.RowKey + assert resp['PartitionKey'] == entity['PartitionKey'] + assert resp['RowKey'] == entity['RowKey'] self._assert_default_entity_json_full_metadata(resp) finally: self._tear_down() @@ -897,13 +906,13 @@ def test_get_entity_no_metadata(self, tables_cosmos_account_name, tables_primary # Act resp = self.table.get_entity( - partition_key=entity.PartitionKey, - row_key=entity.RowKey, + partition_key=entity['PartitionKey'], + row_key=entity['RowKey'], headers={'accept': 'application/json;odata=nometadata'}) # Assert - assert resp.PartitionKey == entity.PartitionKey - assert resp.RowKey == entity.RowKey + assert resp['PartitionKey'] == entity['PartitionKey'] + assert resp['RowKey'] == entity['RowKey'] self._assert_default_entity_json_no_metadata(resp) finally: self._tear_down() @@ -918,8 +927,8 @@ def test_get_entity_not_existing(self, tables_cosmos_account_name, tables_primar # Act with pytest.raises(ResourceNotFoundError): - self.table.get_entity(partition_key=entity.PartitionKey, - row_key=entity.RowKey) + self.table.get_entity(partition_key=entity['PartitionKey'], + row_key=entity['RowKey']) # Assert finally: @@ -944,9 +953,9 @@ def test_get_entity_with_special_doubles(self, tables_cosmos_account_name, table row_key=entity['RowKey']) # Assert - assert resp.inf == float('inf') - assert resp.negativeinf == float('-inf') - assert isnan(resp.nan) + assert resp['inf'] == float('inf') + assert resp['negativeinf'] == float('-inf') + assert isnan(resp['nan']) finally: self._tear_down() self.sleep(SLEEP_DELAY) @@ -959,14 +968,14 @@ def test_update_entity(self, tables_cosmos_account_name, tables_primary_cosmos_a entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) self.table.update_entity(mode=UpdateMode.REPLACE, entity=sent_entity) # Assert # assert resp - received_entity = self.table.get_entity(partition_key=entity.PartitionKey, - row_key=entity.RowKey) + received_entity = self.table.get_entity(partition_key=entity['PartitionKey'], + row_key=entity['RowKey']) self._assert_updated_entity(received_entity) finally: @@ -998,7 +1007,7 @@ def test_update_entity_with_if_matches(self, tables_cosmos_account_name, tables_ entity, etag = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) # , response_hook=lambda e, h: h) self.table.update_entity( mode=UpdateMode.REPLACE, entity=sent_entity, etag=etag, @@ -1006,7 +1015,7 @@ def test_update_entity_with_if_matches(self, tables_cosmos_account_name, tables_ # Assert # assert resp - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) finally: self._tear_down() @@ -1020,7 +1029,7 @@ def test_update_entity_with_if_doesnt_match(self, tables_cosmos_account_name, ta entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) with pytest.raises(HttpResponseError): self.table.update_entity( mode=UpdateMode.MERGE, @@ -1042,12 +1051,12 @@ def test_insert_or_merge_entity_with_existing_entity(self, tables_cosmos_account entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.upsert_entity(mode=UpdateMode.MERGE, entity=sent_entity) # Assert assert resp is not None - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_merged_entity(received_entity) finally: self._tear_down() @@ -1083,12 +1092,12 @@ def test_insert_or_replace_entity_with_existing_entity(self, tables_cosmos_accou entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.upsert_entity(mode=UpdateMode.REPLACE, entity=sent_entity) # Assert # assert resp is not None - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) finally: self._tear_down() @@ -1123,12 +1132,12 @@ def test_merge_entity(self, tables_cosmos_account_name, tables_primary_cosmos_ac entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity) # Assert assert resp is not None - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_merged_entity(received_entity) finally: self._tear_down() @@ -1159,7 +1168,7 @@ def test_merge_entity_with_if_matches(self, tables_cosmos_account_name, tables_p entity, etag = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.update_entity( mode=UpdateMode.MERGE, entity=sent_entity, @@ -1168,7 +1177,7 @@ def test_merge_entity_with_if_matches(self, tables_cosmos_account_name, tables_p # Assert assert resp is not None - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_merged_entity(received_entity) finally: self._tear_down() @@ -1182,7 +1191,7 @@ def test_merge_entity_with_if_doesnt_match(self, tables_cosmos_account_name, tab entity, _ = self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) with pytest.raises(HttpResponseError): self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity, @@ -1202,11 +1211,11 @@ def test_delete_entity(self, tables_cosmos_account_name, tables_primary_cosmos_a entity, _ = self._insert_random_entity() # Act - self.table.delete_entity(partition_key=entity.PartitionKey, row_key=entity.RowKey) + self.table.delete_entity(partition_key=entity['PartitionKey'], row_key=entity['RowKey']) # Assert with pytest.raises(ResourceNotFoundError): - self.table.get_entity(entity.PartitionKey, entity.RowKey) + self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: self._tear_down() self.sleep(SLEEP_DELAY) @@ -1236,15 +1245,15 @@ def test_delete_entity_with_if_matches(self, tables_cosmos_account_name, tables_ # Act self.table.delete_entity( - entity.PartitionKey, - entity.RowKey, + entity['PartitionKey'], + entity['RowKey'], etag=etag, match_condition=MatchConditions.IfNotModified ) # Assert with pytest.raises(ResourceNotFoundError): - self.table.get_entity(entity.PartitionKey, entity.RowKey) + self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: self._tear_down() self.sleep(SLEEP_DELAY) @@ -1259,7 +1268,7 @@ def test_delete_entity_with_if_doesnt_match(self, tables_cosmos_account_name, ta # Act with pytest.raises(HttpResponseError): self.table.delete_entity( - entity.PartitionKey, entity.RowKey, + entity['PartitionKey'], entity['RowKey'], etag=u'W/"datetime\'2012-06-15T22%3A51%3A44.9662825Z\'"', match_condition=MatchConditions.IfNotModified) @@ -1287,8 +1296,8 @@ def test_unicode_property_value(self, tables_cosmos_account_name, tables_primary # Assert assert len(entities) == 2 - assert entities[0].Description == u'ꀕ' - assert entities[1].Description == u'ꀕ' + assert entities[0]['Description'] == u'ꀕ' + assert entities[1]['Description'] == u'ꀕ' finally: self._tear_down() self.sleep(SLEEP_DELAY) @@ -1330,13 +1339,13 @@ def test_operations_on_entity_with_partition_key_having_single_quote(self, table entity, _ = self._insert_random_entity(pk=partition_key_with_single_quote, rk=row_key_with_single_quote) # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = self.table.upsert_entity(mode=UpdateMode.MERGE, entity=sent_entity) # Assert assert resp is not None # row key here only has 2 quotes - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) # Act @@ -1345,12 +1354,12 @@ def test_operations_on_entity_with_partition_key_having_single_quote(self, table # Assert assert resp is not None - received_entity = self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) assert received_entity['newField'] == 'newFieldValue' # Act - resp = self.table.delete_entity(entity.PartitionKey, entity.RowKey) + resp = self.table.delete_entity(entity['PartitionKey'], entity['RowKey']) # Assert assert resp is not None @@ -1382,17 +1391,16 @@ def test_empty_and_spaces_property_value(self, tables_cosmos_account_name, table resp = self.table.get_entity(entity['PartitionKey'], entity['RowKey']) # Assert - assert resp is not None - assert resp.EmptyByte.value == b'' - assert resp.EmptyUnicode == u'' - assert resp.SpacesOnlyByte.value == b' ' - assert resp.SpacesOnlyUnicode == u' ' - assert resp.SpacesBeforeByte.value == b' Text' - assert resp.SpacesBeforeUnicode == u' Text' - assert resp.SpacesAfterByte.value == b'Text ' - assert resp.SpacesAfterUnicode == u'Text ' - assert resp.SpacesBeforeAndAfterByte.value == b' Text ' - assert resp.SpacesBeforeAndAfterUnicode == u' Text ' + assert resp['EmptyByte'].value == b'' + assert resp['EmptyUnicode'] == u'' + assert resp['SpacesOnlyByte'].value == b' ' + assert resp['SpacesOnlyUnicode'] == u' ' + assert resp['SpacesBeforeByte'].value == b' Text' + assert resp['SpacesBeforeUnicode'] == u' Text' + assert resp['SpacesAfterByte'].value == b'Text ' + assert resp['SpacesAfterUnicode'] == u'Text ' + assert resp['SpacesBeforeAndAfterByte'].value == b' Text ' + assert resp['SpacesBeforeAndAfterUnicode'] == u' Text ' finally: self._tear_down() self.sleep(SLEEP_DELAY) @@ -1431,7 +1439,7 @@ def test_binary_property_value(self, tables_cosmos_account_name, tables_primary_ # Assert assert resp is not None - assert resp.binary.value == binary_data + assert resp['binary'].value == binary_data finally: self._tear_down() self.sleep(SLEEP_DELAY) @@ -1453,8 +1461,8 @@ def test_timezone(self, tables_cosmos_account_name, tables_primary_cosmos_accoun # Assert assert resp is not None # times are not equal because request is made after - assert resp.date.astimezone(tzutc()) == local_date.astimezone(tzutc()) - assert resp.date.astimezone(local_tz) == local_date + assert resp['date'].astimezone(tzutc()) == local_date.astimezone(tzutc()) + assert resp['date'].astimezone(local_tz) == local_date finally: self._tear_down() self.sleep(SLEEP_DELAY) @@ -1576,16 +1584,16 @@ def test_query_entities_with_filter(self, tables_cosmos_account_name, tables_pri self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) try: entity, _ = self._insert_random_entity() - entity2, _ = self._insert_random_entity(pk="foo" + entity.PartitionKey) - entity3, _ = self._insert_random_entity(pk="bar" + entity.PartitionKey) + entity2, _ = self._insert_random_entity(pk="foo" + entity['PartitionKey']) + entity3, _ = self._insert_random_entity(pk="bar" + entity['PartitionKey']) # Act entities = list(self.table.query_entities( - "PartitionKey eq '{}'".format(entity.PartitionKey))) + "PartitionKey eq '{}'".format(entity['PartitionKey']))) # Assert assert len(entities) == 1 - assert entity.PartitionKey == entities[0].PartitionKey + assert entity['PartitionKey'] == entities[0]['PartitionKey'] self._assert_default_entity(entities[0]) finally: self._tear_down() @@ -1671,11 +1679,11 @@ def test_query_entities_with_select(self, tables_cosmos_account_name, tables_pri entities = [] for entity in table.list_entities(select=['age', 'sex']): entities.append(entity) - assert entity.age == 39 - assert entity.sex == 'male' - assert not hasattr(entity, "birthday") - assert not hasattr(entity, "married") - assert not hasattr(entity, "deceased") + assert entities[0]['age'] == 39 + assert entities[0]['sex'] == 'male' + assert not "birthday" in entities[0] + assert not "married" in entities[0] + assert not "deceased" in entities[0] # Assert assert len(entities) == 2 @@ -1769,15 +1777,15 @@ def test_datetime_str_passthrough(self, tables_cosmos_account_name, tables_prima self.table.create_entity(entity) received = self.table.get_entity(partition, row) assert isinstance(received['datetime1'], datetime) - assert received.datetime1.tables_service_value == dotnet_timestamp + assert received['datetime1'].tables_service_value == dotnet_timestamp - received['datetime2'] = received.datetime1.replace(year=2020) + received['datetime2'] = received['datetime1'].replace(year=2020) assert received['datetime2'].tables_service_value == "" self.table.update_entity(received, mode=UpdateMode.REPLACE) updated = self.table.get_entity(partition, row) assert isinstance(updated['datetime1'], datetime) assert isinstance(updated['datetime2'], datetime) - assert updated.datetime1.tables_service_value == dotnet_timestamp + assert updated['datetime1'].tables_service_value == dotnet_timestamp finally: self._tear_down() 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 7d3ec78178f2..106ce07d322b 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 @@ -131,8 +131,7 @@ async def _insert_two_opposite_entities(self, pk=None, rk=None): 'other': EntityProperty(40, EdmType.INT32), 'clsid': uuid.UUID('c8da6455-213e-42d9-9b79-3f9149a57833') } - entity = TableEntity(**properties) - await self.table.create_entity(entity) + await self.table.create_entity(properties) return entity1, resp def _create_random_entity_dict(self, pk=None, rk=None): @@ -200,6 +199,8 @@ def _assert_default_entity(self, entity, headers=None): 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): ''' @@ -219,6 +220,8 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None): 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): ''' @@ -240,43 +243,49 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None): 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 hasattr(entity, "married") - assert not hasattr(entity, "deceased") - assert entity.sign == 'aquarius' - assert not hasattr(entity, "optional") - assert not hasattr(entity, "ratio") - assert not hasattr(entity, "evenratio") - assert not hasattr(entity, "large") - assert not hasattr(entity, "Birthday") - assert entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()) - assert not hasattr(entity, "other") - assert not hasattr(entity, "clsid") + 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['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() @@ -304,10 +313,10 @@ async def test_url_encoding_at_symbol(self, tables_cosmos_account_name, tables_p count = 0 async for e in entities: - assert e.PartitionKey == entity[u"PartitionKey"] - assert e.RowKey == entity[u"RowKey"] - assert e.Value == entity[u"Value"] - await self.table.delete_entity(e.PartitionKey, e.RowKey) + assert e['PartitionKey'] == entity[u"PartitionKey"] + assert e['RowKey'] == entity[u"RowKey"] + assert e['Value'] == entity[u"Value"] + await self.table.delete_entity(e['PartitionKey'], e['RowKey']) count += 1 assert count == 1 @@ -612,13 +621,13 @@ async def test_get_entity_full_metadata(self, tables_cosmos_account_name, tables # Act resp = await self.table.get_entity( - entity.PartitionKey, - entity.RowKey, + entity['PartitionKey'], + entity['RowKey'], headers={'accept': 'application/json;odata=fullmetadata'}) # Assert - assert resp.PartitionKey == entity.PartitionKey - assert resp.RowKey == entity.RowKey + assert resp['PartitionKey'] == entity['PartitionKey'] + assert resp['RowKey'] == entity['RowKey'] self._assert_default_entity_json_full_metadata(resp) finally: await self._tear_down() @@ -632,13 +641,13 @@ async def test_get_entity_no_metadata(self, tables_cosmos_account_name, tables_p # Act resp = await self.table.get_entity( - partition_key=entity.PartitionKey, - row_key=entity.RowKey, + partition_key=entity['PartitionKey'], + row_key=entity['RowKey'], headers={'accept': 'application/json;odata=nometadata'}) # Assert - assert resp.PartitionKey == entity.PartitionKey - assert resp.RowKey == entity.RowKey + assert resp['PartitionKey'] == entity['PartitionKey'] + assert resp['RowKey'] == entity['RowKey'] self._assert_default_entity_json_no_metadata(resp) finally: await self._tear_down() @@ -652,8 +661,8 @@ async def test_get_entity_not_existing(self, tables_cosmos_account_name, tables_ # Act with pytest.raises(ResourceNotFoundError): - await self.table.get_entity(partition_key=entity.PartitionKey, - row_key=entity.RowKey) + await self.table.get_entity(partition_key=entity['PartitionKey'], + row_key=entity['RowKey']) # Assert finally: @@ -678,9 +687,9 @@ async def test_get_entity_with_special_doubles(self, tables_cosmos_account_name, row_key=entity['RowKey']) # Assert - assert resp.inf == float('inf') - assert resp.negativeinf == float('-inf') - assert isnan(resp.nan) + assert resp['inf'] == float('inf') + assert resp['negativeinf'] == float('-inf') + assert isnan(resp['nan']) finally: await self._tear_down() @@ -692,15 +701,15 @@ async def test_update_entity(self, tables_cosmos_account_name, tables_primary_co entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.update_entity(mode=UpdateMode.REPLACE, entity=sent_entity) # Assert # assert resp received_entity = await self.table.get_entity( - partition_key=entity.PartitionKey, - row_key=entity.RowKey) + partition_key=entity['PartitionKey'], + row_key=entity['RowKey']) self._assert_updated_entity(received_entity) finally: @@ -730,7 +739,7 @@ async def test_update_entity_with_if_matches(self, tables_cosmos_account_name, t entity, etag = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) await self.table.update_entity( mode=UpdateMode.REPLACE, entity=sent_entity, etag=etag, @@ -738,8 +747,8 @@ async def test_update_entity_with_if_matches(self, tables_cosmos_account_name, t # Assert # assert resp - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_updated_entity(received_entity) finally: await self._tear_down() @@ -753,7 +762,7 @@ async def test_update_entity_with_if_doesnt_match(self, tables_cosmos_account_na entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) with pytest.raises(HttpResponseError): await self.table.update_entity( mode=UpdateMode.REPLACE, @@ -774,12 +783,12 @@ async def test_insert_or_merge_entity_with_existing_entity(self, tables_cosmos_a entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) await self.table.upsert_entity(mode=UpdateMode.MERGE, entity=sent_entity) # Assert - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_merged_entity(received_entity) finally: await self._tear_down() @@ -811,12 +820,12 @@ async def test_insert_or_replace_entity_with_existing_entity(self, tables_cosmos entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.upsert_entity(mode=UpdateMode.REPLACE, entity=sent_entity) # Assert - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_updated_entity(received_entity) finally: await self._tear_down() @@ -846,11 +855,11 @@ async def test_merge_entity(self, tables_cosmos_account_name, tables_primary_cos entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) await self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity) - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_merged_entity(received_entity) finally: await self._tear_down() @@ -879,13 +888,13 @@ async def test_merge_entity_with_if_matches(self, tables_cosmos_account_name, ta entity, etag = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) resp = await self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity, etag=etag, match_condition=MatchConditions.IfNotModified) - received_entity = await self.table.get_entity(entity.PartitionKey, - entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], + entity['RowKey']) self._assert_merged_entity(received_entity) finally: await self._tear_down() @@ -899,7 +908,7 @@ async def test_merge_entity_with_if_doesnt_match(self, tables_cosmos_account_nam entity, _ = await self._insert_random_entity() # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) with pytest.raises(HttpResponseError): await self.table.update_entity(mode=UpdateMode.MERGE, entity=sent_entity, @@ -918,10 +927,10 @@ async def test_delete_entity(self, tables_cosmos_account_name, tables_primary_co entity, _ = await self._insert_random_entity() # Act - await self.table.delete_entity(partition_key=entity.PartitionKey, row_key=entity.RowKey) + await self.table.delete_entity(partition_key=entity['PartitionKey'], row_key=entity['RowKey']) with pytest.raises(ResourceNotFoundError): - await self.table.get_entity(entity.PartitionKey, entity.RowKey) + await self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: await self._tear_down() @@ -948,11 +957,11 @@ async def test_delete_entity_with_if_matches(self, tables_cosmos_account_name, t entity, etag = await self._insert_random_entity() # Act - await self.table.delete_entity(entity.PartitionKey, entity.RowKey, etag=etag, + await self.table.delete_entity(entity['PartitionKey'], entity['RowKey'], etag=etag, match_condition=MatchConditions.IfNotModified) with pytest.raises(ResourceNotFoundError): - await self.table.get_entity(entity.PartitionKey, entity.RowKey) + await self.table.get_entity(entity['PartitionKey'], entity['RowKey']) finally: await self._tear_down() @@ -967,7 +976,7 @@ async def test_delete_entity_with_if_doesnt_match(self, tables_cosmos_account_na # Act with pytest.raises(HttpResponseError): await self.table.delete_entity( - entity.PartitionKey, entity.RowKey, + entity['PartitionKey'], entity['RowKey'], etag=u'W/"datetime\'2012-06-15T22%3A51%3A44.9662825Z\'"', match_condition=MatchConditions.IfNotModified) @@ -997,8 +1006,8 @@ async def test_unicode_property_value(self, tables_cosmos_account_name, tables_p # Assert assert len(entities) == 2 - assert entities[0].Description == u'ꀕ' - assert entities[1].Description == u'ꀕ' + assert entities[0]['Description'] == u'ꀕ' + assert entities[1]['Description'] == u'ꀕ' finally: await self._tear_down() @@ -1039,23 +1048,23 @@ async def test_operations_on_entity_with_partition_key_having_single_quote(self, entity, _ = await self._insert_random_entity(pk=partition_key_with_single_quote, rk=row_key_with_single_quote) # Act - sent_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey) + sent_entity = self._create_updated_entity_dict(entity['PartitionKey'], entity['RowKey']) await self.table.upsert_entity(mode=UpdateMode.REPLACE, entity=sent_entity) # row key here only has 2 quotes - received_entity = await self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) # Act sent_entity['newField'] = 'newFieldValue' await self.table.update_entity(mode=UpdateMode.REPLACE, entity=sent_entity) - received_entity = await self.table.get_entity(entity.PartitionKey, entity.RowKey) + received_entity = await self.table.get_entity(entity['PartitionKey'], entity['RowKey']) self._assert_updated_entity(received_entity) assert received_entity['newField'] == 'newFieldValue' # Act - await self.table.delete_entity(entity.PartitionKey, entity.RowKey) + await self.table.delete_entity(entity['PartitionKey'], entity['RowKey']) finally: await self._tear_down() @@ -1085,16 +1094,16 @@ async def test_empty_and_spaces_property_value(self, tables_cosmos_account_name, # Assert assert resp is not None - assert resp.EmptyByte == '' - assert resp.EmptyUnicode == u'' - assert resp.SpacesOnlyByte == ' ' - assert resp.SpacesOnlyUnicode == u' ' - assert resp.SpacesBeforeByte == ' Text' - assert resp.SpacesBeforeUnicode == u' Text' - assert resp.SpacesAfterByte == 'Text ' - assert resp.SpacesAfterUnicode == u'Text ' - assert resp.SpacesBeforeAndAfterByte == ' Text ' - assert resp.SpacesBeforeAndAfterUnicode == u' Text ' + assert resp['EmptyByte'] == '' + assert resp['EmptyUnicode'] == u'' + assert resp['SpacesOnlyByte'] == ' ' + assert resp['SpacesOnlyUnicode'] == u' ' + assert resp['SpacesBeforeByte'] == ' Text' + assert resp['SpacesBeforeUnicode'] == u' Text' + assert resp['SpacesAfterByte'] == 'Text ' + assert resp['SpacesAfterUnicode'] == u'Text ' + assert resp['SpacesBeforeAndAfterByte'] == ' Text ' + assert resp['SpacesBeforeAndAfterUnicode'] == u' Text ' finally: await self._tear_down() @@ -1131,7 +1140,7 @@ async def test_binary_property_value(self, tables_cosmos_account_name, tables_pr # Assert assert resp is not None - assert resp.binary.value == binary_data + assert resp['binary'].value == binary_data finally: await self._tear_down() @@ -1152,8 +1161,8 @@ async def test_timezone(self, tables_cosmos_account_name, tables_primary_cosmos_ # Assert assert resp is not None # times are not equal because request is made after - # assert resp.date.astimezone(tzutc()) == local_date.astimezone(tzutc()) - # assert resp.date.astimezone(local_tz) == local_date + assert resp['date'].astimezone(tzutc()) == local_date.astimezone(tzutc()) + assert resp['date'].astimezone(local_tz) == local_date finally: await self._tear_down() @@ -1467,18 +1476,18 @@ async def test_query_entities_with_filter(self, tables_cosmos_account_name, tabl await self._set_up(tables_cosmos_account_name, tables_primary_cosmos_account_key) try: entity, _ = await self._insert_random_entity() - entity2, _ = await self._insert_random_entity(pk="foo" + entity.PartitionKey) - entity3, _ = await self._insert_random_entity(pk="bar" + entity.PartitionKey) + entity2, _ = await self._insert_random_entity(pk="foo" + entity['PartitionKey']) + entity3, _ = await self._insert_random_entity(pk="bar" + entity['PartitionKey']) # Act entities = [] async for t in self.table.query_entities( - "PartitionKey eq '{}'".format(entity.PartitionKey)): + "PartitionKey eq '{}'".format(entity['PartitionKey'])): entities.append(t) # Assert assert len(entities) == 1 - assert entity.PartitionKey == entities[0].PartitionKey + assert entity['PartitionKey'] == entities[0]['PartitionKey'] self._assert_default_entity(entities[0]) finally: await self._tear_down() @@ -1608,11 +1617,11 @@ async def test_query_entities_with_select(self, tables_cosmos_account_name, tabl entities = [] async for entity in table.list_entities(select=['age', 'sex']): entities.append(entity) - assert entity.age == 39 - assert entity.sex == 'male' - assert not hasattr(entity, "birthday") - assert not hasattr(entity, "married") - assert not hasattr(entity, "deceased") + assert entities[0]['age'] == 39 + assert entities[0]['sex'] == 'male' + assert not "birthday" in entities[0] + assert not "married" in entities[0] + assert not "deceased" in entities[0] # Assert assert len(entities) == 2 @@ -1705,15 +1714,15 @@ async def test_datetime_str_passthrough(self, tables_cosmos_account_name, tables await self.table.create_entity(entity) received = await self.table.get_entity(partition, row) assert isinstance(received['datetime1'], datetime) - assert received.datetime1.tables_service_value == dotnet_timestamp + assert received['datetime1'].tables_service_value == dotnet_timestamp - received['datetime2'] = received.datetime1.replace(year=2020) + received['datetime2'] = received['datetime1'].replace(year=2020) assert received['datetime2'].tables_service_value == "" await self.table.update_entity(received, mode=UpdateMode.REPLACE) updated = await self.table.get_entity(partition, row) assert isinstance(updated['datetime1'], datetime) assert isinstance(updated['datetime2'], datetime) - assert updated.datetime1.tables_service_value == dotnet_timestamp + assert updated['datetime1'].tables_service_value == dotnet_timestamp finally: await self._tear_down() \ No newline at end of file