Example #1
0
 def test_that_ghs_statement_is_rendered_correctly(self):
     for n in range(1, 10):
         input_html = self.input_html_template.format(id=n)
         parser = HTMLShortcodeParser(input_html)
         parser.register_inline_shortcode(GHSStatementProcessor)
         output_html = parser.get_rendered_html()
         self.assertEqual(
             output_html,
             self.expected_html_template.format(
                 url=static("/static/img/ghs/symbol_{id}.png".format(
                     id=n))))
Example #2
0
    def test_that_inline_link_to_topic_is_rendered(self):
        topic = Initialiser.create_base_topic()
        input_html = self.input_html_template.format(page_ids=topic.pk)

        parser = HTMLShortcodeParser(input_html)
        parser.register_inline_shortcode(InternalLinkProcessor)
        output_html = parser.get_rendered_html()

        expected_html = self.expected_html_template.format(
            url=topic.get_absolute_url())

        self.assertEqual(output_html, expected_html)
Example #3
0
    def test_that_figure_can_be_inserted_within_figgroup(self):
        input_html = self.get_n_paras(5)

        figure_renderers = [
            FigureRenderer(StubFileObj(i, "/img/%s.jpg" % i),
                           alt="Image %s" % i) for i in range(0, 1)
        ]

        renderer = FigureGroupRenderer(figures=figure_renderers)

        parser = HTMLShortcodeParser(input_html)
        output_html = parser.insert_shortcode(3, renderer)
        expected_shortcode = "<p>[figgroup:figure:][figure:local:0:Image 0][/figgroup]</p>"

        self.assertEqual(
            output_html,
            self.get_n_paras(3) + expected_shortcode + self.get_n_paras(2))
Example #4
0
    def test_that_multiple_figures_can_be_inserted_within_figgroup(self):
        input_html = self.get_n_paras(5)

        figure_renderers = [
            FigureRenderer(StubFileObj(i, "/img/%s.jpg" % i),
                           alt="Image %s" % i) for i in range(0, 4)
        ]

        renderer = FigureGroupRenderer(figures=figure_renderers,
                                       layout=['stacked2'])

        parser = HTMLShortcodeParser(input_html)
        output_html = parser.insert_shortcode(1, renderer)
        expected_shortcode = "<p>[figgroup:figure:stacked2][figure:local:0:Image 0][figure:local:1:Image 1]" + \
                             "[figure:local:2:Image 2][figure:local:3:Image 3][/figgroup]</p>"

        self.assertEqual(
            output_html,
            self.get_n_paras(1) + expected_shortcode + self.get_n_paras(4))
Example #5
0
    def test_that_figgroups_are_rendered_as_html(self):
        input_html = self.get_n_paras(5)
        files = [self._create_file(i) for i in range(0, 4)]
        figure_renderers = [
            FigureRenderer(file_obj=f, alt="Image %s" % f.pk) for f in files
        ]

        renderer = FigureGroupRenderer(figures=figure_renderers)

        parser = HTMLShortcodeParser(input_html)
        shortcode_html = parser.insert_shortcode(1, renderer)
        parser2 = HTMLShortcodeParser(shortcode_html)
        parser2.register_block_shortcode(FigureGroupProcessor)

        output_html = parser2.get_rendered_html()

        expected_rendered_html = "<aside><figure class=\" inline\">"
        expected_rendered_html += "".join(
            [self._expected_rendered_image_html(f) for f in files])
        expected_rendered_html += "</figure></aside>"

        self.assertEqual(
            output_html,
            self.get_n_paras(1) + expected_rendered_html + self.get_n_paras(4))
Example #6
0
 def test_that_inline_link_with_bad_params_passes_thru_contents(self):
     input_html = self.input_html_template.format(page_ids="  abc d &* fg")
     parser = HTMLShortcodeParser(input_html)
     parser.register_inline_shortcode(InternalLinkProcessor)
     output_html = parser.get_rendered_html()
     self.assertEqual(output_html, self.noop_html)