@@ -333,24 +333,27 @@ def test_user_can_login(self):
333
333
login (self .request , self .user )
334
334
self .assertEqual (self .request .user , self .user )
335
335
336
- def test_calling_user_fails_when_exception_is_raised (self ):
337
- class AuthRaisesError (object ):
336
+ def test_calling_user_fails_when_attribute_error_is_raised (self ):
337
+ """
338
+ This proves that when an AttributeError is raised inside of the request.user
339
+ property, that we can handle this and report the true, underlying error.
340
+ """
341
+ class AuthRaisesAttributeError (object ):
338
342
def authenticate (self , request ):
339
- raise AttributeError ('We should see this error!' )
340
- # import rest_framework
341
- # rest_framework.MISSPELLED_NAME_THAT_DOESNT_EXIST
343
+ import rest_framework
344
+ rest_framework .MISSPELLED_NAME_THAT_DOESNT_EXIST
342
345
343
- self .request = Request (factory .get ('/' ), authenticators = (AuthRaisesError (),))
346
+ self .request = Request (factory .get ('/' ), authenticators = (AuthRaisesAttributeError (),))
344
347
SessionMiddleware ().process_request (self .request )
345
348
346
349
login (self .request , self .user )
347
350
error_seen = None
348
351
try :
349
352
self .request .user
350
- except AttributeError as error :
353
+ except RuntimeError as error :
351
354
error_seen = error
352
355
353
- self .assertEqual ('We should see this error!' , error_seen .message )
356
+ self .assertEqual ("AttributeError: 'module' object has no attribute 'MISSPELLED_NAME_THAT_DOESNT_EXIST'" , error_seen .message )
354
357
355
358
def test_user_can_logout (self ):
356
359
self .request .user = self .user
0 commit comments