Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rich text block factory #88

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/wagtail_factories/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"PageChooserBlockFactory",
"ImageChooserBlockFactory",
"DocumentChooserBlockFactory",
"RichTextBlockFactory",
]


Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
"<p>This is some <strong>richtext</strong></p>"
),
)
assert Image.objects.count() == 1
image = Image.objects.first()
Expand Down
1 change: 1 addition & 0 deletions tests/testapp/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class MyTestPageWithStreamFieldFactory(wagtail_factories.PageFactory):
"document": factory.SubFactory(
wagtail_factories.DocumentChooserBlockFactory
),
"richtext": factory.SubFactory(wagtail_factories.RichTextBlockFactory),
}
)

Expand Down
1 change: 1 addition & 0 deletions tests/testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MyTestPage(Page):
("page", blocks.PageChooserBlock()),
("image", ImageChooserBlock()),
("document", DocumentChooserBlock()),
("richtext", blocks.RichTextBlock()),
],
use_json_field=True,
)
Expand Down
Loading