skillbox/server/book/factories.py

45 lines
1.1 KiB
Python

import random
import factory
from book.models import Book, Topic, Module, Chapter, ContentBlock
from core.factories import BasePageFactory, fake, DummyImageFactory
class BookFactory(BasePageFactory):
class Meta:
model = Book
class TopicFactory(BasePageFactory):
class Meta:
model = Topic
order = 0
teaser = factory.LazyAttribute(lambda x: fake.sentence(nb_words=random.randint(8, 12)))
description = factory.LazyAttribute(lambda x: fake.text(max_nb_chars=200))
class ModuleFactory(BasePageFactory):
class Meta:
model = Module
order = 0
meta_title = factory.LazyAttribute(lambda x: fake.text(max_nb_chars=20))
teaser = factory.LazyAttribute(lambda x: fake.sentence(nb_words=random.randint(8, 12)))
intro = factory.LazyAttribute(lambda x: fake.text(max_nb_chars=200))
hero_image = factory.SubFactory(DummyImageFactory)
class ChapterFactory(BasePageFactory):
class Meta:
model = Chapter
class ContentBlockFactory(BasePageFactory):
class Meta:
model = ContentBlock
type = factory.LazyAttribute(lambda x: random.choice(['plain', 'yellow', 'green', 'blue']))