def insert_test_user(app: fixture, init_db: fixture): """写入测试用户""" with app.app_context(): user = User(username=TEST_USERNAME, password=TEST_PASSWORD, email=TEST_EMAIL) user.save()
def login_client(app: fixture, client: fixture, insert_test_user: fixture): """test login client""" with app.app_context(): data = { "email": TEST_EMAIL, "password": TEST_PASSWORD, } res = client.post(LOGIN_URL, data=data) access_token = json.loads(res.get_data()).get("data", {}).get("token") assert len(access_token) > 0 headers = {"Authorization": "Bearer " + access_token} client.token = access_token client.headers = headers return client
def init_db(app: fixture): """初始化数据库""" with app.app_context(): db.create_all()
def clear_mysql(app: fixture): """清理 mysql 数据""" yield with app.app_context(): db.session.commit() db.drop_all()