diff --git a/common/djangoapps/xmodule_modifiers.py b/common/djangoapps/xmodule_modifiers.py index 2c34994c453b1d956f8488821e2cd38788e9ca4b..654482fab6d30edae72ffce5d5a8718e48c7fb9e 100644 --- a/common/djangoapps/xmodule_modifiers.py +++ b/common/djangoapps/xmodule_modifiers.py @@ -147,7 +147,7 @@ def grade_histogram(module_id): return grades -def add_histogram(user, block, view, frag, context): # pylint: disable=unused-argument +def add_staff_debug_info(user, block, view, frag, context): # pylint: disable=unused-argument """ Updates the supplied module with a new get_html function that wraps the output of the old get_html function with additional information diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 952d3734df43517f01f78745be91c62dc611dce5..cb2036a04c8036ff5e891b87c52a9dcc3a196c5f 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -38,7 +38,7 @@ from xmodule.modulestore import Location from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.util.duedate import get_extended_due_date -from xmodule_modifiers import replace_course_urls, replace_jump_to_id_urls, replace_static_urls, add_histogram, wrap_xblock +from xmodule_modifiers import replace_course_urls, replace_jump_to_id_urls, replace_static_urls, add_staff_debug_info, wrap_xblock from xmodule.lti_module import LTIModule from xmodule.x_module import XModuleDescriptor @@ -368,9 +368,9 @@ def get_module_for_descriptor_internal(user, descriptor, field_data_cache, cours reverse('jump_to_id', kwargs={'course_id': course_id, 'module_id': ''}), )) - if settings.FEATURES.get('DISPLAY_HISTOGRAMS_TO_STAFF'): + if settings.FEATURES.get('DISPLAY_DEBUG_INFO_TO_STAFF'): if has_access(user, descriptor, 'staff', course_id): - block_wrappers.append(partial(add_histogram, user)) + block_wrappers.append(partial(add_staff_debug_info, user)) # These modules store data using the anonymous_student_id as a key. # To prevent loss of data, we will continue to provide old modules with diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index 3bdc3b104978d1acee97757aae415b850d64415d..0f942b4d3fab8c91ad3912a4e2a006dbc9995821 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -12,6 +12,7 @@ from django.test import TestCase from django.test.client import RequestFactory from django.test.utils import override_settings +from capa.tests.response_xml_factory import OptionResponseXMLFactory from xblock.field_data import FieldData from xblock.runtime import Runtime from xblock.fields import ScopeIds @@ -21,14 +22,14 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory from xmodule.x_module import XModuleDescriptor -import courseware.module_render as render -from courseware.tests.tests import LoginEnrollmentTestCase -from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE -from courseware.model_data import FieldDataCache +from courseware import module_render as render from courseware.courses import get_course_with_access, course_image_url, get_course_info_section +from courseware.model_data import FieldDataCache +from courseware.tests.factories import StudentModuleFactory, UserFactory +from courseware.tests.tests import LoginEnrollmentTestCase +from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE -from .factories import UserFactory from lms.lib.xblock.runtime import quote_slashes @@ -506,8 +507,42 @@ class TestHtmlModifiers(ModuleStoreTestCase): result_fragment.content ) - @patch('courseware.module_render.has_access', Mock(return_value=True)) - def test_histogram(self): + +@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@patch.dict('django.conf.settings.FEATURES', {'DISPLAY_DEBUG_INFO_TO_STAFF': True, 'DISPLAY_HISTOGRAMS_TO_STAFF': True}) +@patch('courseware.module_render.has_access', Mock(return_value=True)) +class TestStaffDebugInfo(ModuleStoreTestCase): + """Tests to verify that Staff Debug Info panel and histograms are displayed to staff.""" + + def setUp(self): + self.user = UserFactory.create() + self.request = RequestFactory().get('/') + self.request.user = self.user + self.request.session = {} + self.course = CourseFactory.create() + + problem_xml = OptionResponseXMLFactory().build_xml( + question_text='The correct answer is Correct', + num_inputs=2, + weight=2, + options=['Correct', 'Incorrect'], + correct_option='Correct' + ) + self.descriptor = ItemFactory.create( + category='problem', + data=problem_xml, + display_name='Option Response Problem' + ) + + self.location = self.descriptor.location + self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents( + self.course.id, + self.user, + self.descriptor + ) + + @patch.dict('django.conf.settings.FEATURES', {'DISPLAY_DEBUG_INFO_TO_STAFF': False}) + def test_staff_debug_info_disabled(self): module = render.get_module( self.user, self.request, @@ -516,11 +551,19 @@ class TestHtmlModifiers(ModuleStoreTestCase): self.course.id, ) result_fragment = module.render('student_view') + self.assertNotIn('Staff Debug', result_fragment.content) - self.assertIn( - 'Staff Debug', - result_fragment.content + def test_staff_debug_info_enabled(self): + module = render.get_module( + self.user, + self.request, + self.location, + self.field_data_cache, + self.course.id, ) + result_fragment = module.render('student_view') + self.assertIn('Staff Debug', result_fragment.content) + PER_COURSE_ANONYMIZED_DESCRIPTORS = (LTIDescriptor, ) diff --git a/lms/envs/common.py b/lms/envs/common.py index 0e2ab8bf345659dd38c984044e7e6697b5675db5..d3724c68b2b904e795c181b9d2a15004cb2ba5f3 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -55,7 +55,9 @@ DISCUSSION_SETTINGS = { FEATURES = { 'SAMPLE': False, 'USE_DJANGO_PIPELINE': True, - 'DISPLAY_HISTOGRAMS_TO_STAFF': True, + + 'DISPLAY_DEBUG_INFO_TO_STAFF': True, + 'REROUTE_ACTIVATION_EMAIL': False, # nonempty string = address for all activation emails 'DEBUG_LEVEL': 0, # 0 = lowest level, least verbose, 255 = max level, most verbose