Merge pull request #235 from edx/sarina/fix-reactivation-email-bug
Fix 500 error on reactivation email
This commit is contained in:
@@ -55,11 +55,15 @@ class ReactivationEmailTests(EmailTestMixin, TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.user = UserFactory.create()
|
||||
self.unregisteredUser = UserFactory.create()
|
||||
self.registration = RegistrationFactory.create(user=self.user)
|
||||
|
||||
def reactivation_email(self):
|
||||
"""Send the reactivation email, and return the response as json data"""
|
||||
return json.loads(reactivation_email_for_user(self.user).content)
|
||||
def reactivation_email(self, user):
|
||||
"""
|
||||
Send the reactivation email to the specified user,
|
||||
and return the response as json data.
|
||||
"""
|
||||
return json.loads(reactivation_email_for_user(user).content)
|
||||
|
||||
def assertReactivateEmailSent(self, email_user):
|
||||
"""Assert that the correct reactivation email has been sent"""
|
||||
@@ -78,13 +82,22 @@ class ReactivationEmailTests(EmailTestMixin, TestCase):
|
||||
|
||||
def test_reactivation_email_failure(self, email_user):
|
||||
self.user.email_user.side_effect = Exception
|
||||
response_data = self.reactivation_email()
|
||||
response_data = self.reactivation_email(self.user)
|
||||
|
||||
self.assertReactivateEmailSent(email_user)
|
||||
self.assertFalse(response_data['success'])
|
||||
|
||||
def test_reactivation_for_unregistered_user(self, email_user):
|
||||
"""
|
||||
Test that trying to send a reactivation email to an unregistered
|
||||
user fails without throwing a 500 error.
|
||||
"""
|
||||
response_data = self.reactivation_email(self.unregisteredUser)
|
||||
|
||||
self.assertFalse(response_data['success'])
|
||||
|
||||
def test_reactivation_email_success(self, email_user):
|
||||
response_data = self.reactivation_email()
|
||||
response_data = self.reactivation_email(self.user)
|
||||
|
||||
self.assertReactivateEmailSent(email_user)
|
||||
self.assertTrue(response_data['success'])
|
||||
@@ -150,7 +163,7 @@ class EmailChangeRequestTests(TestCase):
|
||||
self.check_duplicate_email(self.new_email)
|
||||
|
||||
def test_capitalized_duplicate_email(self):
|
||||
raise SkipTest("We currently don't check for emails in a case insensitive way, but we should")
|
||||
"""Test that we check for email addresses in a case insensitive way"""
|
||||
UserFactory.create(email=self.new_email)
|
||||
self.check_duplicate_email(self.new_email.capitalize())
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ def _cert_info(user, course, cert_status):
|
||||
CertificateStatuses.downloadable: 'ready',
|
||||
CertificateStatuses.notpassing: 'notpassing',
|
||||
CertificateStatuses.restricted: 'restricted',
|
||||
}
|
||||
}
|
||||
|
||||
status = template_state.get(cert_status['status'], default_status)
|
||||
|
||||
@@ -185,10 +185,10 @@ def _cert_info(user, course, cert_status):
|
||||
'show_disabled_download_button': status == 'generating', }
|
||||
|
||||
if (status in ('generating', 'ready', 'notpassing', 'restricted') and
|
||||
course.end_of_course_survey_url is not None):
|
||||
course.end_of_course_survey_url is not None):
|
||||
d.update({
|
||||
'show_survey_button': True,
|
||||
'survey_url': process_survey_link(course.end_of_course_survey_url, user)})
|
||||
'show_survey_button': True,
|
||||
'survey_url': process_survey_link(course.end_of_course_survey_url, user)})
|
||||
else:
|
||||
d['show_survey_button'] = False
|
||||
|
||||
@@ -913,8 +913,8 @@ def get_random_post_override():
|
||||
'password': id_generator(),
|
||||
'name': (id_generator(size=5, chars=string.ascii_lowercase) + " " +
|
||||
id_generator(size=7, chars=string.ascii_lowercase)),
|
||||
'honor_code': u'true',
|
||||
'terms_of_service': u'true', }
|
||||
'honor_code': u'true',
|
||||
'terms_of_service': u'true', }
|
||||
|
||||
|
||||
def create_random_account(create_account_function):
|
||||
@@ -986,7 +986,11 @@ def password_reset(request):
|
||||
|
||||
|
||||
def reactivation_email_for_user(user):
|
||||
reg = Registration.objects.get(user=user)
|
||||
try:
|
||||
reg = Registration.objects.get(user=user)
|
||||
except Registration.DoesNotExist:
|
||||
return HttpResponse(json.dumps({'success': False,
|
||||
'error': 'No inactive user with this e-mail exists'}))
|
||||
|
||||
d = {'name': user.profile.name,
|
||||
'key': reg.activation_key}
|
||||
|
||||
Reference in New Issue
Block a user