def testDatastoreTypes(self):
        """Puts and gets different basic datastore types."""

        entity = datastore.Entity('TestKind')

        entity.update({
            'rating':
            datastore_types.Rating(1),
            'category':
            datastore_types.Category('bugs'),
            'key':
            datastore_types.Key.from_path('foo', 'bar'),
            'user':
            users.User('*****@*****.**'),
            'text':
            datastore_types.Text('some text'),
            'blob':
            datastore_types.Blob('data'),
            'bytestring':
            datastore_types.ByteString('data'),
            'im':
            datastore_types.IM('http://example.com/', 'Larry97'),
            'geopt':
            datastore_types.GeoPt(1.1234, -1.1234),
            'email':
            datastore_types.Email('*****@*****.**'),
            'blobkey':
            datastore_types.BlobKey('27f5a7'),
        })

        datastore.Put(entity)
        e = datastore.Get(entity)
        datastore.Delete(entity)
Beispiel #2
0
 def __create_value_for_mongo_value(self, mongo_value):
     if isinstance(mongo_value, Binary):
         return datastore_types.Blob(str(mongo_value))
     if isinstance(mongo_value, types.DictType):
         if mongo_value['class'] == 'rating':
             return datastore_types.Rating(int(mongo_value["rating"]))
         if mongo_value['class'] == 'category':
             return datastore_types.Category(mongo_value["category"])
         if mongo_value['class'] == 'key':
             return self.__key_for_id(mongo_value['path'])
         if mongo_value['class'] == 'list':
             return [
                 self.__create_value_for_mongo_value(v)
                 for v in mongo_value['list']
             ]
         if mongo_value['class'] == 'user':
             return users.User(email=mongo_value["email"])
         if mongo_value['class'] == 'text':
             return datastore_types.Text(mongo_value['string'])
         if mongo_value['class'] == 'im':
             return datastore_types.IM(mongo_value['protocol'],
                                       mongo_value['address'])
         if mongo_value['class'] == 'geopt':
             return datastore_types.GeoPt(mongo_value['lat'],
                                          mongo_value['lon'])
         if mongo_value['class'] == 'email':
             return datastore_types.Email(mongo_value['value'])
         if mongo_value['class'] == 'bytes':
             return datastore_types.ByteString(mongo_value['value'])
         if mongo_value['class'] == 'blobkey':
             return datastore_types.BlobKey(mongo_value['value'])
     return mongo_value
Beispiel #3
0
 def __init__(self):
     bulkloader.Loader.__init__(
         self, 'User',
         [('email', lambda e: datastore_types.Email(e.lower())),
          ('first_name', str), ('last_name', str), ('password', str),
          ('is_active', bool), ('is_superuser', bool),
          ('date_joined',
           lambda x: datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S')),
          ('roles', str.split)])
 def parse(self, value):
     return datastore_types.Email(value)