diff options
| author | Erik Romijn <eromijn@solidlinks.nl> | 2014-03-01 10:42:08 +0100 |
|---|---|---|
| committer | Erik Romijn <eromijn@solidlinks.nl> | 2014-03-01 14:07:57 +0100 |
| commit | 775975f15d7d461c154e558cba5fb0592539126f (patch) | |
| tree | 818be1016cf0527aa38888151778bfd59fcd9012 /tests | |
| parent | 8c98f39624a60c63a16e097b64e5f71ecc27271f (diff) | |
Fixed #22130 -- Deprecated fix_ampersands, removed utils.clean_html()
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/defaultfilters/tests.py | 8 | ||||
| -rw-r--r-- | tests/template_tests/tests.py | 5 | ||||
| -rw-r--r-- | tests/utils_tests/test_html.py | 49 |
3 files changed, 38 insertions, 24 deletions
diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py index f10b1c3305..5ff31cc025 100644 --- a/tests/defaultfilters/tests.py +++ b/tests/defaultfilters/tests.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import datetime import decimal import unittest +import warnings from django.template.defaultfilters import ( add, addslashes, capfirst, center, cut, date, default, default_if_none, @@ -124,8 +125,11 @@ class DefaultFiltersTests(TestCase): 'paragraph separator:\\u2029and line separator:\\u2028') def test_fix_ampersands(self): - self.assertEqual(fix_ampersands_filter('Jack & Jill & Jeroboam'), - 'Jack & Jill & Jeroboam') + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always", DeprecationWarning) + self.assertEqual(fix_ampersands_filter('Jack & Jill & Jeroboam'), + 'Jack & Jill & Jeroboam') + self.assertEqual(len(w), 1) def test_linenumbers(self): self.assertEqual(linenumbers('line 1\nline 2'), diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index dee11e4bba..1a0e0d4456 100644 --- a/tests/template_tests/tests.py +++ b/tests/template_tests/tests.py @@ -607,7 +607,10 @@ class TemplateTests(TestCase): failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name)) try: - output = self.render(test_template, vals) + with warnings.catch_warnings(): + # Ignore deprecation of fix_ampersands + warnings.filterwarnings("ignore", category=DeprecationWarning, module='django.template.defaultfilters') + output = self.render(test_template, vals) except ShouldNotExecuteException: failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template rendering invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name)) except ContextStackException: diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py index cafdee5c03..3f316e1a8b 100644 --- a/tests/utils_tests/test_html.py +++ b/tests/utils_tests/test_html.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals from datetime import datetime import os from unittest import TestCase +import warnings from django.utils import html, safestring from django.utils._os import upath @@ -130,25 +131,29 @@ class TestUtilsHtml(TestCase): self.check_output(f, in_pattern % {'entity': entity}, output) def test_fix_ampersands(self): - f = html.fix_ampersands - # Strings without ampersands or with ampersands already encoded. - values = ("a", "b", "&a;", "& &x; ", "asdf") - patterns = ( - ("%s", "%s"), - ("&%s", "&%s"), - ("&%s&", "&%s&"), - ) - for value in values: - for in_pattern, out_pattern in patterns: - self.check_output(f, in_pattern % value, out_pattern % value) - # Strings with ampersands that need encoding. - items = ( - ("&#;", "&#;"), - ("ͫ ;", "&#875 ;"), - ("abc;", "&#4abc;"), - ) - for value, output in items: - self.check_output(f, value, output) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + f = html.fix_ampersands + # Strings without ampersands or with ampersands already encoded. + values = ("a", "b", "&a;", "& &x; ", "asdf") + patterns = ( + ("%s", "%s"), + ("&%s", "&%s"), + ("&%s&", "&%s&"), + ) + + for value in values: + for in_pattern, out_pattern in patterns: + self.check_output(f, in_pattern % value, out_pattern % value) + + # Strings with ampersands that need encoding. + items = ( + ("&#;", "&#;"), + ("ͫ ;", "&#875 ;"), + ("abc;", "&#4abc;"), + ) + for value, output in items: + self.check_output(f, value, output) def test_escapejs(self): f = html.escapejs @@ -171,8 +176,10 @@ class TestUtilsHtml(TestCase): # also a regression test for #7267: this used to raise an UnicodeDecodeError ('<p>* foo</p><p>* bar</p>', '<ul>\n<li> foo</li><li> bar</li>\n</ul>'), ) - for value, output in items: - self.check_output(f, value, output) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + for value, output in items: + self.check_output(f, value, output) def test_remove_tags(self): f = html.remove_tags |
