summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-05-02 18:04:51 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-05-11 09:07:33 +0200
commit72a170b4c3c4c2db8192bb1a6424bcc8eb533973 (patch)
treeba027dc00dc31cd0e2e8869e45eed35162bf1e98 /tests/template_tests
parentd8cb8fdf40b92961a62effbc9231583901e258b5 (diff)
downloaddjango-72a170b4c3c4c2db8192bb1a6424bcc8eb533973.tar.gz
Fixed #25236 -- Deprecated {% ifequal %} and {% ifnotequal %} template tags.
The {% if %} tag provides all features of these tags. Since Django 1.2 (May 17, 2010), the docs have hinted that {% ifequal %} and {% ifnotequal %} will be deprecated in a future Django version. Time to make it official.
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/syntax_tests/test_autoescape.py4
-rw-r--r--tests/template_tests/syntax_tests/test_if_equal.py31
-rw-r--r--tests/template_tests/syntax_tests/test_resetcycle.py8
-rw-r--r--tests/template_tests/test_nodelist.py4
4 files changed, 39 insertions, 8 deletions
diff --git a/tests/template_tests/syntax_tests/test_autoescape.py b/tests/template_tests/syntax_tests/test_autoescape.py
index e684bc94bd..84af2baf5f 100644
--- a/tests/template_tests/syntax_tests/test_autoescape.py
+++ b/tests/template_tests/syntax_tests/test_autoescape.py
@@ -1,5 +1,6 @@
from django.template import TemplateSyntaxError
-from django.test import SimpleTestCase
+from django.test import SimpleTestCase, ignore_warnings
+from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.safestring import mark_safe
from ..utils import SafeClass, UnsafeClass, setup
@@ -81,6 +82,7 @@ class AutoescapeTagTests(SimpleTestCase):
with self.assertRaises(TemplateSyntaxError):
self.engine.render_to_string('autoescape-filtertag01', {'first': '<a>'})
+ @ignore_warnings(category=RemovedInDjango40Warning)
@setup({'autoescape-ifequal01': '{% ifequal var "this & that" %}yes{% endifequal %}'})
def test_autoescape_ifequal01(self):
"""
diff --git a/tests/template_tests/syntax_tests/test_if_equal.py b/tests/template_tests/syntax_tests/test_if_equal.py
index f416b95523..29ad00de8d 100644
--- a/tests/template_tests/syntax_tests/test_if_equal.py
+++ b/tests/template_tests/syntax_tests/test_if_equal.py
@@ -1,10 +1,12 @@
from django.template import TemplateSyntaxError
from django.template.defaulttags import IfEqualNode
-from django.test import SimpleTestCase
+from django.test import SimpleTestCase, ignore_warnings
+from django.utils.deprecation import RemovedInDjango40Warning
from ..utils import setup
+@ignore_warnings(category=RemovedInDjango40Warning)
class IfEqualTagTests(SimpleTestCase):
@setup({'ifequal01': '{% ifequal a b %}yes{% endifequal %}'})
@@ -196,6 +198,7 @@ class IfEqualTagTests(SimpleTestCase):
self.assertEqual(output, 'x')
+@ignore_warnings(category=RemovedInDjango40Warning)
class IfNotEqualTagTests(SimpleTestCase):
@setup({'ifnotequal01': '{% ifnotequal a b %}yes{% endifnotequal %}'})
@@ -224,7 +227,31 @@ class IfNotEqualTagTests(SimpleTestCase):
self.engine.render_to_string('one_var', {'a': 1})
-class IfEqualTests(SimpleTestCase):
+class DeprecationTests(SimpleTestCase):
+ @setup(
+ {'ifequal_warning': '{% ifequal a b %}yes{% endifequal %}'},
+ test_once=True,
+ )
+ def test_ifequal_warning(self):
+ msg = (
+ 'The {% ifequal %} template tag is deprecated in favor of '
+ '{% if %}.'
+ )
+ with self.assertRaisesMessage(RemovedInDjango40Warning, msg):
+ self.engine.render_to_string('ifequal_warning', {'a': 1, 'b': 2})
+
+ @setup(
+ {'ifnotequal_warning': '{% ifnotequal a b %}yes{% endifnoequal %}'},
+ test_once=True,
+ )
+ def test_ifnotequal_warning(self):
+ msg = (
+ 'The {% ifnotequal %} template tag is deprecated in favor of '
+ '{% if %}.'
+ )
+ with self.assertRaisesMessage(RemovedInDjango40Warning, msg):
+ self.engine.render_to_string('ifnotequal_warning', {'a': 1, 'b': 2})
+
def test_repr(self):
node = IfEqualNode(var1='a', var2='b', nodelist_true=[], nodelist_false=[], negate=False)
self.assertEqual(repr(node), '<IfEqualNode>')
diff --git a/tests/template_tests/syntax_tests/test_resetcycle.py b/tests/template_tests/syntax_tests/test_resetcycle.py
index 669a849864..7c3bfc55fb 100644
--- a/tests/template_tests/syntax_tests/test_resetcycle.py
+++ b/tests/template_tests/syntax_tests/test_resetcycle.py
@@ -75,9 +75,9 @@ class ResetCycleTagTests(SimpleTestCase):
@setup({'resetcycle10': "{% for i in test %}"
"{% cycle 'X' 'Y' 'Z' as XYZ %}"
"{% cycle 'a' 'b' 'c' as abc %}"
- "{% ifequal i 1 %}"
+ "{% if i == 1 %}"
"{% resetcycle abc %}"
- "{% endifequal %}"
+ "{% endif %}"
"{% endfor %}"})
def test_resetcycle10(self):
output = self.engine.render_to_string('resetcycle10', {'test': list(range(5))})
@@ -86,9 +86,9 @@ class ResetCycleTagTests(SimpleTestCase):
@setup({'resetcycle11': "{% for i in test %}"
"{% cycle 'X' 'Y' 'Z' as XYZ %}"
"{% cycle 'a' 'b' 'c' as abc %}"
- "{% ifequal i 1 %}"
+ "{% if i == 1 %}"
"{% resetcycle XYZ %}"
- "{% endifequal %}"
+ "{% endif %}"
"{% endfor %}"})
def test_resetcycle11(self):
output = self.engine.render_to_string('resetcycle11', {'test': list(range(5))})
diff --git a/tests/template_tests/test_nodelist.py b/tests/template_tests/test_nodelist.py
index d3b8a5bb7e..b0e97b88da 100644
--- a/tests/template_tests/test_nodelist.py
+++ b/tests/template_tests/test_nodelist.py
@@ -1,6 +1,7 @@
from django.template import Context, Engine
from django.template.base import TextNode, VariableNode
-from django.test import SimpleTestCase
+from django.test import SimpleTestCase, ignore_warnings
+from django.utils.deprecation import RemovedInDjango40Warning
class NodelistTest(SimpleTestCase):
@@ -20,6 +21,7 @@ class NodelistTest(SimpleTestCase):
vars = template.nodelist.get_nodes_by_type(VariableNode)
self.assertEqual(len(vars), 1)
+ @ignore_warnings(category=RemovedInDjango40Warning)
def test_ifequal(self):
template = self.engine.from_string('{% ifequal x y %}{{ a }}{% endifequal %}')
vars = template.nodelist.get_nodes_by_type(VariableNode)