本文整理匯總了Python中azure.storage.TableService.begin_batch方法的典型用法代碼示例。如果您正苦於以下問題:Python TableService.begin_batch方法的具體用法?Python TableService.begin_batch怎麽用?Python TableService.begin_batch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類azure.storage.TableService
的用法示例。
在下文中一共展示了TableService.begin_batch方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TableServiceTest
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import begin_batch [as 別名]
#.........這裏部分代碼省略.........
# Act
resp = self.ts.get_entity(
self.table_name, 'MyPartition', '1', 'age,sex')
# Assert
self.assertEqual(resp.age, 39)
self.assertEqual(resp.sex, 'male')
self.assertFalse(hasattr(resp, "birthday"))
self.assertFalse(hasattr(resp, "married"))
self.assertFalse(hasattr(resp, "deceased"))
def test_query_entities(self):
# Arrange
self._create_table_with_default_entities(self.table_name, 2)
# Act
resp = self.ts.query_entities(self.table_name)
# Assert
self.assertEqual(len(resp), 2)
for entity in resp:
self.assertEqual(entity.PartitionKey, 'MyPartition')
self._assert_default_entity(entity)
self.assertEqual(resp[0].RowKey, '1')
self.assertEqual(resp[1].RowKey, '2')
def test_query_entities_large(self):
# Arrange
self._create_table(self.table_name)
total_entities_count = 1000
entities_per_batch = 50
for j in range(total_entities_count // entities_per_batch):
self.ts.begin_batch()
for i in range(entities_per_batch):
entity = Entity()
entity.PartitionKey = 'large'
entity.RowKey = 'batch{0}-item{1}'.format(j, i)
entity.test = EntityProperty('Edm.Boolean', 'true')
entity.test2 = 'hello world;' * 100
entity.test3 = 3
entity.test4 = EntityProperty('Edm.Int64', '1234567890')
entity.test5 = datetime.utcnow()
self.ts.insert_entity(self.table_name, entity)
self.ts.commit_batch()
# Act
start_time = datetime.now()
resp = self.ts.query_entities(self.table_name)
elapsed_time = datetime.now() - start_time
# Assert
print('query_entities took {0} secs.'.format(elapsed_time.total_seconds()))
# azure allocates 5 seconds to execute a query
# if it runs slowly, it will return fewer results and make the test fail
self.assertEqual(len(resp), total_entities_count)
def test_query_entities_with_filter(self):
# Arrange
self._create_table_with_default_entities(self.table_name, 2)
self.ts.insert_entity(
self.table_name,
self._create_default_entity_dict('MyOtherPartition', '3'))
# Act
resp = self.ts.query_entities(
示例2: TableServiceTest
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import begin_batch [as 別名]
#.........這裏部分代碼省略.........
def test_with_filter_chained(self):
called = []
def filter_a(request, next):
called.append('a')
return next(request)
def filter_b(request, next):
called.append('b')
return next(request)
tc = self.tc.with_filter(filter_a).with_filter(filter_b)
tc.create_table(self.table_name)
self.assertEqual(called, ['b', 'a'])
tc.delete_table(self.table_name)
def test_batch_insert(self):
# Arrange
self._create_table(self.table_name)
# Act
entity = Entity()
entity.PartitionKey = '001'
entity.RowKey = 'batch_insert'
entity.test = EntityProperty('Edm.Boolean', 'true')
entity.test2 = 'value'
entity.test3 = 3
entity.test4 = EntityProperty('Edm.Int64', '1234567890')
entity.test5 = datetime.utcnow()
self.tc.begin_batch()
self.tc.insert_entity(self.table_name, entity)
self.tc.commit_batch()
# Assert
result = self.tc.get_entity(self.table_name, '001', 'batch_insert')
self.assertIsNotNone(result)
def test_batch_update(self):
# Arrange
self._create_table(self.table_name)
# Act
entity = Entity()
entity.PartitionKey = '001'
entity.RowKey = 'batch_update'
entity.test = EntityProperty('Edm.Boolean', 'true')
entity.test2 = 'value'
entity.test3 = 3
entity.test4 = EntityProperty('Edm.Int64', '1234567890')
entity.test5 = datetime.utcnow()
self.tc.insert_entity(self.table_name, entity)
entity = self.tc.get_entity(self.table_name, '001', 'batch_update')
self.assertEqual(3, entity.test3)
entity.test2 = 'value1'
self.tc.begin_batch()
self.tc.update_entity(self.table_name, '001', 'batch_update', entity)
self.tc.commit_batch()
entity = self.tc.get_entity(self.table_name, '001', 'batch_update')
# Assert
self.assertEqual('value1', entity.test2)