summaryrefslogtreecommitdiff
path: root/tests/template_loader
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-12-27 23:39:43 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-12-28 17:00:07 +0100
commit969e082858339b8da79af2c036d434ce91c27ee0 (patch)
treeb26d51a7cf25cb02f4ba85b0eebe4ccab38c6872 /tests/template_loader
parent90805b240fdb1a1570c414f7d55fa1b0b77e1f24 (diff)
downloaddjango-969e082858339b8da79af2c036d434ce91c27ee0.tar.gz
Added tests for django.template.loader.
Deprecated features aren't tested.
Diffstat (limited to 'tests/template_loader')
-rw-r--r--tests/template_loader/__init__.py0
-rw-r--r--tests/template_loader/template_strings/template_loader/hello.html1
-rw-r--r--tests/template_loader/templates/template_loader/goodbye.html1
-rw-r--r--tests/template_loader/templates/template_loader/hello.html1
-rw-r--r--tests/template_loader/tests.py104
5 files changed, 107 insertions, 0 deletions
diff --git a/tests/template_loader/__init__.py b/tests/template_loader/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template_loader/__init__.py
diff --git a/tests/template_loader/template_strings/template_loader/hello.html b/tests/template_loader/template_strings/template_loader/hello.html
new file mode 100644
index 0000000000..70175fd954
--- /dev/null
+++ b/tests/template_loader/template_strings/template_loader/hello.html
@@ -0,0 +1 @@
+Hello! (template strings)
diff --git a/tests/template_loader/templates/template_loader/goodbye.html b/tests/template_loader/templates/template_loader/goodbye.html
new file mode 100644
index 0000000000..b8fb727ddd
--- /dev/null
+++ b/tests/template_loader/templates/template_loader/goodbye.html
@@ -0,0 +1 @@
+Goodbye! (Django templates)
diff --git a/tests/template_loader/templates/template_loader/hello.html b/tests/template_loader/templates/template_loader/hello.html
new file mode 100644
index 0000000000..7f54a62edb
--- /dev/null
+++ b/tests/template_loader/templates/template_loader/hello.html
@@ -0,0 +1 @@
+Hello! (Django templates)
diff --git a/tests/template_loader/tests.py b/tests/template_loader/tests.py
new file mode 100644
index 0000000000..3ec785a6a4
--- /dev/null
+++ b/tests/template_loader/tests.py
@@ -0,0 +1,104 @@
+from django.test import override_settings, SimpleTestCase
+from django.template import TemplateDoesNotExist
+from django.template.loader import (
+ get_template, select_template, render_to_string)
+
+
+@override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.dummy.TemplateStrings',
+ 'APP_DIRS': True,
+}, {
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'APP_DIRS': True,
+}])
+class TemplateLoaderTests(SimpleTestCase):
+
+ def test_get_template_first_engine(self):
+ template = get_template("template_loader/hello.html")
+ self.assertEqual(template.render(), "Hello! (template strings)\n")
+
+ def test_get_template_second_engine(self):
+ template = get_template("template_loader/goodbye.html")
+ self.assertEqual(template.render(), "Goodbye! (Django templates)\n")
+
+ def test_get_template_using_engine(self):
+ template = get_template("template_loader/hello.html", using="django")
+ self.assertEqual(template.render(), "Hello! (Django templates)\n")
+
+ def test_get_template_not_found(self):
+ with self.assertRaises(TemplateDoesNotExist):
+ get_template("template_loader/unknown.html")
+
+ def test_select_template_first_engine(self):
+ template = select_template(["template_loader/unknown.html",
+ "template_loader/hello.html"])
+ self.assertEqual(template.render(), "Hello! (template strings)\n")
+
+ def test_select_template_second_engine(self):
+ template = select_template(["template_loader/unknown.html",
+ "template_loader/goodbye.html"])
+ self.assertEqual(template.render(), "Goodbye! (Django templates)\n")
+
+ def test_select_template_using_engine(self):
+ template = select_template(["template_loader/unknown.html",
+ "template_loader/hello.html"], using="django")
+ self.assertEqual(template.render(), "Hello! (Django templates)\n")
+
+ def test_select_template_empty(self):
+ with self.assertRaises(TemplateDoesNotExist):
+ select_template([])
+
+ def test_select_template_not_found(self):
+ with self.assertRaises(TemplateDoesNotExist):
+ select_template(["template_loader/unknown.html",
+ "template_loader/missing.html"])
+
+ def test_select_template_tries_all_engines_before_names(self):
+ template = select_template(["template_loader/goodbye.html",
+ "template_loader/hello.html"])
+ self.assertEqual(template.render(), "Goodbye! (Django templates)\n")
+
+ def test_render_to_string_first_engine(self):
+ content = render_to_string("template_loader/hello.html")
+ self.assertEqual(content, "Hello! (template strings)\n")
+
+ def test_render_to_string_second_engine(self):
+ content = render_to_string("template_loader/goodbye.html")
+ self.assertEqual(content, "Goodbye! (Django templates)\n")
+
+ def test_render_to_string_using_engine(self):
+ content = render_to_string("template_loader/hello.html", using="django")
+ self.assertEqual(content, "Hello! (Django templates)\n")
+
+ def test_render_to_string_not_found(self):
+ with self.assertRaises(TemplateDoesNotExist):
+ render_to_string("template_loader/unknown.html")
+
+ def test_render_to_string_with_list_first_engine(self):
+ content = render_to_string(["template_loader/unknown.html",
+ "template_loader/hello.html"])
+ self.assertEqual(content, "Hello! (template strings)\n")
+
+ def test_render_to_string_with_list_second_engine(self):
+ content = render_to_string(["template_loader/unknown.html",
+ "template_loader/goodbye.html"])
+ self.assertEqual(content, "Goodbye! (Django templates)\n")
+
+ def test_render_to_string_with_list_using_engine(self):
+ content = render_to_string(["template_loader/unknown.html",
+ "template_loader/hello.html"], using="django")
+ self.assertEqual(content, "Hello! (Django templates)\n")
+
+ def test_render_to_string_with_list_empty(self):
+ with self.assertRaises(TemplateDoesNotExist):
+ render_to_string([])
+
+ def test_render_to_string_with_list_not_found(self):
+ with self.assertRaises(TemplateDoesNotExist):
+ render_to_string(["template_loader/unknown.html",
+ "template_loader/missing.html"])
+
+ def test_render_to_string_with_list_tries_all_engines_before_names(self):
+ content = render_to_string(["template_loader/goodbye.html",
+ "template_loader/hello.html"])
+ self.assertEqual(content, "Goodbye! (Django templates)\n")