diff --git a/specs/test_html.py b/specs/test_html.py new file mode 100644 index 0000000..f03d4c2 --- /dev/null +++ b/specs/test_html.py @@ -0,0 +1,60 @@ + +try: + import unittest2 as unittest +except ImportError: + import unittest + + +from isso.core import Config +from isso.utils import html + + +class TestHTML(unittest.TestCase): + + def test_markdown(self): + convert = html.Markdown(extensions=()) + examples = [ + ("*Ohai!*", "

Ohai!

"), + ("Hi", "

Hi

"), + ("http://example.org/", '

http://example.org/

')] + + for (input, expected) in examples: + self.assertEqual(convert(input), expected) + + def test_markdown_extensions(self): + convert = html.Markdown(extensions=("strikethrough", "superscript")) + examples = [ + ("~~strike~~ through", "

strike through

"), + ("sup^(script)", "

supscript

")] + + for (input, expected) in examples: + self.assertEqual(convert(input), expected) + + @unittest.skipIf(html.html5lib_version == "0.95", "backport") + def test_sanitizer(self): + sanitizer = html.Sanitizer(elements=[], attributes=[]) + examples = [ + ('Look: ', 'Look: '), + ('Ha', 'Ha'), + ('Ha', 'Ha'), + ('

Test

', '

Test

'), + ('', 'alert("Onoe")')] + + for (input, expected) in examples: + self.assertEqual(html.sanitize(sanitizer, input), expected) + + @unittest.skipIf(html.html5lib_version == "0.95", "backport") + def test_sanitizer_extensions(self): + sanitizer = html.Sanitizer(elements=["img"], attributes=["src"]) + examples = [ + ('', ''), + ('', '')] + + for (input, expected) in examples: + self.assertEqual(html.sanitize(sanitizer, input), expected) + + def test_render(self): + conf = Config.load(None).section("markup") + renderer = html.Markup(conf).render + self.assertEqual(renderer("http://example.org/ and sms:+1234567890"), + '

http://example.org/ and sms:+1234567890

')