Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lms/djangoapps/bulk_email/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class OptoutAdmin(admin.ModelAdmin):


class CourseEmailTemplateAdmin(admin.ModelAdmin):
"""Admin for course email templates."""
form = CourseEmailTemplateForm
fieldsets = (
(None, {
Expand Down
5 changes: 4 additions & 1 deletion lms/djangoapps/bulk_email/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Defines a form for providing validation of CourseEmail templates.
"""
import logging

from django import forms
Expand All @@ -11,7 +14,7 @@
class CourseEmailTemplateForm(forms.ModelForm):
"""Form providing validation of CourseEmail templates."""

class Meta:
class Meta: # pylint: disable=C0111
model = CourseEmailTemplate

def _validate_template(self, template):
Expand Down
4 changes: 3 additions & 1 deletion lms/djangoapps/bulk_email/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def course_email(email_id, to_list, course_title, course_url, image_url, throttl
optouts = set(optouts)
num_optout = len(optouts)

to_list = filter(lambda x: x['email'] not in optouts, to_list)
to_list = [recipient for recipient in to_list if recipient['email'] not in optouts]

subject = "[" + course_title + "] " + msg.subject

Expand Down Expand Up @@ -226,6 +226,8 @@ def course_email(email_id, to_list, course_title, course_url, image_url, throttl
log.exception('Email with id %d caused course_email task to fail with uncaught exception. To list: %s',
email_id,
[i['email'] for i in to_list])
# Close the connection before we exit
connection.close()
raise


Expand Down
6 changes: 0 additions & 6 deletions lms/djangoapps/bulk_email/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,6 @@ class TestEmailSendExceptions(ModuleStoreTestCase):
"""
Test that exceptions are handled correctly.
"""

def test_get_course_exc(self):
# Make sure delegate_email_batches handles Http404 exception from get_course_by_id.
with self.assertRaises(Exception):
delegate_email_batches("_", "_", "blah/blah/blah", "_", "_")

def test_no_course_email_obj(self):
# Make sure course_email handles CourseEmail.DoesNotExist exception.
with self.assertRaises(CourseEmail.DoesNotExist):
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/bulk_email/tests/test_err_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


class EmailTestException(Exception):
"""Mock exception for email testing."""
pass


Expand Down Expand Up @@ -165,7 +166,7 @@ def test_nonexist_email(self, mock_log, retry, result):
Tests retries when the email doesn't exist
"""
delegate_email_batches.delay(-1, self.instructor.id)
((log_str, email_id, num_retries), _) = mock_log.warning.call_args
((log_str, email_id, _num_retries), _) = mock_log.warning.call_args
self.assertTrue(mock_log.warning.called)
self.assertIn('Failed to get CourseEmail with id', log_str)
self.assertEqual(email_id, -1)
Expand Down