def make_celery(): from cmdb import create_app capp = create_app() celery = Celery(__name__, broker=capp.config['CELERY_BROKER_URL']) celery.conf.update(capp.config) TaskBase = celery.Task celery.flask = capp class ContextTask(TaskBase): abstract = True def __call__(self, *args, **kwargs): if has_app_context(): return TaskBase.__call__(self, *args, **kwargs) else: with capp.app_context(): return TaskBase.__call__(self, *args, **kwargs) celery.Task = ContextTask return celery
# coding=utf-8 from cmdb import create_app, celery from cmdb.config import BaseConfig app = create_app(BaseConfig.CMDB_CONFIG or 'default') app.app_context().push()
def setUp(self): self.app = cmdb.create_app() self.app.testing = True self.client = self.app.test_client() self.app.config['BASIC_AUTH_FORCE'] = False # disable basic auth
# -*- coding: utf-8 -*- from __future__ import unicode_literals from flask_sqlalchemy import SQLAlchemy from flask_script import Manager, Server from flask_migrate import MigrateCommand, Migrate from cmdb import create_app app = create_app() # db = SQLAlchemy(app) with app.app_context(): from cmdb.core.db import Base migrate = Migrate(app, Base) manager = Manager(app) manager.add_command( 'server', Server(host=app.config['LISTEN'], port=app.config['LISTEN_ON'], use_reloader=True)) manager.add_command('db', MigrateCommand) @manager.command def test(): """Run the tests.""" import subprocess code = subprocess.call( ['py.test', 'tests', '--cov', 'zaih-ed', '--verbose']) return code