diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index 52edca3843..66cae5c0da 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -307,25 +307,14 @@ class ProblemBlock( """ Return dictionary prepared with module content and type for indexing. """ - def _make_optionresponse_indexable(xml_content): - """ - Extract options from dropdown and replace the actual xml for optionresponse with them. - """ - xml_content_copy = xml_content[:] - root = etree.fromstring(xml_content_copy) - for option_response in root.findall("optionresponse"): - option_response_xml = etree.tostring(option_response, method="html").decode("utf-8") - option_input = option_response.find("optioninput") - if option_input is not None and "options" in option_input: - option_input_attrib = option_input.get("options", "") - option_input_attrib = "[" + option_input_attrib.strip("()").replace("'", '"') + "]" - values_of_dropdown = ", ".join(json.loads(option_input_attrib)) - xml_content_copy = xml_content_copy.replace(option_response_xml, values_of_dropdown) - return xml_content_copy - xblock_body = super(ProblemBlock, self).index_dictionary() - capa_content = _make_optionresponse_indexable(self.data) + # Make optioninput's options index friendly by replacing the actual tag with the values + capa_content = re.sub( + r'\s*|\S*<\/optioninput>', + lambda matched: matched.group(1).replace("'", '').replace(",", ", ") if matched.group(1) else None, + self.data + ) # Removing solutions and hints, as well as script and style capa_content = re.sub( diff --git a/common/lib/xmodule/xmodule/tests/test_capa_module.py b/common/lib/xmodule/xmodule/tests/test_capa_module.py index bd4b04c087..0869fe4513 100644 --- a/common/lib/xmodule/xmodule/tests/test_capa_module.py +++ b/common/lib/xmodule/xmodule/tests/test_capa_module.py @@ -39,8 +39,6 @@ from xmodule.tests import DATA_DIR from ..capa_base import RANDOMIZATION, SHOWANSWER from . import get_test_system -unittest.TestCase.maxDiff = None - class CapaFactory(object): """ @@ -2539,12 +2537,14 @@ class ProblemBlockXMLTest(unittest.TestCase): descriptor = self._create_descriptor(xml, name=name) self.assertEqual(descriptor.problem_types, {"multiplechoiceresponse", "optionresponse"}) six.assertCountEqual( - self, descriptor.index_dictionary(), { + self, + descriptor.index_dictionary(), + { 'content_type': ProblemBlock.INDEX_CONTENT_TYPE, - 'problem_types': ["optionresponse", "multiplechoiceresponse"], + 'problem_types': ["multiplechoiceresponse", "optionresponse"], 'content': { 'display_name': name, - 'capa_content': 'Label Some comment Donut Buggy' + 'capa_content': 'Label Some comment Donut Buggy 1, 2' } } ) @@ -2621,7 +2621,7 @@ class ProblemBlockXMLTest(unittest.TestCase): Dropdown problems allow learners to select only one option from a list of options. Description You can use the following example problem as a model. - Which of the following countries celebrates its independence on August 15? + Which of the following countries celebrates its independence on August 15? India, Spain, China, Bermuda """) self.assertEqual(descriptor.problem_types, {"optionresponse"}) self.assertEqual(