diff options
| author | Tom Christie | 2015-02-09 17:56:25 +0000 |
|---|---|---|
| committer | Tom Christie | 2015-02-09 17:56:25 +0000 |
| commit | 873fb69395de6fd230e4aba1b707c1f1979c0f07 (patch) | |
| tree | 3ba0bdc1bbb21fcb7e36c37cd6170112c94a7054 /tests/test_request.py | |
| parent | 235b98e427e2bae2b52fb386a42c8045724de251 (diff) | |
| parent | 1a087c8c5bac6f157979ef9ff540c0eb23848fb4 (diff) | |
| download | django-rest-framework-873fb69395de6fd230e4aba1b707c1f1979c0f07.tar.bz2 | |
Merge pull request #2530 from tomchristie/attribute-proxying-fix
Fix misleading `AttributeError` tracebacks on `Request` objects.
Diffstat (limited to 'tests/test_request.py')
| -rw-r--r-- | tests/test_request.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/test_request.py b/tests/test_request.py index 02a9b1e2..c274ab69 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -249,9 +249,29 @@ class TestUserSetter(TestCase): login(self.request, self.user) self.assertEqual(self.wrapped_request.user, self.user) + def test_calling_user_fails_when_attribute_error_is_raised(self): + """ + This proves that when an AttributeError is raised inside of the request.user + property, that we can handle this and report the true, underlying error. + """ + class AuthRaisesAttributeError(object): + def authenticate(self, request): + import rest_framework + rest_framework.MISSPELLED_NAME_THAT_DOESNT_EXIST -class TestAuthSetter(TestCase): + self.request = Request(factory.get('/'), authenticators=(AuthRaisesAttributeError(),)) + SessionMiddleware().process_request(self.request) + login(self.request, self.user) + try: + self.request.user + except AttributeError as error: + self.assertEqual(str(error), "'module' object has no attribute 'MISSPELLED_NAME_THAT_DOESNT_EXIST'") + else: + assert False, 'AttributeError not raised' + + +class TestAuthSetter(TestCase): def test_auth_can_be_set(self): request = Request(factory.get('/')) request.auth = 'DUMMY' |
