test_everything.py 文件源码

python
阅读 14 收藏 0 点赞 0 评论 0

项目:osp-api 作者: opensyllabus 项目源码 文件源码
def setup_client(before_create_app: Callable = None) -> FlaskClient:
    """Create and return the testing client.

    Arguments:
        before_create_app: A function which will be called before the
            Flask app is created. Originally implemented to support
            creating resources for testing.

    """

    # We need a secret key for JWT to work!
    config.SECRET_KEY = 'loltestingkey'

    # We don't wanna use redis for testing (too much of a hassle)
    config.FLASK_CACHE['CACHE_TYPE'] = 'simple'
    config.TESTING = True
    config.RATELIMIT_STORAGE_URL = 'memory://'

    # We'll be using unauthed/free a lot
    RATELIMIT_DEFAULT = config.RATELIMIT_DEFAULT_FREE
    config.RATELIMIT_DEFAULT = '2000 per minute'

    if before_create_app:
        before_create_app()

    app = create_app()
    client = app.test_client()
    with app.app_context():
        users.create_db_and_default_roles()
        users.create_dummy_users()

    return client
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号