def app(): """An application for the tests.""" _app = create_app('testing') _app.config['SERVER_NAME'] = SITE_URL ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
import os from playhouse.migrate import migrate, CharField, BooleanField, ForeignKeyField from flask_script import Manager from werkzeug.security import generate_password_hash from cronmon import create_app from cronmon.models import User, Permission, Notifier, Business, BusinessNotifier, TaskMonitor, TaskMonitorLog,\ ApiRequestLog, BaseModel, DB, MIGRATOR # 创建app,初始化manager app = create_app(os.getenv('FLASK_CONFIG') or 'default') manager = Manager(app) def create_table(): """初始化数据库表结构,包括所有model,后续调整使用migrate.py""" DB.create_tables([User, Permission, Notifier, Business, BusinessNotifier, TaskMonitor, TaskMonitorLog, ApiRequestLog]) def drop_table(): """初始化数据库表结构,包括所有model,后续调整使用migrate.py""" DB.drop_tables([User, Permission, Notifier, Business, BusinessNotifier, TaskMonitor, TaskMonitorLog, ApiRequestLog]) def insert_first_admin(): """插入系统初始管理员帐号,相关用户属性可后续自行更改""" first_admin = User() first_admin.username = '******' first_admin.password_hash = 'cronadmin' first_admin.email = '*****@*****.**'
def test_development_config(): """Production config.""" app = create_app('development') assert app.config['DEBUG'] is True
def test_default_config(): """Development config.""" app = create_app('default') assert app.config['DEBUG'] is True assert app.config['DB_DATABASE'] == 'cronmon'
def test_production_config(): """Development config.""" app = create_app('production') assert app.config['PRODUCTION'] is True
def test_testing_config(): """Development config.""" app = create_app('testing') assert app.config['TESTING'] is True