mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 09:57:55 +03:00 
			
		
		
		
	Merge pull request #458 from asfaltboy/fix_authtoken_response
Fix authtoken response
This commit is contained in:
		
						commit
						52b12434d0
					
				| 
						 | 
					@ -18,7 +18,7 @@ class ObtainAuthToken(APIView):
 | 
				
			||||||
        if serializer.is_valid():
 | 
					        if serializer.is_valid():
 | 
				
			||||||
            token, created = Token.objects.get_or_create(user=serializer.object['user'])
 | 
					            token, created = Token.objects.get_or_create(user=serializer.object['user'])
 | 
				
			||||||
            return Response({'token': token.key})
 | 
					            return Response({'token': token.key})
 | 
				
			||||||
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
 | 
					        return Response(serializer.errors, status=status.HTTP_401_UNAUTHORIZED)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
obtain_auth_token = ObtainAuthToken.as_view()
 | 
					obtain_auth_token = ObtainAuthToken.as_view()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,14 +167,14 @@ class TokenAuthTests(TestCase):
 | 
				
			||||||
        client = Client(enforce_csrf_checks=True)
 | 
					        client = Client(enforce_csrf_checks=True)
 | 
				
			||||||
        response = client.post('/auth-token/login/', 
 | 
					        response = client.post('/auth-token/login/', 
 | 
				
			||||||
                               json.dumps({'username': self.username, 'password': "badpass"}), 'application/json')
 | 
					                               json.dumps({'username': self.username, 'password': "badpass"}), 'application/json')
 | 
				
			||||||
        self.assertEqual(response.status_code, 400)
 | 
					        self.assertEqual(response.status_code, 401)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_token_login_json_missing_fields(self):
 | 
					    def test_token_login_json_missing_fields(self):
 | 
				
			||||||
        """Ensure token login view using JSON POST fails if missing fields."""
 | 
					        """Ensure token login view using JSON POST fails if missing fields."""
 | 
				
			||||||
        client = Client(enforce_csrf_checks=True)
 | 
					        client = Client(enforce_csrf_checks=True)
 | 
				
			||||||
        response = client.post('/auth-token/login/', 
 | 
					        response = client.post('/auth-token/login/', 
 | 
				
			||||||
                               json.dumps({'username': self.username}), 'application/json')
 | 
					                               json.dumps({'username': self.username}), 'application/json')
 | 
				
			||||||
        self.assertEqual(response.status_code, 400)
 | 
					        self.assertEqual(response.status_code, 401)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_token_login_form(self):
 | 
					    def test_token_login_form(self):
 | 
				
			||||||
        """Ensure token login view using form POST works."""
 | 
					        """Ensure token login view using form POST works."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user