      def test_token_login_json_bad_creds(self):
          """Ensure token login view using JSON POST fails if bad credentials are used."""
          client = Client(enforce_csrf_checks=True)
          response = client.post('/auth-token/login/', 
                                      json.dumps({'username': self.username, 'password': "badpass"}), 'application/json')
          self.assertEqual(response.status_code, 400)
  
      def test_token_login_json_missing_fields(self):
          """Ensure token login view using JSON POST fails if missing fields."""
          client = Client(enforce_csrf_checks=True)
 
</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                                     {'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)
 </s> add                                {'username': self.username, 'password': self.password}) </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     def convert_object(self, obj):
        ret = self._dict_class()
        ret['token'] = obj.key
        ret['user'] = obj.user.id
        return ret

    def restore_object(self, attrs, instance=None):
        token, created = Token.objects.get_or_create(user=attrs['user'])
        return token
 </s> add 
                               json.dumps({'username': self.username, 'password': "badpass"}), 'application/json')
      def test_token_login_json_bad_creds(self):
          """Ensure token login view using JSON POST fails if bad credentials are used."""
          client = Client(enforce_csrf_checks=True)
          response = client.post('/auth-token/login/', 
                               json.dumps({'username': self.username, 'password': "badpass"}), 'application/json')
          self.assertEqual(response.status_code, 400)
  
      def test_token_login_json_missing_fields(self):
          """Ensure token login view using JSON POST fails if missing fields."""
          client = Client(enforce_csrf_checks=True)
keep keep keep keep replace keep keep keep keep keep
 Updates to login view for TokenAuthentication from feedback from Tom 
rest_framework/tests/authentication.py