mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #26479 -- Documented is/is not if tag operator behavior for nonexistent variables.
This commit is contained in:
parent
246020efc5
commit
dac075e910
2 changed files with 35 additions and 6 deletions
|
@ -564,6 +564,16 @@ class IfTagTests(SimpleTestCase):
|
|||
output = self.engine.render_to_string('template', {'foo': 1})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'template': '{% if foo is bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_variable_missing(self):
|
||||
output = self.engine.render_to_string('template', {'foo': 1})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'template': '{% if foo is bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_both_variables_missing(self):
|
||||
output = self.engine.render_to_string('template', {})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'template': '{% if foo is not None %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_not_match(self):
|
||||
# For this to act as a regression test, it's important not to use
|
||||
|
@ -575,3 +585,13 @@ class IfTagTests(SimpleTestCase):
|
|||
def test_if_is_not_no_match(self):
|
||||
output = self.engine.render_to_string('template', {'foo': None})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'template': '{% if foo is not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_not_variable_missing(self):
|
||||
output = self.engine.render_to_string('template', {'foo': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'template': '{% if foo is not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_not_both_variables_missing(self):
|
||||
output = self.engine.render_to_string('template', {})
|
||||
self.assertEqual(output, 'no')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue