Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def init_db(app: fixture):
    """初始化数据库"""
    with app.app_context():
        db.create_all()
Exemplo n.º 4
0
def clear_mysql(app: fixture):
    """清理 mysql 数据"""
    yield
    with app.app_context():
        db.session.commit()
        db.drop_all()