Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Django UserFactory with factory_boy
import datetime
import md5
from django.contrib.auth.models import User
import factory
class UserFactory(factory.Factory):
Creates a new ``User`` object.
Username will be a random 30 character md5 value.
Email will be ```` with ``N`` being a counter.
Password will be ``test123`` by default.
username = factory.LazyAttribute(
lambda x:
email = factory.Sequence(lambda n: 'user{0}'.format(n))
def _prepare(cls, create, **kwargs):
password = 'test123'
if 'password' in kwargs:
password = kwargs.pop('password')
user = super(UserFactory, cls)._prepare(create, **kwargs)
if create:
return user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.