Commit 8ee682d4 by Usman Khalid

Fixed and added more tests for bulk email.

LMS-2565
parent c955fd0b
......@@ -41,6 +41,7 @@ class MockCourseEmailResult(object):
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestEmailSendFromDashboard(ModuleStoreTestCase):
"""
Test that emails send correctly.
......@@ -88,6 +89,20 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
"""
patch.stopall()
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': True})
def test_email_disabled(self):
"""
Test response when email is disabled for course.
"""
test_email = {
'action': 'Send email',
'to_option': 'myself',
'subject': 'test subject for myself',
'message': 'test message for myself'
}
response = self.client.post(self.url, test_email)
self.assertContains(response, "Email is not enabled for this course.")
def test_send_to_self(self):
"""
Make sure email send to myself goes to myself.
......
......@@ -38,6 +38,7 @@ class EmailTestException(Exception):
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestEmailErrors(ModuleStoreTestCase):
"""
Test that errors from sending email are handled properly.
......
......@@ -11,6 +11,7 @@ from urllib import quote
from django.test import TestCase
from nose.tools import raises
from mock import Mock, patch
from django.conf import settings
from django.test.utils import override_settings
from django.core.urlresolvers import reverse
from django.http import HttpRequest, HttpResponse
......@@ -99,6 +100,7 @@ class TestCommonExceptions400(unittest.TestCase):
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Ensure that users cannot access endpoints they shouldn't be able to.
......@@ -1570,6 +1572,7 @@ class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestInstructorSendEmail(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Checks that only instructors have access to email endpoints, and that
......
......@@ -108,3 +108,38 @@ class TestInstructorDashboardEmailView(ModuleStoreTestCase):
# Assert that the URL for the email view is not in the response
response = self.client.get(self.url)
self.assertFalse(self.email_link in response.content)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True})
def test_send_mail_unauthorized(self):
""" Test 'Send email' action returns an error if course is not authorized to send email. """
response = self.client.post(
self.url, {
'action': 'Send email',
'to_option': 'all',
'subject': "Welcome to the course!",
'message': "Lets start with an introduction!"
}
)
self.assertContains(response, "Email is not enabled for this course.")
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True})
def test_send_mail_authorized(self):
""" Test 'Send email' action when course is authorized to send email. """
course_authorization = CourseAuthorization(course_id=self.course.id, email_enabled=True)
course_authorization.save()
session = self.client.session
session[u'idash_mode:{0}'.format(self.course.location.course_id)] = 'Email'
session.save()
response = self.client.post(
self.url, {
'action': 'Send email',
'to_option': 'all',
'subject': 'Welcome to the course!',
'message': 'Lets start with an introduction!',
}
)
self.assertContains(response, "Your email was successfully queued for sending.")
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