diff options
| author | django-bot <ops@djangoproject.com> | 2022-02-03 20:24:19 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-07 20:37:05 +0100 |
| commit | 9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch) | |
| tree | f0506b668a013d0063e5fba3dbf4863b466713ba /tests/template_loader | |
| parent | f68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff) | |
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/template_loader')
| -rw-r--r-- | tests/template_loader/tests.py | 130 |
1 files changed, 72 insertions, 58 deletions
diff --git a/tests/template_loader/tests.py b/tests/template_loader/tests.py index c3bb444175..569f86b391 100644 --- a/tests/template_loader/tests.py +++ b/tests/template_loader/tests.py @@ -1,28 +1,30 @@ from django.template import TemplateDoesNotExist -from django.template.loader import ( - get_template, render_to_string, select_template, -) +from django.template.loader import get_template, render_to_string, select_template from django.test import SimpleTestCase, override_settings from django.test.client import RequestFactory -@override_settings(TEMPLATES=[{ - 'BACKEND': 'django.template.backends.dummy.TemplateStrings', - 'APP_DIRS': True, -}, { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.request', - ], - 'loaders': [ - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', - ] - }, -}]) +@override_settings( + TEMPLATES=[ + { + "BACKEND": "django.template.backends.dummy.TemplateStrings", + "APP_DIRS": True, + }, + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.request", + ], + "loaders": [ + "django.template.loaders.filesystem.Loader", + "django.template.loaders.app_directories.Loader", + ], + }, + }, + ] +) 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") @@ -40,23 +42,27 @@ class TemplateLoaderTests(SimpleTestCase): get_template("template_loader/unknown.html") self.assertEqual( e.exception.chain[-1].tried[0][0].template_name, - 'template_loader/unknown.html', + "template_loader/unknown.html", ) - self.assertEqual(e.exception.chain[-1].backend.name, 'django') + self.assertEqual(e.exception.chain[-1].backend.name, "django") def test_select_template_first_engine(self): - template = select_template(["template_loader/unknown.html", - "template_loader/hello.html"]) + 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"]) + 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") + 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): @@ -68,28 +74,30 @@ class TemplateLoaderTests(SimpleTestCase): TypeError, "select_template() takes an iterable of template names but got a " "string: 'template_loader/hello.html'. Use get_template() if you " - "want to load a single template by name." + "want to load a single template by name.", ): - select_template('template_loader/hello.html') + select_template("template_loader/hello.html") def test_select_template_not_found(self): with self.assertRaises(TemplateDoesNotExist) as e: - select_template(["template_loader/unknown.html", - "template_loader/missing.html"]) + select_template( + ["template_loader/unknown.html", "template_loader/missing.html"] + ) self.assertEqual( e.exception.chain[0].tried[0][0].template_name, - 'template_loader/unknown.html', + "template_loader/unknown.html", ) - self.assertEqual(e.exception.chain[0].backend.name, 'dummy') + self.assertEqual(e.exception.chain[0].backend.name, "dummy") self.assertEqual( e.exception.chain[-1].tried[0][0].template_name, - 'template_loader/missing.html', + "template_loader/missing.html", ) - self.assertEqual(e.exception.chain[-1].backend.name, 'django') + self.assertEqual(e.exception.chain[-1].backend.name, "django") def test_select_template_tries_all_engines_before_names(self): - template = select_template(["template_loader/goodbye.html", - "template_loader/hello.html"]) + 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): @@ -101,7 +109,7 @@ class TemplateLoaderTests(SimpleTestCase): self.assertEqual(content, "Goodbye! (Django templates)\n") def test_render_to_string_with_request(self): - request = RequestFactory().get('/foobar/') + request = RequestFactory().get("/foobar/") content = render_to_string("template_loader/request.html", request=request) self.assertEqual(content, "/foobar/\n") @@ -114,23 +122,27 @@ class TemplateLoaderTests(SimpleTestCase): render_to_string("template_loader/unknown.html") self.assertEqual( e.exception.chain[-1].tried[0][0].template_name, - 'template_loader/unknown.html', + "template_loader/unknown.html", ) - self.assertEqual(e.exception.chain[-1].backend.name, 'django') + self.assertEqual(e.exception.chain[-1].backend.name, "django") def test_render_to_string_with_list_first_engine(self): - content = render_to_string(["template_loader/unknown.html", - "template_loader/hello.html"]) + 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"]) + 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") + 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): @@ -139,30 +151,32 @@ class TemplateLoaderTests(SimpleTestCase): def test_render_to_string_with_list_not_found(self): with self.assertRaises(TemplateDoesNotExist) as e: - render_to_string(["template_loader/unknown.html", - "template_loader/missing.html"]) + render_to_string( + ["template_loader/unknown.html", "template_loader/missing.html"] + ) self.assertEqual( e.exception.chain[0].tried[0][0].template_name, - 'template_loader/unknown.html', + "template_loader/unknown.html", ) - self.assertEqual(e.exception.chain[0].backend.name, 'dummy') + self.assertEqual(e.exception.chain[0].backend.name, "dummy") self.assertEqual( e.exception.chain[1].tried[0][0].template_name, - 'template_loader/unknown.html', + "template_loader/unknown.html", ) - self.assertEqual(e.exception.chain[1].backend.name, 'django') + self.assertEqual(e.exception.chain[1].backend.name, "django") self.assertEqual( e.exception.chain[2].tried[0][0].template_name, - 'template_loader/missing.html', + "template_loader/missing.html", ) - self.assertEqual(e.exception.chain[2].backend.name, 'dummy') + self.assertEqual(e.exception.chain[2].backend.name, "dummy") self.assertEqual( e.exception.chain[3].tried[0][0].template_name, - 'template_loader/missing.html', + "template_loader/missing.html", ) - self.assertEqual(e.exception.chain[3].backend.name, 'django') + self.assertEqual(e.exception.chain[3].backend.name, "django") 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"]) + content = render_to_string( + ["template_loader/goodbye.html", "template_loader/hello.html"] + ) self.assertEqual(content, "Goodbye! (Django templates)\n") |
