Exemplo n.º 1
0
class Test_persistent( object ):
  def setUp( self ):
    self.object_id = "17"
    self.obj = Persistent( self.object_id )
    self.delta = timedelta( seconds = 1 )

  def test_create( self ):
    assert self.obj.object_id == self.object_id
    assert datetime.now( tz = utc ) - self.obj.revision < self.delta

  def test_update_revision( self ):
    previous_revision = self.obj.revision
    self.obj.update_revision()
    assert self.obj.revision > previous_revision
    assert datetime.now( tz = utc ) - self.obj.revision < self.delta

    previous_revision = self.obj.revision
    self.obj.update_revision()
    assert self.obj.revision > previous_revision
    assert datetime.now( tz = utc ) - self.obj.revision < self.delta

  def test_to_dict( self ):
    d = self.obj.to_dict()

    assert d.get( "object_id" ) == self.object_id
    assert d.get( "revision" ) == self.obj.revision
Exemplo n.º 2
0
class Test_persistent(object):
    def setUp(self):
        self.object_id = "17"
        self.obj = Persistent(self.object_id)
        self.delta = timedelta(seconds=1)

    def test_create(self):
        assert self.obj.object_id == self.object_id
        assert datetime.now(tz=utc) - self.obj.revision < self.delta

    def test_update_revision(self):
        previous_revision = self.obj.revision
        self.obj.update_revision()
        assert self.obj.revision > previous_revision
        assert datetime.now(tz=utc) - self.obj.revision < self.delta

        previous_revision = self.obj.revision
        self.obj.update_revision()
        assert self.obj.revision > previous_revision
        assert datetime.now(tz=utc) - self.obj.revision < self.delta

    def test_to_dict(self):
        d = self.obj.to_dict()

        assert d.get("object_id") == self.object_id
        assert d.get("revision") == self.obj.revision
Exemplo n.º 3
0
  def load( self, Object_type, object_id, revision = None ):
    """
    Load the object corresponding to the given object id from the database and return it, or None if
    the object_id is unknown. If a revision is provided, a specific revision of the object will be
    loaded.

    @type Object_type: type
    @param Object_type: class of the object to load 
    @type object_id: unicode
    @param object_id: id of the object to load
    @type revision: int or NoneType
    @param revision: revision of the object to load (optional)
    @rtype: Object_type or NoneType
    @return: loaded object, or None if no match
    """
    if revision or Object_type in self.CLASSES_NOT_TO_CACHE:
      cache = None
    else:
      cache = self.__get_cache_connection()

    if cache: # don't bother caching old revisions
      obj = cache.get( Persistent.make_cache_key( Object_type, object_id ) )
      if obj:
        return obj

    obj = self.select_one( Object_type, Object_type.sql_load( object_id, revision ) )
    if obj and cache:
      cache.set( obj.cache_key, obj )

    return obj
Exemplo n.º 4
0
 def setUp(self):
     self.object_id = "17"
     self.obj = Persistent(self.object_id)
     self.delta = timedelta(seconds=1)
Exemplo n.º 5
0
 def setUp(self):
     self.object_id = "17"
     self.revision = datetime.now(tz=utc) - timedelta(hours=24)
     self.obj = Persistent(self.object_id, self.revision)
     self.delta = timedelta(seconds=1)
Exemplo n.º 6
0
 def __init__(self, object_id, revision=None, value=None, value2=None):
     Persistent.__init__(self, object_id, revision)
     self.__value = value
     self.__value2 = value2
Exemplo n.º 7
0
  def uncache_many( self, Object_type, obj_ids ):
    cache = self.__get_cache_connection()
    if not cache: return

    for obj_id in obj_ids:
      cache.delete( Persistent.make_cache_key( Object_type, obj_id ) )
Exemplo n.º 8
0
 def setUp( self ):
   self.object_id = "17"
   self.obj = Persistent( self.object_id )
   self.delta = timedelta( seconds = 1 )
Exemplo n.º 9
0
 def setUp( self ):
   self.object_id = "17"
   self.revision = datetime.now( tz = utc ) - timedelta( hours = 24 )
   self.obj = Persistent( self.object_id, self.revision )
   self.delta = timedelta( seconds = 1 )
Exemplo n.º 10
0
 def __init__(self, object_id, revision=None, value=None, value2=None):
     Persistent.__init__(self, object_id, revision)
     self.__value = value
     self.__value2 = value2