diff --git a/lms/djangoapps/instructor/tests/test_email.py b/lms/djangoapps/instructor/tests/test_email.py index de8832a625..2085ac1384 100644 --- a/lms/djangoapps/instructor/tests/test_email.py +++ b/lms/djangoapps/instructor/tests/test_email.py @@ -90,7 +90,7 @@ class TestNewInstructorDashboardEmailViewMongoBacked(ModuleStoreTestCase): # Assert that instructor email is enabled for this course self.assertTrue(CourseAuthorization.instructor_email_enabled(self.course.id)) - # Assert that the URL for the email view is not in the response + # Assert that the URL for the email view is in the response response = self.client.get(self.url) self.assertTrue(self.email_link in response.content) diff --git a/lms/djangoapps/instructor/tests/test_legacy_email.py b/lms/djangoapps/instructor/tests/test_legacy_email.py index 20b8271bdf..fed6c0e1b0 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_email.py +++ b/lms/djangoapps/instructor/tests/test_legacy_email.py @@ -15,6 +15,8 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore import XML_MODULESTORE_TYPE +from bulk_email.models import CourseAuthorization + from mock import patch @@ -59,6 +61,32 @@ class TestInstructorDashboardEmailView(ModuleStoreTestCase): send_to_label = '' self.assertTrue(send_to_label in response.content) + @patch.dict(settings.MITX_FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': True}) + def test_email_flag_unauthorized(self): + # Assert that the URL for the email view is not in the response + # email is enabled, but this course is not authorized to send email + response = self.client.get(self.url) + self.assertFalse(self.email_link in response.content) + + @patch.dict(settings.MITX_FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': True}) + def test_email_flag_authorized(self): + # Assert that the URL for the email view is in the response + # email is enabled, and this course is authorized to send email + + # Assert that instructor email is not enabled for this course + self.assertFalse(CourseAuthorization.instructor_email_enabled(self.course.id)) + response = self.client.get(self.url) + self.assertFalse(self.email_link in response.content) + + # Authorize the course to use email + cauth = CourseAuthorization(course_id=self.course.id, email_enabled=True) + cauth.save() + + # Assert that instructor email is enabled for this course + self.assertTrue(CourseAuthorization.instructor_email_enabled(self.course.id)) + response = self.client.get(self.url) + self.assertTrue(self.email_link in response.content) + @patch.dict(settings.MITX_FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': False}) def test_email_flag_false(self): # Assert that the URL for the email view is not in the response