When trying to unit test some part of my code, I need a user to be logged in. For reducing the number of fixtures I am using django_factory_boy User factory but the User generated is unable to authenticate.
from django_factory_boy.auth import UserF
from django.contrib.auth import authenticate
user = UserF()
user.set_password('password')
then authenticate(username=user.username, password='password') return None instead of the User. Any ideas about what is missing here?
You should call
user.save()afteruser.set_password()becauseset_passworditself does not save the user, only sets the data.