Skip to content
Snippets Groups Projects
Commit c009d455 authored by Feanil Patel's avatar Feanil Patel
Browse files

Pass back the answer html as a string instead of bytes.

We did this already for the 'get_html' function for a capa problem but
there wasn't a test to ensure this works correctly for the
get_question_answer function that powers the show answer button.

I ran into it while doing a quick smoke test on the python 3 sandbox.
parent 98f605e2
No related branches found
No related tags found
No related merge requests found
......@@ -485,7 +485,7 @@ class LoncapaProblem(object):
# include solutions from <solution>...</solution> stanzas
for entry in self.tree.xpath("//" + "|//".join(solution_tags)):
answer = etree.tostring(entry)
answer = etree.tostring(entry).decode('utf-8')
if answer:
answer_map[entry.get('id')] = contextualize_text(answer, self.context)
......
......@@ -719,3 +719,24 @@ class CAPAProblemReportHelpersTest(unittest.TestCase):
"""
)
self.assertEquals(problem.find_answer_text('1_2_1', 'hide'), 'hide')
def test_get_question_answer(self):
problem = new_loncapa_problem(
"""
<problem>
<optionresponse>
<optioninput options="('yellow','blue','green')" correct="blue" label="Color_1"/>
</optionresponse>
<solution>
<div class="detailed-solution">
<p>Explanation</p>
<p>Blue is the answer.</p>
</div>
</solution>
</problem>
"""
)
# Ensure that the answer is a string so that the dict returned from this
# function can eventualy be serialized to json without issues.
self.assertIsInstance(problem.get_question_answers()['1_solution_1'], six.text_type)
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