Пример #1
0
    def setUpClass(cls):
        # 启动Chrome
        try:
            cls.client = webdriver.Chrome()
        except:
            pass

        # 如果无法启动浏览器,则跳过
        if cls.client:
            # 创建程序
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # 禁止日志,保持输出整洁
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel('ERROR')

            # 创建数据库,并插入一些数据
            db.create_all()
            Role.insert_roles()
            User.insert_test_user()

            # 在线程中启动服务器
            threading.Thread(target=cls.app.run).start()
Пример #2
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
     self.client = self.app.test_client()
Пример #3
0
 def create_app(self):
     app = simple.create_app('settings')
     app.config.from_pyfile('tests/sample_responses.py')
     app.config['TESTING'] = True
     return app
Пример #4
0
import os, sys
import click
from simple import create_app
from simple.models import db, User, Role, Post

# coverage的配置
COV = None
if os.environ.get('FLASK_COVERAGE'):
    import coverage
    COV = coverage.coverage(branch=True, include='simple/*')
    COV.start()

# 创建simpleblog实例
app = create_app(os.getenv('FLASK_CONFIG') or 'development')


# shell上下文
@app.shell_context_processor
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Post=Post)


# 测试的命令
@app.cli.command()
@click.option('--coverage/--no-coverage',
              default=False,
              help='run tests under code coverage')
def test(coverage):
    # 设置coverage的环境变量
    if coverage and not os.environ.get('FLASK_COVERAGE'):
        import subprocess
Пример #5
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     self.client = self.app.test_client(use_cookies=True)
Пример #6
0
from simple import create_app

application = create_app('settings')
Пример #7
0
#!/usr/bin/env python

import simple

app = simple.create_app("settings")
app.run()