How to use the micawber.test_utils.test_pr.parse_html function in micawber

To help you get started, we’ve selected a few micawber examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coleifer / micawber / micawber / tests.py View on Github external
def test_urlize_params(self):
        text = 'test http://foo.com/'
        urlize_params = {'target': '_blank', 'rel': 'nofollow'}
        exp = ('test <a rel="nofollow" href="http://foo.com/">'
               '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)
github coleifer / micawber / micawber / tests.py View on Github external
def test_parse_html_entities(self):
        e = '&lt;script&gt;&lt;/script&gt;'
        p = '<p>Test %s</p>' % e
        self.assertEqual(test_pr.parse_html(p), p)

        a = '<p>http://google.com %s</p>' % e
        self.assertEqual(test_pr.parse_html(a),
                         '<p><a href="http://google.com">http://google.com</a>'
                         ' %s</p>' % e)

        h = ('<p><a href="http://foo.com">http://foo.com</a> http://bar.com '
             '<span>http://baz.com &lt;script&gt; '
             '<b>http://nug.com <i>X &lt;foo&gt;</i></b></span></p>')
        self.assertEqual(test_pr.parse_html(h), (
            '<p><a href="http://foo.com">http://foo.com</a> '
            '<a href="http://bar.com">http://bar.com</a> '
            '<span><a href="http://baz.com">http://baz.com</a> &lt;script&gt; '
            '<b><a href="http://nug.com">http://nug.com</a> '
            '<i>X &lt;foo&gt;</i></b></span></p>'))

        h = ('<p><a href="http://foo.com">http://foo.com</a> http://bar.com '
             '&lt;script&gt; http://baz.com &lt;/script&gt;\n'
             'http://baze.com\n&lt;foo&gt;</p>')
github coleifer / micawber / micawber / tests.py View on Github external
def test_html_entities(self):
        frame_html = '<p>test %s</p><p><a href="foo">%s</a></p>'

        for url, expected in self.data_pairs.items():
            esc_url = url.replace('&amp;', '&amp;')
            html = frame_html % (esc_url, esc_url)
            all_urls, extracted = test_pr.extract_html(html)
            self.assertEqual(all_urls, [url])

            if 'url' not in expected:
                expected['url'] = url
            if 'title' not in expected:
                expected['title'] = expected['url']
            self.assertEqual(extracted, {url: expected})

            rendered = test_pr.parse_html('<p>%s</p>' % esc_url)
            self.assertHTMLEqual(rendered, '<p>%s</p>' % self.full_pairs[url])
github coleifer / micawber / micawber / tests.py View on Github external
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)
github coleifer / micawber / micawber / tests.py View on Github external
def test_parse_html_entities(self):
        e = '&lt;script&gt;&lt;/script&gt;'
        p = '<p>Test %s</p>' % e
        self.assertEqual(test_pr.parse_html(p), p)

        a = '<p>http://google.com %s</p>' % e
        self.assertEqual(test_pr.parse_html(a),
                         '<p><a href="http://google.com">http://google.com</a>'
                         ' %s</p>' % e)

        h = ('<p><a href="http://foo.com">http://foo.com</a> http://bar.com '
             '<span>http://baz.com &lt;script&gt; '
             '<b>http://nug.com <i>X &lt;foo&gt;</i></b></span></p>')
        self.assertEqual(test_pr.parse_html(h), (
            '<p><a href="http://foo.com">http://foo.com</a> '
            '<a href="http://bar.com">http://bar.com</a> '
            '<span><a href="http://baz.com">http://baz.com</a> &lt;script&gt; '
            '<b><a href="http://nug.com">http://nug.com</a> '
            '<i>X &lt;foo&gt;</i></b></span></p>'))
github coleifer / micawber / micawber / tests.py View on Github external
' %s<p></p>' % e)

        h = ('<p><a href="http://foo.com">http://foo.com</a> http://bar.com '
             '<span>http://baz.com &lt;script&gt; '
             '<b>http://nug.com <i>X &lt;foo&gt;</i></b></span></p>')
        self.assertEqual(test_pr.parse_html(h), (
            '<p><a href="http://foo.com">http://foo.com</a> '
            '<a href="http://bar.com">http://bar.com</a> '
            '<span><a href="http://baz.com">http://baz.com</a> &lt;script&gt; '
            '<b><a href="http://nug.com">http://nug.com</a> '
            '<i>X &lt;foo&gt;</i></b></span></p>'))

        h = ('<p><a href="http://foo.com">http://foo.com</a> http://bar.com '
             '&lt;script&gt; http://baz.com &lt;/script&gt;\n'
             'http://baze.com\n&lt;foo&gt;</p>')
        self.assertEqual(test_pr.parse_html(h), (
            '<p><a href="http://foo.com">http://foo.com</a> '
            '<a href="http://bar.com">http://bar.com</a> &lt;script&gt; '</p>
github coleifer / micawber / micawber / tests.py View on Github external
def test_outside_of_markup(self):
        frame = '%s<p>testing</p>'
        for url, expected in self.full_pairs.items():
            parsed = test_pr.parse_html(frame % (url))
            self.assertHTMLEqual(parsed, frame % (expected))
github coleifer / micawber / micawber / tests.py View on Github external
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))
github coleifer / micawber / micawber / tests.py View on Github external
# if the link comes on its own line it gets included in full
        for url, expected in self.full_pairs.items():
            parsed = test_pr.parse_text(url)
            self.assertHTMLEqual(parsed, expected)

        # links inside block tags will render as inline
        frame = '<p>Testing %s</p>'
        for url, expected in self.inline_pairs.items():
            parsed = test_pr.parse_html(frame % (url))
            self.assertHTMLEqual(parsed, frame % (expected))

        # links inside <a> tags won't change at all
        frame = '</a><p><a></a><a href="%s">%s</a></p>'
        for url, expected in self.inline_pairs.items():
            parsed = test_pr.parse_html(frame % (url, url))
            self.assertHTMLEqual(parsed, frame % (url, url))

        # links within tags within a tags are fine too
        frame = '<p><a href="%s"><span>%s</span></a></p>'
        for url, expected in self.inline_pairs.items():
            parsed = test_pr.parse_html(frame % (url, url))
            self.assertHTMLEqual(parsed, frame % (url, url))