def test_openclose_tag(self, tag): raw_body = "<{tag}>some text</{tag}>".format(tag=tag) is_inline_tag = tag in [ "b", "code", "del", "em", "i", "kbd", "s", "sup", "sub", "strong", "strike" ] rendered_body = _add_p_tags(raw_body) if is_inline_tag else raw_body self.assertEqual(render_body(raw_body), rendered_body)
def test_selfclosing_tag(self, tag): raw_body = "<{tag}>".format(tag=tag) is_inline_tag = tag == "br" rendered_body = _add_p_tags(raw_body) if is_inline_tag else raw_body self.assertEqual(render_body(raw_body), rendered_body)
def test_openclose_tag(self, tag): raw_body = "<{tag}>some text</{tag}>".format(tag=tag) is_inline_tag = tag in ["b", "code", "del", "em", "i", "kbd", "s", "sup", "sub", "strong", "strike"] rendered_body = _add_p_tags(raw_body) if is_inline_tag else raw_body self.assertEqual(render_body(raw_body), rendered_body)
def test_markdown_inline(self, delimiter, tag): self.assertEqual( render_body( "{delimiter}some text{delimiter}".format(delimiter=delimiter)), "<p><{tag}>some text</{tag}></p>".format(tag=tag))
def get_rendered_body(self, obj): """Returns the rendered body content.""" return render_body(obj["body"])
def test_unpaired_end_tag(self): self.assertEqual(render_body("foo</i>bar"), "<p>foobar</p>")
def test_script_tag(self): raw_body = '<script type="text/javascript">alert("evil script");</script>' self.assertEqual(render_body(raw_body), 'alert("evil script");')
def test_allowed_img_tag(self, protocol): raw_body = '<img src="{protocol}://foo" width="111" height="222" alt="bar" title="baz">'.format( protocol=protocol ) self.assertEqual(render_body(raw_body), _add_p_tags(raw_body))
def test_disallowed_img_tag(self): raw_body = '<img src="gopher://foo">' self.assertEqual(render_body(raw_body), "<p></p>")
def test_allowed_img_tag(self, protocol): raw_body = '<img src="{protocol}://foo" width="111" height="222" alt="bar" title="baz">'.format( protocol=protocol) self.assertEqual(render_body(raw_body), _add_p_tags(raw_body))
def test_disallowed_a_tag(self): raw_body = '<a href="gopher://foo">link content</a>' self.assertEqual(render_body(raw_body), "<p>link content</p>")
def test_allowed_a_tag(self, protocol): raw_body = '<a href="{protocol}://foo" title="bar">baz</a>'.format( protocol=protocol) self.assertEqual(render_body(raw_body), _add_p_tags(raw_body))
def test_allowed_a_tag(self, protocol): raw_body = '<a href="{protocol}://foo" title="bar">baz</a>'.format(protocol=protocol) self.assertEqual(render_body(raw_body), _add_p_tags(raw_body))
def test_allowed_unpaired_tags(self, tag): raw_body = "foo<{tag}>bar".format(tag=tag) self.assertEqual(render_body(raw_body), _add_p_tags(raw_body))
def test_interleaved_tags(self): self.assertEqual(render_body("foo<i>bar<b>baz</i>quux</b>greg"), "<p>foo<i>barbaz</i>quuxgreg</p>")
def test_empty(self): self.assertEqual(render_body(""), "")
def test_interleaved_tags(self): self.assertEqual( render_body("foo<i>bar<b>baz</i>quux</b>greg"), "<p>foo<i>barbaz</i>quuxgreg</p>" )
def test_markdown_inline(self, delimiter, tag): self.assertEqual( render_body("{delimiter}some text{delimiter}".format(delimiter=delimiter)), "<p><{tag}>some text</{tag}></p>".format(tag=tag) )