Commit 1d0c169e by Tom Christie

Merge pull request #1505 from ticosax/test.client.logout

reset stored credentials when call client.logout()
parents c092b4df af8a362d
......@@ -154,6 +154,10 @@ class APIClient(APIRequestFactory, DjangoClient):
kwargs.update(self._credentials)
return super(APIClient, self).request(**kwargs)
def logout(self):
self._credentials = {}
return super(APIClient, self).logout()
class APITransactionTestCase(testcases.TransactionTestCase):
client_class = APIClient
......
......@@ -99,6 +99,17 @@ class TestAPITestClient(TestCase):
self.assertEqual(response.status_code, 403)
self.assertEqual(response.data, expected)
def test_can_logout(self):
"""
`logout()` reset stored credentials
"""
self.client.credentials(HTTP_AUTHORIZATION='example')
response = self.client.get('/view/')
self.assertEqual(response.data['auth'], 'example')
self.client.logout()
response = self.client.get('/view/')
self.assertEqual(response.data['auth'], b'')
class TestAPIRequestFactory(TestCase):
def test_csrf_exempt_by_default(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment