Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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))
Example #5
0
 def get_rendered_body(self, obj):
     """Returns the rendered body content."""
     return render_body(obj["body"])
Example #6
0
 def test_unpaired_end_tag(self):
     self.assertEqual(render_body("foo</i>bar"), "<p>foobar</p>")
Example #7
0
 def test_script_tag(self):
     raw_body = '<script type="text/javascript">alert("evil script");</script>'
     self.assertEqual(render_body(raw_body), 'alert("evil script");')
Example #8
0
 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))
Example #9
0
 def test_script_tag(self):
     raw_body = '<script type="text/javascript">alert("evil script");</script>'
     self.assertEqual(render_body(raw_body), 'alert("evil script");')
Example #10
0
 def test_disallowed_img_tag(self):
     raw_body = '<img src="gopher://foo">'
     self.assertEqual(render_body(raw_body), "<p></p>")
Example #11
0
 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))
Example #12
0
 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>")
Example #13
0
 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))
Example #14
0
 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)
Example #15
0
 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))
Example #16
0
 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))
Example #17
0
 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>")
Example #18
0
 def test_unpaired_end_tag(self):
     self.assertEqual(render_body("foo</i>bar"), "<p>foobar</p>")
Example #19
0
 def test_disallowed_img_tag(self):
     raw_body = '<img src="gopher://foo">'
     self.assertEqual(render_body(raw_body), "<p></p>")
Example #20
0
 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>")
Example #21
0
 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))
Example #22
0
 def test_empty(self):
     self.assertEqual(render_body(""), "")
Example #23
0
 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>"
     )
Example #24
0
 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)
     )
Example #25
0
 def get_rendered_body(self, obj):
     """Returns the rendered body content."""
     return render_body(obj["body"])
Example #26
0
 def test_empty(self):
     self.assertEqual(render_body(""), "")