Skip to content

Commit

Permalink
use Factoryboy's fakersyntax
Browse files Browse the repository at this point in the history
  • Loading branch information
crccheck committed Dec 31, 2018
1 parent 9ef73cc commit 638d943
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions example_project/polls/factories.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import factory
from django.contrib.auth import get_user_model
from django.utils import timezone
from factory import faker

from . import models


fake = faker.faker.Factory.create()


class UserFactory(factory.DjangoModelFactory):
class Meta:
model = get_user_model()
first_name = factory.LazyAttribute(lambda i: fake.first_name())
last_name = factory.LazyAttribute(lambda i: fake.last_name())
username = factory.LazyAttribute(lambda x: '{0}{1}'.format(x.first_name, x.last_name))
email = factory.LazyAttribute(lambda x: '{0}@{1}.com'.format(
x.first_name.lower(), x.last_name.lower()))
first_name = factory.Faker('first_name')
last_name = factory.Faker('last_name')
username = factory.Faker('slug')
email = factory.Faker('email')
password = factory.PostGenerationMethodCall('set_password', 'password')


class PollFactory(factory.DjangoModelFactory):
class Meta:
model = models.Poll

question = factory.LazyAttribute(lambda __: fake.sentence())
question = factory.Faker('sentence')
pub_date = factory.LazyAttribute(lambda __: timezone.now())


Expand All @@ -33,8 +28,8 @@ class Meta:
model = models.Choice

poll = factory.SubFactory(PollFactory)
choice_text = factory.LazyAttribute(lambda __: fake.word())
votes = factory.LazyAttribute(lambda __: fake.pyint())
choice_text = factory.Faker('word')
votes = factory.Faker('pyint')


class CommentFactory(factory.DjangoModelFactory):
Expand Down

0 comments on commit 638d943

Please sign in to comment.