How to use render_body method in Selene

Best Python code snippet using selene_python

test_render.py

Source:test_render.py Github

copy

Full Screen

...10@ddt.ddt11class RenderBodyTest(TestCase):12 """Tests for render_body"""13 def test_empty(self):14 self.assertEqual(render_body(""), "")15 @ddt.data(16 ("*", "em"),17 ("**", "strong"),18 ("`", "code"),19 )20 @ddt.unpack21 def test_markdown_inline(self, delimiter, tag):22 self.assertEqual(23 render_body(u"{delimiter}some text{delimiter}".format(delimiter=delimiter)),24 u"<p><{tag}>some text</{tag}></p>".format(tag=tag)25 )26 @ddt.data(27 "b", "blockquote", "code", "del", "dd", "dl", "dt", "em", "h1", "h2", "h3", "i", "kbd",28 "li", "ol", "p", "pre", "s", "sup", "sub", "strong", "strike", "ul"29 )30 def test_openclose_tag(self, tag):31 raw_body = "<{tag}>some text</{tag}>".format(tag=tag)32 is_inline_tag = tag in ["b", "code", "del", "em", "i", "kbd", "s", "sup", "sub", "strong", "strike"]33 rendered_body = _add_p_tags(raw_body) if is_inline_tag else raw_body34 self.assertEqual(render_body(raw_body), rendered_body)35 @ddt.data("br", "hr")36 def test_selfclosing_tag(self, tag):37 raw_body = "<{tag}>".format(tag=tag)38 is_inline_tag = tag == "br"39 rendered_body = _add_p_tags(raw_body) if is_inline_tag else raw_body40 self.assertEqual(render_body(raw_body), rendered_body)41 @ddt.data("http", "https", "ftp")42 def test_allowed_a_tag(self, protocol):43 raw_body = '<a href="{protocol}://foo" title="bar">baz</a>'.format(protocol=protocol)44 self.assertEqual(render_body(raw_body), _add_p_tags(raw_body))45 def test_disallowed_a_tag(self):46 raw_body = '<a href="gopher://foo">link content</a>'47 self.assertEqual(render_body(raw_body), "<p>link content</p>")48 @ddt.data("http", "https")49 def test_allowed_img_tag(self, protocol):50 raw_body = '<img src="{protocol}://foo" width="111" height="222" alt="bar" title="baz">'.format(51 protocol=protocol52 )53 self.assertEqual(render_body(raw_body), _add_p_tags(raw_body))54 def test_disallowed_img_tag(self):55 raw_body = '<img src="gopher://foo">'56 self.assertEqual(render_body(raw_body), "<p></p>")57 def test_script_tag(self):58 raw_body = '<script type="text/javascript">alert("evil script");</script>'59 self.assertEqual(render_body(raw_body), 'alert("evil script");')60 @ddt.data("p", "br", "li", "hr") # img is tested above61 def test_allowed_unpaired_tags(self, tag):62 raw_body = "foo<{tag}>bar".format(tag=tag)63 self.assertEqual(render_body(raw_body), _add_p_tags(raw_body))64 def test_unpaired_start_tag(self):65 self.assertEqual(render_body("foo<i>bar"), "<p>foobar</p>")66 def test_unpaired_end_tag(self):67 self.assertEqual(render_body("foo</i>bar"), "<p>foobar</p>")68 def test_interleaved_tags(self):69 self.assertEqual(70 render_body("foo<i>bar<b>baz</i>quux</b>greg"),71 "<p>foo<i>barbaz</i>quuxgreg</p>"...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful