Commit be0c46aa by Kelketek

Merge pull request #64 from open-craft/feedback-jump-to-id

Make sure messages get jump_to_id URLs rewritten.
parents e1950513 eb1f83df
...@@ -469,6 +469,8 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM ...@@ -469,6 +469,8 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM
if result and result.get('status') != 'correct': if result and result.get('status') != 'correct':
# The student got this wrong. Check if there is a review tip to show. # The student got this wrong. Check if there is a review tip to show.
tip_html = child.get_review_tip() tip_html = child.get_review_tip()
if hasattr(self.runtime, 'replace_jump_to_id_urls'):
tip_html = self.runtime.replace_jump_to_id_urls(tip_html)
if tip_html: if tip_html:
review_tips.append(tip_html) review_tips.append(tip_html)
return review_tips return review_tips
...@@ -746,7 +748,10 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM ...@@ -746,7 +748,10 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM
if child_isinstance(self, child_id, MentoringMessageBlock): if child_isinstance(self, child_id, MentoringMessageBlock):
child = self.runtime.get_block(child_id) child = self.runtime.get_block(child_id)
if child.type == message_type: if child.type == message_type:
return child.content content = child.content
if hasattr(self.runtime, 'replace_jump_to_id_urls'):
content = self.runtime.replace_jump_to_id_urls(content)
return content
if or_default: if or_default:
# Return the default value since no custom message is set. # Return the default value since no custom message is set.
# Note the WYSIWYG editor usually wraps the .content HTML in a <p> tag so we do the same here. # Note the WYSIWYG editor usually wraps the .content HTML in a <p> tag so we do the same here.
......
...@@ -2,7 +2,7 @@ import unittest ...@@ -2,7 +2,7 @@ import unittest
import ddt import ddt
from mock import MagicMock, Mock, patch from mock import MagicMock, Mock, patch
from xblock.field_data import DictFieldData from xblock.field_data import DictFieldData
from problem_builder import MentoringBlock from problem_builder import MentoringBlock, MentoringMessageBlock, MCQBlock
from problem_builder.mentoring import _default_theme_config from problem_builder.mentoring import _default_theme_config
...@@ -139,3 +139,33 @@ class TestMentoringBlockTheming(unittest.TestCase): ...@@ -139,3 +139,33 @@ class TestMentoringBlockTheming(unittest.TestCase):
with patch.object(self.block, 'include_theme_files') as patched_include_theme_files: with patch.object(self.block, 'include_theme_files') as patched_include_theme_files:
fragment = self.block.author_preview_view({}) fragment = self.block.author_preview_view({})
patched_include_theme_files.assert_called_with(fragment) patched_include_theme_files.assert_called_with(fragment)
class TestMentoringBlockJumpToIds(unittest.TestCase):
def setUp(self):
self.service_mock = Mock()
self.runtime_mock = Mock()
self.runtime_mock.service = Mock(return_value=self.service_mock)
self.block = MentoringBlock(self.runtime_mock, DictFieldData({'mode': 'assessment'}), Mock())
self.block.children = ['dummy_id']
self.message_block = MentoringMessageBlock(
self.runtime_mock, DictFieldData({'type': 'bogus', 'content': 'test'}), Mock()
)
self.block.runtime.replace_jump_to_id_urls = lambda x: x.replace('test', 'replaced-url')
def test_get_message_content(self):
with patch('problem_builder.mentoring.child_isinstance') as mock_child_isinstance:
mock_child_isinstance.return_value = True
self.runtime_mock.get_block = Mock()
self.runtime_mock.get_block.return_value = self.message_block
self.assertEqual(self.block.get_message_content('bogus'), 'replaced-url')
def test_get_tip_content(self):
self.mcq_block = MCQBlock(self.runtime_mock, DictFieldData({'name': 'test_mcq'}), Mock())
self.mcq_block.get_review_tip = Mock()
self.mcq_block.get_review_tip.return_value = self.message_block.content
self.block.steps = []
self.block.get_steps = Mock()
self.block.get_steps.return_value = [self.mcq_block]
self.block.student_results = {'test_mcq': {'status': 'incorrect'}}
self.assertEqual(self.block.review_tips, ['replaced-url'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment