Exemplo n.º 1
0
 def to_delete_mutation(key):
     if not helper.is_key_valid(key):
         raise ValueError(
             'Keys to be deleted from the Cloud Datastore must be '
             'complete:\n%s", key')
     mutation = datastore_pb2.Mutation()
     mutation.delete.CopyFrom(key)
     return mutation
Exemplo n.º 2
0
 def to_upsert_mutation(entity):
     if not helper.is_key_valid(entity.key):
         raise ValueError(
             'Entities to be written to the Cloud Datastore must '
             'have complete keys:\n%s' % entity)
     mutation = datastore_pb2.Mutation()
     mutation.upsert.CopyFrom(entity)
     return mutation
Exemplo n.º 3
0
    def test_is_key_valid(self):
        key = entity_pb2.Key()
        # Complete with name, no ancestor
        datastore_helper.add_key_path(key, 'kind', 'name')
        self.assertTrue(helper.is_key_valid(key))

        key = entity_pb2.Key()
        # Complete with id, no ancestor
        datastore_helper.add_key_path(key, 'kind', 12)
        self.assertTrue(helper.is_key_valid(key))

        key = entity_pb2.Key()
        # Incomplete, no ancestor
        datastore_helper.add_key_path(key, 'kind')
        self.assertFalse(helper.is_key_valid(key))

        key = entity_pb2.Key()
        # Complete with name and ancestor
        datastore_helper.add_key_path(key, 'kind', 'name', 'kind2', 'name2')
        self.assertTrue(helper.is_key_valid(key))

        key = entity_pb2.Key()
        # Complete with id and ancestor
        datastore_helper.add_key_path(key, 'kind', 'name', 'kind2', 123)
        self.assertTrue(helper.is_key_valid(key))

        key = entity_pb2.Key()
        # Incomplete with ancestor
        datastore_helper.add_key_path(key, 'kind', 'name', 'kind2')
        self.assertFalse(helper.is_key_valid(key))

        key = entity_pb2.Key()
        self.assertFalse(helper.is_key_valid(key))