'Verifies that delete_user_preference returns appropriate errors.'

@patch('openedx.core.djangoapps.user_api.models.UserPreference.delete')
def test_delete_user_preference_errors(self, user_preference_delete):

    with self.assertRaises(UserNotFound):
        delete_user_preference(self.user, self.test_preference_key, username='no_such_user')
    with self.assertRaises(UserNotFound):
        delete_user_preference(self.no_such_user, self.test_preference_key)
    with self.assertRaises(UserNotAuthorized):
        delete_user_preference(self.staff_user, self.test_preference_key, username=self.user.username)
    with self.assertRaises(UserNotAuthorized):
        delete_user_preference(self.different_user, self.test_preference_key, username=self.user.username)
    user_preference_delete.side_effect = [Exception, None]
    with self.assertRaises(PreferenceUpdateError) as context_manager:
        delete_user_preference(self.user, self.test_preference_key)
    self.assertEqual(context_manager.exception.developer_message, u"Delete    failed    for    user    preference    'test_key':    ")
    self.assertEqual(context_manager.exception.user_message, u"Delete    failed    for    user    preference    'test_key'.")
