aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Christie2014-08-18 20:37:25 +0100
committerTom Christie2014-08-18 20:37:25 +0100
commit1d0c169e945086bf6c25ee7a661bc3b5737c767a (patch)
treeea073c509d1054af4e33d2211457029e969a0781
parentc092b4df7873b1bf9ead5ac65406f1347d4c4365 (diff)
parentaf8a362d6b513b71de45109b441f79ed7d1b103c (diff)
downloaddjango-rest-framework-1d0c169e945086bf6c25ee7a661bc3b5737c767a.tar.bz2
Merge pull request #1505 from ticosax/test.client.logout
reset stored credentials when call client.logout()
-rw-r--r--rest_framework/test.py4
-rw-r--r--rest_framework/tests/test_testing.py11
2 files changed, 15 insertions, 0 deletions
diff --git a/rest_framework/test.py b/rest_framework/test.py
index 284bcee0..d4ec50a0 100644
--- a/rest_framework/test.py
+++ b/rest_framework/test.py
@@ -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
diff --git a/rest_framework/tests/test_testing.py b/rest_framework/tests/test_testing.py
index a55d4b22..b16d1962 100644
--- a/rest_framework/tests/test_testing.py
+++ b/rest_framework/tests/test_testing.py
@@ -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):