'Test that an administrator can change a user\'s password, while a regular user cannot.'

def test_change_user_passwd(self):

    url = u'/v1/auth/passwd'
    old_password = self.user1.password
    new_password = u'password'
    submit = {u'username': self.user1.username, u'new_password': new_password}
    response = self.client.post(url, json.dumps(submit), content_type=u'application/json', HTTP_AUTHORIZATION=u'token    {}'.format(self.admin_token))
    self.assertEqual(response.status_code, 200)
    url = u'/v1/auth/login/'
    payload = urllib.urlencode({u'username': self.user1.username, u'password': old_password})
    response = self.client.post(url, data=payload, content_type=u'application/x-www-form-urlencoded')
    self.assertEqual(response.status_code, 400)
    payload = urllib.urlencode({u'username': self.user1.username, u'password': new_password})
    response = self.client.post(url, data=payload, content_type=u'application/x-www-form-urlencoded')
    self.assertEqual(response.status_code, 200)
    (submit[u'password'], submit[u'new_password']) = (submit[u'new_password'], old_password)
    url = u'/v1/auth/passwd'
    response = self.client.post(url, json.dumps(submit), content_type=u'application/json', HTTP_AUTHORIZATION=u'token    {}'.format(self.user2_token))
    self.assertEqual(response.status_code, 403)
    response = self.client.post(url, json.dumps(submit), content_type=u'application/json', HTTP_AUTHORIZATION=u'token    {}'.format(self.user1_token))
    self.assertEqual(response.status_code, 200)
    url = u'/v1/auth/login/'
    payload = urllib.urlencode({u'username': self.user1.username, u'password': old_password})
    response = self.client.post(url, data=payload, content_type=u'application/x-www-form-urlencoded')
    self.assertEqual(response.status_code, 200)
