def app(request): '''Session-wide test application''' app = create_app(TestingConfig) ctx = app.app_context() ctx.push() def teardown(): ctx.pop() request.addfinalizer(teardown) return app
def create_app(settings_override: Optional[object] = None): """Returns the frontend application instance""" cwd = os.path.dirname(os.path.abspath(__file__)) package_path = [cwd] app = factory.create_app( __name__, package_path, settings_override, ) api.errors = {} api.init_app(app) return app
def create_app(settings_override: Optional[object] = None): """Returns the frontend application instance""" cwd = os.path.dirname(os.path.abspath(__file__)) package_path = [cwd] app = factory.create_app( __name__, package_path, settings_override, ) setup_jinja_env(app) # Register custom error handlers if not app.debug: for e in [500, 404]: app.errorhandler(e)(handle_error) return app
# server/__init__.py import os import logging from flask import jsonify, make_response from server.factory import create_app, create_users, setup_extensions from server.utils.errors import InvalidAPIUsage from server.utils import html_codes from server.blueprints.auth.views import auth_blueprint from server.blueprints.api.views import api_blueprint __version__ = '0.0.2' app_settings = os.getenv('FLASK_CONFIGURATION', 'server.config.DevelopmentConfig') app = create_app(app_settings) setup_extensions(app) logger = logging.getLogger() app.register_blueprint(auth_blueprint, url_prefix='/auth') app.register_blueprint(api_blueprint, url_prefix='/api') @app.errorhandler(Exception) def handle_errors(error): if isinstance(error, InvalidAPIUsage): error_dict = error.to_dict() status_code = error.status_code logger.error(error_dict['message']) else: error_dict = dict() error_dict['message'] = 'Some error occurred. Please try again.'
import os from flask_migrate import MigrateCommand from flask_script import Manager from server.factory import create_app from server.core import db env = os.getenv('FLASK_ENV', 'dev') app = create_app(env.lower()) manager = Manager(app) # migrations manager.add_command('db', MigrateCommand) @manager.command def create_db(): """Creates the db tables.""" db.create_all() @manager.command def drop_db(): """Drops the db tables.""" db.drop_all() @manager.command def create_data(): """Creates sample data."""
# server/__init__.py import os import logging from flask import jsonify, make_response from server.factory import create_app, create_users, setup_extensions from server.utils.errors import InvalidAPIUsage from server.utils import html_codes from server.blueprints.auth.views import auth_blueprint from server.blueprints.api.views import api_blueprint __version__ = '0.0.2' app_settings = os.getenv('FLASK_CONFIGURATION', 'server.config.DevelopmentConfig') app = create_app(app_settings) setup_extensions(app) logger = logging.getLogger() app.register_blueprint(auth_blueprint, url_prefix='/auth') app.register_blueprint(api_blueprint, url_prefix='/api') @app.errorhandler(Exception) def handle_errors(error): if isinstance(error, InvalidAPIUsage): error_dict = error.to_dict() status_code = error.status_code logger.error(error_dict['message']) else: error_dict = dict()
def create_app(self): new_app = create_app('server.config.TestingConfig', app) create_users(new_app) return new_app
from server.factory import create_app from server.database import db app = create_app() app.app_context().push() session = db.session
import os from server.factory import create_app app = create_app(os.getenv('FLASK_ENV', 'dev'))