diff --git a/src/wagtail_factories/blocks.py b/src/wagtail_factories/blocks.py index 3316a7f..059a893 100644 --- a/src/wagtail_factories/blocks.py +++ b/src/wagtail_factories/blocks.py @@ -24,6 +24,7 @@ "PageChooserBlockFactory", "ImageChooserBlockFactory", "DocumentChooserBlockFactory", + "RichTextBlockFactory", ] @@ -239,3 +240,8 @@ def _build(cls, model_class, document): @classmethod def _create(cls, model_class, document): return document + + +class RichTextBlockFactory(BlockFactory): + class Meta: + model = blocks.RichTextBlock diff --git a/tests/test_blocks.py b/tests/test_blocks.py index 4af99df..4b90093 100644 --- a/tests/test_blocks.py +++ b/tests/test_blocks.py @@ -6,6 +6,7 @@ from wagtail.documents.models import Document from wagtail.images.models import Image from wagtail.models import Page +from wagtail.rich_text import RichText from tests.testapp.factories import ( MyBlockFactory, @@ -135,6 +136,9 @@ def test_custom_page_streamfield_data_complex(): body__3__image__image__title="Blub", body__4__page__page__title="Bulb", body__5__document__document__title="Bubl", + body__6__richtext__value=RichText( + "
This is some richtext
" + ), ) assert Image.objects.count() == 1 image = Image.objects.first() diff --git a/tests/testapp/factories.py b/tests/testapp/factories.py index 676918e..a651195 100644 --- a/tests/testapp/factories.py +++ b/tests/testapp/factories.py @@ -52,6 +52,7 @@ class MyTestPageWithStreamFieldFactory(wagtail_factories.PageFactory): "document": factory.SubFactory( wagtail_factories.DocumentChooserBlockFactory ), + "richtext": factory.SubFactory(wagtail_factories.RichTextBlockFactory), } ) diff --git a/tests/testapp/models.py b/tests/testapp/models.py index 7ae052a..b234c36 100644 --- a/tests/testapp/models.py +++ b/tests/testapp/models.py @@ -41,6 +41,7 @@ class MyTestPage(Page): ("page", blocks.PageChooserBlock()), ("image", ImageChooserBlock()), ("document", DocumentChooserBlock()), + ("richtext", blocks.RichTextBlock()), ], use_json_field=True, )