Merge pull request #24680 from open-craft/ahmed/fix-capa-dropdown-indexing

[TNL-6993] [BD-29]: Handle edge case where dropdown values are not being indexed
This commit is contained in:
Dave St.Germain
2020-08-11 11:35:29 -04:00
committed by GitHub
2 changed files with 25 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ import re
import sys
import six
from bleach.sanitizer import Cleaner
from lxml import etree
from pkg_resources import resource_string
from web_fragments.fragment import Fragment
@@ -17,7 +18,6 @@ from xmodule.contentstore.django import contentstore
from xmodule.editing_module import EditingMixin
from xmodule.exceptions import NotFoundError, ProcessingError
from xmodule.raw_module import RawMixin
from xmodule.util.misc import escape_html_characters
from xmodule.util.sandboxing import get_python_lib_zip
from xmodule.util.xmodule_django import add_webpack_to_fragment
from xmodule.x_module import (
@@ -302,6 +302,10 @@ class ProblemBlock(
Return dictionary prepared with module content and type for indexing.
"""
xblock_body = super(ProblemBlock, self).index_dictionary()
# Make optioninput's options index friendly by replacing the actual tag with the values
capa_content = re.sub(r'<optioninput options="\(([^"]+)\)".*?>\s*|\S*<\/optioninput>', r'\1', self.data)
# Removing solutions and hints, as well as script and style
capa_content = re.sub(
re.compile(
@@ -314,9 +318,14 @@ class ProblemBlock(
re.DOTALL |
re.VERBOSE),
"",
self.data
capa_content
)
capa_content = escape_html_characters(capa_content)
capa_content = re.sub(
r"(\s|&nbsp;|//)+",
" ",
Cleaner(tags=[], strip=True).clean(capa_content)
)
capa_body = {
"capa_content": capa_content,
"display_name": self.display_name,

View File

@@ -2536,14 +2536,21 @@ class ProblemBlockXMLTest(unittest.TestCase):
name = "Other Test Capa Problem"
descriptor = self._create_descriptor(xml, name=name)
self.assertEqual(descriptor.problem_types, {"multiplechoiceresponse", "optionresponse"})
six.assertCountEqual(
self, descriptor.index_dictionary(), {
# We are converting problem_types to a set to compare it later without taking into account the order
# the reasoning behind is that the problem_types (property) is represented by dict and when it is converted
# to list its ordering is different everytime.
indexing_result = descriptor.index_dictionary()
indexing_result['problem_types'] = set(indexing_result['problem_types'])
self.assertDictEqual(
indexing_result, {
'content_type': ProblemBlock.INDEX_CONTENT_TYPE,
'problem_types': ["optionresponse", "multiplechoiceresponse"],
'problem_types': set(["optionresponse", "multiplechoiceresponse"]),
'content': {
'display_name': name,
'capa_content': ' Label Some comment Donut Buggy '
}
'capa_content': " Label Some comment Donut Buggy '1','2' "
},
}
)
@@ -2619,7 +2626,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(