Merge PR #27202 fix/capa/empty-option-text
* Commits: fix: Allow capa_problem optioninput option with empty text refactor: Refactor capa_problem optioninput option text handling
This commit is contained in:
@@ -285,7 +285,9 @@ class LoncapaProblem(object):
|
||||
correct_option = None
|
||||
child_options = []
|
||||
for option_element in optioninput.findall('./option'):
|
||||
option_name = option_element.text.strip()
|
||||
text = option_element.text
|
||||
text = text or ''
|
||||
option_name = text.strip()
|
||||
if option_element.get('correct').upper() == 'TRUE':
|
||||
correct_option = option_name
|
||||
child_options.append("'" + option_name + "'")
|
||||
|
||||
@@ -397,6 +397,26 @@ class CAPAProblemTest(unittest.TestCase):
|
||||
problem = new_loncapa_problem(xml.format(correctness=False))
|
||||
assert problem is not None
|
||||
|
||||
def test_optionresponse_option_with_empty_text(self):
|
||||
"""
|
||||
Verify successful instantiation of an optionresponse problem
|
||||
with an option with empty text
|
||||
"""
|
||||
xml = """
|
||||
<problem>
|
||||
<optionresponse>
|
||||
<label>Select True or False</label>
|
||||
<optioninput>
|
||||
<option correct="False">True <optionhint>Not this one</optionhint></option>
|
||||
<option correct="True">False</option>
|
||||
<option correct="False"><optionhint>Not this empty one either</optionhint></option>
|
||||
</optioninput>
|
||||
</optionresponse>
|
||||
</problem>
|
||||
"""
|
||||
problem = new_loncapa_problem(xml)
|
||||
assert problem is not None
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class CAPAMultiInputProblemTest(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user