Esempio n. 1
0
    def testing_scoped_session(self):
        # don't want to have to import this if we are in production, so put import
        # inside of the method
        from flask.ext.webtest import get_scopefunc

        # flask-sqlalchemy creates the session when the class is initialized.  We have to re-create
        # with different session options and override the session attribute with the new session
        db.session = db.create_scoped_session(options={'scopefunc': get_scopefunc()})
Esempio n. 2
0
    def testing_scoped_session(self):
        # don't want to have to import this if we are in production, so put import
        # inside of the method
        from flask.ext.webtest import get_scopefunc

        # flask-sqlalchemy creates the session when the class is initialized.  We have to re-create
        # with different session options and override the session attribute with the new session
        db.session = db.create_scoped_session(
            options={'scopefunc': get_scopefunc()})
Esempio n. 3
0
    def create_database(self, use_migrations=True):
        self.db.session = self.db.create_scoped_session({
            'scopefunc': get_scopefunc(),
        })

        self.db.session.execute('SET storage_engine=InnoDB;')
        if use_migrations:
            try:
                self.db.session.execute('TRUNCATE alembic_version;')
            except sqlalchemy.exc.ProgrammingError:
                self.db.session.rollback()
            config = Config('migrations/alembic.ini', 'alembic')
            alembic_upgrade(config, 'head')
        else:
            self.db.create_all()
Esempio n. 4
0
def make_db(app):
    session_options = {}
    if app.testing:
        session_options['scopefunc'] = get_scopefunc()
    return SQLAlchemy(app, session_options=session_options)
Esempio n. 5
0
 def create_database(self):
     self.db.session = self.db.create_scoped_session({
         'scopefunc': get_scopefunc(),
     })
     self.db.create_all()