summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-12-17 22:10:57 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-12-28 17:02:30 +0100
commitcf0fd65ed42d5d4f0585da413db4b1cf7c6b0d1a (patch)
tree3f4f652525adf16178018e4ce0c7eddeb0f61360 /django
parentd3a982556d655adcf4ba331d2def685d8249170f (diff)
Deprecated TEMPLATE_LOADERS.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/auth/tests/settings.py26
-rw-r--r--django/contrib/auth/tests/test_context_processors.py32
-rw-r--r--django/contrib/auth/tests/test_forms.py59
-rw-r--r--django/contrib/auth/tests/test_views.py22
-rw-r--r--django/views/debug.py6
5 files changed, 72 insertions, 73 deletions
diff --git a/django/contrib/auth/tests/settings.py b/django/contrib/auth/tests/settings.py
new file mode 100644
index 0000000000..7697558387
--- /dev/null
+++ b/django/contrib/auth/tests/settings.py
@@ -0,0 +1,26 @@
+import os
+
+from django.utils._os import upath
+
+
+AUTH_MIDDLEWARE_CLASSES = (
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+)
+
+AUTH_TEMPLATES = [{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'templates')],
+ 'APP_DIRS': True,
+ 'OPTIONS': {
+ 'context_processors': (
+ 'django.contrib.auth.context_processors.auth',
+ 'django.template.context_processors.debug',
+ 'django.template.context_processors.i18n',
+ 'django.template.context_processors.media',
+ 'django.template.context_processors.static',
+ 'django.template.context_processors.tz',
+ 'django.contrib.messages.context_processors.messages',
+ ),
+ },
+}]
diff --git a/django/contrib/auth/tests/test_context_processors.py b/django/contrib/auth/tests/test_context_processors.py
index cb96bf5d6d..f96eac9db7 100644
--- a/django/contrib/auth/tests/test_context_processors.py
+++ b/django/contrib/auth/tests/test_context_processors.py
@@ -1,13 +1,12 @@
-import os
-
from django.contrib.auth import authenticate
-from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.auth.models import User, Permission
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.context_processors import PermWrapper, PermLookupDict
from django.db.models import Q
from django.test import TestCase, override_settings
-from django.utils._os import upath
+
+from .settings import AUTH_MIDDLEWARE_CLASSES, AUTH_TEMPLATES
+from .utils import skipIfCustomUser
class MockUser(object):
@@ -61,17 +60,10 @@ class PermWrapperTests(TestCase):
@skipIfCustomUser
@override_settings(
- TEMPLATE_LOADERS=('django.template.loaders.filesystem.Loader',),
- TEMPLATE_DIRS=(
- os.path.join(os.path.dirname(upath(__file__)), 'templates'),
- ),
- TEMPLATE_CONTEXT_PROCESSORS=(
- 'django.contrib.auth.context_processors.auth',
- 'django.contrib.messages.context_processors.messages'
- ),
+ PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
ROOT_URLCONF='django.contrib.auth.tests.urls',
+ TEMPLATES=AUTH_TEMPLATES,
USE_TZ=False, # required for loading the fixture
- PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
)
class AuthContextProcessorTests(TestCase):
"""
@@ -79,12 +71,7 @@ class AuthContextProcessorTests(TestCase):
"""
fixtures = ['context-processors-users.xml']
- @override_settings(
- MIDDLEWARE_CLASSES=(
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- ),
- )
+ @override_settings(MIDDLEWARE_CLASSES=AUTH_MIDDLEWARE_CLASSES)
def test_session_not_accessed(self):
"""
Tests that the session is not accessed simply by including
@@ -93,12 +80,7 @@ class AuthContextProcessorTests(TestCase):
response = self.client.get('/auth_processor_no_attr_access/')
self.assertContains(response, "Session not accessed")
- @override_settings(
- MIDDLEWARE_CLASSES=(
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- ),
- )
+ @override_settings(MIDDLEWARE_CLASSES=AUTH_MIDDLEWARE_CLASSES)
def test_session_is_accessed(self):
"""
Tests that the session is accessed if the auth context processor
diff --git a/django/contrib/auth/tests/test_forms.py b/django/contrib/auth/tests/test_forms.py
index 0c13e8af74..93ce9ad073 100644
--- a/django/contrib/auth/tests/test_forms.py
+++ b/django/contrib/auth/tests/test_forms.py
@@ -1,6 +1,5 @@
from __future__ import unicode_literals
-import os
import re
from django import forms
@@ -8,17 +7,18 @@ from django.contrib.auth.models import User
from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm,
PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm,
ReadOnlyPasswordHashField, ReadOnlyPasswordHashWidget)
-from django.contrib.auth.tests.utils import skipIfCustomUser
from django.core import mail
from django.core.mail import EmailMultiAlternatives
from django.forms.fields import Field, CharField
from django.test import TestCase, override_settings
from django.utils.encoding import force_text
-from django.utils._os import upath
from django.utils import translation
from django.utils.text import capfirst
from django.utils.translation import ugettext as _
+from .settings import AUTH_TEMPLATES
+from .utils import skipIfCustomUser
+
@skipIfCustomUser
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
@@ -360,10 +360,7 @@ class UserChangeFormTest(TestCase):
@skipIfCustomUser
@override_settings(
PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
- TEMPLATE_LOADERS=('django.template.loaders.filesystem.Loader',),
- TEMPLATE_DIRS=(
- os.path.join(os.path.dirname(upath(__file__)), 'templates'),
- ),
+ TEMPLATES=AUTH_TEMPLATES,
USE_TZ=False,
)
class PasswordResetFormTest(TestCase):
@@ -416,33 +413,31 @@ class PasswordResetFormTest(TestCase):
self.assertEqual(mail.outbox[0].subject, 'Custom password reset on example.com')
def test_custom_email_constructor(self):
- template_path = os.path.join(os.path.dirname(__file__), 'templates')
- with self.settings(TEMPLATE_DIRS=(template_path,)):
- data = {'email': 'testclient@example.com'}
+ data = {'email': 'testclient@example.com'}
- class CustomEmailPasswordResetForm(PasswordResetForm):
- def send_mail(self, subject_template_name, email_template_name,
- context, from_email, to_email,
- html_email_template_name=None):
- EmailMultiAlternatives(
- "Forgot your password?",
- "Sorry to hear you forgot your password.",
- None, [to_email],
- ['site_monitor@example.com'],
- headers={'Reply-To': 'webmaster@example.com'},
- alternatives=[("Really sorry to hear you forgot your password.",
- "text/html")]).send()
+ class CustomEmailPasswordResetForm(PasswordResetForm):
+ def send_mail(self, subject_template_name, email_template_name,
+ context, from_email, to_email,
+ html_email_template_name=None):
+ EmailMultiAlternatives(
+ "Forgot your password?",
+ "Sorry to hear you forgot your password.",
+ None, [to_email],
+ ['site_monitor@example.com'],
+ headers={'Reply-To': 'webmaster@example.com'},
+ alternatives=[("Really sorry to hear you forgot your password.",
+ "text/html")]).send()
- form = CustomEmailPasswordResetForm(data)
- self.assertTrue(form.is_valid())
- # Since we're not providing a request object, we must provide a
- # domain_override to prevent the save operation from failing in the
- # potential case where contrib.sites is not installed. Refs #16412.
- form.save(domain_override='example.com')
- self.assertEqual(len(mail.outbox), 1)
- self.assertEqual(mail.outbox[0].subject, 'Forgot your password?')
- self.assertEqual(mail.outbox[0].bcc, ['site_monitor@example.com'])
- self.assertEqual(mail.outbox[0].content_subtype, "plain")
+ form = CustomEmailPasswordResetForm(data)
+ self.assertTrue(form.is_valid())
+ # Since we're not providing a request object, we must provide a
+ # domain_override to prevent the save operation from failing in the
+ # potential case where contrib.sites is not installed. Refs #16412.
+ form.save(domain_override='example.com')
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertEqual(mail.outbox[0].subject, 'Forgot your password?')
+ self.assertEqual(mail.outbox[0].bcc, ['site_monitor@example.com'])
+ self.assertEqual(mail.outbox[0].content_subtype, "plain")
def test_preserve_username_case(self):
"""
diff --git a/django/contrib/auth/tests/test_views.py b/django/contrib/auth/tests/test_views.py
index 251af54ec8..b28615374c 100644
--- a/django/contrib/auth/tests/test_views.py
+++ b/django/contrib/auth/tests/test_views.py
@@ -1,14 +1,17 @@
from importlib import import_module
import itertools
-import os
import re
import warnings
from django.apps import apps
-from django.conf import global_settings, settings
+from django.conf import settings
from django.contrib.sites.requests import RequestSite
from django.contrib.admin.models import LogEntry
+from django.contrib.auth import SESSION_KEY, REDIRECT_FIELD_NAME
+from django.contrib.auth.forms import (AuthenticationForm, PasswordChangeForm,
+ SetPasswordForm)
from django.contrib.auth.models import User
+from django.contrib.auth.views import login as login_view
from django.core import mail
from django.core.urlresolvers import reverse, NoReverseMatch
from django.http import QueryDict, HttpRequest
@@ -16,19 +19,15 @@ from django.utils.encoding import force_text
from django.utils.http import urlquote
from django.utils.six.moves.urllib.parse import urlparse, ParseResult
from django.utils.translation import LANGUAGE_SESSION_KEY
-from django.utils._os import upath
from django.test import TestCase, override_settings
from django.test.utils import patch_logger
from django.middleware.csrf import CsrfViewMiddleware
from django.contrib.sessions.middleware import SessionMiddleware
-from django.contrib.auth import SESSION_KEY, REDIRECT_FIELD_NAME
-from django.contrib.auth.forms import (AuthenticationForm, PasswordChangeForm,
- SetPasswordForm)
# Needed so model is installed when tests are run independently:
-from django.contrib.auth.tests.custom_user import CustomUser # NOQA
-from django.contrib.auth.tests.utils import skipIfCustomUser
-from django.contrib.auth.views import login as login_view
+from .custom_user import CustomUser # NOQA
+from .settings import AUTH_TEMPLATES
+from .utils import skipIfCustomUser
@override_settings(
@@ -36,10 +35,7 @@ from django.contrib.auth.views import login as login_view
('en', 'English'),
),
LANGUAGE_CODE='en',
- TEMPLATE_LOADERS=global_settings.TEMPLATE_LOADERS,
- TEMPLATE_DIRS=(
- os.path.join(os.path.dirname(upath(__file__)), 'templates'),
- ),
+ TEMPLATES=AUTH_TEMPLATES,
USE_TZ=False,
PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
ROOT_URLCONF='django.contrib.auth.tests.urls',
diff --git a/django/views/debug.py b/django/views/debug.py
index 09cc5c462e..b0392c1a6d 100644
--- a/django/views/debug.py
+++ b/django/views/debug.py
@@ -781,7 +781,7 @@ TECHNICAL_500_TEMPLATE = ("""
{% endfor %}
</ul>
{% else %}
- <p>Django couldn't find any templates because your <code>TEMPLATE_LOADERS</code> setting is empty!</p>
+ <p>Django couldn't find any templates because your <code>'loaders'</code> option is empty!</p>
{% endif %}
</div>
{% endif %}
@@ -900,7 +900,7 @@ Installed Middleware:
{% for loader in loader_debug_info %}Using loader {{ loader.loader }}:
{% for t in loader.templates %}{{ t.name }} ({{ t.status }})
{% endfor %}{% endfor %}
-{% else %}Django couldn't find any templates because your TEMPLATE_LOADERS setting is empty!
+{% else %}Django couldn't find any templates because your 'loaders' option is empty!
{% endif %}
{% endif %}{% if template_info %}
Template error:
@@ -1091,7 +1091,7 @@ Installed Middleware:
{% for loader in loader_debug_info %}Using loader {{ loader.loader }}:
{% for t in loader.templates %}{{ t.name }} ({{ t.status }})
{% endfor %}{% endfor %}
-{% else %}Django couldn't find any templates because your TEMPLATE_LOADERS setting is empty!
+{% else %}Django couldn't find any templates because your 'loaders' option is empty!
{% endif %}
{% endif %}{% if template_info %}
Template error: