def setUp(self): """Prepare model test fixture.""" try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def get(cls, text): """ Get an object from the cache or the database using the key `text`. If the object doesn't exists, it'll be stores in the cache and in the database. """ cls.check(text) if cls.fk_cache.has_key(text): return cls.fk_cache[text] query = DBSession.query(cls) query._autoflush = False try: data = query.filter(cls.text == text).one() except NoResultFound: data = cls() data.text = text DBSession.add(data) cls.fk_cache[text] = data return data