summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-11-15 20:41:30 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-11-16 21:40:50 +0100
commitb503fee7ec03485bf7172a6a85ca7228847705de (patch)
tree9025bc3bfecb6def8c333a9547869f1dde38a2c2 /tests
parentd58597a7b8b47add828c9418cdf48299e3b8f5bb (diff)
Removed override_template_loaders and override_with_test_loader.
They can be replaced with override_settings and that makes the corresponding tests much more obvious.
Diffstat (limited to 'tests')
-rw-r--r--tests/template_tests/tests.py38
-rw-r--r--tests/view_tests/tests/test_debug.py10
-rw-r--r--tests/view_tests/tests/test_defaults.py9
3 files changed, 33 insertions, 24 deletions
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index 41663c678a..334dd31f7b 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -16,8 +16,7 @@ from django.template import (base as template_base, loader, Context,
RequestContext, Template, TemplateSyntaxError)
from django.template.loaders import app_directories, filesystem, cached
from django.test import RequestFactory, TestCase
-from django.test.utils import (override_settings, override_template_loaders,
- override_with_test_loader, extend_sys_path)
+from django.test.utils import override_settings, extend_sys_path
from django.utils.deprecation import RemovedInDjango19Warning, RemovedInDjango20Warning
from django.utils.encoding import python_2_unicode_compatible
from django.utils.formats import date_format
@@ -213,7 +212,7 @@ class TemplateLoaderTests(TestCase):
test_template_sources('/DIR1/index.HTML', template_dirs,
['/DIR1/index.HTML'])
- @override_template_loaders(filesystem.Loader())
+ @override_settings(TEMPLATE_LOADERS=['django.template.loaders.filesystem.Loader'])
# Turn TEMPLATE_DEBUG on, so that the origin file name will be kept with
# the compiled templates.
@override_settings(TEMPLATE_DEBUG=True)
@@ -264,7 +263,7 @@ class TemplateLoaderTests(TestCase):
# Test the base loader class via the app loader. load_template
# from base is used by all shipped loaders excepting cached,
# which has its own test.
- @override_template_loaders(app_directories.Loader())
+ @override_settings(TEMPLATE_LOADERS=['django.template.loaders.app_directories.Loader'])
def test_include_missing_template(self):
"""
Tests that the correct template is identified as not existing
@@ -285,7 +284,7 @@ class TemplateLoaderTests(TestCase):
# Test the base loader class via the app loader. load_template
# from base is used by all shipped loaders excepting cached,
# which has its own test.
- @override_template_loaders(app_directories.Loader())
+ @override_settings(TEMPLATE_LOADERS=['django.template.loaders.app_directories.Loader'])
def test_extends_include_missing_baseloader(self):
"""
Tests that the correct template is identified as not existing
@@ -308,9 +307,11 @@ class TemplateLoaderTests(TestCase):
Same as test_extends_include_missing_baseloader, only tests
behavior of the cached loader instead of base loader.
"""
- cache_loader = cached.Loader(('',))
- cache_loader._cached_loaders = (app_directories.Loader(),)
- with override_template_loaders(cache_loader,):
+ with override_settings(TEMPLATE_LOADERS=[
+ ('django.template.loaders.cached.Loader', [
+ 'django.template.loaders.app_directories.Loader',
+ ]),
+ ]):
load_name = 'test_extends_error.html'
tmpl = loader.get_template(load_name)
r = None
@@ -534,7 +535,11 @@ class TemplateTests(TestCase):
template_tests.update(filter_tests)
templates = dict((name, t[0]) for name, t in six.iteritems(template_tests))
- with override_with_test_loader(templates, use_cached_loader=True) as cache_loader:
+ with override_settings(TEMPLATE_LOADERS=[
+ ('django.template.loaders.cached.Loader', [
+ ('django.template.loaders.locmem.Loader', templates),
+ ]),
+ ]):
failures = []
tests = sorted(template_tests.items())
@@ -607,7 +612,8 @@ class TemplateTests(TestCase):
continue
if output != result:
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Expected %r, got %r" % (is_cached, invalid_str, template_debug, name, result, output))
- cache_loader.reset()
+
+ loader.template_source_loaders[0].reset()
if template_base.invalid_var_format_string:
expected_invalid_str = 'INVALID'
@@ -1880,15 +1886,13 @@ class TemplateTagLoading(TestCase):
class RequestContextTests(unittest.TestCase):
def setUp(self):
- templates = {
- 'child': '{{ var|default:"none" }}',
- }
- override_with_test_loader.override(templates)
self.fake_request = RequestFactory().get('/')
- def tearDown(self):
- override_with_test_loader.restore()
-
+ @override_settings(TEMPLATE_LOADERS=[
+ ('django.template.loaders.locmem.Loader', {
+ 'child': '{{ var|default:"none" }}',
+ }),
+ ])
def test_include_only(self):
"""
Regression test for #15721, ``{% include %}`` and ``RequestContext``
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index e50a29f1d1..b9987c72b0 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -17,7 +17,6 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse
from django.template.base import TemplateDoesNotExist
from django.test import TestCase, RequestFactory, override_settings
-from django.test.utils import override_with_test_loader
from django.utils.encoding import force_text, force_bytes
from django.utils import six
from django.views.debug import CallableSettingWrapper, ExceptionReporter
@@ -66,14 +65,17 @@ class DebugViewTests(TestCase):
def test_403(self):
# Ensure no 403.html template exists to test the default case.
- with override_with_test_loader({}):
+ with override_settings(TEMPLATE_LOADERS=[]):
response = self.client.get('/raises403/')
self.assertContains(response, '<h1>403 Forbidden</h1>', status_code=403)
def test_403_template(self):
# Set up a test 403.html template.
- with override_with_test_loader({'403.html': 'This is a test template '
- 'for a 403 Forbidden error.'}):
+ with override_settings(TEMPLATE_LOADERS=[
+ ('django.template.loaders.locmem.Loader', {
+ '403.html': 'This is a test template for a 403 Forbidden error.',
+ })
+ ]):
response = self.client.get('/raises403/')
self.assertContains(response, 'test template', status_code=403)
diff --git a/tests/view_tests/tests/test_defaults.py b/tests/view_tests/tests/test_defaults.py
index 1f6a554c19..6a3a495c23 100644
--- a/tests/view_tests/tests/test_defaults.py
+++ b/tests/view_tests/tests/test_defaults.py
@@ -1,7 +1,7 @@
from __future__ import unicode_literals
from django.test import TestCase
-from django.test.utils import override_settings, override_with_test_loader
+from django.test.utils import override_settings
from ..models import UrlArticle
@@ -40,9 +40,12 @@ class DefaultsTests(TestCase):
Test that 404.html and 500.html templates are picked by their respective
handler.
"""
- with override_with_test_loader({
+ with override_settings(TEMPLATE_LOADERS=[
+ ('django.template.loaders.locmem.Loader', {
'404.html': 'This is a test template for a 404 error.',
- '500.html': 'This is a test template for a 500 error.'}):
+ '500.html': 'This is a test template for a 500 error.',
+ }),
+ ]):
for code, url in ((404, '/non_existing_url/'), (500, '/server_error/')):
response = self.client.get(url)
self.assertContains(response, "test template for a %d error" % code,