Applied ignore_warnings to Django tests

This commit is contained in:
Claude Paroz 2014-12-21 21:19:05 +01:00
parent 66f9a74b45
commit 51890ce889
57 changed files with 513 additions and 711 deletions

View file

@ -1,57 +1,49 @@
import warnings
from django.template.defaultfilters import removetags
from django.test import SimpleTestCase
from django.test import SimpleTestCase, ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.safestring import mark_safe
from ..utils import setup
@ignore_warnings(category=RemovedInDjango20Warning)
class RemovetagsTests(SimpleTestCase):
@setup({'removetags01': '{{ a|removetags:"a b" }} {{ b|removetags:"a b" }}'})
def test_removetags01(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
output = self.engine.render_to_string(
'removetags01',
{
'a': '<a>x</a> <p><b>y</b></p>',
'b': mark_safe('<a>x</a> <p><b>y</b></p>'),
},
)
self.assertEqual(output, 'x &lt;p&gt;y&lt;/p&gt; x <p>y</p>')
output = self.engine.render_to_string(
'removetags01',
{
'a': '<a>x</a> <p><b>y</b></p>',
'b': mark_safe('<a>x</a> <p><b>y</b></p>'),
},
)
self.assertEqual(output, 'x &lt;p&gt;y&lt;/p&gt; x <p>y</p>')
@setup({'removetags02':
'{% autoescape off %}{{ a|removetags:"a b" }} {{ b|removetags:"a b" }}{% endautoescape %}'})
def test_removetags02(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
output = self.engine.render_to_string(
'removetags02',
{
'a': '<a>x</a> <p><b>y</b></p>',
'b': mark_safe('<a>x</a> <p><b>y</b></p>'),
},
)
output = self.engine.render_to_string(
'removetags02',
{
'a': '<a>x</a> <p><b>y</b></p>',
'b': mark_safe('<a>x</a> <p><b>y</b></p>'),
},
)
self.assertEqual(output, 'x <p>y</p> x <p>y</p>')
@ignore_warnings(category=RemovedInDjango20Warning)
class FunctionTests(SimpleTestCase):
def test_removetags(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
self.assertEqual(
removetags(
'some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags',
'script img',
),
'some <b>html</b> with alert("You smell") disallowed tags',
)
self.assertEqual(
removetags(
'some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags',
'script img',
),
'some <b>html</b> with alert("You smell") disallowed tags',
)
def test_non_string_input(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
self.assertEqual(removetags(123, 'a'), '123')
self.assertEqual(removetags(123, 'a'), '123')

View file

@ -1,7 +1,5 @@
import warnings
from django.template.defaultfilters import unordered_list
from django.test import SimpleTestCase
from django.test import SimpleTestCase, ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import python_2_unicode_compatible
from django.utils.safestring import mark_safe
@ -16,11 +14,10 @@ class UnorderedListTests(SimpleTestCase):
output = self.engine.render_to_string('unordered_list01', {'a': ['x>', ['<y']]})
self.assertEqual(output, '\t<li>x&gt;\n\t<ul>\n\t\t<li>&lt;y</li>\n\t</ul>\n\t</li>')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'unordered_list02': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
def test_unordered_list02(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
output = self.engine.render_to_string('unordered_list02', {'a': ['x>', ['<y']]})
output = self.engine.render_to_string('unordered_list02', {'a': ['x>', ['<y']]})
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
@setup({'unordered_list03': '{{ a|unordered_list }}'})
@ -39,41 +36,32 @@ class UnorderedListTests(SimpleTestCase):
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
@ignore_warnings(category=RemovedInDjango20Warning)
class DeprecatedUnorderedListSyntaxTests(SimpleTestCase):
@setup({'unordered_list01': '{{ a|unordered_list }}'})
def test_unordered_list01(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
output = self.engine.render_to_string('unordered_list01', {'a': ['x>', [['<y', []]]]})
output = self.engine.render_to_string('unordered_list01', {'a': ['x>', [['<y', []]]]})
self.assertEqual(output, '\t<li>x&gt;\n\t<ul>\n\t\t<li>&lt;y</li>\n\t</ul>\n\t</li>')
@setup({'unordered_list02': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
def test_unordered_list02(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
output = self.engine.render_to_string('unordered_list02', {'a': ['x>', [['<y', []]]]})
output = self.engine.render_to_string('unordered_list02', {'a': ['x>', [['<y', []]]]})
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
@setup({'unordered_list03': '{{ a|unordered_list }}'})
def test_unordered_list03(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
output = self.engine.render_to_string('unordered_list03', {'a': ['x>', [[mark_safe('<y'), []]]]})
output = self.engine.render_to_string('unordered_list03', {'a': ['x>', [[mark_safe('<y'), []]]]})
self.assertEqual(output, '\t<li>x&gt;\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
@setup({'unordered_list04': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
def test_unordered_list04(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
output = self.engine.render_to_string('unordered_list04', {'a': ['x>', [[mark_safe('<y'), []]]]})
output = self.engine.render_to_string('unordered_list04', {'a': ['x>', [[mark_safe('<y'), []]]]})
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
@setup({'unordered_list05': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
def test_unordered_list05(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
output = self.engine.render_to_string('unordered_list05', {'a': ['x>', [['<y', []]]]})
output = self.engine.render_to_string('unordered_list05', {'a': ['x>', [['<y', []]]]})
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
@ -130,28 +118,26 @@ class FunctionTests(SimpleTestCase):
self.assertEqual(unordered_list(item_generator()), '\t<li>ulitem-a</li>\n\t<li>ulitem-b</li>')
@ignore_warnings(category=RemovedInDjango20Warning)
def test_legacy(self):
"""
Old format for unordered lists should still work
"""
with warnings.catch_warnings():
warnings.simplefilter('ignore', RemovedInDjango20Warning)
self.assertEqual(unordered_list(['item 1', []]), '\t<li>item 1</li>')
self.assertEqual(unordered_list(['item 1', []]), '\t<li>item 1</li>')
self.assertEqual(
unordered_list(['item 1', [['item 1.1', []]]]),
'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t</ul>\n\t</li>',
)
self.assertEqual(
unordered_list(['item 1', [['item 1.1', []]]]),
'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t</ul>\n\t</li>',
)
self.assertEqual(
unordered_list(['item 1', [['item 1.1', []],
['item 1.2', []]]]), '\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1'
'</li>\n\t\t<li>item 1.2</li>\n\t</ul>\n\t</li>',
)
self.assertEqual(
unordered_list(['item 1', [['item 1.1', []],
['item 1.2', []]]]), '\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1'
'</li>\n\t\t<li>item 1.2</li>\n\t</ul>\n\t</li>',
)
self.assertEqual(
unordered_list(['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]),
'\t<li>States\n\t<ul>\n\t\t<li>Kansas\n\t\t<ul>\n\t\t\t<li>Lawrence</li>'
'\n\t\t\t<li>Topeka</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>Illinois</li>\n\t</ul>\n\t</li>',
)
self.assertEqual(
unordered_list(['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]),
'\t<li>States\n\t<ul>\n\t\t<li>Kansas\n\t\t<ul>\n\t\t\t<li>Lawrence</li>'
'\n\t\t\t<li>Topeka</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>Illinois</li>\n\t</ul>\n\t</li>',
)

View file

@ -1,7 +1,5 @@
import warnings
from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from django.test import SimpleTestCase, ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from ..utils import setup
@ -141,24 +139,21 @@ class CycleTagTests(SimpleTestCase):
output = self.engine.render_to_string('cycle25', {'a': '<'})
self.assertEqual(output, '&lt;')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'cycle26': '{% load cycle from future %}{% cycle a b as ab %}{% cycle ab %}'})
def test_cycle26(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('cycle26', {'a': '<', 'b': '>'})
output = self.engine.render_to_string('cycle26', {'a': '<', 'b': '>'})
self.assertEqual(output, '&lt;&gt;')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'cycle27': '{% load cycle from future %}'
'{% autoescape off %}{% cycle a b as ab %}{% cycle ab %}{% endautoescape %}'})
def test_cycle27(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('cycle27', {'a': '<', 'b': '>'})
output = self.engine.render_to_string('cycle27', {'a': '<', 'b': '>'})
self.assertEqual(output, '<>')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'cycle28': '{% load cycle from future %}{% cycle a|safe b as ab %}{% cycle ab %}'})
def test_cycle28(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('cycle28', {'a': '<', 'b': '>'})
output = self.engine.render_to_string('cycle28', {'a': '<', 'b': '>'})
self.assertEqual(output, '<&gt;')

View file

@ -1,9 +1,8 @@
# coding: utf-8
from __future__ import unicode_literals
import warnings
from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from django.test import SimpleTestCase, ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from ..utils import setup, SomeClass, SomeOtherException, UTF8Class
@ -76,14 +75,13 @@ class FilterSyntaxTests(SimpleTestCase):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('filter-syntax08')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'filter-syntax09': '{{ var|removetags:"b i"|upper|lower }}'})
def test_filter_syntax09(self):
"""
Chained filters, with an argument to the first one
"""
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('filter-syntax09', {'var': '<b><i>Yes</i></b>'})
output = self.engine.render_to_string('filter-syntax09', {'var': '<b><i>Yes</i></b>'})
self.assertEqual(output, 'yes')
@setup({'filter-syntax10': r'{{ var|default_if_none:" endquote\" hah" }}'})

View file

@ -1,7 +1,5 @@
import warnings
from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from django.test import SimpleTestCase, ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from ..utils import setup
@ -59,31 +57,27 @@ class FirstOfTagTests(SimpleTestCase):
output = self.engine.render_to_string('firstof10', {'a': '<'})
self.assertEqual(output, '&lt;')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'firstof11': '{% load firstof from future %}{% firstof a b %}'})
def test_firstof11(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('firstof11', {'a': '<', 'b': '>'})
output = self.engine.render_to_string('firstof11', {'a': '<', 'b': '>'})
self.assertEqual(output, '&lt;')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'firstof12': '{% load firstof from future %}{% firstof a b %}'})
def test_firstof12(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('firstof12', {'a': '', 'b': '>'})
output = self.engine.render_to_string('firstof12', {'a': '', 'b': '>'})
self.assertEqual(output, '&gt;')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'firstof13': '{% load firstof from future %}'
'{% autoescape off %}{% firstof a %}{% endautoescape %}'})
def test_firstof13(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('firstof13', {'a': '<'})
output = self.engine.render_to_string('firstof13', {'a': '<'})
self.assertEqual(output, '<')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'firstof14': '{% load firstof from future %}{% firstof a|safe b %}'})
def test_firstof14(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('firstof14', {'a': '<'})
output = self.engine.render_to_string('firstof14', {'a': '<'})
self.assertEqual(output, '<')

View file

@ -1,7 +1,5 @@
import warnings
from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from django.test import SimpleTestCase, ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from ..utils import setup
@ -129,48 +127,44 @@ class ForTagTests(SimpleTestCase):
# These tests raise deprecation warnings and will raise an exception
# in Django 2.0. The existing behavior is silent truncation if the
# length of loopvars differs to the length of each set of items.
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'for-tag-unpack10': '{% for x,y in items %}{{ x }}:{{ y }}/{% endfor %}'})
def test_for_tag_unpack10(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string(
'for-tag-unpack10',
{'items': (('one', 1, 'carrot'), ('two', 2, 'orange'))},
)
output = self.engine.render_to_string(
'for-tag-unpack10',
{'items': (('one', 1, 'carrot'), ('two', 2, 'orange'))},
)
self.assertEqual(output, 'one:1/two:2/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'for-tag-unpack11': '{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}'})
def test_for_tag_unpack11(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string(
'for-tag-unpack11',
{'items': (('one', 1), ('two', 2))},
)
output = self.engine.render_to_string(
'for-tag-unpack11',
{'items': (('one', 1), ('two', 2))},
)
if self.engine.string_if_invalid:
self.assertEqual(output, 'one:1,INVALID/two:2,INVALID/')
else:
self.assertEqual(output, 'one:1,/two:2,/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'for-tag-unpack12': '{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}'})
def test_for_tag_unpack12(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string(
'for-tag-unpack12',
{'items': (('one', 1, 'carrot'), ('two', 2))}
)
output = self.engine.render_to_string(
'for-tag-unpack12',
{'items': (('one', 1, 'carrot'), ('two', 2))}
)
if self.engine.string_if_invalid:
self.assertEqual(output, 'one:1,carrot/two:2,INVALID/')
else:
self.assertEqual(output, 'one:1,carrot/two:2,/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'for-tag-unpack14': '{% for x,y in items %}{{ x }}:{{ y }}/{% endfor %}'})
def test_for_tag_unpack14(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('for-tag-unpack14', {'items': (1, 2)})
output = self.engine.render_to_string('for-tag-unpack14', {'items': (1, 2)})
if self.engine.string_if_invalid:
self.assertEqual(output, 'INVALID:INVALID/INVALID:INVALID/')

View file

@ -1,7 +1,6 @@
import os
import warnings
from django.test import SimpleTestCase
from django.test import ignore_warnings, SimpleTestCase
from django.utils.deprecation import RemovedInDjango19Warning
from ..utils import ROOT, setup
@ -32,20 +31,18 @@ class SsiTagTests(SimpleTestCase):
self.assertEqual(output, ''),
# Test passing as a variable
@ignore_warnings(category=RemovedInDjango19Warning)
@setup({'ssi04': '{% load ssi from future %}{% ssi ssi_file %}'})
def test_ssi04(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango19Warning)
output = self.engine.render_to_string('ssi04', {
'ssi_file': os.path.join(ROOT, 'templates', 'ssi_include.html')
})
output = self.engine.render_to_string('ssi04', {
'ssi_file': os.path.join(ROOT, 'templates', 'ssi_include.html')
})
self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n')
@ignore_warnings(category=RemovedInDjango19Warning)
@setup({'ssi05': '{% load ssi from future %}{% ssi ssi_file %}'})
def test_ssi05(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango19Warning)
output = self.engine.render_to_string('ssi05', {'ssi_file': 'no_file'})
output = self.engine.render_to_string('ssi05', {'ssi_file': 'no_file'})
self.assertEqual(output, '')
# Test parsed output

View file

@ -1,9 +1,7 @@
# coding: utf-8
import warnings
from django.core.urlresolvers import NoReverseMatch
from django.template import TemplateSyntaxError
from django.test import override_settings, SimpleTestCase
from django.test import ignore_warnings, override_settings, SimpleTestCase
from django.utils.deprecation import RemovedInDjango20Warning
from ..utils import setup
@ -13,46 +11,40 @@ from ..utils import setup
class UrlTagTests(SimpleTestCase):
# Successes
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url01': '{% url "template_tests.views.client" client.id %}'})
def test_url01(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url01', {'client': {'id': 1}})
output = self.engine.render_to_string('url01', {'client': {'id': 1}})
self.assertEqual(output, '/client/1/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url02': '{% url "template_tests.views.client_action" id=client.id action="update" %}'})
def test_url02(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url02', {'client': {'id': 1}})
output = self.engine.render_to_string('url02', {'client': {'id': 1}})
self.assertEqual(output, '/client/1/update/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url02a': '{% url "template_tests.views.client_action" client.id "update" %}'})
def test_url02a(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url02a', {'client': {'id': 1}})
output = self.engine.render_to_string('url02a', {'client': {'id': 1}})
self.assertEqual(output, '/client/1/update/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url02b': "{% url 'template_tests.views.client_action' id=client.id action='update' %}"})
def test_url02b(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url02b', {'client': {'id': 1}})
output = self.engine.render_to_string('url02b', {'client': {'id': 1}})
self.assertEqual(output, '/client/1/update/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url02c': "{% url 'template_tests.views.client_action' client.id 'update' %}"})
def test_url02c(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url02c', {'client': {'id': 1}})
output = self.engine.render_to_string('url02c', {'client': {'id': 1}})
self.assertEqual(output, '/client/1/update/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url03': '{% url "template_tests.views.index" %}'})
def test_url03(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url03')
output = self.engine.render_to_string('url03')
self.assertEqual(output, '/')
@setup({'url04': '{% url "named.client" client.id %}'})
@ -70,11 +62,10 @@ class UrlTagTests(SimpleTestCase):
output = self.engine.render_to_string('url06', {'v': 'Ω'})
self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url07': '{% url "template_tests.views.client2" tag=v %}'})
def test_url07(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url07', {'v': 'Ω'})
output = self.engine.render_to_string('url07', {'v': 'Ω'})
self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/')
@setup({'url08': '{% url "метка_оператора" v %}'})
@ -87,62 +78,54 @@ class UrlTagTests(SimpleTestCase):
output = self.engine.render_to_string('url09', {'v': 'Ω'})
self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url10': '{% url "template_tests.views.client_action" id=client.id action="two words" %}'})
def test_url10(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url10', {'client': {'id': 1}})
output = self.engine.render_to_string('url10', {'client': {'id': 1}})
self.assertEqual(output, '/client/1/two%20words/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url11': '{% url "template_tests.views.client_action" id=client.id action="==" %}'})
def test_url11(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url11', {'client': {'id': 1}})
output = self.engine.render_to_string('url11', {'client': {'id': 1}})
self.assertEqual(output, '/client/1/==/')
@setup({'url12': '{% url "template_tests.views.client_action" '
'id=client.id action="!$&\'()*+,;=~:@," %}'})
@ignore_warnings(category=RemovedInDjango20Warning)
def test_url12(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url12', {'client': {'id': 1}})
output = self.engine.render_to_string('url12', {'client': {'id': 1}})
self.assertEqual(output, '/client/1/!$&\'()*+,;=~:@,/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url13': '{% url "template_tests.views.client_action" '
'id=client.id action=arg|join:"-" %}'})
def test_url13(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url13', {'client': {'id': 1}, 'arg': ['a', 'b']})
output = self.engine.render_to_string('url13', {'client': {'id': 1}, 'arg': ['a', 'b']})
self.assertEqual(output, '/client/1/a-b/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url14': '{% url "template_tests.views.client_action" client.id arg|join:"-" %}'})
def test_url14(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url14', {'client': {'id': 1}, 'arg': ['a', 'b']})
output = self.engine.render_to_string('url14', {'client': {'id': 1}, 'arg': ['a', 'b']})
self.assertEqual(output, '/client/1/a-b/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url15': '{% url "template_tests.views.client_action" 12 "test" %}'})
def test_url15(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url15')
output = self.engine.render_to_string('url15')
self.assertEqual(output, '/client/12/test/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url18': '{% url "template_tests.views.client" "1,2" %}'})
def test_url18(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url18')
output = self.engine.render_to_string('url18')
self.assertEqual(output, '/client/1,2/')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url19': '{% url named_url client.id %}'})
def test_url19(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url19', {'client': {'id': 1}, 'named_url': 'template_tests.views.client'})
output = self.engine.render_to_string('url19', {'client': {'id': 1}, 'named_url': 'template_tests.views.client'})
self.assertEqual(output, '/client/1/')
@setup({'url20': '{% url url_name_in_var client.id %}'})
@ -161,12 +144,11 @@ class UrlTagTests(SimpleTestCase):
with self.assertRaises(NoReverseMatch):
self.engine.render_to_string('url-fail02')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url-fail03': '{% url "template_tests.views.client" %}'})
def test_url_fail03(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
with self.assertRaises(NoReverseMatch):
self.engine.render_to_string('url-fail03')
with self.assertRaises(NoReverseMatch):
self.engine.render_to_string('url-fail03')
@setup({'url-fail04': '{% url "view" id, %}'})
def test_url_fail04(self):
@ -208,12 +190,11 @@ class UrlTagTests(SimpleTestCase):
with self.assertRaises(NoReverseMatch):
self.engine.render_to_string('url-fail12', {'named_url': 'no_such_view'})
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url-fail13': '{% url named_url %}'})
def test_url_fail13(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
with self.assertRaises(NoReverseMatch):
self.engine.render_to_string('url-fail13', {'named_url': 'template_tests.views.client'})
with self.assertRaises(NoReverseMatch):
self.engine.render_to_string('url-fail13', {'named_url': 'template_tests.views.client'})
@setup({'url-fail14': '{% url named_url id, %}'})
def test_url_fail14(self):
@ -246,18 +227,16 @@ class UrlTagTests(SimpleTestCase):
self.engine.render_to_string('url-fail19', {'named_url': 'view'})
# {% url ... as var %}
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url-asvar01': '{% url "template_tests.views.index" as url %}'})
def test_url_asvar01(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url-asvar01')
output = self.engine.render_to_string('url-asvar01')
self.assertEqual(output, '')
@ignore_warnings(category=RemovedInDjango20Warning)
@setup({'url-asvar02': '{% url "template_tests.views.index" as url %}{{ url }}'})
def test_url_asvar02(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango20Warning)
output = self.engine.render_to_string('url-asvar02')
output = self.engine.render_to_string('url-asvar02')
self.assertEqual(output, '/')
@setup({'url-asvar03': '{% url "no_such_view" as url %}{{ url }}'})

View file

@ -1,9 +1,9 @@
from __future__ import unicode_literals
from unittest import TestCase
import warnings
from django import template
from django.test import ignore_warnings
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
@ -246,6 +246,7 @@ class CustomTagTests(TestCase):
self.verify_tag(custom.inclusion_tag_current_app, 'inclusion_tag_current_app')
self.verify_tag(custom.inclusion_unlimited_args_kwargs, 'inclusion_unlimited_args_kwargs')
@ignore_warnings(category=RemovedInDjango20Warning)
def test_15070_current_app(self):
"""
Test that inclusion tag passes down `current_app` of context to the
@ -255,10 +256,9 @@ class CustomTagTests(TestCase):
t = template.Template('{% load custom %}{% inclusion_tag_current_app %}')
self.assertEqual(t.render(c).strip(), 'None')
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=RemovedInDjango20Warning)
c = template.Context({}, current_app='advanced')
self.assertEqual(t.render(c).strip(), 'advanced')
# That part produces the deprecation warning
c = template.Context({}, current_app='advanced')
self.assertEqual(t.render(c).strip(), 'advanced')
def test_15070_use_l10n(self):
"""

View file

@ -19,9 +19,9 @@ from django.template import TemplateDoesNotExist, Context
from django.template.loaders import cached, eggs
from django.template.engine import Engine
from django.template import loader
from django.test import SimpleTestCase, override_settings
from django.test.utils import IgnorePendingDeprecationWarningsMixin
from django.test import SimpleTestCase, ignore_warnings, override_settings
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils._os import upath
from django.utils.six import StringIO
@ -166,11 +166,12 @@ class RenderToStringTest(SimpleTestCase):
loader.select_template, [])
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATES_DIR],
}])
class DeprecatedRenderToStringTest(IgnorePendingDeprecationWarningsMixin, SimpleTestCase):
class DeprecatedRenderToStringTest(SimpleTestCase):
def test_existing_context_kept_clean(self):
context = Context({'obj': 'before'})
@ -192,10 +193,11 @@ class DeprecatedRenderToStringTest(IgnorePendingDeprecationWarningsMixin, Simple
loader.render_to_string('test_context_stack.html', context_instance=Context()).strip())
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
}])
class TemplateDirsOverrideTest(IgnorePendingDeprecationWarningsMixin, SimpleTestCase):
class TemplateDirsOverrideTest(SimpleTestCase):
dirs_tuple = (os.path.join(os.path.dirname(upath(__file__)), 'other_templates'),)
dirs_list = list(dirs_tuple)

View file

@ -4,14 +4,13 @@ from datetime import datetime
import os
import pickle
import time
import warnings
from django.test import RequestFactory, SimpleTestCase
from django.conf import settings
from django.template import Template, Context
from django.template.response import (TemplateResponse, SimpleTemplateResponse,
ContentNotRenderedError)
from django.test import override_settings
from django.test import ignore_warnings, override_settings
from django.utils._os import upath
from django.utils.deprecation import RemovedInDjango20Warning
@ -256,10 +255,9 @@ class TemplateResponseTest(SimpleTestCase):
self.assertEqual(response['content-type'], 'application/json')
self.assertEqual(response.status_code, 504)
@ignore_warnings(category=RemovedInDjango20Warning)
def test_custom_app(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=RemovedInDjango20Warning)
response = self._response('{{ foo }}', current_app="foobar")
response = self._response('{{ foo }}', current_app="foobar")
rc = response.resolve_context(response.context_data)