Esempio n. 1
0
    def test_parse_text_full(self):
        for url, expected in self.full_pairs.items():
            parsed = test_pr.parse_text_full(url)
            self.assertHTMLEqual(parsed, expected)

        # the parse_text_full will replace even inline content
        for url, expected in self.full_pairs.items():
            parsed = test_pr.parse_text_full('this is inline: %s' % url)
            self.assertHTMLEqual(parsed, 'this is inline: %s' % expected)

        for url, expected in self.full_pairs.items():
            parsed = test_pr.parse_html('<p>%s</p>' % url)
            self.assertHTMLEqual(parsed, '<p>%s</p>' % expected)
Esempio n. 2
0
    def test_urlize(self):
        blank = 'http://fapp.io/foo/'
        blank_e = '<a href="http://fapp.io/foo/">http://fapp.io/foo/</a>'
        for url, expected in self.full_pairs.items():
            expected_inline = self.inline_pairs[url]
            frame = 'test %s\n%s\n%s\nand finally %s'

            test_str = frame % (url, blank, url, blank)

            parsed = test_pr.parse_text(test_str)
            self.assertHTMLEqual(
                parsed, frame % (expected_inline, blank_e, expected, blank_e))

            parsed = test_pr.parse_text(test_str, urlize_all=False)
            self.assertHTMLEqual(
                parsed, frame % (expected_inline, blank, expected, blank))

            parsed = test_pr.parse_text_full(test_str)
            self.assertHTMLEqual(
                parsed, frame % (expected, blank_e, expected, blank_e))

            parsed = test_pr.parse_text_full(test_str, urlize_all=False)
            self.assertHTMLEqual(parsed,
                                 frame % (expected, blank, expected, blank))

            parsed = test_pr.parse_html(test_str)
            self.assertHTMLEqual(
                parsed,
                frame % (expected_inline, blank_e, expected_inline, blank_e))

            parsed = test_pr.parse_html(test_str, urlize_all=False)
            self.assertHTMLEqual(
                parsed,
                frame % (expected_inline, blank, expected_inline, blank))

            frame = '<p>test %s</p>\n<a href="foo">%s</a>\n<a href="foo2">%s</a>\n<p>and finally %s</p>'

            test_str = frame % (url, blank, url, blank)

            parsed = test_pr.parse_html(test_str)
            self.assertHTMLEqual(
                parsed, frame % (expected_inline, blank, url, blank_e))

            parsed = test_pr.parse_html(test_str, urlize_all=False)
            self.assertHTMLEqual(parsed,
                                 frame % (expected_inline, blank, url, blank))
Esempio n. 3
0
    def test_multiline_full(self):
        for url, expected in self.full_pairs.items():
            frame = 'this is inline: %s\n%s\nand yet another %s'

            test_str = frame % (url, url, url)

            parsed = test_pr.parse_text_full(test_str)
            self.assertHTMLEqual(parsed, frame % (expected, expected, expected))
Esempio n. 4
0
    def test_urlize_params(self):
        text = 'test http://foo.com/'
        urlize_params = {'target': '_blank', 'rel': 'nofollow'}
        exp = ('test <a href="http://foo.com/" rel="nofollow" target="_blank">'
               'http://foo.com/</a>')

        result = test_pr.parse_text(text, urlize_params=urlize_params)
        self.assertEqual(result, exp)

        result = test_pr.parse_text_full(text, urlize_params=urlize_params)
        self.assertEqual(result, exp)

        result = test_pr.parse_html(text, urlize_params=urlize_params)
        self.assertEqual(result, exp)