Ejemplo n.º 1
0
def init_dbs(app):
    """
    Initializes database configurations if extensions
    are included
    """
    if 'Flask-Philo-SQLAlchemy' in app.config['FLASK_PHILO_EXTENSIONS']:
        from flask_philo_sqlalchemy.connection import create_pool
        with app.app_context():
            create_pool()
Ejemplo n.º 2
0
 def __init__(self):
     self.app = current_app._get_current_object()
     if 'FLASK_PHILO_SQLALCHEMY' not in self.app.config:
         raise ConfigurationError(
             'Not configuration found for Flask_Philo_SQLAlchemy')
     ctx = _app_ctx_stack.top
     if ctx is not None:
         if not hasattr(ctx, 'sqlalchemy_pool'):
             ctx.sqlalchemy_pool = create_pool()
     self.sqlalchemy_pool = ctx.sqlalchemy_pool
Ejemplo n.º 3
0
def cleandb(pool=None):
    from flask_philo_sqlalchemy.schema import Base  # noqa
    from flask_philo_sqlalchemy.orm import BaseModel  # noqa
    from flask_philo_sqlalchemy.connection import create_pool

    if pool is None:
        pool = create_pool()

    for t in reversed(BaseModel.metadata.sorted_tables):
        sql = 'delete from {} cascade;'.format(t.name)
        for conn_name, conn in pool.connections.items():
            conn.session.execute(sql)
            conn.session.commit()
Ejemplo n.º 4
0
def syncdb(pool=None):
    """
    Create tables if they don't exist
    """
    from flask_philo_sqlalchemy.schema import Base  # noqa
    from flask_philo_sqlalchemy.orm import BaseModel  # noqa
    from flask_philo_sqlalchemy.connection import create_pool

    if pool is None:
        pool = create_pool()

    for conn_name, conn in pool.connections.items():
        Base.metadata.create_all(conn.engine)
Ejemplo n.º 5
0
    def test_postgresql_connection(self):
        """
        checks if connection is open
        """
        config = {}
        # Creates a Flask-Philo_Core with no postgresql config
        config['FLASK_PHILO_SQLALCHEMY'] = {
            'DEFAULT': 'postgresql://*****:*****@pgdb:5432/ds_test',
        }

        app = BaseTestFactory.create_test_app(config=config)
        with app.app_context():
            pool = create_pool()
            result = pool.connections['DEFAULT'].session.execute('SELECT 19;')
            assert result.fetchone()[0] == 19
            pool.connections['DEFAULT'].session.close()
Ejemplo n.º 6
0
 def pool(self):
     if self._pool is None:
         self._pool = create_pool()
     return self._pool
Ejemplo n.º 7
0
 def setup(self):
     super(SQLAlchemyTestCase, self).setup()
     with self.app.app_context():
         self.pool = create_pool()
         syncdb(pool=self.pool)