diff options
| author | Nicolas Delaby | 2014-04-07 14:59:27 +0200 | 
|---|---|---|
| committer | Nicolas Delaby | 2014-04-07 14:59:27 +0200 | 
| commit | af8a362d6b513b71de45109b441f79ed7d1b103c (patch) | |
| tree | 2095eab0c8ab0145d25c974685df248ca6d92665 | |
| parent | 115fe04842b58226b9fa29069b95af7df62b046a (diff) | |
| download | django-rest-framework-af8a362d6b513b71de45109b441f79ed7d1b103c.tar.bz2 | |
reset stored credentials when call client.logout()
| -rw-r--r-- | rest_framework/test.py | 4 | ||||
| -rw-r--r-- | rest_framework/tests/test_testing.py | 11 | 
2 files changed, 15 insertions, 0 deletions
| diff --git a/rest_framework/test.py b/rest_framework/test.py index df5a5b3b..79982cb0 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): | 
