Don't send emails to students who haven't activated.
This commit is contained in:
@@ -93,7 +93,10 @@ def _get_recipient_queryset(user_id, to_option, course_id, course_location):
|
||||
instructor_qset = instructor_group.user_set.all()
|
||||
recipient_qset = staff_qset | instructor_qset
|
||||
if to_option == SEND_TO_ALL:
|
||||
# We also require students to have activated their accounts to
|
||||
# provide verification that the provided email address is valid.
|
||||
enrollment_qset = User.objects.filter(
|
||||
is_active=True,
|
||||
courseenrollment__course_id=course_id,
|
||||
courseenrollment__is_active=True
|
||||
)
|
||||
|
||||
@@ -154,6 +154,19 @@ class TestBulkEmailInstructorTask(InstructorTaskCourseTestCase):
|
||||
get_conn.return_value.send_messages.side_effect = cycle([None])
|
||||
self._test_run_with_task(send_bulk_course_email, 'emailed', num_emails, num_emails)
|
||||
|
||||
def test_unactivated_user(self):
|
||||
# Select number of emails to fit into a single subtask.
|
||||
num_emails = settings.EMAILS_PER_TASK
|
||||
# We also send email to the instructor:
|
||||
students = self._create_students(num_emails - 1)
|
||||
# mark a student as not yet having activated their email:
|
||||
student = students[0]
|
||||
student.is_active = False
|
||||
student.save()
|
||||
with patch('bulk_email.tasks.get_connection', autospec=True) as get_conn:
|
||||
get_conn.return_value.send_messages.side_effect = cycle([None])
|
||||
self._test_run_with_task(send_bulk_course_email, 'emailed', num_emails - 1, num_emails - 1)
|
||||
|
||||
def test_skipped(self):
|
||||
# Select number of emails to fit into a single subtask.
|
||||
num_emails = settings.EMAILS_PER_TASK
|
||||
|
||||
Reference in New Issue
Block a user