Skip to content

Commit 0768339

Browse files
committed
Fix testing with token
1 parent acf6582 commit 0768339

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

rest_framework/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def force_authenticate(self, user=None, token=None):
277277
"""
278278
self.handler._force_user = user
279279
self.handler._force_token = token
280-
if user is None:
280+
if user is None and token is None:
281281
self.logout() # Also clear any possible session info if required
282282

283283
def request(self, **kwargs):

tests/test_testing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ def test_force_authenticate_with_sessions(self):
102102
response = self.client.get('/session-view/')
103103
assert response.data['active_session'] is True
104104

105-
# Force authenticating as `None` should also logout the user session.
106-
self.client.force_authenticate(None)
105+
# Force authenticating with `None` user and token should also logout
106+
# the user session.
107+
self.client.force_authenticate(user=None, token=None)
107108
response = self.client.get('/session-view/')
108109
assert response.data['active_session'] is False
109110

0 commit comments

Comments
 (0)