'Ensures the email opt-in flag is handled, if present, and that problems handling the
flag don\'t cause the rest of the enrollment transaction to fail.'

@mock.patch('commerce.api.v0.views.update_email_opt_in')
@ddt.data(*itertools.product((False, True), (False, True), (False, True)))
@ddt.unpack
def test_marketing_email_opt_in(self, is_opt_in, has_sku, is_exception, mock_update):

    if (not has_sku):
        for course_mode in CourseMode.objects.filter(course_id=self.course.id):
            course_mode.sku = None
            course_mode.save()
    if is_exception:
        mock_update.side_effect = Exception('boink')
    return_value = {'id': TEST_BASKET_ID, 'payment_data': None, 'order': {'number': TEST_ORDER_NUMBER}}
    with mock_create_basket(response=return_value, expect_called=has_sku):
        response = self._post_to_view(marketing_email_opt_in=is_opt_in)
    self.assertEqual(mock_update.called, is_opt_in)
    self.assertEqual(response.status_code, 200)
