<s> from __future__ import unicode_literals <EOL> from django . utils . text import slugify <EOL> import factory <EOL> from factory import fuzzy <EOL> from faker import Factory as FakerFactory <EOL> from machina . core . db . models import get_model <EOL> from machina . test . factories . auth import UserFactory <EOL> from machina . test . factories . forum import ForumFactory <EOL> faker = FakerFactory . create ( ) <EOL> Post = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Topic = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TopicFactory ( factory . DjangoModelFactory ) : <EOL> forum = factory . SubFactory ( ForumFactory ) <EOL> poster = factory . SubFactory ( UserFactory ) <EOL> status = Topic . TOPIC_UNLOCKED <EOL> subject = factory . LazyAttribute ( lambda t : faker . text ( max_nb_chars = <NUM_LIT:200> ) ) <EOL> slug = factory . LazyAttribute ( lambda t : slugify ( t . subject ) ) <EOL> class Meta : <EOL> model = Topic <EOL> class PostFactory ( factory . DjangoModelFactory ) : <EOL> topic = factory . SubFactory ( TopicFactory ) <EOL> poster = factory . SubFactory ( UserFactory ) <EOL> subject = factory . LazyAttribute ( lambda t : faker . text ( max_nb_chars = <NUM_LIT:200> ) ) <EOL> content = fuzzy . FuzzyText ( length = <NUM_LIT:255> ) <EOL> class Meta : <EOL> model = Post <EOL> def build_topic ( ** attrs ) : <EOL> """<STR_LIT>""" <EOL> params_dict = { '<STR_LIT:type>' : Topic . TOPIC_POST } <EOL> params_dict . update ( attrs ) <EOL> topic = TopicFactory . build ( ** params_dict ) <EOL> return topic <EOL> def create_topic ( ** attrs ) : <EOL> """<STR_LIT>""" <EOL> topic = build_topic ( ** attrs ) <EOL> topic . save ( ) <EOL> return topic </s>
