From 9afa58f9636003ad9163dc14f418da1eb2c11ad6 Mon Sep 17 00:00:00 2001 From: stvn Date: Wed, 31 Mar 2021 00:30:59 -0700 Subject: [PATCH 1/2] refactor: Refactor capa_problem optioninput option text handling to make it easier to add/remove parsing/processing logic (in pending commits). --- common/lib/capa/capa/capa_problem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 7a2408e209..5f06f1477e 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -285,7 +285,8 @@ 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 + option_name = text.strip() if option_element.get('correct').upper() == 'TRUE': correct_option = option_name child_options.append("'" + option_name + "'") From 21dce731f9c6f61184383e67762d57ef656eaa1c Mon Sep 17 00:00:00 2001 From: stvn Date: Wed, 31 Mar 2021 00:39:42 -0700 Subject: [PATCH 2/2] fix: Allow capa_problem optioninput option with empty text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes TNL-7973 [1]. Background ---------- > An alert was sent out because a malformed capa problem caused block > transformers to fail to run. > This specific error/alert was triggered when an optionresponse problem > lacked text. The authoring-based fix is to edit the offending > option-response problem to remove the empty option. > Expected behavior: We should be able to keep the error local to the > ProblemBlock and not blow up the whole course publish block > transformer collection process. > This is a really easy error for authors to make, and the consequences > to them (one problem doesn’t work) are disproportionate to the > consequences [...] (alerting triggered). - [1] https://openedx.atlassian.net/browse/TNL-7973 --- common/lib/capa/capa/capa_problem.py | 1 + .../lib/capa/capa/tests/test_capa_problem.py | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 5f06f1477e..84af4db4b6 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -286,6 +286,7 @@ class LoncapaProblem(object): child_options = [] for option_element in optioninput.findall('./option'): text = option_element.text + text = text or '' option_name = text.strip() if option_element.get('correct').upper() == 'TRUE': correct_option = option_name diff --git a/common/lib/capa/capa/tests/test_capa_problem.py b/common/lib/capa/capa/tests/test_capa_problem.py index 6b2cc02fc4..f4cbf8eb2a 100644 --- a/common/lib/capa/capa/tests/test_capa_problem.py +++ b/common/lib/capa/capa/tests/test_capa_problem.py @@ -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 = new_loncapa_problem(xml) + assert problem is not None + @ddt.ddt class CAPAMultiInputProblemTest(unittest.TestCase):