Refrain from setting email opt-in preference when checkbox is missing

This commit is contained in:
Renzo Lucioni
2014-12-03 17:01:21 -05:00
parent db9bb20c25
commit 5e41a34dd1
3 changed files with 42 additions and 23 deletions

View File

@@ -110,10 +110,13 @@ class EnrollmentTest(ModuleStoreTestCase):
@ddt.data(
([], 'true'),
([], 'false'),
([], None),
(['honor', 'verified'], 'true'),
(['honor', 'verified'], 'false'),
(['honor', 'verified'], None),
(['professional'], 'true'),
(['professional'], 'false'),
(['professional'], None),
)
@ddt.unpack
def test_enroll_with_email_opt_in(self, course_modes, email_opt_in, mock_update_email_opt_in):
@@ -129,8 +132,11 @@ class EnrollmentTest(ModuleStoreTestCase):
self._change_enrollment('enroll', email_opt_in=email_opt_in)
# Verify that the profile API has been called as expected
opt_in = email_opt_in == 'true'
mock_update_email_opt_in.assert_called_once_with(self.USERNAME, self.course.org, opt_in)
if email_opt_in is not None:
opt_in = email_opt_in == 'true'
mock_update_email_opt_in.assert_called_once_with(self.USERNAME, self.course.org, opt_in)
else:
self.assertFalse(mock_update_email_opt_in.called)
def test_user_not_authenticated(self):
# Log out, so we're no longer authenticated

View File

@@ -776,8 +776,10 @@ def try_change_enrollment(request):
def _update_email_opt_in(request, username, org):
"""Helper function used to hit the profile API if email opt-in is enabled."""
email_opt_in = request.POST.get('email_opt_in') == 'true'
profile_api.update_email_opt_in(username, org, email_opt_in)
email_opt_in = request.POST.get('email_opt_in')
if email_opt_in is not None:
email_opt_in_boolean = email_opt_in == 'true'
profile_api.update_email_opt_in(username, org, email_opt_in_boolean)
@require_POST