flask unit test: how to test request from logged in user

佐手、 提交于 2019-11-28 07:40:58

Flask-Login looks for user_id in the session, you can set this in the tests using session_transaction:

with app.test_client() as c:
    with c.session_transaction() as sess:
        sess['user_id'] = 'myuserid'
        sess['_fresh'] = True # https://flask-login.readthedocs.org/en/latest/#fresh-logins
    resp = c.get('/someurl')

Where myuserid is the id of your user object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!