PageRenderTime 39ms CodeModel.GetById 33ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/views/tests/shortcuts.py

https://code.google.com/p/mango-py/
Python | 66 lines | 53 code | 13 blank | 0 comment | 0 complexity | ee1b2075b0a4e1281147efad488cf73b MD5 | raw file
 1from django.conf import settings
 2from django.test import TestCase
 3
 4class ShortcutTests(TestCase):
 5    def setUp(self):
 6        self.old_STATIC_URL = settings.STATIC_URL
 7        self.old_TEMPLATE_CONTEXT_PROCESSORS = settings.TEMPLATE_CONTEXT_PROCESSORS
 8
 9        settings.STATIC_URL = '/path/to/static/media'
10        settings.TEMPLATE_CONTEXT_PROCESSORS = (
11            'django.core.context_processors.static'
12        )
13
14    def tearDown(self):
15        settings.STATIC_URL = self.old_STATIC_URL
16        settings.TEMPLATE_CONTEXT_PROCESSORS = self.old_TEMPLATE_CONTEXT_PROCESSORS
17
18    def test_render_to_response(self):
19        response = self.client.get('/views/shortcuts/render_to_response/')
20        self.assertEqual(response.status_code, 200)
21        self.assertEqual(response.content, 'FOO.BAR..\n')
22        self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
23
24    def test_render_to_response_with_request_context(self):
25        response = self.client.get('/views/shortcuts/render_to_response/request_context/')
26        self.assertEqual(response.status_code, 200)
27        self.assertEqual(response.content, 'FOO.BAR../path/to/static/media\n')
28        self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
29
30    def test_render_to_response_with_mimetype(self):
31        response = self.client.get('/views/shortcuts/render_to_response/mimetype/')
32        self.assertEqual(response.status_code, 200)
33        self.assertEqual(response.content, 'FOO.BAR..\n')
34        self.assertEqual(response['Content-Type'], 'application/x-rendertest')
35
36    def test_render(self):
37        response = self.client.get('/views/shortcuts/render/')
38        self.assertEqual(response.status_code, 200)
39        self.assertEqual(response.content, 'FOO.BAR../path/to/static/media\n')
40        self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
41        self.assertEqual(response.context.current_app, None)
42
43    def test_render_with_base_context(self):
44        response = self.client.get('/views/shortcuts/render/base_context/')
45        self.assertEqual(response.status_code, 200)
46        self.assertEqual(response.content, 'FOO.BAR..\n')
47        self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
48
49    def test_render_with_content_type(self):
50        response = self.client.get('/views/shortcuts/render/content_type/')
51        self.assertEqual(response.status_code, 200)
52        self.assertEqual(response.content, 'FOO.BAR../path/to/static/media\n')
53        self.assertEqual(response['Content-Type'], 'application/x-rendertest')
54
55    def test_render_with_status(self):
56        response = self.client.get('/views/shortcuts/render/status/')
57        self.assertEqual(response.status_code, 403)
58        self.assertEqual(response.content, 'FOO.BAR../path/to/static/media\n')
59
60    def test_render_with_current_app(self):
61        response = self.client.get('/views/shortcuts/render/current_app/')
62        self.assertEqual(response.context.current_app, "foobar_app")
63
64    def test_render_with_current_app_conflict(self):
65        self.assertRaises(ValueError, self.client.get, '/views/shortcuts/render/current_app_conflict/')
66