Esempio n. 1
0
    def create(hints=None,
               previous_answers=None,
               user_voted=None,
               moderate=None,
               mod_queue=None):
        """
        A factory method for making CHM's
        """
        model_data = {'data': CHModuleFactory.sample_problem_xml}

        if hints is not None:
            model_data['hints'] = hints
        else:
            model_data['hints'] = {
                '24.0': {
                    '0': ['Best hint', 40],
                    '3': ['Another hint', 30],
                    '4': ['A third hint', 20],
                    '6': ['A less popular hint', 3]
                },
                '25.0': {
                    '1': ['Really popular hint', 100]
                }
            }

        if mod_queue is not None:
            model_data['mod_queue'] = mod_queue
        else:
            model_data['mod_queue'] = {
                '24.0': {
                    '2': ['A non-approved hint']
                },
                '26.0': {
                    '5': ['Another non-approved hint']
                }
            }

        if previous_answers is not None:
            model_data['previous_answers'] = previous_answers
        else:
            model_data['previous_answers'] = [['24.0', [0, 3, 4]],
                                              ['29.0', [None, None, None]]]

        if user_voted is not None:
            model_data['user_voted'] = user_voted

        if moderate is not None:
            model_data['moderate'] = moderate

        descriptor = Mock(weight="1")
        system = get_test_system()
        module = CrowdsourceHinterModule(system, descriptor, model_data)

        return module
Esempio n. 2
0
    def create(hints=None,
               previous_answers=None,
               user_submissions=None,
               user_voted=None,
               moderate=None,
               mod_queue=None):
        """
        A factory method for making CHM's
        """
        # Should have a single child, but it doesn't matter what that child is
        field_data = {
            'data': CHModuleFactory.sample_problem_xml,
            'children': [None]
        }

        if hints is not None:
            field_data['hints'] = hints
        else:
            field_data['hints'] = {
                '24.0': {
                    '0': ['Best hint', 40],
                    '3': ['Another hint', 30],
                    '4': ['A third hint', 20],
                    '6': ['A less popular hint', 3]
                },
                '25.0': {
                    '1': ['Really popular hint', 100]
                }
            }

        if mod_queue is not None:
            field_data['mod_queue'] = mod_queue
        else:
            field_data['mod_queue'] = {
                '24.0': {
                    '2': ['A non-approved hint']
                },
                '26.0': {
                    '5': ['Another non-approved hint']
                }
            }

        if previous_answers is not None:
            field_data['previous_answers'] = previous_answers
        else:
            field_data['previous_answers'] = [['24.0', [0, 3, 4]],
                                              ['29.0', []]]

        if user_submissions is not None:
            field_data['user_submissions'] = user_submissions
        else:
            field_data['user_submissions'] = ['24.0', '29.0']

        if user_voted is not None:
            field_data['user_voted'] = user_voted

        if moderate is not None:
            field_data['moderate'] = moderate

        descriptor = Mock(weight='1')
        # Make the descriptor have a capa problem child.
        capa_descriptor = MagicMock()
        capa_descriptor.name = 'capa'
        capa_descriptor.displayable_items.return_value = [capa_descriptor]
        descriptor.get_children.return_value = [capa_descriptor]

        # Make a fake capa module.
        capa_module = MagicMock()
        capa_module.lcp = MagicMock()
        responder = MagicMock()

        def validate_answer(answer):
            """ A mock answer validator - simulates a numerical response"""
            try:
                float(answer)
                return True
            except ValueError:
                return False

        responder.validate_answer = validate_answer

        def compare_answer(ans1, ans2):
            """ A fake answer comparer """
            return ans1 == ans2

        responder.compare_answer = compare_answer

        capa_module.lcp.responders = {'responder0': responder}
        capa_module.displayable_items.return_value = [capa_module]

        system = get_test_system()

        # Make the system have a marginally-functional get_module

        def fake_get_module(descriptor):
            """
            A fake module-maker.
            """
            return capa_module

        system.get_module = fake_get_module
        module = CrowdsourceHinterModule(descriptor, system,
                                         DictFieldData(field_data), Mock())

        return module