      def test_token_login_form(self):
          """Ensure token login view using form POST works."""
          client = Client(enforce_csrf_checks=True)
          response = client.post('/auth-token/login/', 
                                      {'username': self.username, 'password': self.password})
          self.assertEqual(response.status_code, 201)
          self.assertEqual(json.loads(response.content)['token'], self.key)
  
      def test_token_logout(self):
          """Ensure token logout view using JSON POST works."""
          # Use different User and Token as to isolate this test's effects on other unittests in class
          username = "ringo"
          user = User.objects.create_user(username, "starr@thebeatles.com", "pass")
          token = Token.objects.create(user=user)
          auth = "Token " + token.key
          client = Client(enforce_csrf_checks=True)
          response = client.post('/auth-token/logout/', HTTP_AUTHORIZATION=auth)
          self.assertEqual(response.status_code, 200)
          # Ensure token no longer exists
          self.assertRaises(Token.DoesNotExist, lambda token: Token.objects.get(key=token.key), token)
 
</s> remove         # Ensure token no longer exists
        self.assertRaises(Token.DoesNotExist, lambda token: Token.objects.get(key=token.key), token)
 </s> add         self.assertEqual(json.loads(response.content)['token'], self.key) </s> remove                                     json.dumps({'username': self.username, 'password': self.password}), 'application/json')
        self.assertEqual(response.status_code, 201)
 </s> add                                json.dumps({'username': self.username, 'password': self.password}), 'application/json')
        self.assertEqual(response.status_code, 200) </s> remove                                     json.dumps({'username': self.username}), 'application/json')
 </s> add                                json.dumps({'username': self.username}), 'application/json') </s> remove                                     json.dumps({'username': self.username, 'password': "badpass"}), 'application/json')
 </s> add                                json.dumps({'username': self.username, 'password': "badpass"}), 'application/json') </s> remove     token = serializers.Field(source="key")
    username = serializers.CharField(max_length=30)
 </s> add     username = serializers.CharField()
                               {'username': self.username, 'password': self.password})
      def test_token_login_form(self):
          """Ensure token login view using form POST works."""
          client = Client(enforce_csrf_checks=True)
          response = client.post('/auth-token/login/', 
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
                               {'username': self.username, 'password': self.password})
          self.assertEqual(response.status_code, 200)
          # Ensure token no longer exists
          self.assertRaises(Token.DoesNotExist, lambda token: Token.objects.get(key=token.key), token)
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep
 Updates to login view for TokenAuthentication from feedback from Tom 
rest_framework/tests/authentication.py