Commit 9dc85bf1 by Christine Lytwynec

PR updates

parent c7ede0df
......@@ -44,9 +44,7 @@ class MockCourseEmailResult(object):
return mock_update_subtask_status
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestEmailSendFromDashboard(ModuleStoreTestCase):
class EmailSendFromDashboardTestCase(ModuleStoreTestCase):
"""
Test that emails send correctly.
"""
......@@ -92,7 +90,14 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
"""
patch.stopall()
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase):
"""
Tests email sending with mocked html_to_text.
"""
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': True})
def test_email_disabled(self):
"""
......@@ -134,7 +139,6 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
'[' + self.course.display_name + ']' + ' test subject for myself'
)
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
def test_send_to_staff(self):
"""
Make sure email send to staff and instructors goes there.
......@@ -158,7 +162,6 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
[self.instructor.email] + [s.email for s in self.staff]
)
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
def test_send_to_all(self):
"""
Make sure email send to all goes there.
......@@ -182,7 +185,6 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
[self.instructor.email] + [s.email for s in self.staff] + [s.email for s in self.students]
)
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
def test_no_duplicate_emails_staff_instructor(self):
"""
Test that no duplicate emails are sent to a course instructor that is
......@@ -191,7 +193,6 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
CourseStaffRole(self.course.id).add_users(self.instructor)
self.test_send_to_all()
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
def test_no_duplicate_emails_enrolled_staff(self):
"""
Test that no duplicate emials are sent to a course instructor that is
......@@ -200,7 +201,6 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
CourseEnrollment.enroll(self.instructor, self.course.id)
self.test_send_to_all()
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
def test_unicode_subject_send_to_all(self):
"""
Make sure email (with Unicode characters) send to all goes there.
......@@ -229,37 +229,6 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
'[' + self.course.display_name + '] ' + uni_subject
)
@skipIf(os.environ.get("Travis") == 'true', "Skip this test in Travis CI.")
def test_unicode_message_send_to_all(self):
"""
Make sure email (with Unicode characters) send to all goes there.
Note that this test is skipped on Travis because we can't use the
function `html_to_text` as it is currently implemented on Travis.
"""
# Now we know we have pulled up the instructor dash's email view
# (in the setUp method), we can test sending an email.
uni_message = u'ẗëṡẗ ṁëṡṡäġë ḟöṛ äḷḷ イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ fоѓ аll'
test_email = {
'action': 'Send email',
'send_to': 'all',
'subject': 'test subject for all',
'message': uni_message
}
# Post the email to the instructor dashboard API
response = self.client.post(self.send_mail_url, test_email)
self.assertEquals(json.loads(response.content), self.success_content)
self.assertEquals(len(mail.outbox), 1 + len(self.staff) + len(self.students))
self.assertItemsEqual(
[e.to[0] for e in mail.outbox],
[self.instructor.email] + [s.email for s in self.staff] + [s.email for s in self.students]
)
message_body = mail.outbox[0].body
self.assertIn(uni_message, message_body)
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
def test_unicode_students_send_to_all(self):
"""
Make sure email (with Unicode characters) send to all goes there.
......@@ -291,7 +260,6 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
@override_settings(BULK_EMAIL_EMAILS_PER_TASK=3)
@patch('bulk_email.tasks.update_subtask_status')
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
def test_chunked_queries_send_numerous_emails(self, email_mock):
"""
Test sending a large number of emails, to test the chunked querying
......@@ -329,3 +297,42 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
[s.email for s in self.students] +
[s.email for s in added_users if s not in optouts])
self.assertItemsEqual(outbox_contents, should_send_contents)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
@skipIf(os.environ.get("TRAVIS") == 'true', "Skip this test in Travis CI.")
class TestEmailSendFromDashboard(EmailSendFromDashboardTestCase):
"""
Tests email sending without mocked html_to_text.
Note that these tests are skipped on Travis because we can't use the
function `html_to_text` as it is currently implemented on Travis.
"""
def test_unicode_message_send_to_all(self):
"""
Make sure email (with Unicode characters) send to all goes there.
"""
# Now we know we have pulled up the instructor dash's email view
# (in the setUp method), we can test sending an email.
uni_message = u'ẗëṡẗ ṁëṡṡäġë ḟöṛ äḷḷ イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ fоѓ аll'
test_email = {
'action': 'Send email',
'send_to': 'all',
'subject': 'test subject for all',
'message': uni_message
}
# Post the email to the instructor dashboard API
response = self.client.post(self.send_mail_url, test_email)
self.assertEquals(json.loads(response.content), self.success_content)
self.assertEquals(len(mail.outbox), 1 + len(self.staff) + len(self.students))
self.assertItemsEqual(
[e.to[0] for e in mail.outbox],
[self.instructor.email] + [s.email for s in self.staff] + [s.email for s in self.students]
)
message_body = mail.outbox[0].body
self.assertIn(uni_message, message_body)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment