2015-09-05 16:25:43 +02:00
|
|
|
from django.test import SimpleTestCase, override_settings
|
2015-01-26 21:57:10 +01:00
|
|
|
from django.test.utils import require_jinja2
|
2010-12-21 18:18:41 +01:00
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2017-02-11 11:49:04 +01:00
|
|
|
@override_settings(ROOT_URLCONF="shortcuts.urls")
|
|
|
|
class RenderTests(SimpleTestCase):
|
2010-12-21 18:18:41 +01:00
|
|
|
def test_render(self):
|
2014-11-22 17:52:12 +01:00
|
|
|
response = self.client.get("/render/")
|
2011-03-03 16:04:39 +01:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-01-12 22:31:44 +01:00
|
|
|
self.assertEqual(response.content, b"FOO.BAR../render/\n")
|
2020-07-14 13:32:24 +02:00
|
|
|
self.assertEqual(response.headers["Content-Type"], "text/html; charset=utf-8")
|
2014-12-14 17:48:51 +01:00
|
|
|
self.assertFalse(hasattr(response.context.request, "current_app"))
|
2010-12-21 18:18:41 +01:00
|
|
|
|
2015-01-03 19:28:15 +01:00
|
|
|
def test_render_with_multiple_templates(self):
|
|
|
|
response = self.client.get("/render/multiple_templates/")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-01-12 22:31:44 +01:00
|
|
|
self.assertEqual(response.content, b"FOO.BAR../render/multiple_templates/\n")
|
2015-01-03 19:28:15 +01:00
|
|
|
|
2010-12-22 05:54:10 +01:00
|
|
|
def test_render_with_content_type(self):
|
2014-11-22 17:52:12 +01:00
|
|
|
response = self.client.get("/render/content_type/")
|
2011-03-03 16:04:39 +01:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-01-12 22:31:44 +01:00
|
|
|
self.assertEqual(response.content, b"FOO.BAR../render/content_type/\n")
|
2020-07-14 13:32:24 +02:00
|
|
|
self.assertEqual(response.headers["Content-Type"], "application/x-rendertest")
|
2010-12-21 18:18:41 +01:00
|
|
|
|
2010-12-22 05:54:10 +01:00
|
|
|
def test_render_with_status(self):
|
2014-11-22 17:52:12 +01:00
|
|
|
response = self.client.get("/render/status/")
|
2011-03-03 16:04:39 +01:00
|
|
|
self.assertEqual(response.status_code, 403)
|
2015-01-12 22:31:44 +01:00
|
|
|
self.assertEqual(response.content, b"FOO.BAR../render/status/\n")
|
2010-12-22 05:54:10 +01:00
|
|
|
|
2015-01-26 21:57:10 +01:00
|
|
|
@require_jinja2
|
|
|
|
def test_render_with_using(self):
|
|
|
|
response = self.client.get("/render/using/")
|
|
|
|
self.assertEqual(response.content, b"DTL\n")
|
|
|
|
response = self.client.get("/render/using/?using=django")
|
|
|
|
self.assertEqual(response.content, b"DTL\n")
|
|
|
|
response = self.client.get("/render/using/?using=jinja2")
|
|
|
|
self.assertEqual(response.content, b"Jinja2\n")
|