Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setter to auth property #528

Merged
merged 1 commit into from Dec 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions rest_framework/request.py
Expand Up @@ -188,6 +188,14 @@ def auth(self):
self._user, self._auth = self._authenticate()
return self._auth

@auth.setter
def auth(self, value):
"""
Sets any non-user authentication information associated with the
request, such as an authentication token.
"""
self._auth = value

def _load_data_and_files(self):
"""
Parses the request content into self.DATA and self.FILES.
Expand Down
8 changes: 8 additions & 0 deletions rest_framework/tests/request.py
Expand Up @@ -303,3 +303,11 @@ def test_user_can_logout(self):
self.assertFalse(self.request.user.is_anonymous())
logout(self.request)
self.assertTrue(self.request.user.is_anonymous())


class TestAuthSetter(TestCase):

def test_auth_can_be_set(self):
request = Request(factory.get('/'))
request.auth = 'DUMMY'
self.assertEqual(request.auth, 'DUMMY')