

def test_composite_ancestor_index(self):
    ci = datastore_pb.CompositeIndex()
    ci.set_app_id(datastore_types.ResolveAppId(None))
    ci.set_id(0)
    ci.set_state(ci.WRITE_ONLY)
    index = ci.mutable_definition()
    index.set_ancestor(1)
    index.set_entity_type('Yar')
    prop = index.add_property()
    prop.set_name('this')
    prop.set_direction(prop.ASCENDING)
    prop = index.add_property()
    prop.set_name('that')
    prop.set_direction(prop.DESCENDING)
    stub = apiproxy_stub_map.apiproxy.GetStub('datastore_v3')
    stub.CreateIndex(ci)
    self.assertEquals(1, len(datastore.GetIndexes()))
    entity = datastore.Entity('Yar', id=123, _app=self.app_id)
    entity['this'] = 4
    entity['that'] = 4
    self.assertEquals(7, datastore_viewer.DatastoreRequestHandler._get_write_ops(entity))
    parent_entity = datastore.Entity('parent', id=123, _app=self.app_id)
    entity = datastore.Entity('Yar', parent=parent_entity.key(), id=123, _app=self.app_id)
    entity['this'] = 4
    entity['that'] = 4
    self.assertEquals(8, datastore_viewer.DatastoreRequestHandler._get_write_ops(entity))
    grandparent_entity = datastore.Entity('grandparent', id=123, _app=self.app_id)
    parent_entity = datastore.Entity('parent', parent=grandparent_entity.key(), id=123, _app=self.app_id)
    entity = datastore.Entity('Yar', parent=parent_entity.key(), id=123, _app=self.app_id)
    entity['this'] = 4
    entity['that'] = 4
    self.assertEquals(9, datastore_viewer.DatastoreRequestHandler._get_write_ops(entity))
    entity['this'] = [None, None, None]
    self.assertEquals(19, datastore_viewer.DatastoreRequestHandler._get_write_ops(entity))
    entity['that'] = [None, None]
    self.assertEquals(30, datastore_viewer.DatastoreRequestHandler._get_write_ops(entity))

dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/tools/devappserver2/admin/datastore_viewer_test.py GetWriteOpsTest.test_composite_ancestor_index/original