Ticket #4540: django-4540.diff

File django-4540.diff, 2.7 KB (added by munhitsu, 16 years ago)
  • django/template/__init__.py

     
    122122class TemplateEncodingError(Exception):
    123123    pass
    124124
     125class TemplateContextError(Exception):
     126    pass
     127
    125128class VariableDoesNotExist(Exception):
    126129
    127130    def __init__(self, msg, params=()):
     
    173176
    174177    def render(self, context):
    175178        "Display stage -- can be called many times"
     179        if (context == None or not isinstance(context,Context)):
     180            raise TemplateContextError
    176181        return self.nodelist.render(context)
    177182
    178183def compile_string(template_string, origin):
  • django/test/utils.py

     
    55from django.core.management import call_command
    66from django.dispatch import dispatcher
    77from django.test import signals
    8 from django.template import Template
     8from django.template import Template, Context, TemplateContextError
    99from django.utils.translation import deactivate
    1010
    1111# The prefix to put on the default database name when creating
     
    1818    that can be intercepted by the test system Client
    1919    """
    2020    dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context)
     21    if (context == None or not isinstance(context,Context)):
     22        raise TemplateContextError
    2123    return self.nodelist.render(context)
    2224
    2325class TestSMTPConnection(object):
  • tests/regressiontests/templates/tests.py

     
    8181        return u'ŠĐĆŽćžšđ'.encode('utf-8')
    8282
    8383class Templates(unittest.TestCase):
     84    def test_context_type(self):
     85        t = template.Template("{% for val in values %}{{ val }}{% endfor %}")
     86        h = {"values": [1, 2, 3], "a":1}
     87        c = template.Context(h)
     88        # Test1
     89        t.original_render(c)
     90        t.render(c)
     91        # Test2
     92        self.assertRaises(template.TemplateContextError, t.original_render, h)
     93        self.assertRaises(template.TemplateContextError, t.render, h)
     94        # Test4
     95        t = template.Template("{{ val }}")
     96        self.assertRaises(template.TemplateContextError, t.original_render, None)
     97        self.assertRaises(template.TemplateContextError, t.render, None)
     98       
    8499    def test_loaders_security(self):
    85100        def test_template_sources(path, template_dirs, expected_sources):
    86101            # Fix expected sources so they are normcased and abspathed
Back to Top