User authentication in tests with Django factory_boy
django, django-authentication, factory, unit-testing
Solution
You should call `user.save()` after `user.set_password()` because `set_password` itself does not save the user, only sets the data.
Problem
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?