Fix testing with token

This commit is contained in:
Will Beaufoy 2021-10-17 15:33:34 +01:00
parent acf6582de4
commit 0768339e57
2 changed files with 4 additions and 3 deletions

View File

@ -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):

View File

@ -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