From cc5477df890f66854275c2b3ce46e8457fe8a6b2 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 31 Mar 2009 17:10:06 +0000 Subject: [PATCH] Fixed #7529: added a FILES section to the debug view. As a bonus, we've now got the start of a suite of tests for the debug views. Thanks, Alex Gaynor. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10271 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/debug.py | 22 +++++++++++++++++++ tests/regressiontests/views/tests/__init__.py | 1 + tests/regressiontests/views/tests/debug.py | 21 ++++++++++++++++++ tests/regressiontests/views/urls.py | 5 +++++ tests/regressiontests/views/views.py | 9 ++++++++ 5 files changed, 58 insertions(+) create mode 100644 tests/regressiontests/views/tests/debug.py diff --git a/django/views/debug.py b/django/views/debug.py index f2288cf1731..650aebae102 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -611,6 +611,28 @@ Exception Value: {{ exception_value|escape }} {% else %}

No POST data

{% endif %} +

FILES

+ {% if request.FILES %} + + + + + + + + + {% for var in request.FILES.items %} + + + + + {% endfor %} + +
VariableValue
{{ var.0 }}
{{ var.1|pprint }}
+ {% else %} +

No FILES data

+ {% endif %} + {% if request.COOKIES %} diff --git a/tests/regressiontests/views/tests/__init__.py b/tests/regressiontests/views/tests/__init__.py index 9964cd5833c..9c363b3f097 100644 --- a/tests/regressiontests/views/tests/__init__.py +++ b/tests/regressiontests/views/tests/__init__.py @@ -3,3 +3,4 @@ from i18n import * from static import * from generic.date_based import * from generic.create_update import * +from debug import * diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py new file mode 100644 index 00000000000..0c0b62f51ff --- /dev/null +++ b/tests/regressiontests/views/tests/debug.py @@ -0,0 +1,21 @@ +from django.conf import settings +from django.core.files.uploadedfile import SimpleUploadedFile +from django.test import TestCase + +class DebugViewTests(TestCase): + def setUp(self): + settings.DEBUG = True + + def tearDown(self): + settings.DEBUG = False + + 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) + self.failUnless('file_data.txt' in response.content) + self.failIf('haha' in response.content) diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py index 6403ab3a392..b6a269f9f44 100644 --- a/tests/regressiontests/views/urls.py +++ b/tests/regressiontests/views/urls.py @@ -82,3 +82,8 @@ urlpatterns += patterns('django.views.generic.create_update', (r'^create_update/no_url/update/article/(?P[-\w]+)/$', 'update_object', dict(slug_field='slug', model=UrlArticle)), ) + +# a view that raises an exception for the debug view +urlpatterns += patterns('', + (r'^raises/$', views.raises) +) diff --git a/tests/regressiontests/views/views.py b/tests/regressiontests/views/views.py index b90852189cd..969d760d8e9 100644 --- a/tests/regressiontests/views/views.py +++ b/tests/regressiontests/views/views.py @@ -1,5 +1,8 @@ +import sys + from django.http import HttpResponse from django import forms +from django.views.debug import technical_500_response from django.views.generic.create_update import create_object from models import Article @@ -27,3 +30,9 @@ def custom_create(request): return create_object(request, post_save_redirect='/views/create_update/view/article/%(slug)s/', form_class=SlugChangingArticleForm) + +def raises(request): + try: + raise Exception + except Exception: + return technical_500_response(request, *sys.exc_info())