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_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)
    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', {})
    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)
    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', {})
 def test_runtime_constant_uuid(self):
     block = MentoringBlock(MagicMock(), DictFieldData({}), Mock())
     mcq1 = MCQBlock(block)
     uuid1 = mcq1.uuid
     # Doesn't change during objects lifetime.
     self.assertEquals(mcq1.uuid, uuid1)
     # Different instance returns a different uuid.
     mcq2 = MCQBlock(block)
     self.assertNotEquals(mcq2.uuid, uuid1)
    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)