2014-11-13 19:25:08 +00:00
|
|
|
from django.utils.deprecation import RemovedInDjango20Warning
|
2014-12-21 20:19:05 +00:00
|
|
|
from django.test import TestCase, ignore_warnings, override_settings
|
2010-12-21 17:18:41 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-04-09 13:24:57 +00:00
|
|
|
@override_settings(
|
|
|
|
STATIC_URL='/path/to/static/media/',
|
2014-11-22 16:52:12 +00:00
|
|
|
ROOT_URLCONF='shortcuts.urls',
|
2012-04-09 13:24:57 +00:00
|
|
|
)
|
2010-12-21 17:18:41 +00:00
|
|
|
class ShortcutTests(TestCase):
|
2011-04-02 13:27:40 +00:00
|
|
|
|
2010-12-21 17:18:41 +00:00
|
|
|
def test_render_to_response(self):
|
2014-11-22 16:52:12 +00:00
|
|
|
response = self.client.get('/render_to_response/')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-08-11 20:29:18 +00:00
|
|
|
self.assertEqual(response.content, b'FOO.BAR..\n')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
|
2010-12-21 17:18:41 +00:00
|
|
|
|
2014-12-21 20:19:05 +00:00
|
|
|
@ignore_warnings(category=RemovedInDjango20Warning)
|
2010-12-21 17:18:41 +00:00
|
|
|
def test_render_to_response_with_request_context(self):
|
2014-12-21 20:19:05 +00:00
|
|
|
response = self.client.get('/render_to_response/request_context/')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-08-11 20:29:18 +00:00
|
|
|
self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
|
2010-12-21 17:18:41 +00:00
|
|
|
|
2013-01-31 12:39:29 +00:00
|
|
|
def test_render_to_response_with_content_type(self):
|
2014-11-22 16:52:12 +00:00
|
|
|
response = self.client.get('/render_to_response/content_type/')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-08-11 20:29:18 +00:00
|
|
|
self.assertEqual(response.content, b'FOO.BAR..\n')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response['Content-Type'], 'application/x-rendertest')
|
2010-12-21 17:18:41 +00:00
|
|
|
|
2014-12-21 20:19:05 +00:00
|
|
|
@ignore_warnings(category=RemovedInDjango20Warning)
|
2013-09-15 21:51:24 +00:00
|
|
|
def test_render_to_response_with_dirs(self):
|
2014-12-21 20:19:05 +00:00
|
|
|
response = self.client.get('/render_to_response/dirs/')
|
2013-09-15 21:51:24 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(response.content, b'spam eggs\n')
|
|
|
|
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
|
|
|
|
|
2014-12-21 20:19:05 +00:00
|
|
|
@ignore_warnings(category=RemovedInDjango20Warning)
|
2014-11-22 08:22:38 +00:00
|
|
|
def test_render_to_response_with_context_instance_misuse(self):
|
|
|
|
"""
|
|
|
|
For backwards-compatibility, ensure that it's possible to pass a
|
|
|
|
RequestContext instance in the dictionary argument instead of the
|
|
|
|
context_instance argument.
|
|
|
|
"""
|
2014-12-21 20:19:05 +00:00
|
|
|
response = self.client.get('/render_to_response/context_instance_misuse/')
|
2014-11-22 08:22:38 +00:00
|
|
|
self.assertContains(response, 'context processor output')
|
|
|
|
|
2010-12-21 17:18:41 +00:00
|
|
|
def test_render(self):
|
2014-11-22 16:52:12 +00:00
|
|
|
response = self.client.get('/render/')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-08-11 20:29:18 +00:00
|
|
|
self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
|
2014-12-14 16:48:51 +00:00
|
|
|
self.assertFalse(hasattr(response.context.request, 'current_app'))
|
2010-12-21 17:18:41 +00:00
|
|
|
|
2014-12-21 20:19:05 +00:00
|
|
|
@ignore_warnings(category=RemovedInDjango20Warning)
|
2010-12-21 17:18:41 +00:00
|
|
|
def test_render_with_base_context(self):
|
2014-12-21 20:19:05 +00:00
|
|
|
response = self.client.get('/render/base_context/')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-08-11 20:29:18 +00:00
|
|
|
self.assertEqual(response.content, b'FOO.BAR..\n')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
|
2010-12-21 17:18:41 +00:00
|
|
|
|
2010-12-22 04:54:10 +00:00
|
|
|
def test_render_with_content_type(self):
|
2014-11-22 16:52:12 +00:00
|
|
|
response = self.client.get('/render/content_type/')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-08-11 20:29:18 +00:00
|
|
|
self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response['Content-Type'], 'application/x-rendertest')
|
2010-12-21 17:18:41 +00:00
|
|
|
|
2010-12-22 04:54:10 +00:00
|
|
|
def test_render_with_status(self):
|
2014-11-22 16:52:12 +00:00
|
|
|
response = self.client.get('/render/status/')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(response.status_code, 403)
|
2012-08-11 20:29:18 +00:00
|
|
|
self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
|
2010-12-22 04:54:10 +00:00
|
|
|
|
2014-12-21 20:19:05 +00:00
|
|
|
@ignore_warnings(category=RemovedInDjango20Warning)
|
2011-01-05 22:41:43 +00:00
|
|
|
def test_render_with_current_app(self):
|
2014-12-21 20:19:05 +00:00
|
|
|
response = self.client.get('/render/current_app/')
|
2014-12-14 16:48:51 +00:00
|
|
|
self.assertEqual(response.context.request.current_app, "foobar_app")
|
2011-01-05 22:41:43 +00:00
|
|
|
|
2014-12-21 20:19:05 +00:00
|
|
|
@ignore_warnings(category=RemovedInDjango20Warning)
|
2013-09-15 21:51:24 +00:00
|
|
|
def test_render_with_dirs(self):
|
2014-12-21 20:19:05 +00:00
|
|
|
response = self.client.get('/render/dirs/')
|
2013-09-15 21:51:24 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(response.content, b'spam eggs\n')
|
|
|
|
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
|
|
|
|
|
2014-12-21 20:19:05 +00:00
|
|
|
@ignore_warnings(category=RemovedInDjango20Warning)
|
2011-01-05 22:41:43 +00:00
|
|
|
def test_render_with_current_app_conflict(self):
|
2014-11-22 16:52:12 +00:00
|
|
|
with self.assertRaises(ValueError):
|
2014-12-21 20:19:05 +00:00
|
|
|
self.client.get('/render/current_app_conflict/')
|