mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 00:19:53 +03:00
Fix testing with token
This commit is contained in:
parent
acf6582de4
commit
0768339e57
|
@ -277,7 +277,7 @@ class APIClient(APIRequestFactory, DjangoClient):
|
|||
"""
|
||||
self.handler._force_user = user
|
||||
self.handler._force_token = token
|
||||
if user is None:
|
||||
if user is None and token is None:
|
||||
self.logout() # Also clear any possible session info if required
|
||||
|
||||
def request(self, **kwargs):
|
||||
|
|
|
@ -102,8 +102,9 @@ class TestAPITestClient(TestCase):
|
|||
response = self.client.get('/session-view/')
|
||||
assert response.data['active_session'] is True
|
||||
|
||||
# Force authenticating as `None` should also logout the user session.
|
||||
self.client.force_authenticate(None)
|
||||
# Force authenticating with `None` user and token should also logout
|
||||
# the user session.
|
||||
self.client.force_authenticate(user=None, token=None)
|
||||
response = self.client.get('/session-view/')
|
||||
assert response.data['active_session'] is False
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user