def test_render(self): text = '<p>To the <a linktype="page" id="{}">moon</a>!</p>'.format( self.single_event_page.id) value = RichText(text) result = str(value) expected = '<p>To the <a href="/foo/pointless-suffix/">moon</a>!</p>' self.assertEqual(result, expected)
def test_can_assign_as_list(self): self.json_body.body = [("rich_text", RichText("<h2>hello world</h2>"))] self.json_body.save() # the body should now be a stream consisting of a single rich_text block fetched_body = self.model.objects.get(id=self.json_body.id).body self.assertIsInstance(fetched_body, StreamValue) self.assertEqual(len(fetched_body), 1) self.assertIsInstance(fetched_body[0].value, RichText) self.assertEqual(fetched_body[0].value.source, "<h2>hello world</h2>")
def value_from_form(self, value): # Rich text editors return a source-HTML string; convert to a RichText object return RichText(value)
def to_python(self, value): # convert a source-HTML string from the JSONish representation # to a RichText object return RichText(value)
def get_default(self): if isinstance(self.meta.default, RichText): return self.meta.default else: return RichText(self.meta.default)
def test_evaluate_value(self): value = RichText(None) self.assertFalse(value) value = RichText("<p>wagtail</p>") self.assertTrue(value)
def test_render(self): value = RichText( '<p>Merry <a linktype="page" id="4">Christmas</a>!</p>') result = str(value) self.assertEqual( result, '<p>Merry <a href="/events/christmas/">Christmas</a>!</p>')
def test_construct_with_nonempty_string(self): value = RichText("<p>hello world</p>") self.assertEqual(value.source, "<p>hello world</p>")
def test_construct_with_empty_string(self): value = RichText("") self.assertEqual(value.source, "")
def test_construct_with_none(self): value = RichText(None) self.assertEqual(value.source, "")
def setUp(self): super().setUp() # Create Blog self.blog_page = BlogPageFactory( body=[ ("heading", "Test heading 1"), ("paragraph", RichText("This is a paragraph.")), ("heading", "Test heading 2"), ("image", wagtail_factories.ImageFactory()), ("decimal", decimal.Decimal(1.2)), ("date", datetime.date.today()), ("datetime", datetime.datetime.now()), ( "carousel", StreamValue( stream_block=CarouselBlock(), stream_data=[ ("image", wagtail_factories.ImageChooserBlockFactory()), ("image", wagtail_factories.ImageChooserBlockFactory()), ], ), ), ( "gallery", { "title": "Gallery title", "images": StreamValue( stream_block=ImageGalleryImages(), stream_data=[ ( "image", { "image": wagtail_factories. ImageChooserBlockFactory() }, ), ( "image", { "image": wagtail_factories. ImageChooserBlockFactory() }, ), ], ), }, ), ("callout", { "text": RichText("<p>Hello, World</p>") }), ("objectives", ["Read all of article!"]), ( "video", { "youtube_link": EmbedValue( "https://www.youtube.com/watch?v=_U79Wc965vw") }, ), ( "text_and_buttons", { "text": "Button text", "buttons": [{ "button_text": "btn", "button_link": "https://www.graphql.com/", }], "mainbutton": { "button_text": "Take me to the source", "button_link": "https://wagtail.io/", }, }, ), ("text_with_callable", TextWithCallableBlockFactory()), ], parent=self.home, )