From 52d9320e62d8a02d84018104fd0c2ebe566b4b2a Mon Sep 17 00:00:00 2001 From: Sarina Canelake Date: Fri, 23 Aug 2013 13:57:24 -0400 Subject: [PATCH] Hide "Email Settings" from student dash if bulk email not enabled Some minor pep8 cleanup --- common/lib/html_to_text.py | 1 + .../bulk_email/tests/test_err_handling.py | 1 - lms/djangoapps/bulk_email/tests/tests.py | 65 ++++++++++++++++++- lms/djangoapps/instructor/views/legacy.py | 1 - lms/templates/dashboard.html | 7 +- 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/common/lib/html_to_text.py b/common/lib/html_to_text.py index daad0c83c7..c1f1993c17 100644 --- a/common/lib/html_to_text.py +++ b/common/lib/html_to_text.py @@ -4,6 +4,7 @@ from subprocess import Popen, PIPE log = logging.getLogger(__name__) + def html_to_text(html_message): """ Converts an html message to plaintext. diff --git a/lms/djangoapps/bulk_email/tests/test_err_handling.py b/lms/djangoapps/bulk_email/tests/test_err_handling.py index 2715804079..e7d2e62d4a 100644 --- a/lms/djangoapps/bulk_email/tests/test_err_handling.py +++ b/lms/djangoapps/bulk_email/tests/test_err_handling.py @@ -40,7 +40,6 @@ class TestEmailErrors(ModuleStoreTestCase): self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id}) - def tearDown(self): self.smtp_server_thread.stop() patch.stopall() diff --git a/lms/djangoapps/bulk_email/tests/tests.py b/lms/djangoapps/bulk_email/tests/tests.py index 66151806f0..210ae63df0 100644 --- a/lms/djangoapps/bulk_email/tests/tests.py +++ b/lms/djangoapps/bulk_email/tests/tests.py @@ -1,5 +1,8 @@ """ Unit tests for email feature flag in instructor dashboard +and student dashboard. Additionally tests that bulk email +is always disabled for non-Mongo backed courses, regardless +of email feature flag. """ from django.test.utils import override_settings @@ -7,7 +10,7 @@ from django.conf import settings from django.core.urlresolvers import reverse from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE -from student.tests.factories import AdminFactory +from student.tests.factories import AdminFactory, UserFactory, CourseEnrollmentFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore import XML_MODULESTORE_TYPE @@ -78,3 +81,63 @@ 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) + + +@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +class TestStudentDashboardEmailView(ModuleStoreTestCase): + """ + Check for email view displayed with flag + """ + def setUp(self): + self.course = CourseFactory.create() + + # Create student account + student = UserFactory.create() + CourseEnrollmentFactory.create(user=student, course_id=self.course.id) + self.client.login(username=student.username, password="test") + + # URL for dashboard + self.url = reverse('dashboard') + # URL for email settings modal + self.email_modal_link = 'Email Settings'.format( + self.course.org, + self.course.number, + self.course.display_name.replace(' ', '_') + ) + + + def tearDown(self): + """ + Undo all patches. + """ + patch.stopall() + + @patch.dict(settings.MITX_FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True}) + def test_email_flag_true(self): + # Assert that the URL for the email view is in the response + response = self.client.get(self.url) + self.assertTrue(self.email_modal_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 + response = self.client.get(self.url) + self.assertFalse(self.email_modal_link in response.content) + + @patch.dict(settings.MITX_FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True}) + def test_email_flag_true_xml_store(self): + # If the enable email setting is enabled, but this is an XML backed course, + # the email view shouldn't be available on the instructor dashboard. + + # The course factory uses a MongoModuleStore backing, so patch the + # `get_modulestore_type` method to pretend to be XML-backed. + # This is OK; we're simply testing that the `is_mongo_modulestore_type` flag + # in `instructor/views/legacy.py` is doing the correct thing. + + with patch('xmodule.modulestore.mongo.base.MongoModuleStore.get_modulestore_type') as mock_modulestore: + mock_modulestore.return_value = XML_MODULESTORE_TYPE + + # Assert that the URL for the email view is not in the response + response = self.client.get(self.url) + self.assertFalse(self.email_modal_link in response.content) diff --git a/lms/djangoapps/instructor/views/legacy.py b/lms/djangoapps/instructor/views/legacy.py index 3065df2c24..a2ccf0a5bc 100644 --- a/lms/djangoapps/instructor/views/legacy.py +++ b/lms/djangoapps/instructor/views/legacy.py @@ -721,7 +721,6 @@ def instructor_dashboard(request, course_id): course_url = request.build_absolute_uri(reverse('course_root', kwargs={'course_id': course_id})) tasks.delegate_email_batches.delay(email.id, email.to_option, course_id, course_url, request.user.id) - if to_option == "all": email_msg = '

Your email was successfully queued for sending. Please note that for large public classes (~10k), it may take 1-2 hours to send all emails.

' else: diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index 96c1741e69..7b077aec43 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -5,6 +5,8 @@ from courseware.courses import course_image_url, get_course_about_section from courseware.access import has_access from certificates.models import CertificateStatuses + from xmodule.modulestore import MONGO_MODULESTORE_TYPE + from xmodule.modulestore.django import modulestore %> <%inherit file="main.html" /> @@ -306,7 +308,10 @@ % endif % endif ${_('Unregister')} - ${_('Email Settings')} + % if settings.MITX_FEATURES['ENABLE_INSTRUCTOR_EMAIL'] and modulestore().get_modulestore_type(course.id) == MONGO_MODULESTORE_TYPE: + + ${_('Email Settings')} + % endif