Added tests for template's Engine.get_default().

This commit is contained in:
Carlton Gibson 2017-03-31 10:54:00 -04:00 committed by Tim Graham
parent 7d1e237753
commit 7019724101
1 changed files with 31 additions and 1 deletions

View File

@ -1,8 +1,9 @@
import os
from django.core.exceptions import ImproperlyConfigured
from django.template import Context
from django.template.engine import Engine
from django.test import SimpleTestCase
from django.test import SimpleTestCase, override_settings
from .utils import ROOT, TEMPLATE_DIR
@ -21,6 +22,35 @@ class RenderToStringTest(SimpleTestCase):
)
class GetDefaultTests(SimpleTestCase):
@override_settings(TEMPLATES=[])
def test_no_engines_configured(self):
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'},
}])
def test_single_engine_configured(self):
self.assertEqual(Engine.get_default().file_charset, 'abc')
@override_settings(TEMPLATES=[{
'NAME': 'default',
'BACKEND': 'django.template.backends.django.DjangoTemplates',
}, {
'NAME': 'other',
'BACKEND': 'django.template.backends.django.DjangoTemplates',
}])
def test_multiple_engines_configured(self):
msg = 'Several DjangoTemplates backends are configured. You must select one explicitly.'
with self.assertRaisesMessage(ImproperlyConfigured, msg):
Engine.get_default()
class LoaderTests(SimpleTestCase):
def test_origin(self):