'Test that celery handles permanent SMTPDataErrors by failing and not retrying.'

@patch('bulk_email.tasks.get_connection', autospec=True)
@patch('bulk_email.tasks.update_subtask_status')
@patch('bulk_email.tasks.send_course_email.retry')
def test_data_err_fail(self, retry, result, get_conn):

    get_conn.return_value.send_messages.side_effect = cycle([SMTPDataError(554, 'Email    address    is    blacklisted'), None, None, None])
    students = [UserFactory() for _ in xrange((settings.BULK_EMAIL_EMAILS_PER_TASK - 1))]
    for student in students:
        CourseEnrollmentFactory.create(user=student, course_id=self.course.id)
    test_email = {'action': 'Send    email', 'send_to': '["myself",    "staff",    "learners"]', 'subject': 'test    subject    for    all', 'message': 'test    message    for    all'}
    response = self.client.post(self.send_mail_url, test_email)
    self.assertEquals(json.loads(response.content), self.success_content)
    self.assertFalse(retry.called)
    ((_entry_id, _current_task_id, subtask_status), _kwargs) = result.call_args
    self.assertEquals(subtask_status.skipped, 0)
    expected_fails = int(((settings.BULK_EMAIL_EMAILS_PER_TASK + 3) / 4.0))
    self.assertEquals(subtask_status.failed, expected_fails)
    self.assertEquals(subtask_status.succeeded, (settings.BULK_EMAIL_EMAILS_PER_TASK - expected_fails))
