fixed issues pointed by kshitij
This commit is contained in:
@@ -35,13 +35,6 @@ from .capa_base import CapaMixin, ComplexEncoder, _
|
||||
log = logging.getLogger("edx.courseware")
|
||||
|
||||
|
||||
def _remove_html_tags_and_extra_spaces(data):
|
||||
""" Remove html tags and extra white spaces e.g newline, tabs etc from provided data """
|
||||
cleaner = Cleaner(tags=[], strip=True)
|
||||
cleaned_text = " ".join(re.split(r"\s+", cleaner.clean(data), flags=re.UNICODE)).strip()
|
||||
return cleaned_text
|
||||
|
||||
|
||||
@XBlock.wants('user')
|
||||
@XBlock.needs('i18n')
|
||||
class ProblemBlock(
|
||||
@@ -310,11 +303,7 @@ class ProblemBlock(
|
||||
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>',
|
||||
lambda matched: matched.group(1).replace("'", '').replace(",", ", ") if matched.group(1) else None,
|
||||
self.data
|
||||
)
|
||||
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(
|
||||
@@ -330,7 +319,12 @@ class ProblemBlock(
|
||||
"",
|
||||
capa_content
|
||||
)
|
||||
capa_content = _remove_html_tags_and_extra_spaces(capa_content)
|
||||
capa_content = re.sub(
|
||||
r"(\s| |//)+",
|
||||
" ",
|
||||
Cleaner(tags=[], strip=True).clean(capa_content)
|
||||
)
|
||||
|
||||
capa_body = {
|
||||
"capa_content": capa_content,
|
||||
"display_name": self.display_name,
|
||||
|
||||
@@ -2109,6 +2109,7 @@ class ProblemBlockTest(unittest.TestCase):
|
||||
|
||||
@ddt.ddt
|
||||
class ProblemBlockXMLTest(unittest.TestCase):
|
||||
maxDiff = None
|
||||
sample_checkbox_problem_xml = textwrap.dedent("""
|
||||
<problem>
|
||||
<p>Title</p>
|
||||
@@ -2509,7 +2510,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["multiplechoiceresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': 'Label Some comment Apple Banana Chocolate Donut'
|
||||
'capa_content': ' Label Some comment Apple Banana Chocolate Donut '
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2536,16 +2537,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': ["multiplechoiceresponse", "optionresponse"],
|
||||
'problem_types': set(["optionresponse", "multiplechoiceresponse"]),
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': 'Label Some comment Donut Buggy 1, 2'
|
||||
}
|
||||
'capa_content': " Label Some comment Donut Buggy '1','2' "
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -2581,7 +2587,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': [],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': ''
|
||||
'capa_content': ' '
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2609,7 +2615,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["choiceresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2621,7 +2627,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? India, Spain, China, Bermuda
|
||||
Which of the following countries celebrates its independence on August 15? 'India','Spain','China','Bermuda'
|
||||
""")
|
||||
self.assertEqual(descriptor.problem_types, {"optionresponse"})
|
||||
self.assertEqual(
|
||||
@@ -2630,7 +2636,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["optionresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2655,7 +2661,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["multiplechoiceresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2683,7 +2689,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["numericalresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2708,7 +2714,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["stringresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2722,7 +2728,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
""")
|
||||
name = "Non latin Input"
|
||||
descriptor = self._create_descriptor(sample_text_input_problem_xml, name=name)
|
||||
capa_content = "FX1_VAL='Καλημέρα' Δοκιμή με μεταβλητές με Ελληνικούς χαρακτήρες μέσα σε python: $FX1_VAL"
|
||||
capa_content = " FX1_VAL='Καλημέρα' Δοκιμή με μεταβλητές με Ελληνικούς χαρακτήρες μέσα σε python: $FX1_VAL "
|
||||
|
||||
descriptor_dict = descriptor.index_dictionary()
|
||||
self.assertEqual(
|
||||
@@ -2754,7 +2760,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["choiceresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2780,7 +2786,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["optionresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2806,7 +2812,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["multiplechoiceresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2830,7 +2836,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["numericalresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2854,7 +2860,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': ["stringresponse"],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -2886,7 +2892,7 @@ class ProblemBlockXMLTest(unittest.TestCase):
|
||||
'problem_types': [],
|
||||
'content': {
|
||||
'display_name': name,
|
||||
'capa_content': capa_content.replace("\n", " ").strip()
|
||||
'capa_content': capa_content.replace("\n", " ")
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user