From a493348cf0d638c922d184af90ee1c755c25dcc0 Mon Sep 17 00:00:00 2001 From: muhammad-ammar Date: Tue, 18 Nov 2014 14:19:38 +0000 Subject: [PATCH] Remove ability to add new ORA 1 problems to courses TNL-827 --- .../contentstore/tests/test_contentstore.py | 2 + .../contentstore/views/component.py | 10 ++++- .../contentstore/views/tests/test_item.py | 37 +++++++++++++++++++ cms/envs/common.py | 4 ++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 7ff89e6a39..f1bfe1dc29 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -4,6 +4,7 @@ import copy import mock +from mock import patch import shutil import lxml @@ -536,6 +537,7 @@ class MiscCourseTests(ContentStoreTestCase): for expected in expected_types: self.assertIn(expected, resp.content) + @patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', []) def test_advanced_components_in_edit_unit(self): # This could be made better, but for now let's just assert that we see the advanced modules mentioned in the page # response HTML diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index acac8ddb82..40209bf37d 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -56,6 +56,13 @@ ADVANCED_COMPONENT_POLICY_KEY = 'advanced_modules' ADVANCED_PROBLEM_TYPES = settings.ADVANCED_PROBLEM_TYPES +def _advanced_component_types(): + """ + Return advanced component types which can be created. + """ + return [c_type for c_type in ADVANCED_COMPONENT_TYPES if c_type not in settings.DEPRECATED_ADVANCED_COMPONENT_TYPES] + + @require_GET @login_required def subsection_handler(request, usage_key_string): @@ -292,10 +299,11 @@ def get_component_templates(course): # enabled for the course. course_advanced_keys = course.advanced_modules advanced_component_templates = {"type": "advanced", "templates": [], "display_name": _("Advanced")} + advanced_component_types = _advanced_component_types() # Set component types according to course policy file if isinstance(course_advanced_keys, list): for category in course_advanced_keys: - if category in ADVANCED_COMPONENT_TYPES and not category in categories: + if category in advanced_component_types and not category in categories: # boilerplates not supported for advanced components try: component_display_name = xblock_type_display_name(category, default_display_name=category) diff --git a/cms/djangoapps/contentstore/views/tests/test_item.py b/cms/djangoapps/contentstore/views/tests/test_item.py index a1296a9495..496eee0c52 100644 --- a/cms/djangoapps/contentstore/views/tests/test_item.py +++ b/cms/djangoapps/contentstore/views/tests/test_item.py @@ -1203,6 +1203,43 @@ class TestComponentTemplates(CourseTestCase): self.assertEqual(ora_template.get('category'), 'openassessment') self.assertIsNone(ora_template.get('boilerplate_name', None)) + @patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ["combinedopenended", "peergrading"]) + def test_ora1_no_advance_component_button(self): + """ + Test that there will be no `Advanced` button on unit page if `combinedopenended` and `peergrading` are + deprecated provided that there are only 'combinedopenended', 'peergrading' modules in `Advanced Module List` + """ + self.course.advanced_modules.extend(['combinedopenended', 'peergrading']) + templates = get_component_templates(self.course) + button_names = [template['display_name'] for template in templates] + self.assertNotIn('Advanced', button_names) + + @patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ["combinedopenended", "peergrading"]) + def test_cannot_create_ora1_problems(self): + """ + Test that we can't create ORA1 problems if `combinedopenended` and `peergrading` are deprecated + """ + self.course.advanced_modules.extend(['annotatable', 'combinedopenended', 'peergrading']) + templates = get_component_templates(self.course) + button_names = [template['display_name'] for template in templates] + self.assertIn('Advanced', button_names) + self.assertEqual(len(templates[0]['templates']), 1) + template_display_names = [template['display_name'] for template in templates[0]['templates']] + self.assertEqual(template_display_names, ['Annotation']) + + @patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', []) + def test_create_ora1_problems(self): + """ + Test that we can create ORA1 problems if `combinedopenended` and `peergrading` are not deprecated + """ + self.course.advanced_modules.extend(['annotatable', 'combinedopenended', 'peergrading']) + templates = get_component_templates(self.course) + button_names = [template['display_name'] for template in templates] + self.assertIn('Advanced', button_names) + self.assertEqual(len(templates[0]['templates']), 3) + template_display_names = [template['display_name'] for template in templates[0]['templates']] + self.assertEqual(template_display_names, ['Annotation', 'Open Response Assessment', 'Peer Grading Interface']) + class TestXBlockInfo(ItemTest): """ diff --git a/cms/envs/common.py b/cms/envs/common.py index c542b373b7..8c2c38028b 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -743,6 +743,10 @@ ADVANCED_COMPONENT_TYPES = [ 'notes', ] +# Adding components in this list will disable the creation of new problem for those +# compoenents in studio. Existing problems will work fine and one can edit them in studio +DEPRECATED_ADVANCED_COMPONENT_TYPES = [] + # Specify xblocks that should be treated as advanced problems. Each entry is a tuple # specifying the xblock name and an optional YAML template to be used. ADVANCED_PROBLEM_TYPES = [