mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 18:08:03 +03:00 
			
		
		
		
	Merge pull request #1505 from ticosax/test.client.logout
reset stored credentials when call client.logout()
This commit is contained in:
		
						commit
						1d0c169e94
					
				| 
						 | 
				
			
			@ -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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user