flask unit test: how to test request from logged in user
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.