parts/django/tests/regressiontests/templates/nodelist.py
author Nishanth Amuluru <nishanth@fossee.in>
Tue, 11 Jan 2011 14:30:25 +0530
changeset 142 e848bd3ad41f
parent 69 c6bca38c1cbf
permissions -rw-r--r--
approval of textbooks works now

from unittest import TestCase
from django.template.loader import get_template_from_string
from django.template import VariableNode


class NodelistTest(TestCase):

    def test_for(self):
        source = '{% for i in 1 %}{{ a }}{% endfor %}'
        template = get_template_from_string(source)
        vars = template.nodelist.get_nodes_by_type(VariableNode)
        self.assertEqual(len(vars), 1)

    def test_if(self):
        source = '{% if x %}{{ a }}{% endif %}'
        template = get_template_from_string(source)
        vars = template.nodelist.get_nodes_by_type(VariableNode)
        self.assertEqual(len(vars), 1)

    def test_ifequal(self):
        source = '{% ifequal x y %}{{ a }}{% endifequal %}'
        template = get_template_from_string(source)
        vars = template.nodelist.get_nodes_by_type(VariableNode)
        self.assertEqual(len(vars), 1)

    def test_ifchanged(self):
        source = '{% ifchanged x %}{{ a }}{% endifchanged %}'
        template = get_template_from_string(source)
        vars = template.nodelist.get_nodes_by_type(VariableNode)
        self.assertEqual(len(vars), 1)