diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py index 3d4a6508a1..1ceb51ea2b 100644 --- a/tests/utils_tests/test_html.py +++ b/tests/utils_tests/test_html.py @@ -2,8 +2,12 @@ import os from datetime import datetime from django.test import SimpleTestCase -from django.utils import html, safestring from django.utils.functional import lazystr +from django.utils.html import ( + conditional_escape, escape, escapejs, format_html, html_safe, linebreaks, + smart_urlquote, strip_spaces_between_tags, strip_tags, +) +from django.utils.safestring import mark_safe class TestUtilsHtml(SimpleTestCase): @@ -18,7 +22,6 @@ class TestUtilsHtml(SimpleTestCase): self.assertEqual(function(value), output) def test_escape(self): - f = html.escape items = ( ('&', '&'), ('<', '<'), @@ -30,26 +33,26 @@ class TestUtilsHtml(SimpleTestCase): patterns = ("%s", "asdf%sfdsa", "%s1", "1%sb") for value, output in items: for pattern in patterns: - self.check_output(f, pattern % value, pattern % output) - self.check_output(f, lazystr(pattern % value), pattern % output) + self.check_output(escape, pattern % value, pattern % output) + self.check_output(escape, lazystr(pattern % value), pattern % output) # Check repeated values. - self.check_output(f, value * 2, output * 2) + self.check_output(escape, value * 2, output * 2) # Verify it doesn't double replace &. - self.check_output(f, '<&', '<&') + self.check_output(escape, '<&', '<&') def test_format_html(self): self.assertEqual( - html.format_html("{} {} {third} {fourth}", - "< Dangerous >", - html.mark_safe("safe"), - third="< dangerous again", - fourth=html.mark_safe("safe again") - ), + format_html( + "{} {} {third} {fourth}", + "< Dangerous >", + mark_safe("safe"), + third="< dangerous again", + fourth=mark_safe("safe again"), + ), "< Dangerous > safe < dangerous again safe again" ) def test_linebreaks(self): - f = html.linebreaks items = ( ("para1\n\npara2\r\rpara3", "

para1

\n\n

para2

\n\n

para3

"), ("para1\nsub1\rsub2\n\npara2", "

para1
sub1
sub2

\n\n

para2

"), @@ -57,11 +60,10 @@ class TestUtilsHtml(SimpleTestCase): ("para1\tmore\n\npara2", "

para1\tmore

\n\n

para2

"), ) for value, output in items: - self.check_output(f, value, output) - self.check_output(f, lazystr(value), output) + self.check_output(linebreaks, value, output) + self.check_output(linebreaks, lazystr(value), output) def test_strip_tags(self): - f = html.strip_tags items = ( ('

See: 'é is an apostrophe followed by e acute

', 'See: 'é is an apostrophe followed by e acute'), @@ -83,14 +85,14 @@ class TestUtilsHtml(SimpleTestCase): ('&gotcha&#;<>', '&gotcha&#;<>'), ) for value, output in items: - self.check_output(f, value, output) - self.check_output(f, lazystr(value), output) + self.check_output(strip_tags, value, output) + self.check_output(strip_tags, lazystr(value), output) # Some convoluted syntax for which parsing may differ between python versions - output = html.strip_tags('ript>test</script>') + output = strip_tags('ript>test</script>') self.assertNotIn('&h') + output = strip_tags('&h') self.assertNotIn('