reset stored credentials when call client.logout()

This commit is contained in:
Nicolas Delaby 2014-04-07 14:59:27 +02:00
parent 115fe04842
commit af8a362d6b
2 changed files with 15 additions and 0 deletions

View File

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

View File

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