Commit cf0fd65e authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Deprecated TEMPLATE_LOADERS.

parent d3a98255
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
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',
        ),
    },
}]
+7 −25
Original line number Diff line number Diff line
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
+29 −34
Original line number Diff line number Diff line
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,8 +413,6 @@ 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'}

        class CustomEmailPasswordResetForm(PasswordResetForm):
+9 −13
Original line number Diff line number Diff line
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',
+3 −3
Original line number Diff line number Diff line
@@ -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:
Loading