mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #27567 -- Fixed crash in the debug view when request.user errors.
This commit is contained in:
committed by
Tim Graham
parent
8f76673f34
commit
373140b07a
@@ -515,6 +515,33 @@ class ExceptionReporterTests(SimpleTestCase):
|
||||
html = reporter.get_traceback_html()
|
||||
self.assertInHTML('<td>items</td><td class="code"><pre>'Oops'</pre></td>', html)
|
||||
|
||||
def test_exception_fetching_user(self):
|
||||
"""
|
||||
The error page can be rendered if the current user can't be retrieved
|
||||
(such as when the database is unavailable).
|
||||
"""
|
||||
class ExceptionUser(object):
|
||||
def __str__(self):
|
||||
raise Exception()
|
||||
|
||||
request = self.rf.get('/test_view/')
|
||||
request.user = ExceptionUser()
|
||||
|
||||
try:
|
||||
raise ValueError('Oops')
|
||||
except ValueError:
|
||||
exc_type, exc_value, tb = sys.exc_info()
|
||||
|
||||
reporter = ExceptionReporter(request, exc_type, exc_value, tb)
|
||||
html = reporter.get_traceback_html()
|
||||
self.assertIn('<h1>ValueError at /test_view/</h1>', html)
|
||||
self.assertIn('<pre class="exception_value">Oops</pre>', html)
|
||||
self.assertIn('<h3 id="user-info">USER</h3>', html)
|
||||
self.assertIn('<p>[unable to retrieve the current user]</p>', html)
|
||||
|
||||
text = reporter.get_traceback_text()
|
||||
self.assertIn('USER: [unable to retrieve the current user]', text)
|
||||
|
||||
|
||||
class PlainTextReportTests(SimpleTestCase):
|
||||
rf = RequestFactory()
|
||||
|
||||
Reference in New Issue
Block a user