Skip to content

Instantly share code, notes, and snippets.

@ddahan
Created January 4, 2017 16:33
Show Gist options
  • Save ddahan/302195f9fbd0ae923fda6cb6cb13867a to your computer and use it in GitHub Desktop.
Save ddahan/302195f9fbd0ae923fda6cb6cb13867a to your computer and use it in GitHub Desktop.
# factories.py
class UserFactory(factory.DjangoModelFactory):
class Meta:
model = User # Le modèle à Utiliser
first_name = factory.Sequence(lambda n: 'Prenom%d' % n) # itération automatique
last_name = factory.Sequence(lambda n: 'Nom%d' % n)
email = factory.LazyAttribute(lambda obj: '%s.%s@yopmail.com' \
% (obj.first_name.lower(), obj.last_name.lower()))
password = factory.PostGenerationMethodCall('set_password', 'azerty42')
birth_date = FuzzyDate(date(1920, 1, 1), date(2002, 1, 1))
gender = FuzzyChoice(choices=(GENDER_CHOICES[0][0], GENDER_CHOICES[1][0]))
email_verified = True
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment