summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-12-17 22:51:42 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-12-28 17:02:30 +0100
commitd3205e3e2eb0202e7bdffaee3e2a80ad444b1ca2 (patch)
tree11cc72ef84a3c35a5736de34b01bd52106fce08f /tests
parentcf0fd65ed42d5d4f0585da413db4b1cf7c6b0d1a (diff)
Deprecated TEMPLATE_DIRS.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_views/tests.py22
-rw-r--r--tests/i18n/patterns/tests.py12
-rw-r--r--tests/template_tests/test_response.py11
-rw-r--r--tests/template_tests/tests.py9
-rw-r--r--tests/test_client_regress/tests.py12
-rw-r--r--tests/view_tests/tests/test_debug.py15
6 files changed, 55 insertions, 26 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 73564d4f94..e8e2abb2ef 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -6,7 +6,7 @@ import re
import datetime
import unittest
-from django.conf import settings, global_settings
+from django.conf import global_settings
from django.core import mail
from django.core.checks import Error
from django.core.files import temp as tempfile
@@ -62,7 +62,6 @@ from .admin import site, site2, CityAdmin
ERROR_MESSAGE = "Please enter the correct username and password \
for a staff account. Note that both fields may be case-sensitive."
-ADMIN_VIEW_TEMPLATES_DIR = settings.TEMPLATE_DIRS + (os.path.join(os.path.dirname(upath(__file__)), 'templates'),)
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
@@ -788,7 +787,24 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
self.assertContains(response, '<a href="/my-site-url/">View site</a>')
-@override_settings(TEMPLATE_DIRS=ADMIN_VIEW_TEMPLATES_DIR)
+@override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ # Put this app's templates dir in DIRS to take precedence over the admin's
+ # templates dir.
+ 'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'templates')],
+ 'APP_DIRS': True,
+ 'OPTIONS': {
+ 'context_processors': [
+ 'django.template.context_processors.debug',
+ 'django.template.context_processors.i18n',
+ 'django.template.context_processors.tz',
+ 'django.template.context_processors.media',
+ 'django.template.context_processors.static',
+ 'django.contrib.auth.context_processors.auth',
+ 'django.contrib.messages.context_processors.messages',
+ ],
+ },
+}])
class AdminCustomTemplateTests(AdminViewBasicTestCase):
def test_extended_bodyclass_template_change_form(self):
"""
diff --git a/tests/i18n/patterns/tests.py b/tests/i18n/patterns/tests.py
index a4049fca13..2bf770434b 100644
--- a/tests/i18n/patterns/tests.py
+++ b/tests/i18n/patterns/tests.py
@@ -21,9 +21,6 @@ class PermanentRedirectLocaleMiddleWare(LocaleMiddleware):
LOCALE_PATHS=(
os.path.join(os.path.dirname(upath(__file__)), 'locale'),
),
- TEMPLATE_DIRS=(
- os.path.join(os.path.dirname(upath(__file__)), 'templates'),
- ),
LANGUAGE_CODE='en-us',
LANGUAGES=(
('nl', 'Dutch'),
@@ -35,6 +32,15 @@ class PermanentRedirectLocaleMiddleWare(LocaleMiddleware):
'django.middleware.common.CommonMiddleware',
),
ROOT_URLCONF='i18n.patterns.urls.default',
+ TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'templates')],
+ 'OPTIONS': {
+ 'context_processors': [
+ 'django.template.context_processors.i18n',
+ ],
+ },
+ }],
)
class URLTestCaseBase(TestCase):
"""
diff --git a/tests/template_tests/test_response.py b/tests/template_tests/test_response.py
index ab01da5804..6ae5457c98 100644
--- a/tests/template_tests/test_response.py
+++ b/tests/template_tests/test_response.py
@@ -208,10 +208,13 @@ class SimpleTemplateResponseTest(SimpleTestCase):
self.assertEqual(unpickled_response.cookies['key'].value, 'value')
-@override_settings(
- TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name],
- TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates')),
-)
+@override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'templates')],
+ 'OPTIONS': {
+ 'context_processors': [test_processor_name],
+ },
+}])
class TemplateResponseTest(SimpleTestCase):
def setUp(self):
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index 876df43aa4..d0e659b76a 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -86,13 +86,11 @@ class TemplateLoaderTests(SimpleTestCase):
# the compiled templates.
@override_settings(TEMPLATE_DEBUG=True)
def test_loader_debug_origin(self):
- # We rely on the fact that runtests.py sets up TEMPLATE_DIRS to
- # point to a directory containing a login.html file.
load_name = 'login.html'
- # We also rely on the fact the file system and app directories loaders
- # both inherit the load_template method from the base Loader class, so
- # we only need to test one of them.
+ # We rely on the fact the file system and app directories loaders both
+ # inherit the load_template method from the base Loader class, so we
+ # only need to test one of them.
template = loader.get_template(load_name).template
template_name = template.nodelist[0].source[0].name
self.assertTrue(template_name.endswith(load_name),
@@ -111,7 +109,6 @@ class TemplateLoaderTests(SimpleTestCase):
}])
@override_settings(TEMPLATE_DEBUG=True)
def test_cached_loader_debug_origin(self):
- # Same comment as in test_loader_debug_origin.
load_name = 'login.html'
# Test the cached loader separately since it overrides load_template.
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
index 8bd4ad44aa..9d263f70b6 100644
--- a/tests/test_client_regress/tests.py
+++ b/tests/test_client_regress/tests.py
@@ -25,10 +25,7 @@ from .models import CustomUser
from .views import CustomTestException
-@override_settings(
- TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates'),),
- ROOT_URLCONF='test_client_regress.urls',
-)
+@override_settings(ROOT_URLCONF='test_client_regress.urls')
class AssertContainsTests(TestCase):
def test_contains(self):
@@ -911,9 +908,10 @@ class ExceptionTests(TestCase):
@override_settings(ROOT_URLCONF='test_client_regress.urls')
class TemplateExceptionTests(TestCase):
- @override_settings(
- TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'bad_templates'),)
- )
+ @override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'bad_templates')],
+ }])
def test_bad_404_template(self):
"Errors found when rendering 404 error templates are re-raised"
try:
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index ab04c6622d..c0026fa758 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -145,7 +145,10 @@ class DebugViewTests(TestCase):
with NamedTemporaryFile(prefix=template_name) as tempfile:
tempdir = os.path.dirname(tempfile.name)
template_path = os.path.join(tempdir, template_name)
- with override_settings(TEMPLATE_DIRS=(tempdir,)):
+ with override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [tempdir],
+ }]):
response = self.client.get(reverse('raises_template_does_not_exist', kwargs={"path": template_name}))
self.assertContains(response, "%s (File does not exist)" % template_path, status_code=500, count=1)
@@ -157,7 +160,10 @@ class DebugViewTests(TestCase):
tempdir = os.path.dirname(tempfile.name)
template_path = os.path.join(tempdir, template_name)
os.chmod(template_path, 0o0222)
- with override_settings(TEMPLATE_DIRS=(tempdir,)):
+ with override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [tempdir],
+ }]):
response = self.client.get(reverse('raises_template_does_not_exist', kwargs={"path": template_name}))
self.assertContains(response, "%s (File is not readable)" % template_path, status_code=500, count=1)
@@ -167,7 +173,10 @@ class DebugViewTests(TestCase):
template_path = mkdtemp()
template_name = os.path.basename(template_path)
tempdir = os.path.dirname(template_path)
- with override_settings(TEMPLATE_DIRS=(tempdir,)):
+ with override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [tempdir],
+ }]):
response = self.client.get(reverse('raises_template_does_not_exist', kwargs={"path": template_name}))
self.assertContains(response, "%s (Not a file)" % template_path, status_code=500, count=1)
finally: