Fixed #18707 -- Added support for the test client to return 500 responses.

This commit is contained in:
Jon Dufresne 2019-02-20 03:16:10 -08:00 committed by Carlton Gibson
parent 7071f8f272
commit 7feddd878c
4 changed files with 60 additions and 6 deletions

View file

@ -759,6 +759,20 @@ class ClientTest(TestCase):
with self.assertRaises(KeyError):
self.client.get("/broken_view/")
def test_exc_info(self):
client = Client(raise_request_exception=False)
response = client.get("/broken_view/")
self.assertEqual(response.status_code, 500)
exc_type, exc_value, exc_traceback = response.exc_info
self.assertIs(exc_type, KeyError)
self.assertIsInstance(exc_value, KeyError)
self.assertEqual(str(exc_value), "'Oops! Looks like you wrote some bad code.'")
self.assertIsNotNone(exc_traceback)
def test_exc_info_none(self):
response = self.client.get("/get_view/")
self.assertIsNone(response.exc_info)
def test_mail_sending(self):
"Mail is redirected to a dummy outbox during test setup"
response = self.client.get('/mail_sending_view/')