From 373140b07aa452946ccb6d5b0317fa09ed5bbdc2 Mon Sep 17 00:00:00 2001 From: Andreas Pelme Date: Sat, 3 Dec 2016 19:51:32 +0100 Subject: Fixed #27567 -- Fixed crash in the debug view when request.user errors. --- tests/view_tests/tests/test_debug.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 3fe89d9bf3..24fa593621 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -515,6 +515,33 @@ class ExceptionReporterTests(SimpleTestCase): html = reporter.get_traceback_html() self.assertInHTML('items
'Oops'
', 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('

ValueError at /test_view/

', html) + self.assertIn('
Oops
', html) + self.assertIn('

USER

', html) + self.assertIn('

[unable to retrieve the current user]

', html) + + text = reporter.get_traceback_text() + self.assertIn('USER: [unable to retrieve the current user]', text) + class PlainTextReportTests(SimpleTestCase): rf = RequestFactory() -- cgit v1.3