diff --git a/common/lib/xmodule/xmodule/capa_base.py b/common/lib/xmodule/xmodule/capa_base.py index cbbee5ecac..72fd88972b 100644 --- a/common/lib/xmodule/xmodule/capa_base.py +++ b/common/lib/xmodule/xmodule/capa_base.py @@ -811,7 +811,10 @@ class CapaMixin(CapaFields): new_answers = dict() for answer_id in answers: try: - new_answer = {answer_id: self.runtime.replace_urls(answers[answer_id])} + answer_content = self.runtime.replace_urls(answers[answer_id]) + if self.runtime.replace_jump_to_id_urls: + answer_content = self.runtime.replace_jump_to_id_urls(answer_content) + new_answer = {answer_id: answer_content} except TypeError: log.debug(u'Unable to perform URL substitution on answers[%s]: %s', answer_id, answers[answer_id]) diff --git a/common/lib/xmodule/xmodule/tests/test_capa_module.py b/common/lib/xmodule/xmodule/tests/test_capa_module.py index 439a2a0cf4..5208b17382 100644 --- a/common/lib/xmodule/xmodule/tests/test_capa_module.py +++ b/common/lib/xmodule/xmodule/tests/test_capa_module.py @@ -1890,3 +1890,29 @@ class TestProblemCheckTracking(unittest.TestCase): 'variant': '' } }) + + def test_get_answer_with_jump_to_id_urls(self): + """ + Make sure replace_jump_to_id_urls() is called in get_answer. + """ + problem_xml = textwrap.dedent(""" + +

What is 1+4?

+ + + + + + + +
+ """) + + data = dict() + problem = CapaFactory.create(showanswer='always', xml=problem_xml) + problem.runtime.replace_jump_to_id_urls = Mock() + problem.get_answer(data) + self.assertTrue(problem.runtime.replace_jump_to_id_urls.called)