public
Last active

UserFactory with raw_password

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13
class UserFactory(factory.Factory):
password = 'test'
 
@classmethod
def _prepare(cls, create, **kwargs):
password = kwargs.pop('password', None)
user = super(UserFactory, cls)._prepare(create, **kwargs)
if password:
user.raw_password = password
user.set_password(password)
if create:
user.save()
return user

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.