class InsertAndDeleteIndexesCase(unittest.TestCase): def setUp(self): datastore_batch = appscale_datastore_batch.DatastoreFactory.getDatastore( DB) self.app_datastore = DatastoreDistributed(datastore_batch) self.entities = [] prev = None for ii in range(0, 3): entity = datastore.Entity("TestKind", _app="test", name=str(ii), parent=prev, namespace='d') prev = entity # have properties with different values bye same property names entity.update({'aaa': "1111_" + str(ii), 'bbb': "2222"}) self.entities.append(entity.ToPb()) self.keys = ['test/d/TestKind/aaa/1111_1\x00/TestKind:0!TestKind:1!'] def runTest(self): self.app_datastore.InsertIndexEntries(self.entities) ret = datastore_batch.batch_get_entity(ASC_PROPERTY_TABLE, self.keys, PROPERTY_SCHEMA) assert 'test/d/TestKind:0!TestKind:1!' in \ ret['test/d/TestKind/aaa/1111_1\x00/TestKind:0!TestKind:1!']['reference'] self.app_datastore.DeleteIndexEntries(self.entities) ret = datastore_batch.batch_get_entity(ASC_PROPERTY_TABLE, self.keys, PROPERTY_SCHEMA) assert 'reference' not in \ ret['test/d/TestKind/aaa/1111_1\x00/TestKind:0!TestKind:1!'] def tearDown(self): pass
class InsertGroupEntityIndexCase(unittest.TestCase): def setUp(self): datastore_batch = appscale_datastore_batch.DatastoreFactory.getDatastore( DB) self.app_datastore = DatastoreDistributed(datastore_batch) self.entities = [] prev = None for ii in range(0, 3): entity = datastore.Entity("TestKind", _app="test", name=str(ii), parent=prev, namespace='c') prev = entity # have properties with different values bye same property names entity.update({'aaa': "1111_" + str(ii), 'bbb': "2222"}) self.entities.append(entity.ToPb()) self.keys = [ 'test/c/TestKind/aaa/1111_0\x00/TestKind:0!', 'test/c/TestKind/bbb/2222\x00/TestKind:0!', 'test/c/TestKind/aaa/1111_1\x00/TestKind:0!TestKind:1!', 'test/c/TestKind/bbb/2222\x00/TestKind:0!TestKind:1!', 'test/c/TestKind/aaa/1111_2\x00/TestKind:0!TestKind:1!TestKind:2!', 'test/c/TestKind/bbb/2222\x00/TestKind:0!TestKind:1!TestKind:2!' ] self.rkeys = [ 'test/c/TestKind/aaa/\xce\xce\xce\xce\xa0\xcf\xff/TestKind:0!', 'test/c/TestKind/bbb/\xcd\xcd\xcd\xcd\xff/TestKind:0!', 'test/c/TestKind/aaa/\xce\xce\xce\xce\xa0\xce\xff/TestKind:0!TestKind:1!', 'test/c/TestKind/bbb/\xcd\xcd\xcd\xcd\xff/TestKind:0!TestKind:1!', 'test/c/TestKind/aaa/\xce\xce\xce\xce\xa0\xcd\xff/TestKind:0!TestKind:1!TestKind:2!', 'test/c/TestKind/bbb/\xcd\xcd\xcd\xcd\xff/TestKind:0!TestKind:1!TestKind:2!' ] def runTest(self): self.app_datastore.InsertIndexEntries(self.entities) datastore_batch = appscale_datastore_batch.DatastoreFactory.getDatastore( DB) # Verify an entity has been stored ret = datastore_batch.batch_get_entity(ASC_PROPERTY_TABLE, self.keys, PROPERTY_SCHEMA) assert 'test/c/TestKind:0!TestKind:1!' in \ ret['test/c/TestKind/aaa/1111_1\x00/TestKind:0!TestKind:1!']['reference'] def tearDown(self): datastore_batch = appscale_datastore_batch.DatastoreFactory.getDatastore( DB) ret = datastore_batch.batch_delete(ASC_PROPERTY_TABLE, self.keys, PROPERTY_SCHEMA) ret = datastore_batch.batch_delete(DSC_PROPERTY_TABLE, self.rkeys, PROPERTY_SCHEMA) # Verify an entity has been deleted ret = datastore_batch.batch_get_entity(ASC_PROPERTY_TABLE, self.keys, PROPERTY_SCHEMA) assert 'reference' not in \ ret['test/c/TestKind/aaa/1111_1\x00/TestKind:0!TestKind:1!']