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
评论列表
文章目录