Switch tests to new TEMPLATES setting

This commit is contained in:
Mathieu Pillard 2015-12-24 16:00:57 +01:00
parent c179a07e8a
commit afae1e1f7a
2 changed files with 32 additions and 11 deletions

View File

@ -34,12 +34,25 @@ STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(TEST_DIR, 'static')
TEMPLATE_DIRS = (
# Specifically choose a name that will not be considered
# by app_directories loader, to make sure each test uses
# a specific template without considering the others.
os.path.join(TEST_DIR, 'test_templates'),
)
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'DIRS': [
# Specifically choose a name that will not be considered
# by app_directories loader, to make sure each test uses
# a specific template without considering the others.
os.path.join(TEST_DIR, 'test_templates'),
],
}, {
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'APP_DIRS': True,
'DIRS': [
# Specifically choose a name that will not be considered
# by app_directories loader, to make sure each test uses
# a specific template without considering the others.
os.path.join(TEST_DIR, 'test_templates_jinja2'),
],
}]
SECRET_KEY = "iufoj=mibkpdz*%bob952x(%49rqgv8gg45k36kjcg76&-y5=!"

View File

@ -1,4 +1,5 @@
from __future__ import with_statement, unicode_literals
import copy
import io
import os
import sys
@ -63,13 +64,20 @@ class OfflineTestCaseMixin(object):
# Specify both Jinja2 and Django template locations. When the wrong
# engine is used to parse a template, the TemplateSyntaxError will
# cause the template to be skipped over.
# We've hardcoded TEMPLATES[0] to be Django templates backend and
# TEMPLATES[1] to be Jinja2 templates backend in test_settings.
TEMPLATES = copy.deepcopy(settings.TEMPLATES)
django_template_dir = os.path.join(
settings.TEST_DIR, 'test_templates', self.templates_dir)
TEMPLATES[0]['DIRS'][0], self.templates_dir)
jinja2_template_dir = os.path.join(
settings.TEST_DIR, 'test_templates_jinja2', self.templates_dir)
TEMPLATES[1]['DIRS'][0], self.templates_dir)
TEMPLATES[0]['DIRS'] = [django_template_dir]
TEMPLATES[1]['DIRS'] = [jinja2_template_dir]
override_settings = {
'TEMPLATE_DIRS': (django_template_dir, jinja2_template_dir,),
'TEMPLATES': TEMPLATES,
'COMPRESS_ENABLED': True,
'COMPRESS_OFFLINE': True
}
@ -164,7 +172,7 @@ class OfflineTestCaseMixin(object):
import jinja2
loader = jinja2.FileSystemLoader(
settings.TEMPLATE_DIRS, encoding=settings.FILE_CHARSET)
settings.TEMPLATES[1]['DIRS'], encoding=settings.FILE_CHARSET)
return loader
@ -545,7 +553,7 @@ class OfflineCompressBlockSuperBaseCompressed(OfflineTestCaseMixin, TestCase):
self.templates = []
for template_name in self.template_names:
template_path = os.path.join(
settings.TEMPLATE_DIRS[0], template_name)
settings.TEMPLATES[0]['DIRS'][0], template_name)
self.template_paths.append(template_path)
with io.open(template_path,
encoding=settings.FILE_CHARSET) as file_: