示例#1
0
    def test_partial_completion_status_migration(self):
        """
        Changed `completed` to `status` in `self.student_results` to accomodate partial responses
        """
        # Instantiate a mentoring block with the old format
        student_results = [
            [u'goal',
                {u'completed': True,
                 u'score': 1,
                 u'student_input': u'test',
                 u'weight': 1}],
            [u'mcq_1_1',
                {u'completed': False,
                 u'score': 0,
                 u'submission': u'maybenot',
                 u'weight': 1}],
        ]
        mentoring = MentoringBlock(MagicMock(), DictFieldData({'student_results': student_results}), Mock())
        self.assertEqual(copy.deepcopy(student_results), mentoring.student_results)

        migrated_student_results = copy.deepcopy(student_results)
        migrated_student_results[0][1]['status'] = 'correct'
        migrated_student_results[1][1]['status'] = 'incorrect'
        del migrated_student_results[0][1]['completed']
        del migrated_student_results[1][1]['completed']
        mentoring.migrate_fields()
        self.assertEqual(migrated_student_results, mentoring.student_results)
 def test_student_view_data(self):
     def get_mock_components():
         child_a = Mock(spec=['student_view_data'])
         child_a.block_id = 'child_a'
         child_a.student_view_data.return_value = 'child_a_json'
         child_b = Mock(spec=[])
         child_b.block_id = 'child_b'
         return [child_a, child_b]
     shared_data = {
         'max_attempts': 3,
         'extended_feedback': True,
         'feedback_label': 'Feedback label',
     }
     children = get_mock_components()
     children_by_id = {child.block_id: child for child in children}
     block_data = {'children': children}
     block_data.update(shared_data)
     block = MentoringBlock(Mock(), DictFieldData(block_data), Mock())
     block.runtime = Mock(
         get_block=lambda block: children_by_id[block.block_id],
         load_block_type=lambda block: Mock,
         id_reader=Mock(get_definition_id=lambda block: block, get_block_type=lambda block: block),
     )
     expected = {
         'components': [
             'child_a_json',
         ],
         'messages': {
             'completed': None,
             'incomplete': None,
             'max_attempts_reached': None,
         }
     }
     expected.update(shared_data)
     self.assertEqual(block.student_view_data(), expected)
 def test_allowed_nested_blocks(self):
     block = MentoringBlock(Mock(), DictFieldData({}), Mock())
     self.assert_allowed_nested_blocks(block, message_blocks=[
             'pb-message',  # Message type: "completed"
             'pb-message',  # Message type: "incomplete"
             'pb-message',  # Message type: "max_attempts_reached"
         ]
     )
 def test_allowed_nested_blocks(self):
     block = MentoringBlock(Mock(), DictFieldData({}), Mock())
     self.assert_allowed_nested_blocks(block, message_blocks=[
             'pb-message',  # Message type: "completed"
             'pb-message',  # Message type: "incomplete"
             'pb-message',  # Message type: "max_attempts_reached"
         ] +
         (['pb-message'] if block.is_assessment else [])  # Message type: "on-assessment-review"
     )
示例#5
0
 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')
示例#6
0
    def test_does_not_send_progress_event_when_rendered_student_view_with_display_submit_true(self):
        block = MentoringBlock(MagicMock(), DictFieldData({
            'display_submit': True
        }), Mock())

        with patch.object(block, 'runtime') as patched_runtime:
            patched_runtime.publish = Mock()

            block.student_view(context={})

            self.assertFalse(patched_runtime.publish.called)
示例#7
0
    def test_sends_progress_event_when_rendered_student_view_with_display_submit_false(self):
        block = MentoringBlock(MagicMock(), DictFieldData({
            'display_submit': False
        }), Mock())

        with patch.object(block, 'runtime') as patched_runtime:
            patched_runtime.publish = Mock()

            block.student_view(context={})

            patched_runtime.publish.assert_called_once_with(block, 'progress', {})
示例#8
0
 def test_get_content_titles(self, has_title_set):
     """
     Test that we don't send a title to the LMS for the sequential's tooltips when no title
     is set
     """
     if has_title_set:
         data = {'display_name': 'Custom Title'}
         expected = ['Custom Title']
     else:
         data = {}
         expected = []
     block = MentoringBlock(MagicMock(), DictFieldData(data), Mock())
     self.assertEqual(block.get_content_titles(), expected)
 def test_correctly_decides_to_show_or_hide_feedback_message(
         self, pb_hide_feedback_if_attempts_remain, max_attempts_reached, expected_show_message
 ):
     block = MentoringBlock(Mock(), DictFieldData({
         'student_results': ['must', 'be', 'non-empty'],
     }), Mock())
     block.get_option = Mock(return_value=pb_hide_feedback_if_attempts_remain)
     with patch(
             'problem_builder.mentoring.MentoringBlock.max_attempts_reached', new_callable=PropertyMock
     ) as patched_max_attempts_reached:
         patched_max_attempts_reached.return_value = max_attempts_reached
         _, _, show_message = block._get_standard_results()
         self.assertEqual(show_message, expected_show_message)
示例#10
0
    def test_does_not_crash_when_get_child_is_broken(self):
        block = MentoringBlock(MagicMock(), DictFieldData({
            'children': ['invalid_id'],
        }), Mock())

        with patch.object(block, 'runtime') as patched_runtime:
            patched_runtime.publish = Mock()
            patched_runtime.service().ugettext = lambda str: str
            patched_runtime.get_block = lambda block_id: None
            patched_runtime.load_block_type = lambda block_id: Mock

            fragment = block.student_view(context={})

            self.assertIn('Unable to load child component', fragment.content)
示例#11
0
 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({}),
                                 Mock())