/tests/regressiontests/templates/nodelist.py

https://code.google.com/p/mango-py/ · Python · 30 lines · 24 code · 6 blank · 0 comment · 0 complexity · 06958aa392db7d271756847654aad780 MD5 · raw file

  1. from django.template.loader import get_template_from_string
  2. from django.template import VariableNode
  3. from django.utils.unittest import TestCase
  4. class NodelistTest(TestCase):
  5. def test_for(self):
  6. source = '{% for i in 1 %}{{ a }}{% endfor %}'
  7. template = get_template_from_string(source)
  8. vars = template.nodelist.get_nodes_by_type(VariableNode)
  9. self.assertEqual(len(vars), 1)
  10. def test_if(self):
  11. source = '{% if x %}{{ a }}{% endif %}'
  12. template = get_template_from_string(source)
  13. vars = template.nodelist.get_nodes_by_type(VariableNode)
  14. self.assertEqual(len(vars), 1)
  15. def test_ifequal(self):
  16. source = '{% ifequal x y %}{{ a }}{% endifequal %}'
  17. template = get_template_from_string(source)
  18. vars = template.nodelist.get_nodes_by_type(VariableNode)
  19. self.assertEqual(len(vars), 1)
  20. def test_ifchanged(self):
  21. source = '{% ifchanged x %}{{ a }}{% endifchanged %}'
  22. template = get_template_from_string(source)
  23. vars = template.nodelist.get_nodes_by_type(VariableNode)
  24. self.assertEqual(len(vars), 1)