I want to mock flask-login
's current_user
under the template rendering. This function return the current logged user.
Right now I'm mocking the AnnonymousUserMixin
from flask-login
which is returned by default if the user is not authenticated. But this leads to all kind of juggles. If I could simply mock current_user
I would be able to create a Mocked object for it to return.
Here a sample of what I'm using today:
import unnittest
from flask_login.mixins import AnonymousUserMixin
class TestFoo(unittest.TestCase):
@patch.object(AnonymousUserMixin, 'is_admin', create=True,
return_value=False)
@patch.object(AnonymousUserMixin, 'is_authenticated', return_value=True)
def test_user_restriction(self, *args):
...
Regards,