Assume we have a user factory like so:
from factory.django import DjangoModelFactory, Password
class UserFactory(DjangoModelFactory[User]):
password = Password(USER_PASSWORD)
...
Then the following does not work as one would expect:
from django.contrib.auth.hashers import check_password
def test_password(user: User) -> None:
assert check_password(USER_PASSWORD, user.password) # raises AssertionError
The following does work properly though:
def test_password() -> None:
user = UserFactory()
assert check_password(USER_PASSWORD, user.password) # succeeds
I think the issue might be that the password is double-hashed when using pytest-factoryboy with this factory. Note that we are using the factories to generate synthetic data as well, so we need them to generate usable passwords (i.e. we cannot set the password to the raw string). Preferably both UserFactory() and the pytest-factoryboy fixture work at the same time.
Assume we have a user factory like so:
Then the following does not work as one would expect:
The following does work properly though:
I think the issue might be that the password is double-hashed when using pytest-factoryboy with this factory. Note that we are using the factories to generate synthetic data as well, so we need them to generate usable passwords (i.e. we cannot set the password to the raw string). Preferably both
UserFactory()and thepytest-factoryboyfixture work at the same time.