|
@@ -544,7 +544,11 @@ class TemplateRegressionTests(TestCase):
|
|
|
t.render(Context({}))
|
|
|
|
|
|
|
|
|
-@override_settings(MEDIA_URL="/media/", STATIC_URL="/static/")
|
|
|
+
|
|
|
+@override_settings(MEDIA_URL="/media/", STATIC_URL="/static/",
|
|
|
+ TEMPLATE_DEBUG=False, ALLOWED_INCLUDE_ROOTS=(
|
|
|
+ os.path.dirname(os.path.abspath(upath(__file__))),),
|
|
|
+ )
|
|
|
class TemplateTests(TransRealMixin, TestCase):
|
|
|
def test_templates(self):
|
|
|
template_tests = self.get_template_tests()
|
|
@@ -565,19 +569,9 @@ class TemplateTests(TransRealMixin, TestCase):
|
|
|
failures = []
|
|
|
tests = sorted(template_tests.items())
|
|
|
|
|
|
-
|
|
|
- old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False
|
|
|
-
|
|
|
|
|
|
- old_invalid = settings.TEMPLATE_STRING_IF_INVALID
|
|
|
expected_invalid_str = 'INVALID'
|
|
|
|
|
|
-
|
|
|
- old_allowed_include_roots = settings.ALLOWED_INCLUDE_ROOTS
|
|
|
- settings.ALLOWED_INCLUDE_ROOTS = (
|
|
|
- os.path.dirname(os.path.abspath(upath(__file__))),
|
|
|
- )
|
|
|
-
|
|
|
|
|
|
|
|
|
urlresolvers.reverse('template_tests.views.client_action',
|
|
@@ -613,34 +607,34 @@ class TemplateTests(TransRealMixin, TestCase):
|
|
|
(expected_invalid_str, False, invalid_string_result),
|
|
|
('', True, template_debug_result)
|
|
|
]:
|
|
|
- settings.TEMPLATE_STRING_IF_INVALID = invalid_str
|
|
|
- settings.TEMPLATE_DEBUG = template_debug
|
|
|
- for is_cached in (False, True):
|
|
|
- try:
|
|
|
- try:
|
|
|
- with warnings.catch_warnings():
|
|
|
-
|
|
|
- warnings.filterwarnings("ignore", category=DeprecationWarning, module='django.template.base')
|
|
|
- test_template = loader.get_template(name)
|
|
|
- except ShouldNotExecuteException:
|
|
|
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
|
|
|
-
|
|
|
+ with override_settings(TEMPLATE_STRING_IF_INVALID=invalid_str,
|
|
|
+ TEMPLATE_DEBUG=template_debug):
|
|
|
+ for is_cached in (False, True):
|
|
|
try:
|
|
|
- output = self.render(test_template, vals)
|
|
|
- except ShouldNotExecuteException:
|
|
|
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template rendering invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
|
|
|
- except ContextStackException:
|
|
|
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Context stack was left imbalanced" % (is_cached, invalid_str, template_debug, name))
|
|
|
- continue
|
|
|
- except Exception:
|
|
|
- exc_type, exc_value, exc_tb = sys.exc_info()
|
|
|
- if exc_type != result:
|
|
|
- tb = '\n'.join(traceback.format_exception(exc_type, exc_value, exc_tb))
|
|
|
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Got %s, exception: %s\n%s" % (is_cached, invalid_str, template_debug, name, exc_type, exc_value, tb))
|
|
|
- continue
|
|
|
- if output != result:
|
|
|
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Expected %r, got %r" % (is_cached, invalid_str, template_debug, name, result, output))
|
|
|
- cache_loader.reset()
|
|
|
+ try:
|
|
|
+ with warnings.catch_warnings():
|
|
|
+
|
|
|
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module='django.template.base')
|
|
|
+ test_template = loader.get_template(name)
|
|
|
+ except ShouldNotExecuteException:
|
|
|
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
|
|
|
+
|
|
|
+ try:
|
|
|
+ output = self.render(test_template, vals)
|
|
|
+ except ShouldNotExecuteException:
|
|
|
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template rendering invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
|
|
|
+ except ContextStackException:
|
|
|
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Context stack was left imbalanced" % (is_cached, invalid_str, template_debug, name))
|
|
|
+ continue
|
|
|
+ except Exception:
|
|
|
+ exc_type, exc_value, exc_tb = sys.exc_info()
|
|
|
+ if exc_type != result:
|
|
|
+ tb = '\n'.join(traceback.format_exception(exc_type, exc_value, exc_tb))
|
|
|
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Got %s, exception: %s\n%s" % (is_cached, invalid_str, template_debug, name, exc_type, exc_value, tb))
|
|
|
+ continue
|
|
|
+ if output != result:
|
|
|
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Expected %r, got %r" % (is_cached, invalid_str, template_debug, name, result, output))
|
|
|
+ cache_loader.reset()
|
|
|
|
|
|
if 'LANGUAGE_CODE' in vals[1]:
|
|
|
deactivate()
|
|
@@ -651,9 +645,6 @@ class TemplateTests(TransRealMixin, TestCase):
|
|
|
|
|
|
restore_template_loaders()
|
|
|
deactivate()
|
|
|
- settings.TEMPLATE_DEBUG = old_td
|
|
|
- settings.TEMPLATE_STRING_IF_INVALID = old_invalid
|
|
|
- settings.ALLOWED_INCLUDE_ROOTS = old_allowed_include_roots
|
|
|
|
|
|
self.assertEqual(failures, [], "Tests failed:\n%s\n%s" %
|
|
|
('-' * 70, ("\n%s\n" % ('-' * 70)).join(failures)))
|