2010-03-09 01:01:21 +08:00
|
|
|
import inspect
|
|
|
|
|
2009-04-01 01:10:06 +08:00
|
|
|
from django.conf import settings
|
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
|
|
|
from django.test import TestCase
|
2010-03-08 23:20:29 +08:00
|
|
|
from django.core.urlresolvers import reverse
|
2010-03-09 01:01:21 +08:00
|
|
|
from django.template import TemplateSyntaxError
|
2010-03-08 23:20:29 +08:00
|
|
|
|
|
|
|
from regressiontests.views import BrokenException, except_args
|
2009-04-01 01:10:06 +08:00
|
|
|
|
|
|
|
class DebugViewTests(TestCase):
|
|
|
|
def setUp(self):
|
2010-03-08 23:20:29 +08:00
|
|
|
self.old_debug = settings.DEBUG
|
2009-04-01 01:10:06 +08:00
|
|
|
settings.DEBUG = True
|
2010-12-04 15:28:12 +08:00
|
|
|
self.old_template_debug = settings.TEMPLATE_DEBUG
|
|
|
|
settings.TEMPLATE_DEBUG = True
|
2009-04-01 01:10:06 +08:00
|
|
|
|
|
|
|
def tearDown(self):
|
2010-03-08 23:20:29 +08:00
|
|
|
settings.DEBUG = self.old_debug
|
2010-03-09 01:01:21 +08:00
|
|
|
settings.TEMPLATE_DEBUG = self.old_template_debug
|
2009-04-01 01:10:06 +08:00
|
|
|
|
|
|
|
def test_files(self):
|
|
|
|
response = self.client.get('/views/raises/')
|
|
|
|
self.assertEquals(response.status_code, 500)
|
|
|
|
|
|
|
|
data = {
|
|
|
|
'file_data.txt': SimpleUploadedFile('file_data.txt', 'haha'),
|
|
|
|
}
|
|
|
|
response = self.client.post('/views/raises/', data)
|
2010-12-04 15:28:12 +08:00
|
|
|
self.assertTrue('file_data.txt' in response.content)
|
|
|
|
self.assertFalse('haha' in response.content)
|
2010-03-06 02:53:07 +08:00
|
|
|
|
|
|
|
def test_404(self):
|
|
|
|
response = self.client.get('/views/raises404/')
|
|
|
|
self.assertEquals(response.status_code, 404)
|
2010-03-08 23:20:29 +08:00
|
|
|
|
|
|
|
def test_view_exceptions(self):
|
|
|
|
for n in range(len(except_args)):
|
|
|
|
self.assertRaises(BrokenException, self.client.get,
|
|
|
|
reverse('view_exception', args=(n,)))
|
|
|
|
|
2010-03-09 01:01:21 +08:00
|
|
|
def test_template_exceptions(self):
|
|
|
|
for n in range(len(except_args)):
|
|
|
|
try:
|
|
|
|
self.client.get(reverse('template_exception', args=(n,)))
|
|
|
|
except TemplateSyntaxError, e:
|
|
|
|
raising_loc = inspect.trace()[-1][-2][0].strip()
|
2010-12-04 15:28:12 +08:00
|
|
|
self.assertFalse(raising_loc.find('raise BrokenException') == -1,
|
|
|
|
"Failed to find 'raise BrokenException' in last frame of traceback, instead found: %s" %
|
|
|
|
raising_loc)
|