コード例 #1
0
ファイル: tests.py プロジェクト: DoTamKma/debug-edx-platform
 def test_get_history_true_true(self):
     student_module = StudentModule.objects.all()
     history = BaseStudentModuleHistory.get_history(student_module)
     self.assertEquals(len(history), 6)
     self.assertEquals({
         'type': 'csmhe',
         'order': 3
     }, json.loads(history[0].state))
     self.assertEquals({
         'type': 'csmhe',
         'order': 2
     }, json.loads(history[1].state))
     self.assertEquals({
         'type': 'csmhe',
         'order': 1
     }, json.loads(history[2].state))
     self.assertEquals({
         'type': 'csmh',
         'order': 3
     }, json.loads(history[3].state))
     self.assertEquals({
         'type': 'csmh',
         'order': 2
     }, json.loads(history[4].state))
     self.assertEquals({
         'type': 'csmh',
         'order': 1
     }, json.loads(history[5].state))
コード例 #2
0
ファイル: tests.py プロジェクト: edx/edx-platform
 def test_get_history_false_true(self):
     student_module = StudentModule.objects.all()
     history = BaseStudentModuleHistory.get_history(student_module)
     self.assertEquals(len(history), 3)
     self.assertEquals({'type': 'csmh', 'order': 3}, json.loads(history[0].state))
     self.assertEquals({'type': 'csmh', 'order': 2}, json.loads(history[1].state))
     self.assertEquals({'type': 'csmh', 'order': 1}, json.loads(history[2].state))
コード例 #3
0
ファイル: tests.py プロジェクト: zhenzhai/edx-platform
 def test_get_history_true_false(self):
     student_module = StudentModule.objects.all()
     history = BaseStudentModuleHistory.get_history(student_module)
     self.assertEquals(len(history), 3)
     self.assertEquals({"type": "csmhe", "order": 3}, json.loads(history[0].state))
     self.assertEquals({"type": "csmhe", "order": 2}, json.loads(history[1].state))
     self.assertEquals({"type": "csmhe", "order": 1}, json.loads(history[2].state))
コード例 #4
0
    def test_show_answer_doesnt_write_to_csm(self):
        self.basic_setup()
        self.submit_question_answer('p1', {'2_1': u'Correct'})

        # Now fetch the state entry for that problem.
        student_module = StudentModule.objects.filter(
            course_id=self.course.id, student=self.student_user)
        # count how many state history entries there are
        baseline = BaseStudentModuleHistory.get_history(student_module)
        self.assertEqual(len(baseline), 3)

        # now click "show answer"
        self.show_question_answer('p1')

        # check that we don't have more state history entries
        csmh = BaseStudentModuleHistory.get_history(student_module)
        self.assertEqual(len(csmh), 3)
コード例 #5
0
    def test_show_answer_doesnt_write_to_csm(self):
        self.basic_setup()
        self.submit_question_answer('p1', {'2_1': u'Correct'})

        # Now fetch the state entry for that problem.
        student_module = StudentModule.objects.filter(
            course_id=self.course.id,
            student=self.student_user
        )
        # count how many state history entries there are
        baseline = BaseStudentModuleHistory.get_history(student_module)
        self.assertEqual(len(baseline), 3)

        # now click "show answer"
        self.show_question_answer('p1')

        # check that we don't have more state history entries
        csmh = BaseStudentModuleHistory.get_history(student_module)
        self.assertEqual(len(csmh), 3)
コード例 #6
0
    def get_history(self, username, block_key, scope=Scope.user_state):
        """
        Retrieve history of state changes for a given block for a given
        student.  We don't guarantee that history for many blocks will be fast.

        If the specified block doesn't exist, raise :class:`~DoesNotExist`.

        Arguments:
            username: The name of the user whose history should be retrieved.
            block_key: The key identifying which xblock history to retrieve.
            scope (Scope): The scope to load data from.

        Yields:
            XBlockUserState entries for each modification to the specified XBlock, from latest
            to earliest.
        """

        if scope != Scope.user_state:
            raise ValueError("Only Scope.user_state is supported")
        student_modules = list(
            student_module
            for student_module, usage_id
            in self._get_student_modules(username, [block_key])
        )
        if len(student_modules) == 0:
            raise self.DoesNotExist()

        history_entries = BaseStudentModuleHistory.get_history(student_modules)

        # If no history records exist, raise an error
        if not history_entries:
            raise self.DoesNotExist()

        for history_entry in history_entries:
            state = history_entry.state

            # If the state is serialized json, then load it
            if state is not None:
                state = json.loads(state)

            # If the state is empty, then for the purposes of `get_history`, it has been
            # deleted, and so we list that entry as `None`.
            if state == {}:
                state = None

            block_key = history_entry.csm.module_state_key
            block_key = block_key.map_into_course(
                history_entry.csm.course_id
            )

            yield XBlockUserState(username, block_key, state, history_entry.created, scope)
コード例 #7
0
    def get_history(self, username, block_key, scope=Scope.user_state):
        """
        Retrieve history of state changes for a given block for a given
        student.  We don't guarantee that history for many blocks will be fast.

        If the specified block doesn't exist, raise :class:`~DoesNotExist`.

        Arguments:
            username: The name of the user whose history should be retrieved.
            block_key: The key identifying which xblock history to retrieve.
            scope (Scope): The scope to load data from.

        Yields:
            XBlockUserState entries for each modification to the specified XBlock, from latest
            to earliest.
        """

        if scope != Scope.user_state:
            raise ValueError("Only Scope.user_state is supported")
        student_modules = list(
            student_module
            for student_module, usage_id
            in self._get_student_modules(username, [block_key])
        )
        if len(student_modules) == 0:
            raise self.DoesNotExist()

        history_entries = BaseStudentModuleHistory.get_history(student_modules)

        # If no history records exist, raise an error
        if not history_entries:
            raise self.DoesNotExist()

        for history_entry in history_entries:
            state = history_entry.state

            # If the state is serialized json, then load it
            if state is not None:
                state = json.loads(state)

            # If the state is empty, then for the purposes of `get_history`, it has been
            # deleted, and so we list that entry as `None`.
            if state == {}:
                state = None

            block_key = history_entry.csm.module_state_key
            block_key = block_key.map_into_course(
                history_entry.csm.course_id
            )

            yield XBlockUserState(username, block_key, state, history_entry.created, scope)
コード例 #8
0
ファイル: tests.py プロジェクト: DoTamKma/debug-edx-platform
 def test_get_history_false_false(self):
     student_module = StudentModule.objects.all()
     history = BaseStudentModuleHistory.get_history(student_module)
     self.assertEquals(len(history), 0)
コード例 #9
0
ファイル: tests.py プロジェクト: edx/edx-platform
 def test_get_history_false_false(self):
     student_module = StudentModule.objects.all()
     history = BaseStudentModuleHistory.get_history(student_module)
     self.assertEquals(len(history), 0)