summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-01-26 21:57:10 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-02-03 08:29:45 +0100
commit2133f3157eff853329bafb7fda74c3c8fb4eae42 (patch)
tree5bb262ab847c79b3f70d8a8888e267b2816b0373 /django/test
parenta53541852d5601232899e54d66e623bc163c6dc2 (diff)
Fixed #24168 -- Allowed selecting a template engine in a few APIs.
Specifically in rendering shortcuts, template responses, and class-based views that return template responses. Also added a test for render_to_response(status=...) which was missing from fdbfc980. Thanks Tim and Carl for the review.
Diffstat (limited to 'django/test')
-rw-r--r--django/test/utils.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index 1991602293..f0d8993a40 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -3,7 +3,7 @@ import logging
import re
import sys
import time
-from unittest import skipUnless
+from unittest import skipIf, skipUnless
import warnings
from functools import wraps
from xml.dom.minidom import parseString, Node
@@ -20,6 +20,11 @@ from django.utils import six
from django.utils.encoding import force_str
from django.utils.translation import deactivate
+try:
+ import jinja2
+except ImportError:
+ jinja2 = None
+
__all__ = (
'Approximate', 'ContextList', 'get_runner',
@@ -573,3 +578,20 @@ def freeze_time(t):
yield
finally:
time.time = _real_time
+
+
+def require_jinja2(test_func):
+ """
+ Decorator to enable a Jinja2 template engine in addition to the regular
+ Django template engine for a test or skip it if Jinja2 isn't available.
+ """
+ test_func = skipIf(jinja2 is None, "this test requires jinja2")(test_func)
+ test_func = override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'APP_DIRS': True,
+ }, {
+ 'BACKEND': 'django.template.backends.jinja2.Jinja2',
+ 'APP_DIRS': True,
+ 'OPTIONS': {'keep_trailing_newline': True},
+ }])(test_func)
+ return test_func