summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2013-09-16 00:51:24 +0300
committerTim Graham <timograham@gmail.com>2013-09-18 07:37:08 -0400
commit2f0566fa61e13277364e3aef338fa5c143f5a704 (patch)
tree207438ec3b7983be24dc972890dda923a9f4ee45 /tests/template_tests
parent893198509e3b821a56a56e4326929e0613aad983 (diff)
Fixed #4278 -- Added a dirs parameter to a few functions to override TEMPLATE_DIRS.
* django.template.loader.get_template() * django.template.loader.select_template() * django.shortcuts.render() * django.shortcuts.render_to_response() Thanks amcnabb for the suggestion.
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/other_templates/test_dirs.html1
-rw-r--r--tests/template_tests/test_loaders.py22
2 files changed, 22 insertions, 1 deletions
diff --git a/tests/template_tests/other_templates/test_dirs.html b/tests/template_tests/other_templates/test_dirs.html
new file mode 100644
index 0000000000..d99b954618
--- /dev/null
+++ b/tests/template_tests/other_templates/test_dirs.html
@@ -0,0 +1 @@
+spam eggs{{ obj }}
diff --git a/tests/template_tests/test_loaders.py b/tests/template_tests/test_loaders.py
index 9d15b95d4b..41aa3b5826 100644
--- a/tests/template_tests/test_loaders.py
+++ b/tests/template_tests/test_loaders.py
@@ -174,8 +174,28 @@ class RenderToStringTest(unittest.TestCase):
'No template names provided$',
loader.render_to_string, [])
-
def test_select_templates_from_empty_list(self):
six.assertRaisesRegex(self, TemplateDoesNotExist,
'No template names provided$',
loader.select_template, [])
+
+
+class TemplateDirsOverrideTest(unittest.TestCase):
+
+ dirs_tuple = (os.path.join(os.path.dirname(upath(__file__)), 'other_templates'),)
+ dirs_list = list(dirs_tuple)
+ dirs_iter = (dirs_tuple, dirs_list)
+
+ def test_render_to_string(self):
+ for dirs in self.dirs_iter:
+ self.assertEqual(loader.render_to_string('test_dirs.html', dirs=dirs), 'spam eggs\n')
+
+ def test_get_template(self):
+ for dirs in self.dirs_iter:
+ template = loader.get_template('test_dirs.html', dirs=dirs)
+ self.assertEqual(template.render(Context({})), 'spam eggs\n')
+
+ def test_select_template(self):
+ for dirs in self.dirs_iter:
+ template = loader.select_template(['test_dirs.html'], dirs=dirs)
+ self.assertEqual(template.render(Context({})), 'spam eggs\n')