Skip to content

Commit dbc4760

Browse files
committed
Merge pull request openedx#5809 from edx/waheed/tnl729-fix-jump-to-id-in-problem-solution
Fixed jump_to_id in problem solution.
2 parents 831453c + b6d4a53 commit dbc4760

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

common/lib/xmodule/xmodule/capa_base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,10 @@ def get_answer(self, _data):
811811
new_answers = dict()
812812
for answer_id in answers:
813813
try:
814-
new_answer = {answer_id: self.runtime.replace_urls(answers[answer_id])}
814+
answer_content = self.runtime.replace_urls(answers[answer_id])
815+
if self.runtime.replace_jump_to_id_urls:
816+
answer_content = self.runtime.replace_jump_to_id_urls(answer_content)
817+
new_answer = {answer_id: answer_content}
815818
except TypeError:
816819
log.debug(u'Unable to perform URL substitution on answers[%s]: %s',
817820
answer_id, answers[answer_id])

common/lib/xmodule/xmodule/tests/test_capa_module.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,3 +1890,29 @@ def test_file_inputs(self):
18901890
'variant': ''
18911891
}
18921892
})
1893+
1894+
def test_get_answer_with_jump_to_id_urls(self):
1895+
"""
1896+
Make sure replace_jump_to_id_urls() is called in get_answer.
1897+
"""
1898+
problem_xml = textwrap.dedent("""
1899+
<problem>
1900+
<p>What is 1+4?</p>
1901+
<numericalresponse answer="5">
1902+
<formulaequationinput />
1903+
</numericalresponse>
1904+
1905+
<solution>
1906+
<div class="detailed-solution">
1907+
<p>Explanation</p>
1908+
<a href="/jump_to_id/c0f8d54964bc44a4a1deb8ecce561ecd">here's the same link to the hint page.</a>
1909+
</div>
1910+
</solution>
1911+
</problem>
1912+
""")
1913+
1914+
data = dict()
1915+
problem = CapaFactory.create(showanswer='always', xml=problem_xml)
1916+
problem.runtime.replace_jump_to_id_urls = Mock()
1917+
problem.get_answer(data)
1918+
self.assertTrue(problem.runtime.replace_jump_to_id_urls.called)

0 commit comments

Comments
 (0)