mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Ensure render_to_string leaves the context instance stack in the state it was originally passed in.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15591 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8ee9a4627e
commit
1073a83f2c
3 changed files with 35 additions and 5 deletions
|
@ -148,5 +148,30 @@ class CachedLoader(unittest.TestCase):
|
|||
# The two templates should not have the same content
|
||||
self.assertNotEqual(t1.render(Context({})), t2.render(Context({})))
|
||||
|
||||
class RenderToStringTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
|
||||
settings.TEMPLATE_DIRS = (
|
||||
os.path.join(os.path.dirname(__file__), 'templates'),
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
settings.TEMPLATE_DIRS = self._old_TEMPLATE_DIRS
|
||||
|
||||
def test_basic(self):
|
||||
self.assertEqual(loader.render_to_string('test_context.html'), 'obj:')
|
||||
|
||||
def test_basic_context(self):
|
||||
self.assertEqual(loader.render_to_string('test_context.html',
|
||||
{'obj': 'test'}), 'obj:test')
|
||||
|
||||
def test_existing_context_kept_clean(self):
|
||||
context = Context({'obj': 'before'})
|
||||
output = loader.render_to_string('test_context.html', {'obj': 'after'},
|
||||
context_instance=context)
|
||||
self.assertEqual(output, 'obj:after')
|
||||
self.assertEqual(context['obj'], 'before')
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
obj:{{ obj }}
|
Loading…
Add table
Add a link
Reference in a new issue