From b6d4a533a9f2b1d8072fb5b943d846e1391b4479 Mon Sep 17 00:00:00 2001 From: Waheed Ahmed Date: Fri, 31 Oct 2014 17:19:40 +0500 Subject: [PATCH] Fixed jump_to_id in problem solution. TNL-729 --- common/lib/xmodule/xmodule/capa_base.py | 5 +++- .../xmodule/xmodule/tests/test_capa_module.py | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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)