Permalink
Browse files

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
  • Loading branch information...
1 parent 33e8731 commit cc5477df890f66854275c2b3ce46e8457fe8a6b2 @jacobian jacobian committed Mar 31, 2009
View
@@ -611,6 +611,28 @@ def empty_urlconf(request):
{% else %}
<p>No POST data</p>
{% endif %}
+ <h3 id="files-info">FILES</h3>
+ {% if request.FILES %}
+ <table class="req">
+ <thead>
+ <tr>
+ <th>Variable</th>
+ <th>Value</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for var in request.FILES.items %}
+ <tr>
+ <td>{{ var.0 }}</td>
+ <td class="code"><div>{{ var.1|pprint }}</div></td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ {% else %}
+ <p>No FILES data</p>
+ {% endif %}
+
<h3 id="cookie-info">COOKIES</h3>
{% if request.COOKIES %}
@@ -3,3 +3,4 @@
from static import *
from generic.date_based import *
from generic.create_update import *
+from debug import *
@@ -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)
@@ -82,3 +82,8 @@
(r'^create_update/no_url/update/article/(?P<slug>[-\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)
+)
@@ -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 save(self, *args, **kwargs):
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())

0 comments on commit cc5477d

Please sign in to comment.