summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChris Beaven <smileychris@gmail.com>2011-02-20 04:55:11 +0000
committerChris Beaven <smileychris@gmail.com>2011-02-20 04:55:11 +0000
commit1073a83f2ceb330c80da275c0709786a7a84c513 (patch)
treeb3a1415e3d4865840aaed710f4d8831363b35742 /tests
parent8ee9a4627e6716f24f529260928a1c36e7941e66 (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/templates/loaders.py25
-rw-r--r--tests/regressiontests/templates/templates/test_context.html1
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/regressiontests/templates/loaders.py b/tests/regressiontests/templates/loaders.py
index f0759ec2c6..6c74033944 100644
--- a/tests/regressiontests/templates/loaders.py
+++ b/tests/regressiontests/templates/loaders.py
@@ -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()
diff --git a/tests/regressiontests/templates/templates/test_context.html b/tests/regressiontests/templates/templates/test_context.html
new file mode 100644
index 0000000000..a100f03de6
--- /dev/null
+++ b/tests/regressiontests/templates/templates/test_context.html
@@ -0,0 +1 @@
+obj:{{ obj }} \ No newline at end of file