diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-01-09 22:59:00 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-01-12 21:01:34 +0100 |
| commit | 79deb6a0716e554cac5308e86f5754f19ad436dc (patch) | |
| tree | 28fb9b1b9983217d91f598c1677a0f048fb3d349 /tests | |
| parent | a3e783fe11dd25bbf84bfb6201186566ed473506 (diff) | |
Accounted for multiple template engines in template responses.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cache/tests.py | 19 | ||||
| -rw-r--r-- | tests/middleware_exceptions/tests.py | 5 | ||||
| -rw-r--r-- | tests/middleware_exceptions/views.py | 8 | ||||
| -rw-r--r-- | tests/template_tests/test_response.py | 22 | ||||
| -rw-r--r-- | tests/test_client_regress/tests.py | 8 | ||||
| -rw-r--r-- | tests/utils_tests/test_decorators.py | 10 |
6 files changed, 42 insertions, 30 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 95cf2675b2..3e2dc5c1a0 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -22,11 +22,11 @@ from django.core.cache import (cache, caches, CacheKeyWarning, close_caches) from django.db import connection, connections, transaction from django.core.cache.utils import make_template_fragment_key -from django.http import HttpResponse, StreamingHttpResponse +from django.http import HttpRequest, HttpResponse, StreamingHttpResponse from django.middleware.cache import (FetchFromCacheMiddleware, UpdateCacheMiddleware, CacheMiddleware) from django.middleware.csrf import CsrfViewMiddleware -from django.template import Template +from django.template import engines from django.template.context_processors import csrf from django.template.response import TemplateResponse from django.test import (TestCase, TransactionTestCase, RequestFactory, @@ -2022,7 +2022,8 @@ class TestWithTemplateResponse(TestCase): ('Cookie , Accept-Encoding', ('Accept-Encoding', 'cookie'), 'Cookie, Accept-Encoding'), ) for initial_vary, newheaders, resulting_vary in headers: - response = TemplateResponse(HttpResponse(), Template("This is a test")) + template = engines['django'].from_string("This is a test") + response = TemplateResponse(HttpRequest(), template) if initial_vary is not None: response['Vary'] = initial_vary patch_vary_headers(response, newheaders) @@ -2030,7 +2031,8 @@ class TestWithTemplateResponse(TestCase): def test_get_cache_key(self): request = self.factory.get(self.path) - response = TemplateResponse(HttpResponse(), Template("This is a test")) + template = engines['django'].from_string("This is a test") + response = TemplateResponse(HttpRequest(), template) key_prefix = 'localprefix' # Expect None if no headers have been set yet. self.assertIsNone(get_cache_key(request)) @@ -2052,7 +2054,8 @@ class TestWithTemplateResponse(TestCase): def test_get_cache_key_with_query(self): request = self.factory.get(self.path, {'test': 1}) - response = TemplateResponse(HttpResponse(), Template("This is a test")) + template = engines['django'].from_string("This is a test") + response = TemplateResponse(HttpRequest(), template) # Expect None if no headers have been set yet. self.assertIsNone(get_cache_key(request)) # Set headers to an empty list. @@ -2066,7 +2069,8 @@ class TestWithTemplateResponse(TestCase): @override_settings(USE_ETAGS=False) def test_without_etag(self): - response = TemplateResponse(HttpResponse(), Template("This is a test")) + template = engines['django'].from_string("This is a test") + response = TemplateResponse(HttpRequest(), template) self.assertFalse(response.has_header('ETag')) patch_response_headers(response) self.assertFalse(response.has_header('ETag')) @@ -2075,7 +2079,8 @@ class TestWithTemplateResponse(TestCase): @override_settings(USE_ETAGS=True) def test_with_etag(self): - response = TemplateResponse(HttpResponse(), Template("This is a test")) + template = engines['django'].from_string("This is a test") + response = TemplateResponse(HttpRequest(), template) self.assertFalse(response.has_header('ETag')) patch_response_headers(response) self.assertFalse(response.has_header('ETag')) diff --git a/tests/middleware_exceptions/tests.py b/tests/middleware_exceptions/tests.py index 8a2ddfa4a1..8c191e4ea5 100644 --- a/tests/middleware_exceptions/tests.py +++ b/tests/middleware_exceptions/tests.py @@ -5,7 +5,7 @@ from django.core.exceptions import MiddlewareNotUsed from django.core.signals import got_request_exception from django.http import HttpResponse from django.template.response import TemplateResponse -from django.template import Template +from django.template import engines from django.test import RequestFactory, TestCase, override_settings from django.test.utils import patch_logger @@ -63,7 +63,8 @@ class ResponseMiddleware(TestMiddleware): class TemplateResponseMiddleware(TestMiddleware): def process_template_response(self, request, response): super(TemplateResponseMiddleware, self).process_template_response(request, response) - return TemplateResponse(request, Template('Template Response Middleware')) + template = engines['django'].from_string('Template Response Middleware') + return TemplateResponse(request, template) class ExceptionMiddleware(TestMiddleware): diff --git a/tests/middleware_exceptions/views.py b/tests/middleware_exceptions/views.py index 59abe26bff..d3d7fae661 100644 --- a/tests/middleware_exceptions/views.py +++ b/tests/middleware_exceptions/views.py @@ -1,6 +1,6 @@ from django import http from django.core.exceptions import PermissionDenied -from django.template import Template +from django.template import engines from django.template.response import TemplateResponse @@ -9,11 +9,13 @@ def normal_view(request): def template_response(request): - return TemplateResponse(request, Template('OK')) + template = engines['django'].from_string('OK') + return TemplateResponse(request, template) def template_response_error(request): - return TemplateResponse(request, Template('{%')) + template = engines['django'].from_string('{%') + return TemplateResponse(request, template) def not_found(request): diff --git a/tests/template_tests/test_response.py b/tests/template_tests/test_response.py index c96eb8ff37..993b2002c8 100644 --- a/tests/template_tests/test_response.py +++ b/tests/template_tests/test_response.py @@ -7,7 +7,7 @@ import time from django.test import RequestFactory, SimpleTestCase from django.conf import settings -from django.template import Template, Context +from django.template import Context, engines from django.template.response import (TemplateResponse, SimpleTemplateResponse, ContentNotRenderedError) from django.test import ignore_warnings, override_settings @@ -29,7 +29,8 @@ class CustomURLConfMiddleware(object): class SimpleTemplateResponseTest(SimpleTestCase): def _response(self, template='foo', *args, **kwargs): - return SimpleTemplateResponse(Template(template), *args, **kwargs) + template = engines['django'].from_string(template) + return SimpleTemplateResponse(template, *args, **kwargs) def test_template_resolving(self): response = SimpleTemplateResponse('first/test.html') @@ -58,7 +59,8 @@ class SimpleTemplateResponseTest(SimpleTestCase): self.assertEqual(response.content, b'foo') # rebaking doesn't change the rendered content - response.template_name = Template('bar{{ baz }}') + template = engines['django'].from_string('bar{{ baz }}') + response.template_name = template response.render() self.assertEqual(response.content, b'foo') @@ -113,6 +115,7 @@ class SimpleTemplateResponseTest(SimpleTestCase): response.render() self.assertEqual(response.content, b'bar') + @ignore_warnings(category=RemovedInDjango20Warning) def test_context_instance(self): response = self._response('{{ foo }}{{ processors }}', Context({'foo': 'bar'})) @@ -220,8 +223,9 @@ class TemplateResponseTest(SimpleTestCase): self.factory = RequestFactory() def _response(self, template='foo', *args, **kwargs): - return TemplateResponse(self.factory.get('/'), Template(template), - *args, **kwargs) + self._request = self.factory.get('/') + template = engines['django'].from_string(template) + return TemplateResponse(self._request, template, *args, **kwargs) def test_render(self): response = self._response('{{ foo }}{{ processors }}').render() @@ -232,6 +236,7 @@ class TemplateResponseTest(SimpleTestCase): {'foo': 'bar'}).render() self.assertEqual(response.content, b'baryes') + @ignore_warnings(category=RemovedInDjango20Warning) def test_render_with_context(self): response = self._response('{{ foo }}{{ processors }}', Context({'foo': 'bar'})).render() @@ -257,11 +262,8 @@ class TemplateResponseTest(SimpleTestCase): @ignore_warnings(category=RemovedInDjango20Warning) def test_custom_app(self): - response = self._response('{{ foo }}', current_app="foobar") - - rc = response.resolve_context(response.context_data) - - self.assertEqual(rc.request.current_app, 'foobar') + self._response('{{ foo }}', current_app="foobar") + self.assertEqual(self._request.current_app, 'foobar') def test_pickling(self): # Create a template response. The context is diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index 6f8d97c886..e17bf4ef81 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -8,7 +8,7 @@ import os import itertools from django.core.urlresolvers import reverse, NoReverseMatch -from django.template import TemplateSyntaxError, Context, Template +from django.template import TemplateSyntaxError, Context, engines from django.test import Client, TestCase, ignore_warnings, override_settings from django.test.client import RedirectCycleError, RequestFactory, encode_file from django.test.utils import ContextList, str_prefix @@ -158,7 +158,8 @@ class AssertContainsTests(TestCase): without throwing an error. Refs #15826. """ - response = SimpleTemplateResponse(Template('Hello'), status=200) + template = engines['django'].from_string('Hello') + response = SimpleTemplateResponse(template) self.assertContains(response, 'Hello') def test_assert_contains_using_non_template_response(self): @@ -174,7 +175,8 @@ class AssertContainsTests(TestCase): without throwing an error. Refs #15826. """ - response = SimpleTemplateResponse(Template('Hello'), status=200) + template = engines['django'].from_string('Hello') + response = SimpleTemplateResponse(template) self.assertNotContains(response, 'Bye') def test_assert_not_contains_using_non_template_response(self): diff --git a/tests/utils_tests/test_decorators.py b/tests/utils_tests/test_decorators.py index a05a736c30..8ef4737e54 100644 --- a/tests/utils_tests/test_decorators.py +++ b/tests/utils_tests/test_decorators.py @@ -1,5 +1,5 @@ from django.http import HttpResponse -from django.template import Template, Context +from django.template import engines from django.template.response import TemplateResponse from django.test import TestCase, RequestFactory from django.utils.decorators import decorator_from_middleware @@ -70,8 +70,8 @@ class DecoratorFromMiddlewareTests(TestCase): @full_dec def normal_view(request): - t = Template("Hello world") - return HttpResponse(t.render(Context({}))) + template = engines['django'].from_string("Hello world") + return HttpResponse(template.render()) request = self.rf.get('/') normal_view(request) @@ -89,8 +89,8 @@ class DecoratorFromMiddlewareTests(TestCase): @full_dec def template_response_view(request): - t = Template("Hello world") - return TemplateResponse(request, t, {}) + template = engines['django'].from_string("Hello world") + return TemplateResponse(request, template) request = self.rf.get('/') response = template_response_view(request) |
