diff options
| author | Andreas Pelme <andreas@pelme.se> | 2016-12-03 19:51:32 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-06 12:58:40 -0500 |
| commit | f1f4a7f5a94b449a2174f2598a8e89c421d83917 (patch) | |
| tree | 8b006a37794f1fd25ce9dc20b284d55b71767d08 /tests | |
| parent | 6265ca25f3fb4f9bf3b38eed8b8eeafdcf02a16e (diff) | |
[1.10.x] Fixed #27567 -- Fixed crash in the debug view when request.user errors.
Backport of 373140b07aa452946ccb6d5b0317fa09ed5bbdc2 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/view_tests/tests/test_debug.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 714723c957..66796c705e 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -464,6 +464,33 @@ class ExceptionReporterTests(SimpleTestCase): html = reporter.get_traceback_html() self.assertIn("http://evil.com/", 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() |
