<s> from datetime import datetime <EOL> from nose . tools import eq_ <EOL> import factory <EOL> from kitsune . questions . models import Question , QuestionVote , Answer , AnswerVote , QuestionLocale <EOL> from kitsune . sumo . tests import LocalizingClient , TestCase , FuzzyUnicode <EOL> from kitsune . users . tests import UserFactory <EOL> class TestCaseBase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> client_class = LocalizingClient <EOL> def tags_eq ( tagged_object , tag_names ) : <EOL> """<STR_LIT>""" <EOL> eq_ ( sorted ( [ t . name for t in tagged_object . tags . all ( ) ] ) , <EOL> sorted ( tag_names ) ) <EOL> class QuestionFactory ( factory . DjangoModelFactory ) : <EOL> class Meta : <EOL> model = Question <EOL> title = FuzzyUnicode ( ) <EOL> content = FuzzyUnicode ( ) <EOL> creator = factory . SubFactory ( UserFactory ) <EOL> @ factory . post_generation <EOL> def metadata ( q , create , extracted , ** kwargs ) : <EOL> if not create : <EOL> return <EOL> if extracted is not None : <EOL> q . add_metadata ( ** extracted ) <EOL> @ factory . post_generation <EOL> def tags ( q , create , extracted , ** kwargs ) : <EOL> if not create : <EOL> return <EOL> if extracted is not None : <EOL> for tag in extracted : <EOL> q . tags . add ( tag ) <EOL> class QuestionVoteFactory ( factory . DjangoModelFactory ) : <EOL> class Meta : <EOL> model = QuestionVote <EOL> created = factory . LazyAttribute ( lambda o : datetime . now ( ) ) <EOL> question = factory . SubFactory ( QuestionFactory ) <EOL> creator = factory . SubFactory ( UserFactory ) <EOL> class QuestionLocaleFactory ( factory . DjangoModelFactory ) : <EOL> class Meta : <EOL> model = QuestionLocale <EOL> @ factory . post_generation <EOL> def products ( obj , create , extracted , ** kwargs ) : <EOL> if not create : <EOL> return <EOL> if extracted is not None : <EOL> for product in extracted : <EOL> obj . products . add ( product ) <EOL> class AnswerFactory ( factory . DjangoModelFactory ) : <EOL> class Meta : <EOL> model = Answer <EOL> content = FuzzyUnicode ( ) <EOL> created = factory . LazyAttribute ( lambda a : datetime . now ( ) ) <EOL> creator = factory . SubFactory ( UserFactory ) <EOL> question = factory . SubFactory ( QuestionFactory ) <EOL> class SolutionAnswerFactory ( AnswerFactory ) : <EOL> @ factory . post_generation <EOL> def set_question_solution ( obj , create , extracted , ** kwargs ) : <EOL> obj . question . solution = obj <EOL> obj . save ( ) <EOL> class AnswerVoteFactory ( factory . DjangoModelFactory ) : <EOL> class Meta : <EOL> model = AnswerVote <EOL> created = factory . LazyAttribute ( lambda a : datetime . now ( ) ) <EOL> helpful = factory . fuzzy . FuzzyChoice ( [ True , False ] ) <EOL> creator = factory . SubFactory ( UserFactory ) <EOL> answer = factory . SubFactory ( AnswerFactory ) </s>
