Beispiel #1
0
def create_app(config_yaml=None):
    """Default application factory.

    Default usage:
        app = create_app()

    Usage with config file:
        app = create_app('/path/to/config.yml')

    If config_file is not provided, will look for default
    config expected at '<proj_root>/config/config.yml'.
    Returns Flask app object.
    Raises EnvironmentError if config_file cannot be found.
    """

    setup = SetupConfig(config_yaml=config_yaml)

    # start app setup
    app = Flask(__name__, template_folder=setup.TEMPLATES)
    app.config['SETUP'] = deepcopy(setup)
    app.config['SECRET_KEY'] = deepcopy(setup.SECRET_KEY)

    set_app_mode(app)

    # setup csrf
    csrf.init_app(app)

    # setup db
    init_db(app, db)

    # register views
    init_views(app)

    return app
Beispiel #2
0
def create_app():
    app = Flask(__name__, static_folder='static')
    configure_app(app)

    db.init_app(app)

    with app.app_context():
        db.init_db()
        from project import routes  # noqa: F401

    return app
def app():
    db_fd, db_path = tempfile.mkstemp()

    app = create_app({
        'TESTING': True,
        'DATABASE': db_path,
    })

    with app.app_context():
        init_db()

    yield app

    os.close(db_fd)
    os.unlink(db_path)
def app():
    """Create and configure a new app instance for each test."""
    # create a temporary file to isolate the database for each test
    db_fd, db_path = tempfile.mkstemp()
    # create the app with common test config
    app = create_app({"TESTING": True, "DATABASE": db_path})

    # create the database and load test data
    with app.app_context():
        init_db()
        get_db().executescript(_data_sql)

    yield app

    # close and remove the temporary database
    os.close(db_fd)
    os.unlink(db_path)
Beispiel #5
0
def create_app(config_yaml=None):
    """Default application factory.

    Default usage:
        app = create_app()

    Usage with config file:
        app = create_app('/path/to/config.yml')

    If config_file is not provided, will look for default
    config expected at '<proj_root>/config/config.yml'.
    Returns Flask app object.
    Raises EnvironmentError if config_file cannot be found.
    """

    setup = SetupConfig(config_yaml=config_yaml)

    # start app setup
    app = Flask(__name__,
                template_folder=setup.TEMPLATES,
                static_folder=setup.STATIC_FILES)
    CORS(app)
    app.config['SETUP'] = deepcopy(setup)
    app.config['SECRET_KEY'] = deepcopy(setup.SECRET_KEY)

    set_app_mode(app)
    login_manager.init_app(app)
    # setup csrf
    if not app.testing:
        csrf.init_app(app)

    # setup db
    init_db(app, db)

    # todo: remove these two lines and replace with migrate
    #db.drop_all()
    #db.create_all()

    # register routes
    init_routes(app)

    return app