mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -7,7 +7,7 @@ from django.test import SimpleTestCase, override_settings
|
||||
|
||||
from .utils import ROOT, TEMPLATE_DIR
|
||||
|
||||
OTHER_DIR = os.path.join(ROOT, 'other_templates')
|
||||
OTHER_DIR = os.path.join(ROOT, "other_templates")
|
||||
|
||||
|
||||
class EngineTest(SimpleTestCase):
|
||||
@@ -20,18 +20,18 @@ class EngineTest(SimpleTestCase):
|
||||
"['django.template.loaders.filesystem.Loader'])] "
|
||||
"string_if_invalid='' file_charset='utf-8' builtins=["
|
||||
"'django.template.defaulttags', 'django.template.defaultfilters', "
|
||||
"'django.template.loader_tags'] autoescape=True>"
|
||||
"'django.template.loader_tags'] autoescape=True>",
|
||||
)
|
||||
|
||||
def test_repr(self):
|
||||
engine = Engine(
|
||||
dirs=[TEMPLATE_DIR],
|
||||
context_processors=['django.template.context_processors.debug'],
|
||||
context_processors=["django.template.context_processors.debug"],
|
||||
debug=True,
|
||||
loaders=['django.template.loaders.filesystem.Loader'],
|
||||
string_if_invalid='x',
|
||||
file_charset='utf-16',
|
||||
libraries={'custom': 'template_tests.templatetags.custom'},
|
||||
loaders=["django.template.loaders.filesystem.Loader"],
|
||||
string_if_invalid="x",
|
||||
file_charset="utf-16",
|
||||
libraries={"custom": "template_tests.templatetags.custom"},
|
||||
autoescape=False,
|
||||
)
|
||||
self.assertEqual(
|
||||
@@ -43,91 +43,100 @@ class EngineTest(SimpleTestCase):
|
||||
"libraries={'custom': 'template_tests.templatetags.custom'} "
|
||||
"builtins=['django.template.defaulttags', "
|
||||
"'django.template.defaultfilters', 'django.template.loader_tags'] "
|
||||
"autoescape=False>"
|
||||
"autoescape=False>",
|
||||
)
|
||||
|
||||
|
||||
class RenderToStringTest(SimpleTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.engine = Engine(dirs=[TEMPLATE_DIR])
|
||||
|
||||
def test_basic_context(self):
|
||||
self.assertEqual(
|
||||
self.engine.render_to_string('test_context.html', {'obj': 'test'}),
|
||||
'obj:test\n',
|
||||
self.engine.render_to_string("test_context.html", {"obj": "test"}),
|
||||
"obj:test\n",
|
||||
)
|
||||
|
||||
def test_autoescape_off(self):
|
||||
engine = Engine(dirs=[TEMPLATE_DIR], autoescape=False)
|
||||
self.assertEqual(
|
||||
engine.render_to_string('test_context.html', {'obj': '<script>'}),
|
||||
'obj:<script>\n',
|
||||
engine.render_to_string("test_context.html", {"obj": "<script>"}),
|
||||
"obj:<script>\n",
|
||||
)
|
||||
|
||||
|
||||
class GetDefaultTests(SimpleTestCase):
|
||||
|
||||
@override_settings(TEMPLATES=[])
|
||||
def test_no_engines_configured(self):
|
||||
msg = 'No DjangoTemplates backend is configured.'
|
||||
msg = "No DjangoTemplates backend is configured."
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
Engine.get_default()
|
||||
|
||||
@override_settings(TEMPLATES=[{
|
||||
'NAME': 'default',
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'OPTIONS': {'file_charset': 'abc'},
|
||||
}])
|
||||
@override_settings(
|
||||
TEMPLATES=[
|
||||
{
|
||||
"NAME": "default",
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"OPTIONS": {"file_charset": "abc"},
|
||||
}
|
||||
]
|
||||
)
|
||||
def test_single_engine_configured(self):
|
||||
self.assertEqual(Engine.get_default().file_charset, 'abc')
|
||||
self.assertEqual(Engine.get_default().file_charset, "abc")
|
||||
|
||||
@override_settings(TEMPLATES=[{
|
||||
'NAME': 'default',
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'OPTIONS': {'file_charset': 'abc'},
|
||||
}, {
|
||||
'NAME': 'other',
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'OPTIONS': {'file_charset': 'def'},
|
||||
}])
|
||||
@override_settings(
|
||||
TEMPLATES=[
|
||||
{
|
||||
"NAME": "default",
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"OPTIONS": {"file_charset": "abc"},
|
||||
},
|
||||
{
|
||||
"NAME": "other",
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"OPTIONS": {"file_charset": "def"},
|
||||
},
|
||||
]
|
||||
)
|
||||
def test_multiple_engines_configured(self):
|
||||
self.assertEqual(Engine.get_default().file_charset, 'abc')
|
||||
self.assertEqual(Engine.get_default().file_charset, "abc")
|
||||
|
||||
|
||||
class LoaderTests(SimpleTestCase):
|
||||
|
||||
def test_origin(self):
|
||||
engine = Engine(dirs=[TEMPLATE_DIR], debug=True)
|
||||
template = engine.get_template('index.html')
|
||||
self.assertEqual(template.origin.template_name, 'index.html')
|
||||
template = engine.get_template("index.html")
|
||||
self.assertEqual(template.origin.template_name, "index.html")
|
||||
|
||||
def test_loader_priority(self):
|
||||
"""
|
||||
#21460 -- The order of template loader works.
|
||||
"""
|
||||
loaders = [
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
"django.template.loaders.filesystem.Loader",
|
||||
"django.template.loaders.app_directories.Loader",
|
||||
]
|
||||
engine = Engine(dirs=[OTHER_DIR, TEMPLATE_DIR], loaders=loaders)
|
||||
template = engine.get_template('priority/foo.html')
|
||||
self.assertEqual(template.render(Context()), 'priority\n')
|
||||
template = engine.get_template("priority/foo.html")
|
||||
self.assertEqual(template.render(Context()), "priority\n")
|
||||
|
||||
def test_cached_loader_priority(self):
|
||||
"""
|
||||
The order of template loader works. Refs #21460.
|
||||
"""
|
||||
loaders = [
|
||||
('django.template.loaders.cached.Loader', [
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
]),
|
||||
(
|
||||
"django.template.loaders.cached.Loader",
|
||||
[
|
||||
"django.template.loaders.filesystem.Loader",
|
||||
"django.template.loaders.app_directories.Loader",
|
||||
],
|
||||
),
|
||||
]
|
||||
engine = Engine(dirs=[OTHER_DIR, TEMPLATE_DIR], loaders=loaders)
|
||||
|
||||
template = engine.get_template('priority/foo.html')
|
||||
self.assertEqual(template.render(Context()), 'priority\n')
|
||||
template = engine.get_template("priority/foo.html")
|
||||
self.assertEqual(template.render(Context()), "priority\n")
|
||||
|
||||
template = engine.get_template('priority/foo.html')
|
||||
self.assertEqual(template.render(Context()), 'priority\n')
|
||||
template = engine.get_template("priority/foo.html")
|
||||
self.assertEqual(template.render(Context()), "priority\n")
|
||||
|
||||
Reference in New Issue
Block a user