Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
    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>")
Ejemplo n.º 3
0
 def value_from_form(self, value):
     # Rich text editors return a source-HTML string; convert to a RichText object
     return RichText(value)
Ejemplo n.º 4
0
 def to_python(self, value):
     # convert a source-HTML string from the JSONish representation
     # to a RichText object
     return RichText(value)
Ejemplo n.º 5
0
 def get_default(self):
     if isinstance(self.meta.default, RichText):
         return self.meta.default
     else:
         return RichText(self.meta.default)
Ejemplo n.º 6
0
    def test_evaluate_value(self):
        value = RichText(None)
        self.assertFalse(value)

        value = RichText("<p>wagtail</p>")
        self.assertTrue(value)
Ejemplo n.º 7
0
 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>')
Ejemplo n.º 8
0
 def test_construct_with_nonempty_string(self):
     value = RichText("<p>hello world</p>")
     self.assertEqual(value.source, "<p>hello world</p>")
Ejemplo n.º 9
0
 def test_construct_with_empty_string(self):
     value = RichText("")
     self.assertEqual(value.source, "")
Ejemplo n.º 10
0
 def test_construct_with_none(self):
     value = RichText(None)
     self.assertEqual(value.source, "")
Ejemplo n.º 11
0
    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,
        )