'Test that a registered user can change the password.'

def test_passwd(self):

    (username, password) = (u'newuser', u'password')
    (first_name, last_name) = (u'Otto', u'Test')
    email = u'autotest@deis.io'
    submit = {u'username': username, u'password': password, u'first_name': first_name, u'last_name': last_name, u'email': email}
    url = u'/v1/auth/register'
    response = self.client.post(url, json.dumps(submit), content_type=u'application/json')
    self.assertEqual(response.status_code, 201)
    url = u'/v1/auth/passwd'
    user = User.objects.get(username=username)
    token = Token.objects.get(user=user).key
    submit = {u'password': u'password2', u'new_password': password}
    response = self.client.post(url, json.dumps(submit), content_type=u'application/json', HTTP_AUTHORIZATION=u'token    {}'.format(token))
    self.assertEqual(response.status_code, 400)
    self.assertEqual(response.data, {u'detail': u'Current    password    does    not    match'})
    self.assertEqual(response.get(u'content-type'), u'application/json')
    submit = {u'password': password, u'new_password': u'password2'}
    response = self.client.post(url, json.dumps(submit), content_type=u'application/json', HTTP_AUTHORIZATION=u'token    {}'.format(token))
    self.assertEqual(response.status_code, 200)
    url = u'/v1/auth/login/'
    payload = urllib.urlencode({u'username': username, u'password': 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': username, u'password': u'password2'})
    response = self.client.post(url, data=payload, content_type=u'application/x-www-form-urlencoded')
    self.assertEqual(response.status_code, 200)
