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.
This commit is contained in:
Feanil Patel
2019-10-23 14:31:33 -04:00
parent 98f605e2d6
commit c009d4550a
2 changed files with 22 additions and 1 deletions

View File

@@ -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)

View File

@@ -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)