Exemple #1
0
class GetCase(unittest.TestCase):
    def setUp(self):
        datastore_batch = appscale_datastore_batch.DatastoreFactory.getDatastore(
            DB)
        self.app_datastore = DatastoreDistributed(datastore_batch)
        self.entities = []
        self.keys = []
        prev = None
        for ii in range(0, 3):
            entity = datastore.Entity("TestKind",
                                      _app="test",
                                      name=str(ii),
                                      parent=prev,
                                      namespace='e')
            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 = [e.key() for e in self.entities]
        self.app_datastore.PutEntities(self.entities)

    def runTest(self):
        results, keys = self.app_datastore.FetchKeys(self.keys)
        self.app_datastore.DeleteEntities(self.keys)
        results, keys = self.app_datastore.FetchKeys(self.keys)
        for ii in results:
            if 'entity' in ii: raise

    def tearDown(self):
        pass
Exemple #2
0
class KindQueryCase(unittest.TestCase):
    def setUp(self):
        datastore_batch = appscale_datastore_batch.DatastoreFactory.getDatastore(
            DB)
        self.app_datastore = DatastoreDistributed(datastore_batch)
        self.entities = []
        self.keys = []
        self.entities2 = []
        self.keys2 = []

        prev = None
        for ii in range(0, 3):
            entity = datastore.Entity(kind="ATestKind",
                                      _app="test",
                                      name=str(ii),
                                      parent=prev,
                                      namespace='f')
            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 = [e.key() for e in self.entities]
        self.app_datastore.PutEntities(self.entities)

        prev = None
        for ii in range(0, 3):
            entity = datastore.Entity(kind="BTestKind",
                                      _app="test",
                                      name=str(ii),
                                      parent=prev,
                                      namespace='f')
            prev = entity
            # have properties with different values bye same property names
            entity.update({'aaa': "1111_" + str(ii), 'bbb': "2222"})
            self.entities2.append(entity.ToPb())
        self.keys2 = [e.key() for e in self.entities2]
        self.app_datastore.PutEntities(self.entities2)

    def runTest(self):
        def testKind(kind):
            q = datastore.Query(kind=kind, _app="test", namespace='f')
            q = q._ToPb()

            result = self.app_datastore.KindQuery(q, [], [])

            for ii in result:
                item = entity_pb.EntityProto(ii)
                for ii in item.entity_group().element_list():
                    assert kind == ii.type()

        testKind("ATestKind")
        testKind("BTestKind")

        q = datastore.Query(kind="ATestKind", _app="test", namespace='f')
        q = q._ToPb()
        q.set_limit(1)

        result = self.app_datastore.KindQuery(q, [], [])
        last_item = entity_pb.EntityProto(result[0])
        last_item = last_item.key()

        q = datastore.Query(kind="ATestKind", _app="test", namespace='f')
        q = q._ToPb()
        f = q.add_filter()
        #entity_pb.Property(last_item)
        #filt = datastore_query.PropertyFilter(">", last_item)
        #print filt

    def tearDown(self):
        self.app_datastore.DeleteEntities(self.keys)
        self.app_datastore.DeleteEntities(self.keys2)
Exemple #3
0
class PutCase(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='e')
            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.entities2 = []
        prev = None
        for ii in range(0, 3):
            entity = datastore.Entity("TestKind",
                                      _app="test",
                                      name=str(ii),
                                      parent=prev,
                                      namespace='e')
            prev = entity
            # have properties with different values bye same property names
            entity.update({'aaa': "x111_" + str(ii), 'bbb': "x222"})
            self.entities2.append(entity.ToPb())

        tuples = sorted(
            (self.app_datastore.GetTablePrefix(x), x) for x in self.entities)

        # keys should be the same for entities and entities2
        self.keys = self.app_datastore.GetIndexKVFromTuple(tuples,
                                                           reverse=False)
        self.keys = [x[0] for x in self.keys]
        tuples = sorted(
            (self.app_datastore.GetTablePrefix(x), x) for x in self.entities2)

        # keys should be the same for entities and entities2
        self.keys2 = self.app_datastore.GetIndexKVFromTuple(tuples,
                                                            reverse=False)
        self.keys2 = [x[0] for x in self.keys2]

    def runTest(self):
        self.app_datastore.PutEntities(self.entities)
        ret = datastore_batch.batch_get_entity(ASC_PROPERTY_TABLE, self.keys,
                                               PROPERTY_SCHEMA)
        assert 'test/e/TestKind:0!TestKind:1' in \
             ret['test/e/TestKind/aaa/1111_1\x00/TestKind:0!TestKind:1!']['reference']
        # overwrite test
        self.app_datastore.PutEntities(self.entities2)
        ret = datastore_batch.batch_get_entity(ASC_PROPERTY_TABLE, self.keys2,
                                               PROPERTY_SCHEMA)
        assert 'test/e/TestKind:0!TestKind:1' in \
             ret['test/e/TestKind/aaa/x111_1\x00/TestKind:0!TestKind:1!']['reference']

    def tearDown(self):
        keys = [e.key() for e in self.entities]
        self.app_datastore.DeleteEntities(keys)