1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixes #15814 -- Added a test util to abstract the process of using a test template loader

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16030 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Chris Beaven
2011-04-17 04:52:17 +00:00
parent d3c08fd813
commit 89e25403ae
2 changed files with 49 additions and 16 deletions

View File

@@ -18,7 +18,8 @@ from django.template import base as template_base
from django.core import urlresolvers
from django.template import loader
from django.template.loaders import app_directories, filesystem, cached
from django.test.utils import get_warnings_state, restore_warnings_state
from django.test.utils import get_warnings_state, restore_warnings_state,\
setup_test_template_loader, restore_template_loaders
from django.utils import unittest
from django.utils.translation import activate, deactivate, ugettext as _
from django.utils.safestring import mark_safe
@@ -390,19 +391,10 @@ class Templates(unittest.TestCase):
template_tests.update(filter_tests)
# Register our custom template loader.
def test_template_loader(template_name, template_dirs=None):
"A custom template loader that loads the unit-test templates."
try:
return (template_tests[template_name][0] , "test:%s" % template_name)
except KeyError:
raise template.TemplateDoesNotExist(template_name)
cache_loader = cached.Loader(('test_template_loader',))
cache_loader._cached_loaders = (test_template_loader,)
old_template_loaders = loader.template_source_loaders
loader.template_source_loaders = [cache_loader]
cache_loader = setup_test_template_loader(
dict([(name, t[0]) for name, t in template_tests.iteritems()]),
use_cached_loader=True,
)
failures = []
tests = template_tests.items()
@@ -490,7 +482,7 @@ class Templates(unittest.TestCase):
expected_invalid_str = 'INVALID'
template_base.invalid_var_format_string = False
loader.template_source_loaders = old_template_loaders
restore_template_loaders()
deactivate()
settings.TEMPLATE_DEBUG = old_td
settings.TEMPLATE_STRING_IF_INVALID = old_invalid