Example #1
0
def flask_app():
    """ Create base flask application for testing. """
    app = create_app('testing')
    app.app_context().push()
    DB.drop_all(app=app)
    DB.create_all(app=app)
    return app
def configure_extensions(app):
    """
    This function configures all extensions used in app.
    """

    DB.init_app(app)

    with app.app_context():
        DB.create_all()
        DB.session.commit()
Example #3
0
def flask_app_user_in_db():
    """ Create flask application for testing with a user in the DB. """
    app = create_app('testing')
    DB.drop_all(app=app)
    DB.create_all(app=app)
    app.app_context().push()

    user_id = {'user_id': "1"}

    schema = UserSchema().load(user_id)
    new_user = UserModel(**schema.data)
    DB.session.begin()
    DB.session.add(new_user)
    DB.session.commit()
    return app
Example #4
0
def create_app(config_name='development'):
    """ Create the application with the relevant configuration. """
    app = Flask(__name__)
    app.config.from_object(CONFIG_MAPPER[config_name])
    app.wsgi_app = ProxyFix(app.wsgi_app)

    from . import extensions
    from . import modules
    for content in (
            extensions,
            modules,
    ):
        content.init_app(app)

    DB.create_all(app=app)

    return app
Example #5
0
def db_init(config):
    """Creation of database"""

    if os.path.isfile(config.DB_FILE):
        print('[WARNING] File [{}] already exists.'.format(config.DB_FILE))
        sys.exit(0)

    if not os.path.exists(os.path.dirname(config.DB_FILE)):
        os.makedirs(os.path.dirname(config.DB_FILE))

    app = create_app(config_object=config)

    with app.app_context():
        DB.init_app(app)
        DB.create_all()
        DB.session.commit()

    print('[SUCCESS] File [{}] created.'.format(config.DB_FILE))
    sys.exit(0)
Example #6
0
def db_init(config):
    """Creation of database"""

    if os.path.isfile(config.DB_FILE):
        print('[WARNING] File [{}] already exists.'.format(config.DB_FILE))
        sys.exit(0)

    if not os.path.exists(os.path.dirname(config.DB_FILE)):
        os.makedirs(os.path.dirname(config.DB_FILE))

    app = create_app(config_object=config)

    with app.app_context():
        DB.init_app(app)
        DB.create_all()

        internal = Internal(db_version=config.DB_VERSION,
                            rights_version=0,
                            updated_at=datetime.now())

        DB.session.add(internal)
        DB.session.commit()

    print('[SUCCESS] File [{}] created.'.format(config.DB_FILE))