本文整理汇总了Python中appscale.datastore.datastore_distributed.DatastoreDistributed._extract_entities_from_composite_indexes方法的典型用法代码示例。如果您正苦于以下问题:Python DatastoreDistributed._extract_entities_from_composite_indexes方法的具体用法?Python DatastoreDistributed._extract_entities_from_composite_indexes怎么用?Python DatastoreDistributed._extract_entities_from_composite_indexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appscale.datastore.datastore_distributed.DatastoreDistributed
的用法示例。
在下文中一共展示了DatastoreDistributed._extract_entities_from_composite_indexes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extract_entities_from_composite_indexes
# 需要导入模块: from appscale.datastore.datastore_distributed import DatastoreDistributed [as 别名]
# 或者: from appscale.datastore.datastore_distributed.DatastoreDistributed import _extract_entities_from_composite_indexes [as 别名]
def test_extract_entities_from_composite_indexes(self):
project_id = 'guestbook'
props = ['prop1', 'prop2']
db_batch = flexmock()
db_batch.should_receive('valid_data_version_sync').and_return(True)
transaction_manager = flexmock()
dd = DatastoreDistributed(db_batch, transaction_manager,
self.get_zookeeper())
query = datastore_pb.Query()
for prop_name in props:
query.add_property_name(prop_name)
index = query.add_composite_index()
definition = index.mutable_definition()
for prop_name in props:
prop = definition.add_property()
prop.set_name(prop_name)
entity_id = 1524699263329044
val1 = entity_pb.PropertyValue()
val1.set_int64value(5)
val2 = entity_pb.PropertyValue()
val2.set_stringvalue('test')
index_key = '\x00'.join(
[project_id, 'namespace', 'index1', str(encode_index_pb(val1)),
str(encode_index_pb(val2)), 'Greeting:{}\x01'.format(entity_id)])
index_results = [{index_key: {'reference': 'ignored-ref'}}]
entities = dd._extract_entities_from_composite_indexes(
query, index_results, index)
self.assertEqual(len(entities), 1)
returned_entity = entity_pb.EntityProto(entities[0])
self.assertEqual(returned_entity.property_size(), 2)
self.assertEqual(returned_entity.key().path().element(0).type(), 'Greeting')
self.assertEqual(returned_entity.key().path().element(0).id(), entity_id)
self.assertEqual(returned_entity.property(0).name(), 'prop1')
self.assertEqual(returned_entity.property(0).value().int64value(), 5)
self.assertEqual(returned_entity.property(1).name(), 'prop2')
self.assertEqual(returned_entity.property(1).value().stringvalue(), 'test')