I'm new to Pytest. I want to test my views which require login (decorated with @login_required).
I have following test function:
def test_add_new_post(self, client, user):
login_user(user)
assert current_user == user
data = {
'title': 'This is test post',
'body': 'This is test body'
}
client.post(url_for('posts.add_new'), data=data)
assert Post.query.count() == 1
where the client is:
@pytest.fixture(scope='session')
def client(request, app):
return app.test_client()
The assert current_user == user returns True, but the client.post returns the login page, because the login_required redirects to a login page. Why is this happening and what is the correct way of doing this?