Skip to content

Commit

Permalink
Test factories upgraded to use factory-boy>=2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ellmetha committed Apr 7, 2015
1 parent 2a83528 commit c3001f5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
4 changes: 3 additions & 1 deletion machina/test/factories/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@


class AttachmentFactory(factory.DjangoModelFactory):
FACTORY_FOR = Attachment
post = factory.SubFactory(PostFactory)
comment = faker.text(max_nb_chars=255)

class Meta:
model = Attachment
8 changes: 6 additions & 2 deletions machina/test/factories/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@


class UserFactory(factory.DjangoModelFactory):
FACTORY_FOR = User
username = factory.LazyAttribute(lambda t: faker.user_name())
email = factory.Sequence(lambda n: 'test{0}@example.com'.format(n))
password = '1234'
is_active = True

class Meta:
model = User

@classmethod
def _prepare(cls, create, **kwargs):
password = kwargs.pop('password', None)
Expand All @@ -31,5 +33,7 @@ def _prepare(cls, create, **kwargs):


class GroupFactory(factory.DjangoModelFactory):
FACTORY_FOR = Group
name = factory.Sequence(lambda n: '{}-{}'.format(str(n), faker.job()))

class Meta:
model = Group
8 changes: 6 additions & 2 deletions machina/test/factories/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@


class TopicFactory(factory.DjangoModelFactory):
FACTORY_FOR = Topic
forum = factory.SubFactory(ForumFactory)
poster = factory.SubFactory(UserFactory)
status = Topic.STATUS_CHOICES.topic_unlocked
subject = factory.LazyAttribute(lambda t: faker.text(max_nb_chars=200))
slug = factory.LazyAttribute(lambda t: slugify(t.subject))

class Meta:
model = Topic


class PostFactory(factory.DjangoModelFactory):
FACTORY_FOR = Post
topic = factory.SubFactory(TopicFactory)
poster = factory.SubFactory(UserFactory)
subject = factory.LazyAttribute(lambda t: faker.text(max_nb_chars=200))
content = fuzzy.FuzzyText(length=255)

class Meta:
model = Post


def build_topic(**attrs):
"""Create a new unlocked topic but do not save it."""
Expand Down
4 changes: 3 additions & 1 deletion machina/test/factories/forum.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@


class ForumFactory(factory.DjangoModelFactory):
FACTORY_FOR = Forum
name = faker.text(max_nb_chars=150)
slug = factory.LazyAttribute(lambda t: slugify(t.name))

# Link forum specific
link = faker.uri()

class Meta:
model = Forum


def build_forum(**attrs):
"""Create a new forum but do not save it."""
Expand Down
12 changes: 9 additions & 3 deletions machina/test/factories/polls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@


class TopicPollFactory(factory.DjangoModelFactory):
FACTORY_FOR = TopicPoll
topic = factory.SubFactory(TopicFactory)
question = faker.text(max_nb_chars=200)

class Meta:
model = TopicPoll


class TopicPollOptionFactory(factory.DjangoModelFactory):
FACTORY_FOR = TopicPollOption
poll = factory.SubFactory(TopicPollFactory)
text = faker.text(max_nb_chars=100)

class Meta:
model = TopicPollOption


class TopicPollVoteFactory(factory.DjangoModelFactory):
FACTORY_FOR = TopicPollVote
poll_option = factory.SubFactory(TopicPollOptionFactory)
voter = factory.SubFactory(UserFactory)

class Meta:
model = TopicPollVote
8 changes: 6 additions & 2 deletions machina/test/factories/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@


class ForumReadTrackFactory(factory.DjangoModelFactory):
FACTORY_FOR = ForumReadTrack
user = factory.SubFactory(UserFactory)
forum = factory.SubFactory(ForumFactory)

class Meta:
model = ForumReadTrack


class TopicReadTrackFactory(factory.DjangoModelFactory):
FACTORY_FOR = TopicReadTrack
user = factory.SubFactory(UserFactory)
topic = factory.SubFactory(TopicFactory)

class Meta:
model = TopicReadTrack
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ django-nose
nose>=1.2.1
spec>=0.11.1,<0.12
coverage>=3.7,<3.8
factory-boy>=2.3,<2.4
fake-factory>=0.4.0,<0.5
factory-boy>=2.4,<2.6
fake-factory>=0.5,<0.6
coveralls>=0.2,<0.3
mock>=1.0.1,<1.1
tox>=1.7,<1.8
Expand Down

0 comments on commit c3001f5

Please sign in to comment.