klen / mixer

Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.
Other
939 stars 96 forks source link

Django: mixer.blend(get_user_model()) - does not hash the password #118

Closed denisvolokh closed 5 years ago

denisvolokh commented 5 years ago

Hi,

The user object created with blend function cannot be authenticated with client.login

user = mixer.blend(get_user_model())
is_logged_in = client.login(username=user.username, password=user.password)
# is_logged_in is always false

What is the right way to make an authenticated user?

Thanks, Denis

denisvolokh commented 5 years ago

Looked at the source code and found that mixer is just saving the object.

I can hash password by myself:

from django.contrib.auth.hashers import make_password

user = mixer.blend(
        get_user_model(),
        password=make_password(TEST_PASSWORD)
    )
ozcanyarimdunya commented 3 years ago

Looked at the source code and found that mixer is just saving the object.

I can hash password by myself:

from django.contrib.auth.hashers import make_password

user = mixer.blend(
        get_user_model(),
        password=make_password(TEST_PASSWORD)
    )

You may set it callable

user = mixer.blend(User, password=lambda: make_password(TEST_PASSWORD))