コード例 #1
0
    def create(cls,
               max_attempts=None,
               attempts=None,
               correct=False,
               last_submission_time=None,
               submission_wait_seconds=None):
        """
        Optional parameters here are cut down to what we actually use vs. the regular CapaFactory.
        """
        location = BlockUsageLocator(CourseLocator('edX',
                                                   'capa_test',
                                                   'run',
                                                   deprecated=True),
                                     'problem',
                                     'SampleProblem{0}'.format(cls.next_num()),
                                     deprecated=True)
        field_data = {'data': cls.sample_problem_xml}

        if max_attempts is not None:
            field_data['max_attempts'] = max_attempts
        if last_submission_time is not None:
            field_data['last_submission_time'] = last_submission_time
        if submission_wait_seconds is not None:
            field_data['submission_wait_seconds'] = submission_wait_seconds

        descriptor = Mock(weight="1")
        if attempts is not None:
            # converting to int here because I keep putting "0" and "1" in the tests
            # since everything else is a string.
            field_data['attempts'] = int(attempts)

        system = get_test_system()
        system.render_template = Mock(
            return_value="<div>Test Template HTML</div>")
        module = CapaModule(
            descriptor,
            system,
            DictFieldData(field_data),
            ScopeIds(None, None, location, location),
        )

        if correct:
            # Could set the internal state formally, but here we just jam in the score.
            module.score = Score(raw_earned=1, raw_possible=1)
        else:
            module.score = Score(raw_earned=0, raw_possible=1)

        return module
コード例 #2
0
    def create(cls,
               max_attempts=None,
               attempts=None,
               correct=False,
               last_submission_time=None,
               submission_wait_seconds=None):
        """
        Optional parameters here are cut down to what we actually use vs. the regular CapaFactory.
        """
        location = Location([
            "i4x", "edX", "capa_test", "problem",
            "SampleProblem{0}".format(cls.next_num())
        ])
        field_data = {'data': cls.sample_problem_xml}

        if max_attempts is not None:
            field_data['max_attempts'] = max_attempts
        if last_submission_time is not None:
            field_data['last_submission_time'] = last_submission_time
        if submission_wait_seconds is not None:
            field_data['submission_wait_seconds'] = submission_wait_seconds

        descriptor = Mock(weight="1")
        if attempts is not None:
            # converting to int here because I keep putting "0" and "1" in the tests
            # since everything else is a string.
            field_data['attempts'] = int(attempts)

        system = get_test_system()
        system.render_template = Mock(
            return_value="<div>Test Template HTML</div>")
        module = CapaModule(
            descriptor,
            system,
            DictFieldData(field_data),
            ScopeIds(None, None, location, location),
        )

        if correct:
            # Could set the internal state formally, but here we just jam in the score.
            module.get_score = lambda: {'score': 1, 'total': 1}
        else:
            module.get_score = lambda: {'score': 0, 'total': 1}

        return module
コード例 #3
0
ファイル: test_capa_module.py プロジェクト: samH99/LexisNexis
    def create(graceperiod=None,
               due=None,
               max_attempts=None,
               showanswer=None,
               rerandomize=None,
               force_save_button=None,
               attempts=None,
               problem_state=None,
               correct=False,
               done=None
               ):
        """
        All parameters are optional, and are added to the created problem if specified.

        Arguments:
            graceperiod:
            due:
            max_attempts:
            showanswer:
            force_save_button:
            rerandomize: all strings, as specified in the policy for the problem

            problem_state: a dict to to be serialized into the instance_state of the
                module.

            attempts: also added to instance state.  Will be converted to an int.
        """
        location = Location(["i4x", "edX", "capa_test", "problem",
                             "SampleProblem{0}".format(CapaFactory.next_num())])
        model_data = {'data': CapaFactory.sample_problem_xml}

        if graceperiod is not None:
            model_data['graceperiod'] = graceperiod
        if due is not None:
            model_data['due'] = due
        if max_attempts is not None:
            model_data['max_attempts'] = max_attempts
        if showanswer is not None:
            model_data['showanswer'] = showanswer
        if force_save_button is not None:
            model_data['force_save_button'] = force_save_button
        if rerandomize is not None:
            model_data['rerandomize'] = rerandomize
        if done is not None:
            model_data['done'] = done

        descriptor = Mock(weight="1")
        if problem_state is not None:
            model_data.update(problem_state)
        if attempts is not None:
            # converting to int here because I keep putting "0" and "1" in the tests
            # since everything else is a string.
            model_data['attempts'] = int(attempts)

        system = test_system()
        system.render_template = Mock(return_value="<div>Test Template HTML</div>")
        module = CapaModule(system, location, descriptor, model_data)

        if correct:
            # TODO: probably better to actually set the internal state properly, but...
            module.get_score = lambda: {'score': 1, 'total': 1}
        else:
            module.get_score = lambda: {'score': 0, 'total': 1}

        return module