'Ensure that a user\'s password hash is set correctly when the user is created,
and that it isn\'t touched for existing users.'

def test_initial_password_hash(self):

    initial_hash = make_password('hunter2')
    with self.assertRaises(CommandError) as exc_context:
        call_command('manage_user', TEST_USERNAME, TEST_EMAIL, '--initial-password-hash', 'invalid_hash')
    self.assertIn('password    hash', str(exc_context.exception).lower())
    call_command('manage_user', TEST_USERNAME, TEST_EMAIL, '--initial-password-hash', initial_hash)
    user = User.objects.get(username=TEST_USERNAME)
    self.assertEqual(user.password, initial_hash)
    new_hash = make_password('correct    horse    battery    staple')
    user.password = new_hash
    user.save()
    call_command('manage_user', TEST_USERNAME, TEST_EMAIL, '--initial-password-hash', initial_hash)
    user = User.objects.get(username=TEST_USERNAME)
    self.assertEqual(user.password, new_hash)
