Enrich test data generation with ImageFields

This commit is contained in:
Pawel Kowalski 2018-08-16 15:23:41 +02:00
parent a24acad07a
commit 80719e9a65
3 changed files with 17 additions and 5 deletions

View File

@ -5,7 +5,7 @@ DEFAULT_RICH_TEXT_FEATURES = ['bold', 'italic', 'link', 'ol', 'ul']
# 'text_block' 'task'
class TextBlock(blocks.StructBlock):
text = blocks.CharBlock()
text = blocks.RichTextBlock()
# 'modal_text'

View File

@ -4,6 +4,7 @@ import factory
import wagtail_factories
from factory import CREATE_STRATEGY
from wagtail.core.rich_text import RichText
from book.blocks import ModalTextBlock
from book.models import Book, Topic, Module, Chapter, ContentBlock, TextBlock
@ -56,6 +57,9 @@ class ModalTextBlockFactory(wagtail_factories.StructBlockFactory):
model = ModalTextBlock
block_types = ['text_block', 'modal_text', 'student_entry', 'image_block', 'task']
class ContentBlockFactory(BasePageFactory):
class Meta:
model = ContentBlock
@ -65,6 +69,7 @@ class ContentBlockFactory(BasePageFactory):
contents = wagtail_factories.StreamFieldFactory({
'text_block': TextBlockFactory,
'modal_text': ModalTextBlockFactory,
'image_block': wagtail_factories.ImageChooserBlockFactory
})
@classmethod
@ -73,11 +78,18 @@ class ContentBlockFactory(BasePageFactory):
for idx, resource in enumerate(kwargs[stream_field_name]):
value = resource['value']
for jdx, field in enumerate(value):
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, resource['type'], field)] = value[field]
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, resource['type'], field)] = RichText(value[field])
del kwargs[stream_field_name]
else:
for i in range(0, random.randint(3, 7)):
kwargs['{}__{}__{}__b'.format(stream_field_name, i, 'text_block', 'text')] = fake_title_noparam()
block_type = random.choice(block_types)
if block_type == 'text_block':
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'text_block', 'text')] = RichText(fake_title_noparam())
elif block_type == 'image_block':
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', 'image__title')] = fake_title_noparam()
# for i in range(4, 6):
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', 'image')] = ''
@classmethod
def create(cls, **kwargs):

View File

@ -69,14 +69,14 @@ data = [
'type': 'text_block',
'value': {
'type': 'text_block',
'text': 'Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?\nHalten Sie Ihre Erfahrungen im Bereich fest und stellen Sie diese anschliessend der Klasse vor.'
'text': '<p>Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?<br/>Halten Sie Ihre Erfahrungen im Bereich fest und stellen Sie diese anschliessend der Klasse vor.</p>'
}
},
{
'type': 'text_block',
'value': {
'type': 'text_block',
'text': 'Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben. Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.'
'text': '<p>Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben.<p></p>Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.</p>'
}
},
# {