From 36fe656b510ab49fbf93d2563bb41a40cdc037eb Mon Sep 17 00:00:00 2001 From: Adam Grant Date: Fri, 10 Oct 2014 18:19:44 -0700 Subject: [PATCH] Added test to simulate an error I had where an imported reference failed and the python property swallowed the exception raised in my authenticator. --- tests/test_request.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_request.py b/tests/test_request.py index 8ddaf0a70..3b72bd22d 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -333,6 +333,25 @@ class TestUserSetter(TestCase): login(self.request, self.user) self.assertEqual(self.request.user, self.user) + def test_calling_user_fails_when_exception_is_raised(self): + class AuthRaisesError(object): + def authenticate(self, request): + raise AttributeError('We should see this error!') + # import rest_framework + # rest_framework.MISSPELLED_NAME_THAT_DOESNT_EXIST + + self.request = Request(factory.get('/'), authenticators=(AuthRaisesError(),)) + SessionMiddleware().process_request(self.request) + + login(self.request, self.user) + error_seen = None + try: + self.request.user + except AttributeError as error: + error_seen = error + + self.assertEqual('We should see this error!', error_seen.message) + def test_user_can_logout(self): self.request.user = self.user self.assertFalse(self.request.user.is_anonymous())