PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/regressiontests/templates/tests.py

https://code.google.com/p/mango-py/
Python | 1675 lines | 1454 code | 122 blank | 99 comment | 132 complexity | a92aba6f23007bf4edf6ab6112873c86 MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. # -*- coding: utf-8 -*-
  2. from django.conf import settings
  3. if __name__ == '__main__':
  4. # When running this file in isolation, we need to set up the configuration
  5. # before importing 'template'.
  6. settings.configure()
  7. from datetime import datetime, timedelta
  8. import time
  9. import os
  10. import sys
  11. import traceback
  12. from django import template
  13. from django.template import base as template_base
  14. from django.core import urlresolvers
  15. from django.template import loader
  16. from django.template.loaders import app_directories, filesystem, cached
  17. from django.test.utils import setup_test_template_loader,\
  18. restore_template_loaders
  19. from django.utils import unittest
  20. from django.utils.translation import activate, deactivate, ugettext as _
  21. from django.utils.safestring import mark_safe
  22. from django.utils.tzinfo import LocalTimezone
  23. from context import ContextTests
  24. from custom import CustomTagTests, CustomFilterTests
  25. from parser import ParserTests
  26. from unicode import UnicodeTests
  27. from nodelist import NodelistTest
  28. from smartif import *
  29. from response import *
  30. try:
  31. from loaders import *
  32. except ImportError:
  33. pass # If setuptools isn't installed, that's fine. Just move on.
  34. import filters
  35. #################################
  36. # Custom template tag for tests #
  37. #################################
  38. register = template.Library()
  39. class EchoNode(template.Node):
  40. def __init__(self, contents):
  41. self.contents = contents
  42. def render(self, context):
  43. return " ".join(self.contents)
  44. def do_echo(parser, token):
  45. return EchoNode(token.contents.split()[1:])
  46. def do_upper(value):
  47. return value.upper()
  48. register.tag("echo", do_echo)
  49. register.tag("other_echo", do_echo)
  50. register.filter("upper", do_upper)
  51. template.libraries['testtags'] = register
  52. #####################################
  53. # Helper objects for template tests #
  54. #####################################
  55. class SomeException(Exception):
  56. silent_variable_failure = True
  57. class SomeOtherException(Exception):
  58. pass
  59. class ContextStackException(Exception):
  60. pass
  61. class SomeClass:
  62. def __init__(self):
  63. self.otherclass = OtherClass()
  64. def method(self):
  65. return "SomeClass.method"
  66. def method2(self, o):
  67. return o
  68. def method3(self):
  69. raise SomeException
  70. def method4(self):
  71. raise SomeOtherException
  72. def __getitem__(self, key):
  73. if key == 'silent_fail_key':
  74. raise SomeException
  75. elif key == 'noisy_fail_key':
  76. raise SomeOtherException
  77. raise KeyError
  78. def silent_fail_attribute(self):
  79. raise SomeException
  80. silent_fail_attribute = property(silent_fail_attribute)
  81. def noisy_fail_attribute(self):
  82. raise SomeOtherException
  83. noisy_fail_attribute = property(noisy_fail_attribute)
  84. class OtherClass:
  85. def method(self):
  86. return "OtherClass.method"
  87. class TestObj(object):
  88. def is_true(self):
  89. return True
  90. def is_false(self):
  91. return False
  92. def is_bad(self):
  93. time.sleep(0.3)
  94. return True
  95. class SilentGetItemClass(object):
  96. def __getitem__(self, key):
  97. raise SomeException
  98. class SilentAttrClass(object):
  99. def b(self):
  100. raise SomeException
  101. b = property(b)
  102. class UTF8Class:
  103. "Class whose __str__ returns non-ASCII data"
  104. def __str__(self):
  105. return u'Š??Ž?žš?'.encode('utf-8')
  106. class Templates(unittest.TestCase):
  107. def setUp(self):
  108. self.old_static_url = settings.STATIC_URL
  109. self.old_media_url = settings.MEDIA_URL
  110. settings.STATIC_URL = u"/static/"
  111. settings.MEDIA_URL = u"/media/"
  112. def tearDown(self):
  113. settings.STATIC_URL = self.old_static_url
  114. settings.MEDIA_URL = self.old_media_url
  115. def test_loaders_security(self):
  116. ad_loader = app_directories.Loader()
  117. fs_loader = filesystem.Loader()
  118. def test_template_sources(path, template_dirs, expected_sources):
  119. if isinstance(expected_sources, list):
  120. # Fix expected sources so they are normcased and abspathed
  121. expected_sources = [os.path.normcase(os.path.abspath(s)) for s in expected_sources]
  122. # Test the two loaders (app_directores and filesystem).
  123. func1 = lambda p, t: list(ad_loader.get_template_sources(p, t))
  124. func2 = lambda p, t: list(fs_loader.get_template_sources(p, t))
  125. for func in (func1, func2):
  126. if isinstance(expected_sources, list):
  127. self.assertEqual(func(path, template_dirs), expected_sources)
  128. else:
  129. self.assertRaises(expected_sources, func, path, template_dirs)
  130. template_dirs = ['/dir1', '/dir2']
  131. test_template_sources('index.html', template_dirs,
  132. ['/dir1/index.html', '/dir2/index.html'])
  133. test_template_sources('/etc/passwd', template_dirs, [])
  134. test_template_sources('etc/passwd', template_dirs,
  135. ['/dir1/etc/passwd', '/dir2/etc/passwd'])
  136. test_template_sources('../etc/passwd', template_dirs, [])
  137. test_template_sources('../../../etc/passwd', template_dirs, [])
  138. test_template_sources('/dir1/index.html', template_dirs,
  139. ['/dir1/index.html'])
  140. test_template_sources('../dir2/index.html', template_dirs,
  141. ['/dir2/index.html'])
  142. test_template_sources('/dir1blah', template_dirs, [])
  143. test_template_sources('../dir1blah', template_dirs, [])
  144. # UTF-8 bytestrings are permitted.
  145. test_template_sources('\xc3\x85ngstr\xc3\xb6m', template_dirs,
  146. [u'/dir1/Ĺngström', u'/dir2/Ĺngström'])
  147. # Unicode strings are permitted.
  148. test_template_sources(u'Ĺngström', template_dirs,
  149. [u'/dir1/Ĺngström', u'/dir2/Ĺngström'])
  150. test_template_sources(u'Ĺngström', ['/Straße'], [u'/Straße/Ĺngström'])
  151. test_template_sources('\xc3\x85ngstr\xc3\xb6m', ['/Straße'],
  152. [u'/Straße/Ĺngström'])
  153. # Invalid UTF-8 encoding in bytestrings is not. Should raise a
  154. # semi-useful error message.
  155. test_template_sources('\xc3\xc3', template_dirs, UnicodeDecodeError)
  156. # Case insensitive tests (for win32). Not run unless we're on
  157. # a case insensitive operating system.
  158. if os.path.normcase('/TEST') == os.path.normpath('/test'):
  159. template_dirs = ['/dir1', '/DIR2']
  160. test_template_sources('index.html', template_dirs,
  161. ['/dir1/index.html', '/dir2/index.html'])
  162. test_template_sources('/DIR1/index.HTML', template_dirs,
  163. ['/dir1/index.html'])
  164. def test_loader_debug_origin(self):
  165. # Turn TEMPLATE_DEBUG on, so that the origin file name will be kept with
  166. # the compiled templates.
  167. old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, True
  168. old_loaders = loader.template_source_loaders
  169. try:
  170. loader.template_source_loaders = (filesystem.Loader(),)
  171. # We rely on the fact that runtests.py sets up TEMPLATE_DIRS to
  172. # point to a directory containing a 404.html file. Also that
  173. # the file system and app directories loaders both inherit the
  174. # load_template method from the BaseLoader class, so we only need
  175. # to test one of them.
  176. load_name = '404.html'
  177. template = loader.get_template(load_name)
  178. template_name = template.nodelist[0].source[0].name
  179. self.assertTrue(template_name.endswith(load_name),
  180. 'Template loaded by filesystem loader has incorrect name for debug page: %s' % template_name)
  181. # Aso test the cached loader, since it overrides load_template
  182. cache_loader = cached.Loader(('',))
  183. cache_loader._cached_loaders = loader.template_source_loaders
  184. loader.template_source_loaders = (cache_loader,)
  185. template = loader.get_template(load_name)
  186. template_name = template.nodelist[0].source[0].name
  187. self.assertTrue(template_name.endswith(load_name),
  188. 'Template loaded through cached loader has incorrect name for debug page: %s' % template_name)
  189. template = loader.get_template(load_name)
  190. template_name = template.nodelist[0].source[0].name
  191. self.assertTrue(template_name.endswith(load_name),
  192. 'Cached template loaded through cached loader has incorrect name for debug page: %s' % template_name)
  193. finally:
  194. loader.template_source_loaders = old_loaders
  195. settings.TEMPLATE_DEBUG = old_td
  196. def test_include_missing_template(self):
  197. """
  198. Tests that the correct template is identified as not existing
  199. when {% include %} specifies a template that does not exist.
  200. """
  201. # TEMPLATE_DEBUG must be true, otherwise the exception raised
  202. # during {% include %} processing will be suppressed.
  203. old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, True
  204. old_loaders = loader.template_source_loaders
  205. try:
  206. # Test the base loader class via the app loader. load_template
  207. # from base is used by all shipped loaders excepting cached,
  208. # which has its own test.
  209. loader.template_source_loaders = (app_directories.Loader(),)
  210. load_name = 'test_include_error.html'
  211. r = None
  212. try:
  213. tmpl = loader.select_template([load_name])
  214. r = tmpl.render(template.Context({}))
  215. except template.TemplateDoesNotExist, e:
  216. settings.TEMPLATE_DEBUG = old_td
  217. self.assertEqual(e.args[0], 'missing.html')
  218. self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
  219. finally:
  220. loader.template_source_loaders = old_loaders
  221. settings.TEMPLATE_DEBUG = old_td
  222. def test_extends_include_missing_baseloader(self):
  223. """
  224. Tests that the correct template is identified as not existing
  225. when {% extends %} specifies a template that does exist, but
  226. that template has an {% include %} of something that does not
  227. exist. See #12787.
  228. """
  229. # TEMPLATE_DEBUG must be true, otherwise the exception raised
  230. # during {% include %} processing will be suppressed.
  231. old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, True
  232. old_loaders = loader.template_source_loaders
  233. try:
  234. # Test the base loader class via the app loader. load_template
  235. # from base is used by all shipped loaders excepting cached,
  236. # which has its own test.
  237. loader.template_source_loaders = (app_directories.Loader(),)
  238. load_name = 'test_extends_error.html'
  239. tmpl = loader.get_template(load_name)
  240. r = None
  241. try:
  242. r = tmpl.render(template.Context({}))
  243. except template.TemplateSyntaxError, e:
  244. settings.TEMPLATE_DEBUG = old_td
  245. self.assertEqual(e.args[0], 'Caught TemplateDoesNotExist while rendering: missing.html')
  246. self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
  247. finally:
  248. loader.template_source_loaders = old_loaders
  249. settings.TEMPLATE_DEBUG = old_td
  250. def test_extends_include_missing_cachedloader(self):
  251. """
  252. Same as test_extends_include_missing_baseloader, only tests
  253. behavior of the cached loader instead of BaseLoader.
  254. """
  255. old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, True
  256. old_loaders = loader.template_source_loaders
  257. try:
  258. cache_loader = cached.Loader(('',))
  259. cache_loader._cached_loaders = (app_directories.Loader(),)
  260. loader.template_source_loaders = (cache_loader,)
  261. load_name = 'test_extends_error.html'
  262. tmpl = loader.get_template(load_name)
  263. r = None
  264. try:
  265. r = tmpl.render(template.Context({}))
  266. except template.TemplateSyntaxError, e:
  267. self.assertEqual(e.args[0], 'Caught TemplateDoesNotExist while rendering: missing.html')
  268. self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
  269. # For the cached loader, repeat the test, to ensure the first attempt did not cache a
  270. # result that behaves incorrectly on subsequent attempts.
  271. tmpl = loader.get_template(load_name)
  272. try:
  273. tmpl.render(template.Context({}))
  274. except template.TemplateSyntaxError, e:
  275. self.assertEqual(e.args[0], 'Caught TemplateDoesNotExist while rendering: missing.html')
  276. self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
  277. finally:
  278. loader.template_source_loaders = old_loaders
  279. settings.TEMPLATE_DEBUG = old_td
  280. def test_token_smart_split(self):
  281. # Regression test for #7027
  282. token = template.Token(template.TOKEN_BLOCK, 'sometag _("Page not found") value|yesno:_("yes,no")')
  283. split = token.split_contents()
  284. self.assertEqual(split, ["sometag", '_("Page not found")', 'value|yesno:_("yes,no")'])
  285. def test_url_reverse_no_settings_module(self):
  286. # Regression test for #9005
  287. from django.template import Template, Context, TemplateSyntaxError
  288. old_settings_module = settings.SETTINGS_MODULE
  289. old_template_debug = settings.TEMPLATE_DEBUG
  290. settings.SETTINGS_MODULE = None
  291. settings.TEMPLATE_DEBUG = True
  292. t = Template('{% url will_not_match %}')
  293. c = Context()
  294. try:
  295. rendered = t.render(c)
  296. except TemplateSyntaxError, e:
  297. # Assert that we are getting the template syntax error and not the
  298. # string encoding error.
  299. self.assertEqual(e.args[0], "Caught NoReverseMatch while rendering: Reverse for 'will_not_match' with arguments '()' and keyword arguments '{}' not found.")
  300. settings.SETTINGS_MODULE = old_settings_module
  301. settings.TEMPLATE_DEBUG = old_template_debug
  302. def test_invalid_block_suggestion(self):
  303. # See #7876
  304. from django.template import Template, TemplateSyntaxError
  305. try:
  306. t = Template("{% if 1 %}lala{% endblock %}{% endif %}")
  307. except TemplateSyntaxError, e:
  308. self.assertEqual(e.args[0], "Invalid block tag: 'endblock', expected 'else' or 'endif'")
  309. def test_templates(self):
  310. template_tests = self.get_template_tests()
  311. filter_tests = filters.get_filter_tests()
  312. # Quickly check that we aren't accidentally using a name in both
  313. # template and filter tests.
  314. overlapping_names = [name for name in filter_tests if name in template_tests]
  315. assert not overlapping_names, 'Duplicate test name(s): %s' % ', '.join(overlapping_names)
  316. template_tests.update(filter_tests)
  317. # Register our custom template loader.
  318. def test_template_loader(template_name, template_dirs=None):
  319. "A custom template loader that loads the unit-test templates."
  320. try:
  321. return (template_tests[template_name][0] , "test:%s" % template_name)
  322. except KeyError:
  323. raise template.TemplateDoesNotExist(template_name)
  324. cache_loader = cached.Loader(('test_template_loader',))
  325. cache_loader._cached_loaders = (test_template_loader,)
  326. old_template_loaders = loader.template_source_loaders
  327. loader.template_source_loaders = [cache_loader]
  328. failures = []
  329. tests = template_tests.items()
  330. tests.sort()
  331. # Turn TEMPLATE_DEBUG off, because tests assume that.
  332. old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False
  333. # Set TEMPLATE_STRING_IF_INVALID to a known string.
  334. old_invalid = settings.TEMPLATE_STRING_IF_INVALID
  335. expected_invalid_str = 'INVALID'
  336. #Set ALLOWED_INCLUDE_ROOTS so that ssi works.
  337. old_allowed_include_roots = settings.ALLOWED_INCLUDE_ROOTS
  338. settings.ALLOWED_INCLUDE_ROOTS = os.path.dirname(os.path.abspath(__file__))
  339. # Warm the URL reversing cache. This ensures we don't pay the cost
  340. # warming the cache during one of the tests.
  341. urlresolvers.reverse('regressiontests.templates.views.client_action',
  342. kwargs={'id':0,'action':"update"})
  343. for name, vals in tests:
  344. if isinstance(vals[2], tuple):
  345. normal_string_result = vals[2][0]
  346. invalid_string_result = vals[2][1]
  347. if isinstance(invalid_string_result, tuple):
  348. expected_invalid_str = 'INVALID %s'
  349. invalid_string_result = invalid_string_result[0] % invalid_string_result[1]
  350. template_base.invalid_var_format_string = True
  351. try:
  352. template_debug_result = vals[2][2]
  353. except IndexError:
  354. template_debug_result = normal_string_result
  355. else:
  356. normal_string_result = vals[2]
  357. invalid_string_result = vals[2]
  358. template_debug_result = vals[2]
  359. if 'LANGUAGE_CODE' in vals[1]:
  360. activate(vals[1]['LANGUAGE_CODE'])
  361. else:
  362. activate('en-us')
  363. for invalid_str, template_debug, result in [
  364. ('', False, normal_string_result),
  365. (expected_invalid_str, False, invalid_string_result),
  366. ('', True, template_debug_result)
  367. ]:
  368. settings.TEMPLATE_STRING_IF_INVALID = invalid_str
  369. settings.TEMPLATE_DEBUG = template_debug
  370. for is_cached in (False, True):
  371. try:
  372. start = datetime.now()
  373. test_template = loader.get_template(name)
  374. end = datetime.now()
  375. if end-start > timedelta(seconds=0.2):
  376. failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Took too long to parse test" % (is_cached, invalid_str, template_debug, name))
  377. start = datetime.now()
  378. output = self.render(test_template, vals)
  379. end = datetime.now()
  380. if end-start > timedelta(seconds=0.2):
  381. failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Took too long to render test" % (is_cached, invalid_str, template_debug, name))
  382. except ContextStackException:
  383. failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Context stack was left imbalanced" % (is_cached, invalid_str, template_debug, name))
  384. continue
  385. except Exception:
  386. exc_type, exc_value, exc_tb = sys.exc_info()
  387. if exc_type != result:
  388. print "CHECK", name, exc_type, result
  389. tb = '\n'.join(traceback.format_exception(exc_type, exc_value, exc_tb))
  390. failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Got %s, exception: %s\n%s" % (is_cached, invalid_str, template_debug, name, exc_type, exc_value, tb))
  391. continue
  392. if output != result:
  393. failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Expected %r, got %r" % (is_cached, invalid_str, template_debug, name, result, output))
  394. cache_loader.reset()
  395. if 'LANGUAGE_CODE' in vals[1]:
  396. deactivate()
  397. if template_base.invalid_var_format_string:
  398. expected_invalid_str = 'INVALID'
  399. template_base.invalid_var_format_string = False
  400. loader.template_source_loaders = old_template_loaders
  401. deactivate()
  402. settings.TEMPLATE_DEBUG = old_td
  403. settings.TEMPLATE_STRING_IF_INVALID = old_invalid
  404. settings.ALLOWED_INCLUDE_ROOTS = old_allowed_include_roots
  405. self.assertEqual(failures, [], "Tests failed:\n%s\n%s" %
  406. ('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
  407. def render(self, test_template, vals):
  408. context = template.Context(vals[1])
  409. before_stack_size = len(context.dicts)
  410. output = test_template.render(context)
  411. if len(context.dicts) != before_stack_size:
  412. raise ContextStackException
  413. return output
  414. def get_template_tests(self):
  415. # SYNTAX --
  416. # 'template_name': ('template contents', 'context dict', 'expected string output' or Exception class)
  417. return {
  418. ### BASIC SYNTAX ################################################
  419. # Plain text should go through the template parser untouched
  420. 'basic-syntax01': ("something cool", {}, "something cool"),
  421. # Variables should be replaced with their value in the current
  422. # context
  423. 'basic-syntax02': ("{{ headline }}", {'headline':'Success'}, "Success"),
  424. # More than one replacement variable is allowed in a template
  425. 'basic-syntax03': ("{{ first }} --- {{ second }}", {"first" : 1, "second" : 2}, "1 --- 2"),
  426. # Fail silently when a variable is not found in the current context
  427. 'basic-syntax04': ("as{{ missing }}df", {}, ("asdf","asINVALIDdf")),
  428. # A variable may not contain more than one word
  429. 'basic-syntax06': ("{{ multi word variable }}", {}, template.TemplateSyntaxError),
  430. # Raise TemplateSyntaxError for empty variable tags
  431. 'basic-syntax07': ("{{ }}", {}, template.TemplateSyntaxError),
  432. 'basic-syntax08': ("{{ }}", {}, template.TemplateSyntaxError),
  433. # Attribute syntax allows a template to call an object's attribute
  434. 'basic-syntax09': ("{{ var.method }}", {"var": SomeClass()}, "SomeClass.method"),
  435. # Multiple levels of attribute access are allowed
  436. 'basic-syntax10': ("{{ var.otherclass.method }}", {"var": SomeClass()}, "OtherClass.method"),
  437. # Fail silently when a variable's attribute isn't found
  438. 'basic-syntax11': ("{{ var.blech }}", {"var": SomeClass()}, ("","INVALID")),
  439. # Raise TemplateSyntaxError when trying to access a variable beginning with an underscore
  440. 'basic-syntax12': ("{{ var.__dict__ }}", {"var": SomeClass()}, template.TemplateSyntaxError),
  441. # Raise TemplateSyntaxError when trying to access a variable containing an illegal character
  442. 'basic-syntax13': ("{{ va>r }}", {}, template.TemplateSyntaxError),
  443. 'basic-syntax14': ("{{ (var.r) }}", {}, template.TemplateSyntaxError),
  444. 'basic-syntax15': ("{{ sp%am }}", {}, template.TemplateSyntaxError),
  445. 'basic-syntax16': ("{{ eggs! }}", {}, template.TemplateSyntaxError),
  446. 'basic-syntax17': ("{{ moo? }}", {}, template.TemplateSyntaxError),
  447. # Attribute syntax allows a template to call a dictionary key's value
  448. 'basic-syntax18': ("{{ foo.bar }}", {"foo" : {"bar" : "baz"}}, "baz"),
  449. # Fail silently when a variable's dictionary key isn't found
  450. 'basic-syntax19': ("{{ foo.spam }}", {"foo" : {"bar" : "baz"}}, ("","INVALID")),
  451. # Fail silently when accessing a non-simple method
  452. 'basic-syntax20': ("{{ var.method2 }}", {"var": SomeClass()}, ("","INVALID")),
  453. # Don't get confused when parsing something that is almost, but not
  454. # quite, a template tag.
  455. 'basic-syntax21': ("a {{ moo %} b", {}, "a {{ moo %} b"),
  456. 'basic-syntax22': ("{{ moo #}", {}, "{{ moo #}"),
  457. # Will try to treat "moo #} {{ cow" as the variable. Not ideal, but
  458. # costly to work around, so this triggers an error.
  459. 'basic-syntax23': ("{{ moo #} {{ cow }}", {"cow": "cow"}, template.TemplateSyntaxError),
  460. # Embedded newlines make it not-a-tag.
  461. 'basic-syntax24': ("{{ moo\n }}", {}, "{{ moo\n }}"),
  462. # Literal strings are permitted inside variables, mostly for i18n
  463. # purposes.
  464. 'basic-syntax25': ('{{ "fred" }}', {}, "fred"),
  465. 'basic-syntax26': (r'{{ "\"fred\"" }}', {}, "\"fred\""),
  466. 'basic-syntax27': (r'{{ _("\"fred\"") }}', {}, "\"fred\""),
  467. # regression test for ticket #12554
  468. # make sure a silent_variable_failure Exception is supressed
  469. # on dictionary and attribute lookup
  470. 'basic-syntax28': ("{{ a.b }}", {'a': SilentGetItemClass()}, ('', 'INVALID')),
  471. 'basic-syntax29': ("{{ a.b }}", {'a': SilentAttrClass()}, ('', 'INVALID')),
  472. # Something that starts like a number but has an extra lookup works as a lookup.
  473. 'basic-syntax30': ("{{ 1.2.3 }}", {"1": {"2": {"3": "d"}}}, "d"),
  474. 'basic-syntax31': ("{{ 1.2.3 }}", {"1": {"2": ("a", "b", "c", "d")}}, "d"),
  475. 'basic-syntax32': ("{{ 1.2.3 }}", {"1": (("x", "x", "x", "x"), ("y", "y", "y", "y"), ("a", "b", "c", "d"))}, "d"),
  476. 'basic-syntax33': ("{{ 1.2.3 }}", {"1": ("xxxx", "yyyy", "abcd")}, "d"),
  477. 'basic-syntax34': ("{{ 1.2.3 }}", {"1": ({"x": "x"}, {"y": "y"}, {"z": "z", "3": "d"})}, "d"),
  478. # Numbers are numbers even if their digits are in the context.
  479. 'basic-syntax35': ("{{ 1 }}", {"1": "abc"}, "1"),
  480. 'basic-syntax36': ("{{ 1.2 }}", {"1": "abc"}, "1.2"),
  481. # Call methods in the top level of the context
  482. 'basic-syntax37': ('{{ callable }}', {"callable": lambda: "foo bar"}, "foo bar"),
  483. # Call methods returned from dictionary lookups
  484. 'basic-syntax38': ('{{ var.callable }}', {"var": {"callable": lambda: "foo bar"}}, "foo bar"),
  485. # List-index syntax allows a template to access a certain item of a subscriptable object.
  486. 'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"),
  487. # Fail silently when the list index is out of range.
  488. 'list-index02': ("{{ var.5 }}", {"var": ["first item", "second item"]}, ("", "INVALID")),
  489. # Fail silently when the variable is not a subscriptable object.
  490. 'list-index03': ("{{ var.1 }}", {"var": None}, ("", "INVALID")),
  491. # Fail silently when variable is a dict without the specified key.
  492. 'list-index04': ("{{ var.1 }}", {"var": {}}, ("", "INVALID")),
  493. # Dictionary lookup wins out when dict's key is a string.
  494. 'list-index05': ("{{ var.1 }}", {"var": {'1': "hello"}}, "hello"),
  495. # But list-index lookup wins out when dict's key is an int, which
  496. # behind the scenes is really a dictionary lookup (for a dict)
  497. # after converting the key to an int.
  498. 'list-index06': ("{{ var.1 }}", {"var": {1: "hello"}}, "hello"),
  499. # Dictionary lookup wins out when there is a string and int version of the key.
  500. 'list-index07': ("{{ var.1 }}", {"var": {'1': "hello", 1: "world"}}, "hello"),
  501. # Basic filter usage
  502. 'filter-syntax01': ("{{ var|upper }}", {"var": "Django is the greatest!"}, "DJANGO IS THE GREATEST!"),
  503. # Chained filters
  504. 'filter-syntax02': ("{{ var|upper|lower }}", {"var": "Django is the greatest!"}, "django is the greatest!"),
  505. # Raise TemplateSyntaxError for space between a variable and filter pipe
  506. 'filter-syntax03': ("{{ var |upper }}", {}, template.TemplateSyntaxError),
  507. # Raise TemplateSyntaxError for space after a filter pipe
  508. 'filter-syntax04': ("{{ var| upper }}", {}, template.TemplateSyntaxError),
  509. # Raise TemplateSyntaxError for a nonexistent filter
  510. 'filter-syntax05': ("{{ var|does_not_exist }}", {}, template.TemplateSyntaxError),
  511. # Raise TemplateSyntaxError when trying to access a filter containing an illegal character
  512. 'filter-syntax06': ("{{ var|fil(ter) }}", {}, template.TemplateSyntaxError),
  513. # Raise TemplateSyntaxError for invalid block tags
  514. 'filter-syntax07': ("{% nothing_to_see_here %}", {}, template.TemplateSyntaxError),
  515. # Raise TemplateSyntaxError for empty block tags
  516. 'filter-syntax08': ("{% %}", {}, template.TemplateSyntaxError),
  517. # Chained filters, with an argument to the first one
  518. 'filter-syntax09': ('{{ var|removetags:"b i"|upper|lower }}', {"var": "<b><i>Yes</i></b>"}, "yes"),
  519. # Literal string as argument is always "safe" from auto-escaping..
  520. 'filter-syntax10': (r'{{ var|default_if_none:" endquote\" hah" }}',
  521. {"var": None}, ' endquote" hah'),
  522. # Variable as argument
  523. 'filter-syntax11': (r'{{ var|default_if_none:var2 }}', {"var": None, "var2": "happy"}, 'happy'),
  524. # Default argument testing
  525. 'filter-syntax12': (r'{{ var|yesno:"yup,nup,mup" }} {{ var|yesno }}', {"var": True}, 'yup yes'),
  526. # Fail silently for methods that raise an exception with a
  527. # "silent_variable_failure" attribute
  528. 'filter-syntax13': (r'1{{ var.method3 }}2', {"var": SomeClass()}, ("12", "1INVALID2")),
  529. # In methods that raise an exception without a
  530. # "silent_variable_attribute" set to True, the exception propagates
  531. 'filter-syntax14': (r'1{{ var.method4 }}2', {"var": SomeClass()}, (SomeOtherException, SomeOtherException, template.TemplateSyntaxError)),
  532. # Escaped backslash in argument
  533. 'filter-syntax15': (r'{{ var|default_if_none:"foo\bar" }}', {"var": None}, r'foo\bar'),
  534. # Escaped backslash using known escape char
  535. 'filter-syntax16': (r'{{ var|default_if_none:"foo\now" }}', {"var": None}, r'foo\now'),
  536. # Empty strings can be passed as arguments to filters
  537. 'filter-syntax17': (r'{{ var|join:"" }}', {'var': ['a', 'b', 'c']}, 'abc'),
  538. # Make sure that any unicode strings are converted to bytestrings
  539. # in the final output.
  540. 'filter-syntax18': (r'{{ var }}', {'var': UTF8Class()}, u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'),
  541. # Numbers as filter arguments should work
  542. 'filter-syntax19': ('{{ var|truncatewords:1 }}', {"var": "hello world"}, "hello ..."),
  543. #filters should accept empty string constants
  544. 'filter-syntax20': ('{{ ""|default_if_none:"was none" }}', {}, ""),
  545. # Fail silently for non-callable attribute and dict lookups which
  546. # raise an exception with a "silent_variable_failure" attribute
  547. 'filter-syntax21': (r'1{{ var.silent_fail_key }}2', {"var": SomeClass()}, ("12", "1INVALID2")),
  548. 'filter-syntax22': (r'1{{ var.silent_fail_attribute }}2', {"var": SomeClass()}, ("12", "1INVALID2")),
  549. # In attribute and dict lookups that raise an unexpected exception
  550. # without a "silent_variable_attribute" set to True, the exception
  551. # propagates
  552. 'filter-syntax23': (r'1{{ var.noisy_fail_key }}2', {"var": SomeClass()}, (SomeOtherException, SomeOtherException, template.TemplateSyntaxError)),
  553. 'filter-syntax24': (r'1{{ var.noisy_fail_attribute }}2', {"var": SomeClass()}, (SomeOtherException, SomeOtherException, template.TemplateSyntaxError)),
  554. ### COMMENT SYNTAX ########################################################
  555. 'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"),
  556. 'comment-syntax02': ("{# this is hidden #}hello{# foo #}", {}, "hello"),
  557. # Comments can contain invalid stuff.
  558. 'comment-syntax03': ("foo{# {% if %} #}", {}, "foo"),
  559. 'comment-syntax04': ("foo{# {% endblock %} #}", {}, "foo"),
  560. 'comment-syntax05': ("foo{# {% somerandomtag %} #}", {}, "foo"),
  561. 'comment-syntax06': ("foo{# {% #}", {}, "foo"),
  562. 'comment-syntax07': ("foo{# %} #}", {}, "foo"),
  563. 'comment-syntax08': ("foo{# %} #}bar", {}, "foobar"),
  564. 'comment-syntax09': ("foo{# {{ #}", {}, "foo"),
  565. 'comment-syntax10': ("foo{# }} #}", {}, "foo"),
  566. 'comment-syntax11': ("foo{# { #}", {}, "foo"),
  567. 'comment-syntax12': ("foo{# } #}", {}, "foo"),
  568. ### COMMENT TAG ###########################################################
  569. 'comment-tag01': ("{% comment %}this is hidden{% endcomment %}hello", {}, "hello"),
  570. 'comment-tag02': ("{% comment %}this is hidden{% endcomment %}hello{% comment %}foo{% endcomment %}", {}, "hello"),
  571. # Comment tag can contain invalid stuff.
  572. 'comment-tag03': ("foo{% comment %} {% if %} {% endcomment %}", {}, "foo"),
  573. 'comment-tag04': ("foo{% comment %} {% endblock %} {% endcomment %}", {}, "foo"),
  574. 'comment-tag05': ("foo{% comment %} {% somerandomtag %} {% endcomment %}", {}, "foo"),
  575. ### CYCLE TAG #############################################################
  576. 'cycle01': ('{% cycle a %}', {}, template.TemplateSyntaxError),
  577. 'cycle02': ('{% cycle a,b,c as abc %}{% cycle abc %}', {}, 'ab'),
  578. 'cycle03': ('{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}', {}, 'abc'),
  579. 'cycle04': ('{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}', {}, 'abca'),
  580. 'cycle05': ('{% cycle %}', {}, template.TemplateSyntaxError),
  581. 'cycle06': ('{% cycle a %}', {}, template.TemplateSyntaxError),
  582. 'cycle07': ('{% cycle a,b,c as foo %}{% cycle bar %}', {}, template.TemplateSyntaxError),
  583. 'cycle08': ('{% cycle a,b,c as foo %}{% cycle foo %}{{ foo }}{{ foo }}{% cycle foo %}{{ foo }}', {}, 'abbbcc'),
  584. 'cycle09': ("{% for i in test %}{% cycle a,b %}{{ i }},{% endfor %}", {'test': range(5)}, 'a0,b1,a2,b3,a4,'),
  585. 'cycle10': ("{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}", {}, 'ab'),
  586. 'cycle11': ("{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}{% cycle abc %}", {}, 'abc'),
  587. 'cycle12': ("{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}", {}, 'abca'),
  588. 'cycle13': ("{% for i in test %}{% cycle 'a' 'b' %}{{ i }},{% endfor %}", {'test': range(5)}, 'a0,b1,a2,b3,a4,'),
  589. 'cycle14': ("{% cycle one two as foo %}{% cycle foo %}", {'one': '1','two': '2'}, '12'),
  590. 'cycle15': ("{% for i in test %}{% cycle aye bee %}{{ i }},{% endfor %}", {'test': range(5), 'aye': 'a', 'bee': 'b'}, 'a0,b1,a2,b3,a4,'),
  591. 'cycle16': ("{% cycle one|lower two as foo %}{% cycle foo %}", {'one': 'A','two': '2'}, 'a2'),
  592. 'cycle17': ("{% cycle 'a' 'b' 'c' as abc silent %}{% cycle abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}", {}, ""),
  593. 'cycle18': ("{% cycle 'a' 'b' 'c' as foo invalid_flag %}", {}, template.TemplateSyntaxError),
  594. 'cycle19': ("{% cycle 'a' 'b' as silent %}{% cycle silent %}", {}, "ab"),
  595. 'cycle20': ("{% cycle one two as foo %} &amp; {% cycle foo %}", {'one' : 'A & B', 'two' : 'C & D'}, "A & B &amp; C & D"),
  596. 'cycle21': ("{% filter force_escape %}{% cycle one two as foo %} & {% cycle foo %}{% endfilter %}", {'one' : 'A & B', 'two' : 'C & D'}, "A &amp; B &amp; C &amp; D"),
  597. 'cycle22': ("{% for x in values %}{% cycle 'a' 'b' 'c' as abc silent %}{{ x }}{% endfor %}", {'values': [1,2,3,4]}, "1234"),
  598. 'cycle23': ("{% for x in values %}{% cycle 'a' 'b' 'c' as abc silent %}{{ abc }}{{ x }}{% endfor %}", {'values': [1,2,3,4]}, "a1b2c3a4"),
  599. 'included-cycle': ('{{ abc }}', {'abc': 'xxx'}, 'xxx'),
  600. 'cycle24': ("{% for x in values %}{% cycle 'a' 'b' 'c' as abc silent %}{% include 'included-cycle' %}{% endfor %}", {'values': [1,2,3,4]}, "abca"),
  601. ### EXCEPTIONS ############################################################
  602. # Raise exception for invalid template name
  603. 'exception01': ("{% extends 'nonexistent' %}", {}, (template.TemplateDoesNotExist, template.TemplateDoesNotExist, template.TemplateSyntaxError)),
  604. # Raise exception for invalid template name (in variable)
  605. 'exception02': ("{% extends nonexistent %}", {}, (template.TemplateSyntaxError, template.TemplateDoesNotExist)),
  606. # Raise exception for extra {% extends %} tags
  607. 'exception03': ("{% extends 'inheritance01' %}{% block first %}2{% endblock %}{% extends 'inheritance16' %}", {}, template.TemplateSyntaxError),
  608. # Raise exception for custom tags used in child with {% load %} tag in parent, not in child
  609. 'exception04': ("{% extends 'inheritance17' %}{% block first %}{% echo 400 %}5678{% endblock %}", {}, template.TemplateSyntaxError),
  610. ### FILTER TAG ############################################################
  611. 'filter01': ('{% filter upper %}{% endfilter %}', {}, ''),
  612. 'filter02': ('{% filter upper %}django{% endfilter %}', {}, 'DJANGO'),
  613. 'filter03': ('{% filter upper|lower %}django{% endfilter %}', {}, 'django'),
  614. 'filter04': ('{% filter cut:remove %}djangospam{% endfilter %}', {'remove': 'spam'}, 'django'),
  615. ### FIRSTOF TAG ###########################################################
  616. 'firstof01': ('{% firstof a b c %}', {'a':0,'b':0,'c':0}, ''),
  617. 'firstof02': ('{% firstof a b c %}', {'a':1,'b':0,'c':0}, '1'),
  618. 'firstof03': ('{% firstof a b c %}', {'a':0,'b':2,'c':0}, '2'),
  619. 'firstof04': ('{% firstof a b c %}', {'a':0,'b':0,'c':3}, '3'),
  620. 'firstof05': ('{% firstof a b c %}', {'a':1,'b':2,'c':3}, '1'),
  621. 'firstof06': ('{% firstof a b c %}', {'b':0,'c':3}, '3'),
  622. 'firstof07': ('{% firstof a b "c" %}', {'a':0}, 'c'),
  623. 'firstof08': ('{% firstof a b "c and d" %}', {'a':0,'b':0}, 'c and d'),
  624. 'firstof09': ('{% firstof %}', {}, template.TemplateSyntaxError),
  625. ### FOR TAG ###############################################################
  626. 'for-tag01': ("{% for val in values %}{{ val }}{% endfor %}", {"values": [1, 2, 3]}, "123"),
  627. 'for-tag02': ("{% for val in values reversed %}{{ val }}{% endfor %}", {"values": [1, 2, 3]}, "321"),
  628. 'for-tag-vars01': ("{% for val in values %}{{ forloop.counter }}{% endfor %}", {"values": [6, 6, 6]}, "123"),
  629. 'for-tag-vars02': ("{% for val in values %}{{ forloop.counter0 }}{% endfor %}", {"values": [6, 6, 6]}, "012"),
  630. 'for-tag-vars03': ("{% for val in values %}{{ forloop.revcounter }}{% endfor %}", {"values": [6, 6, 6]}, "321"),
  631. 'for-tag-vars04': ("{% for val in values %}{{ forloop.revcounter0 }}{% endfor %}", {"values": [6, 6, 6]}, "210"),
  632. 'for-tag-vars05': ("{% for val in values %}{% if forloop.first %}f{% else %}x{% endif %}{% endfor %}", {"values": [6, 6, 6]}, "fxx"),
  633. 'for-tag-vars06': ("{% for val in values %}{% if forloop.last %}l{% else %}x{% endif %}{% endfor %}", {"values": [6, 6, 6]}, "xxl"),
  634. 'for-tag-unpack01': ("{% for key,value in items %}{{ key }}:{{ value }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, "one:1/two:2/"),
  635. 'for-tag-unpack03': ("{% for key, value in items %}{{ key }}:{{ value }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, "one:1/two:2/"),
  636. 'for-tag-unpack04': ("{% for key , value in items %}{{ key }}:{{ value }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, "one:1/two:2/"),
  637. 'for-tag-unpack05': ("{% for key ,value in items %}{{ key }}:{{ value }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, "one:1/two:2/"),
  638. 'for-tag-unpack06': ("{% for key value in items %}{{ key }}:{{ value }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, template.TemplateSyntaxError),
  639. 'for-tag-unpack07': ("{% for key,,value in items %}{{ key }}:{{ value }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, template.TemplateSyntaxError),
  640. 'for-tag-unpack08': ("{% for key,value, in items %}{{ key }}:{{ value }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, template.TemplateSyntaxError),
  641. # Ensure that a single loopvar doesn't truncate the list in val.
  642. 'for-tag-unpack09': ("{% for val in items %}{{ val.0 }}:{{ val.1 }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, "one:1/two:2/"),
  643. # Otherwise, silently truncate if the length of loopvars differs to the length of each set of items.
  644. 'for-tag-unpack10': ("{% for x,y in items %}{{ x }}:{{ y }}/{% endfor %}", {"items": (('one', 1, 'carrot'), ('two', 2, 'orange'))}, "one:1/two:2/"),
  645. 'for-tag-unpack11': ("{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, ("one:1,/two:2,/", "one:1,INVALID/two:2,INVALID/")),
  646. 'for-tag-unpack12': ("{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}", {"items": (('one', 1, 'carrot'), ('two', 2))}, ("one:1,carrot/two:2,/", "one:1,carrot/two:2,INVALID/")),
  647. 'for-tag-unpack13': ("{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}", {"items": (('one', 1, 'carrot'), ('two', 2, 'cheese'))}, ("one:1,carrot/two:2,cheese/", "one:1,carrot/two:2,cheese/")),
  648. 'for-tag-unpack14': ("{% for x,y in items %}{{ x }}:{{ y }}/{% endfor %}", {"items": (1, 2)}, (":/:/", "INVALID:INVALID/INVALID:INVALID/")),
  649. 'for-tag-empty01': ("{% for val in values %}{{ val }}{% empty %}empty text{% endfor %}", {"values": [1, 2, 3]}, "123"),
  650. 'for-tag-empty02': ("{% for val in values %}{{ val }}{% empty %}values array empty{% endfor %}", {"values": []}, "values array empty"),
  651. 'for-tag-empty03': ("{% for val in values %}{{ val }}{% empty %}values array not found{% endfor %}", {}, "values array not found"),
  652. ### IF TAG ################################################################
  653. 'if-tag01': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": True}, "yes"),
  654. 'if-tag02': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": False}, "no"),
  655. 'if-tag03': ("{% if foo %}yes{% else %}no{% endif %}", {}, "no"),
  656. # Filters
  657. 'if-tag-filter01': ("{% if foo|length == 5 %}yes{% else %}no{% endif %}", {'foo': 'abcde'}, "yes"),
  658. 'if-tag-filter02': ("{% if foo|upper == 'ABC' %}yes{% else %}no{% endif %}", {}, "no"),
  659. # Equality
  660. 'if-tag-eq01': ("{% if foo == bar %}yes{% else %}no{% endif %}", {}, "yes"),
  661. 'if-tag-eq02': ("{% if foo == bar %}yes{% else %}no{% endif %}", {'foo': 1}, "no"),
  662. 'if-tag-eq03': ("{% if foo == bar %}yes{% else %}no{% endif %}", {'foo': 1, 'bar': 1}, "yes"),
  663. 'if-tag-eq04': ("{% if foo == bar %}yes{% else %}no{% endif %}", {'foo': 1, 'bar': 2}, "no"),
  664. 'if-tag-eq05': ("{% if foo == '' %}yes{% else %}no{% endif %}", {}, "no"),
  665. # Comparison
  666. 'if-tag-gt-01': ("{% if 2 > 1 %}yes{% else %}no{% endif %}", {}, "yes"),
  667. 'if-tag-gt-02': ("{% if 1 > 1 %}yes{% else %}no{% endif %}", {}, "no"),
  668. 'if-tag-gte-01': ("{% if 1 >= 1 %}yes{% else %}no{% endif %}", {}, "yes"),
  669. 'if-tag-gte-02': ("{% if 1 >= 2 %}yes{% else %}no{% endif %}", {}, "no"),
  670. 'if-tag-lt-01': ("{% if 1 < 2 %}yes{% else %}no{% endif %}", {}, "yes"),
  671. 'if-tag-lt-02': ("{% if 1 < 1 %}yes{% else %}no{% endif %}", {}, "no"),
  672. 'if-tag-lte-01': ("{% if 1 <= 1 %}yes{% else %}no{% endif %}", {}, "yes"),
  673. 'if-tag-lte-02': ("{% if 2 <= 1 %}yes{% else %}no{% endif %}", {}, "no"),
  674. # Contains
  675. 'if-tag-in-01': ("{% if 1 in x %}yes{% else %}no{% endif %}", {'x':[1]}, "yes"),
  676. 'if-tag-in-02': ("{% if 2 in x %}yes{% else %}no{% endif %}", {'x':[1]}, "no"),
  677. 'if-tag-not-in-01': ("{% if 1 not in x %}yes{% else %}no{% endif %}", {'x':[1]}, "no"),
  678. 'if-tag-not-in-02': ("{% if 2 not in x %}yes{% else %}no{% endif %}", {'x':[1]}, "yes"),
  679. # AND
  680. 'if-tag-and01': ("{% if foo and bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': True}, 'yes'),
  681. 'if-tag-and02': ("{% if foo and bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': False}, 'no'),
  682. 'if-tag-and03': ("{% if foo and bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': True}, 'no'),
  683. 'if-tag-and04': ("{% if foo and bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': False}, 'no'),
  684. 'if-tag-and05': ("{% if foo and bar %}yes{% else %}no{% endif %}", {'foo': False}, 'no'),
  685. 'if-tag-and06': ("{% if foo and bar %}yes{% else %}no{% endif %}", {'bar': False}, 'no'),
  686. 'if-tag-and07': ("{% if foo and bar %}yes{% else %}no{% endif %}", {'foo': True}, 'no'),
  687. 'if-tag-and08': ("{% if foo and bar %}yes{% else %}no{% endif %}", {'bar': True}, 'no'),
  688. # OR
  689. 'if-tag-or01': ("{% if foo or bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': True}, 'yes'),
  690. 'if-tag-or02': ("{% if foo or bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': False}, 'yes'),
  691. 'if-tag-or03': ("{% if foo or bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': True}, 'yes'),
  692. 'if-tag-or04': ("{% if foo or bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': False}, 'no'),
  693. 'if-tag-or05': ("{% if foo or bar %}yes{% else %}no{% endif %}", {'foo': False}, 'no'),
  694. 'if-tag-or06': ("{% if foo or bar %}yes{% else %}no{% endif %}", {'bar': False}, 'no'),
  695. 'if-tag-or07': ("{% if foo or bar %}yes{% else %}no{% endif %}", {'foo': True}, 'yes'),
  696. 'if-tag-or08': ("{% if foo or bar %}yes{% else %}no{% endif %}", {'bar': True}, 'yes'),
  697. # multiple ORs
  698. 'if-tag-or09': ("{% if foo or bar or baz %}yes{% else %}no{% endif %}", {'baz': True}, 'yes'),
  699. # NOT
  700. 'if-tag-not01': ("{% if not foo %}no{% else %}yes{% endif %}", {'foo': True}, 'yes'),
  701. 'if-tag-not02': ("{% if not not foo %}no{% else %}yes{% endif %}", {'foo': True}, 'no'),
  702. # not03 to not05 removed, now TemplateSyntaxErrors
  703. 'if-tag-not06': ("{% if foo and not bar %}yes{% else %}no{% endif %}", {}, 'no'),
  704. 'if-tag-not07': ("{% if foo and not bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': True}, 'no'),
  705. 'if-tag-not08': ("{% if foo and not bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': False}, 'yes'),
  706. 'if-tag-not09': ("{% if foo and not bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': True}, 'no'),
  707. 'if-tag-not10': ("{% if foo and not bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': False}, 'no'),
  708. 'if-tag-not11': ("{% if not foo and bar %}yes{% else %}no{% endif %}", {}, 'no'),
  709. 'if-tag-not12': ("{% if not foo and bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': True}, 'no'),
  710. 'if-tag-not13': ("{% if not foo and bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': False}, 'no'),
  711. 'if-tag-not14': ("{% if not foo and bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': True}, 'yes'),
  712. 'if-tag-not15': ("{% if not foo and bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': False}, 'no'),
  713. 'if-tag-not16': ("{% if foo or not bar %}yes{% else %}no{% endif %}", {}, 'yes'),
  714. 'if-tag-not17': ("{% if foo or not bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': True}, 'yes'),
  715. 'if-tag-not18': ("{% if foo or not bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': False}, 'yes'),
  716. 'if-tag-not19': ("{% if foo or not bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': True}, 'no'),
  717. 'if-tag-not20': ("{% if foo or not bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': False}, 'yes'),
  718. 'if-tag-not21': ("{% if not foo or bar %}yes{% else %}no{% endif %}", {}, 'yes'),
  719. 'if-tag-not22': ("{% if not foo or bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': True}, 'yes'),
  720. 'if-tag-not23': ("{% if not foo or bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': False}, 'no'),
  721. 'if-tag-not24': ("{% if not foo or bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': True}, 'yes'),
  722. 'if-tag-not25': ("{% if not foo or bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': False}, 'yes'),
  723. 'if-tag-not26': ("{% if not foo and not bar %}yes{% else %}no{% endif %}", {}, 'yes'),
  724. 'if-tag-not27': ("{% if not foo and not bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': True}, 'no'),
  725. 'if-tag-not28': ("{% if not foo and not bar %}yes{% else %}no{% endif %}", {'foo': True, 'bar': False}, 'no'),
  726. 'if-tag-not29': ("{% if not foo and not bar %}yes{% else %}no{% endif %}", {'foo': False, 'bar': True}, 'no'),
  727. 'if-tag-not30': ("{% if not foo and not bar %}yes{% else %}no{% endif %}", {'foo'

Large files files are truncated, but you can click here to view the full file