mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Added test to simulate an error I had where an imported reference failed and the python property swallowed the exception raised in my authenticator.
This commit is contained in:
parent
b3af4d9fe7
commit
36fe656b51
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue
Block a user