Example #1
0
 def delete(cls, *keys):
     """Deletes this Model from the datastore and cache"""
     todelete = []
     namespace, kind, member = Schema.Get(cls)
     for key in keys:
         assert isinstance(key, str)
         todelete.append(Key(namespace, kind, key)) 
     Lisa.delete(*todelete)
Example #2
0
 def read(cls, key, mode = FetchMode.All):
     """Retreives objects from the datastore """
     assert isinstance(key, (basestring, Key))
     namespace, kind, member = Schema.Get(cls)
     if isinstance(key, Key):
         assert kind == key.kind, "Mismatched Model, reading a %s with %s" % (kind, key.kind)
         return Lisa.read(key, mode)
     else: 
         key = Key(namespace, kind, key)
         return Lisa.read(key, mode)
Example #3
0
 def save(self):
     """Stores this object in the datastore and in the cache"""
     # Makes sure that all required properties are available before persistence.
     for name, prop in fields(self, Property).items():
         if hasattr(prop, 'required') and prop.required:
             value = getattr(self, name)
             if prop.empty(value):
                 raise BadValueError("Property: %s is required" % name)
     
     Lisa.save(self)
     self.differ.commit()
Example #4
0
 def deconvert(self, value):
     '''Pulls the referenced model from the datastore, and sets it'''
     key = eval(value) #Change the @value back to a key.
     if key:
         found = Lisa.read(key, FetchMode.All)
         return found
     else: return None
Example #5
0
class BaseTestCase(TestCase):
    '''Base Class for all tests'''
    def setUp(self):
        '''Create the Lisa instance, we all know and love'''
        self.db = Lisa()
        self.connection = cql.connect("localhost", 9160).cursor()
          
    def tearDown(self):
        '''Release resources that have been allocated'''
        try:
            self.db.clear()
            Schema.Clear()
            self.connection.execute("DROP KEYSPACE %s" % Settings.keyspace())
            self.connection.close()
        except Exception as e:
            print e
Example #6
0
 def setUp(self):
     '''Create the Lisa instance, we all know and love'''
     self.db = Lisa()
     self.connection = cql.connect("localhost", 9160).cursor()