Raised a warning when using the legacy TEMPLATE_* settings.

All tests now rely on TEMPLATES.
This commit is contained in:
Aymeric Augustin 2014-12-18 21:54:02 +01:00
parent 9eb4f28e89
commit b7282db833
2 changed files with 28 additions and 11 deletions

View File

@ -1,14 +1,14 @@
from collections import Counter, OrderedDict from collections import Counter, OrderedDict
import os import os
import sys import sys
# import warnings import warnings
from django.apps import apps from django.apps import apps
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils import lru_cache from django.utils import lru_cache
from django.utils import six from django.utils import six
# from django.utils.deprecation import RemovedInDjango20Warning from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.module_loading import import_string from django.utils.module_loading import import_string
@ -32,12 +32,10 @@ class EngineHandler(object):
self._templates = settings.TEMPLATES self._templates = settings.TEMPLATES
if not self._templates: if not self._templates:
# TODO: re-enable this warning once the entire test suite has been warnings.warn(
# updated to rely on TEMPLATES instead of legacy settings. "You haven't defined a TEMPLATES setting. You must do so "
# warnings.warn( "before upgrading to Django 2.0. Otherwise Django will be "
# "You haven't defined a TEMPLATES setting. You must do so " "unable to load templates.", RemovedInDjango20Warning)
# "before upgrading to Django 2.0. Otherwise Django will be "
# "unable to load templates.", RemovedInDjango20Warning)
self._templates = [ self._templates = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',

View File

@ -25,11 +25,11 @@ warnings.simplefilter("error", RemovedInDjango20Warning)
CONTRIB_MODULE_PATH = 'django.contrib' CONTRIB_MODULE_PATH = 'django.contrib'
TEST_TEMPLATE_DIR = 'templates'
CONTRIB_DIR = os.path.dirname(upath(contrib.__file__)) CONTRIB_DIR = os.path.dirname(upath(contrib.__file__))
RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__))) RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__)))
TEMPLATE_DIR = os.path.join(RUNTESTS_DIR, 'templates')
TEMP_DIR = tempfile.mkdtemp(prefix='django_') TEMP_DIR = tempfile.mkdtemp(prefix='django_')
os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR
@ -101,7 +101,9 @@ def setup(verbosity, test_labels):
state = { state = {
'INSTALLED_APPS': settings.INSTALLED_APPS, 'INSTALLED_APPS': settings.INSTALLED_APPS,
'ROOT_URLCONF': getattr(settings, "ROOT_URLCONF", ""), 'ROOT_URLCONF': getattr(settings, "ROOT_URLCONF", ""),
# Remove the following line in Django 2.0.
'TEMPLATE_DIRS': settings.TEMPLATE_DIRS, 'TEMPLATE_DIRS': settings.TEMPLATE_DIRS,
'TEMPLATES': settings.TEMPLATES,
'LANGUAGE_CODE': settings.LANGUAGE_CODE, 'LANGUAGE_CODE': settings.LANGUAGE_CODE,
'STATIC_URL': settings.STATIC_URL, 'STATIC_URL': settings.STATIC_URL,
'STATIC_ROOT': settings.STATIC_ROOT, 'STATIC_ROOT': settings.STATIC_ROOT,
@ -113,7 +115,24 @@ def setup(verbosity, test_labels):
settings.ROOT_URLCONF = 'urls' settings.ROOT_URLCONF = 'urls'
settings.STATIC_URL = '/static/' settings.STATIC_URL = '/static/'
settings.STATIC_ROOT = os.path.join(TEMP_DIR, 'static') settings.STATIC_ROOT = os.path.join(TEMP_DIR, 'static')
settings.TEMPLATE_DIRS = (os.path.join(RUNTESTS_DIR, TEST_TEMPLATE_DIR),) # Remove the following line in Django 2.0.
settings.TEMPLATE_DIRS = (TEMPLATE_DIR,)
settings.TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR],
'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',
],
},
}]
settings.LANGUAGE_CODE = 'en' settings.LANGUAGE_CODE = 'en'
settings.SITE_ID = 1 settings.SITE_ID = 1
settings.MIDDLEWARE_CLASSES = ALWAYS_MIDDLEWARE_CLASSES settings.MIDDLEWARE_CLASSES = ALWAYS_MIDDLEWARE_CLASSES