mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
reset stored credentials when call client.logout()
This commit is contained in:
parent
115fe04842
commit
af8a362d6b
|
@ -154,6 +154,10 @@ class APIClient(APIRequestFactory, DjangoClient):
|
||||||
kwargs.update(self._credentials)
|
kwargs.update(self._credentials)
|
||||||
return super(APIClient, self).request(**kwargs)
|
return super(APIClient, self).request(**kwargs)
|
||||||
|
|
||||||
|
def logout(self):
|
||||||
|
self._credentials = {}
|
||||||
|
return super(APIClient, self).logout()
|
||||||
|
|
||||||
|
|
||||||
class APITransactionTestCase(testcases.TransactionTestCase):
|
class APITransactionTestCase(testcases.TransactionTestCase):
|
||||||
client_class = APIClient
|
client_class = APIClient
|
||||||
|
|
|
@ -99,6 +99,17 @@ class TestAPITestClient(TestCase):
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
self.assertEqual(response.data, expected)
|
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):
|
class TestAPIRequestFactory(TestCase):
|
||||||
def test_csrf_exempt_by_default(self):
|
def test_csrf_exempt_by_default(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user