def app(): """Create application for the tests.""" _app = create_app("tests.settings") ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def app(): db_fd, db_path = tempfile.mkstemp() app = create_app({ 'TESTING': True, 'SQLALCHEMY_DATABASE_URI': 'sqlite:///'+db_path, }) with app.app_context(): init_db(app) yield app os.close(db_fd) os.unlink(db_path)
def create_celery_app(app=None): CONFIG = DevConfig if get_debug_flag() else ProdConfig app = app or create_app(CONFIG) celery = Celery(__name__, broker=app.config['CELERY_BROKER_URL']) celery.conf.update(app.config) TaskBase = celery.Task class ContextTask(TaskBase): abstract = True def __call__(self, *args, **kwargs): with app.app_context(): return TaskBase.__call__(self, *args, **kwargs) celery.Task = ContextTask return celery
# -*- coding: utf-8 -*- """Create an application instance.""" from apps.app import create_app app = create_app()
# -*- coding: utf-8 -*- """Create an application instance.""" from flask.helpers import get_debug_flag from apps.app import create_app from apps.settings import DevConfig, ProdConfig CONFIG = DevConfig if get_debug_flag() else ProdConfig app = create_app(CONFIG)
def db_context(app): if app is None: app = create_app() with app.app_context(): yield
#!/usr/bin/python from apps.app import create_app from flask import abort app = create_app() if __name__ == '__main__': app.run(debug=True)