summaryrefslogtreecommitdiff
path: root/tests/template_tests/syntax_tests/test_if.py
diff options
context:
space:
mode:
authorOla Sitarska <ola@sitarska.com>2014-12-01 21:20:37 +0000
committerTim Graham <timograham@gmail.com>2015-01-11 15:21:01 -0500
commitd563e3be68369694a3bac1efd7779d8e03bb6a51 (patch)
tree0b53bdc3d55bfe0a78d25a3fb2006f02fa9fa326 /tests/template_tests/syntax_tests/test_if.py
parent412066e71e81e899bca63523f239e56138ec9e9d (diff)
Fixed #23913 -- Deprecated the `=` comparison in `if` template tag.
Diffstat (limited to 'tests/template_tests/syntax_tests/test_if.py')
-rw-r--r--tests/template_tests/syntax_tests/test_if.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/template_tests/syntax_tests/test_if.py b/tests/template_tests/syntax_tests/test_if.py
index 4ca11fb79d..357841444a 100644
--- a/tests/template_tests/syntax_tests/test_if.py
+++ b/tests/template_tests/syntax_tests/test_if.py
@@ -1,5 +1,8 @@
+import warnings
+
from django.template import TemplateSyntaxError
-from django.test import SimpleTestCase
+from django.test import ignore_warnings, SimpleTestCase
+from django.utils.deprecation import RemovedInDjango20Warning
from ..utils import setup, TestObj
@@ -521,3 +524,42 @@ class IfTagTests(SimpleTestCase):
def test_if_tag_badarg04(self):
output = self.engine.render_to_string('if-tag-badarg04')
self.assertEqual(output, 'no')
+
+ @setup({'if-tag-eq-deprecated': '{% if foo = bar %}yes{% else %}no{% endif %}'},
+ test_once=True)
+ def test_if_tag_eq_deprecated(self):
+ with warnings.catch_warnings(record=True) as warns:
+ warnings.simplefilter('always')
+ output = self.engine.render_to_string('if-tag-eq-deprecated')
+ self.assertEqual(output, 'yes')
+ self.assertEqual(len(warns), 1)
+ self.assertEqual(
+ str(warns[0].message),
+ "Operator '=' is deprecated and will be removed in Django 2.0. "
+ "Use '==' instead."
+ )
+
+
+@ignore_warnings(category=RemovedInDjango20Warning)
+class TestEqualitySingleEqualsSign(SimpleTestCase):
+ # The following tests should be changed to template.TemplateSyntaxError
+ # (or simply removed) when the deprecation path ends in Django 2.0.
+ @setup({'if-tag-eq01': '{% if foo = bar %}yes{% else %}no{% endif %}'})
+ def test_if_tag_eq01(self):
+ output = self.engine.render_to_string('if-tag-eq01', {'foo': 1})
+ self.assertEqual(output, 'no')
+
+ @setup({'if-tag-eq02': '{% if foo = bar %}yes{% else %}no{% endif %}'})
+ def test_if_tag_eq02(self):
+ output = self.engine.render_to_string('if-tag-eq02', {'foo': 1, 'bar': 1})
+ self.assertEqual(output, 'yes')
+
+ @setup({'if-tag-eq03': '{% if foo = bar %}yes{% else %}no{% endif %}'})
+ def test_if_tag_eq03(self):
+ output = self.engine.render_to_string('if-tag-eq03', {'foo': 1, 'bar': 2})
+ self.assertEqual(output, 'no')
+
+ @setup({'if-tag-eq04': '{% if foo == \'\' %}yes{% else %}no{% endif %}'})
+ def test_if_tag_eq04(self):
+ output = self.engine.render_to_string('if-tag-eq04')
+ self.assertEqual(output, 'no')