Skip to content
Snippets Groups Projects
Unverified Commit c3682237 authored by Awais Jibran's avatar Awais Jibran Committed by GitHub
Browse files

Merge pull request #19782 from edx/aj/fix-capa-problem-response-csv

Fix csv of problem responses silent failure
parents d29956be 04d17d55
No related branches found
No related tags found
No related merge requests found
......@@ -31,7 +31,7 @@ import capa.xqueue_interface as xqueue_interface
from capa.correctmap import CorrectMap
from capa.safe_exec import safe_exec
from capa.util import contextualize_text, convert_files_to_filenames
from openedx.core.djangolib.markup import HTML
from openedx.core.djangolib.markup import HTML, Text
from xmodule.stringify import stringify_children
# extra things displayed after "show answers" is pressed
......@@ -884,7 +884,7 @@ class LoncapaProblem(object):
)
except Exception as err:
log.exception("Error while execing script code: " + all_code)
msg = "Error while executing script code: %s" % str(err).replace('<', '&lt;')
msg = Text("Error while executing script code: %s" % str(err))
raise responsetypes.LoncapaProblemError(msg)
# Store code source in context, along with the Python path needed to run it correctly.
......@@ -1119,7 +1119,7 @@ class LoncapaProblem(object):
for inputfield in inputfields:
problem_data[inputfield.get('id')] = {
'group_label': group_label_tag_text,
'label': inputfield.attrib.get('label', ''),
'label': HTML(inputfield.attrib.get('label', '')),
'descriptions': {}
}
else:
......
......@@ -3,7 +3,10 @@ Test capa problem.
"""
import ddt
import textwrap
import six
from lxml import etree
from markupsafe import Markup
from mock import patch
import unittest
......@@ -145,7 +148,6 @@ class CAPAProblemTest(unittest.TestCase):
'descriptions': {}
}
}
)
for question in (question1, question2):
self.assertEqual(
......@@ -467,16 +469,21 @@ class CAPAMultiInputProblemTest(unittest.TestCase):
"""
return new_loncapa_problem(xml, use_capa_render_template=True)
def assert_problem_html(self, problme_html, group_label, *input_labels):
def assert_problem_data(self, problem_data):
"""Verify problem data is in expected state"""
for problem_value in six.viewvalues(problem_data):
self.assertIsInstance(problem_value['label'], Markup)
def assert_problem_html(self, problem_html, group_label, *input_labels):
"""
Verify that correct html is rendered for multiple inputtypes.
Arguments:
problme_html (str): problem HTML
problem_html (str): problem HTML
group_label (str or None): multi input group label or None if label is not present
input_labels (tuple): individual input labels
"""
html = etree.XML(problme_html)
html = etree.XML(problem_html)
# verify that only one multi input group div is present at correct path
multi_inputs_group = html.xpath(
......@@ -523,6 +530,7 @@ class CAPAMultiInputProblemTest(unittest.TestCase):
""".format(label_html=label_html, input1_label=input1_label, input2_label=input2_label)
problem = self.capa_problem(xml)
self.assert_problem_html(problem.get_html(), group_label, input1_label, input2_label)
self.assert_problem_data(problem.problem_data)
@ddt.unpack
@ddt.data(
......@@ -552,6 +560,7 @@ class CAPAMultiInputProblemTest(unittest.TestCase):
""".format(group_label, input1_label, input2_label, inputtype=inputtype))
problem = self.capa_problem(xml)
self.assert_problem_html(problem.get_html(), group_label, input1_label, input2_label)
self.assert_problem_data(problem.problem_data)
@ddt.unpack
@ddt.data(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment