mirror of
https://github.com/django/django.git
synced 2025-07-19 09:09:13 +00:00
[1.8.x] Refs #26253 -- Added tests for deprecation shims in SimpleTemplateResponse.
Backport of 3fedfc452fa94f8a6c9a64289d00202313ceb564 from stable/1.9.x
This commit is contained in:
parent
5127ab4e73
commit
061a7ff366
42
tests/template_tests/test_response_deprecations.py
Normal file
42
tests/template_tests/test_response_deprecations.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import warnings
|
||||||
|
|
||||||
|
from django.http import HttpRequest
|
||||||
|
from django.template import Template
|
||||||
|
from django.template.response import TemplateResponse
|
||||||
|
from django.test import SimpleTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class MyTemplateResponse(TemplateResponse):
|
||||||
|
def resolve_template(self, template_name):
|
||||||
|
return Template(template_name)
|
||||||
|
|
||||||
|
|
||||||
|
class DeprecationTests(SimpleTestCase):
|
||||||
|
|
||||||
|
def test_template_response(self):
|
||||||
|
msg = (
|
||||||
|
"TemplateResponse's template argument cannot be a "
|
||||||
|
"django.template.Template anymore. It may be a backend-specific "
|
||||||
|
"template like those created by get_template()."
|
||||||
|
)
|
||||||
|
with warnings.catch_warnings(record=True) as warns:
|
||||||
|
warnings.simplefilter('always')
|
||||||
|
response = TemplateResponse(HttpRequest(), Template('foo'))
|
||||||
|
response.render()
|
||||||
|
self.assertEqual(response.content, b'foo')
|
||||||
|
self.assertEqual(len(warns), 1)
|
||||||
|
self.assertEqual(str(warns[0].message), msg)
|
||||||
|
|
||||||
|
def test_custom_template_response(self):
|
||||||
|
response = MyTemplateResponse(HttpRequest(), 'baz')
|
||||||
|
msg = (
|
||||||
|
"MyTemplateResponse.resolve_template() must return a "
|
||||||
|
"backend-specific template like those created by get_template(), "
|
||||||
|
"not a Template."
|
||||||
|
)
|
||||||
|
with warnings.catch_warnings(record=True) as warns:
|
||||||
|
warnings.simplefilter('always')
|
||||||
|
response.render()
|
||||||
|
self.assertEqual(response.content, b'baz')
|
||||||
|
self.assertEqual(len(warns), 1)
|
||||||
|
self.assertEqual(str(warns[0].message), msg)
|
Loading…
x
Reference in New Issue
Block a user