Exemplo n.º 1
0
    def test_no_action_is_performed_for_deleted_exploration(self):
        """Test that no action is performed on deleted explorations."""

        exploration = exp_domain.Exploration.create_default_exploration(
            self.VALID_EXP_ID, title='title', category='category')

        exploration.add_states(['State1'])

        state1 = exploration.states['State1']

        state1.update_interaction_id('ItemSelectionInput')

        customization_args_dict = {
            'choices': {'value': [{
                'html': '<p>This is value1 for ItemSelection</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for ItemSelection</p>',
                'content_id': 'ca_choices_1'
            }]},
            'minAllowableSelectionCount': {'value': 0},
            'maxAllowableSelectionCount': {'value': 1}
        }

        state_answer_group_list = [state_domain.AnswerGroup(
            state_domain.Outcome(
                'State1', state_domain.SubtitledHtml(
                    'feedback', '<p>Outcome for state2</p>'),
                False, [], None, None),
            [
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value1 for ItemSelection</p>']
                    }),
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value3 for ItemSelection</p>']
                    })
            ],
            [],
            None
        )]

        state1.update_interaction_customization_args(customization_args_dict)
        state1.update_next_content_id_index(2)
        state1.update_interaction_answer_groups(state_answer_group_list)

        exp_services.save_new_exploration(self.albert_id, exploration)

        exp_services.delete_exploration(self.albert_id, self.VALID_EXP_ID)

        run_job_for_deleted_exp(
            self,
            (
                interaction_jobs_one_off
                .RuleInputToCustomizationArgsMappingOneOffJob)
        )
Exemplo n.º 2
0
    def test_no_action_is_performed_for_deleted_exploration(self):
        """Test that no action is performed on deleted explorations."""

        exploration = exp_domain.Exploration.create_default_exploration(
            self.VALID_EXP_ID, title='title', category='category')

        exploration.add_states(['State1'])

        state1 = exploration.states['State1']

        state1.update_interaction_id('DragAndDropSortInput')

        customization_args_dict = {
            'choices': {'value': [{
                'html': '<p>This is value1 for DragAndDropSortInput</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for DragAndDropSortInput</p>',
                'content_id': 'ca_choices_1'
            }]},
            'allowMultipleItemsInSamePosition': {'value': True}
        }

        state_answer_groups = [state_domain.AnswerGroup(
            state_domain.Outcome(
                'State1', state_domain.SubtitledHtml(
                    'feedback', '<p>Outcome for state2</p>'),
                False, [], None, None),
            [
                state_domain.RuleSpec(
                    'IsEqualToOrdering',
                    {
                        'x': []
                    }),
                state_domain.RuleSpec(
                    'IsEqualToOrdering',
                    {
                        'x': []
                    })
            ],
            [],
            None
        )]

        state1.update_interaction_customization_args(customization_args_dict)
        state1.update_next_content_id_index(2)
        state1.update_interaction_answer_groups(state_answer_groups)

        exp_services.save_new_exploration(self.albert_id, exploration)

        exp_services.delete_exploration(self.albert_id, self.VALID_EXP_ID)

        run_job_for_deleted_exp(
            self,
            interaction_jobs_one_off.DragAndDropSortInputInteractionOneOffJob)
Exemplo n.º 3
0
    def test_exp_state_pairs_are_produced_for_item_selection_interactions(self):
        """Checks (exp, state) pairs are produced correctly for ItemSelection
        interactions.
        """
        owner = user_services.get_user_actions_info(self.albert_id)
        exploration = exp_domain.Exploration.create_default_exploration(
            self.VALID_EXP_ID, title='title', category='category')

        exploration.add_states(['State1', 'State2'])

        state1 = exploration.states['State1']
        state2 = exploration.states['State2']

        customization_args_dict1 = {
            'choices': {'value': [{
                'html': '<p>This is value1 for ItemSelection</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for ItemSelection</p>',
                'content_id': 'ca_choices_1'
            }]},
            'minAllowableSelectionCount': {'value': 0},
            'maxAllowableSelectionCount': {'value': 1}
        }

        state_answer_group_list1 = [state_domain.AnswerGroup(
            state_domain.Outcome(
                'Introduction', state_domain.SubtitledHtml(
                    'feedback', '<p>Outcome for state1</p>'),
                False, [], None, None),
            [
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value1 for ItemSelection</p>']
                    }),
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value2 for ItemSelection</p>']
                    })
            ],
            [],
            None
        )]

        solution1 = state_domain.Solution.from_dict('ItemSelectionInput', {
            'answer_is_exclusive': True,
            'correct_answer': ['<p>This is value2 for DragAndDropSort</p>'],
            'explanation': {
                'content_id': 'solution',
                'html': ''
            }
        })

        hint_list1 = [state_domain.Hint.from_dict({
            'hint_content': {
                'content_id': 'hint_0',
                'html': ''
            }
        })]

        state1.update_interaction_id('ItemSelectionInput')
        state1.update_interaction_customization_args(customization_args_dict1)
        state1.update_next_content_id_index(2)
        state1.update_interaction_answer_groups(state_answer_group_list1)
        exp_services.save_new_exploration(self.albert_id, exploration)
        state1.update_interaction_solution(solution1)
        state1.update_interaction_hints(hint_list1)

        # Start RuleInputToCustomizationArgsMappingOneOffJob job on sample
        # exploration.
        job_id = (
            interaction_jobs_one_off
            .RuleInputToCustomizationArgsMappingOneOffJob.create_new())
        (
            interaction_jobs_one_off
            .RuleInputToCustomizationArgsMappingOneOffJob.enqueue(job_id))
        self.process_and_flush_pending_mapreduce_tasks()

        actual_output = (
            interaction_jobs_one_off
            .RuleInputToCustomizationArgsMappingOneOffJob.get_output(job_id))
        self.assertEqual(actual_output, [])

        customization_args_dict2 = {
            'choices': {'value': [{
                'html': '<p>This is value1 for ItemSelection</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for ItemSelection</p>',
                'content_id': 'ca_choices_1'
            }]},
            'minAllowableSelectionCount': {'value': 0},
            'maxAllowableSelectionCount': {'value': 1}
        }

        state_answer_group_list2 = [state_domain.AnswerGroup(
            state_domain.Outcome(
                'State1', state_domain.SubtitledHtml(
                    'feedback', '<p>Outcome for state2</p>'),
                False, [], None, None),
            [
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value1 for ItemSelection</p>']
                    }),
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value3 for ItemSelection</p>']
                    })
            ],
            [],
            None
        )]

        solution2 = state_domain.Solution.from_dict('ItemSelectionInput', {
            'answer_is_exclusive': True,
            'correct_answer': ['<p>This is value3 for DragAndDropSort</p>'],
            'explanation': {
                'content_id': 'solution',
                'html': ''
            }
        })

        hint_list2 = [state_domain.Hint.from_dict({
            'hint_content': {
                'content_id': 'hint_0',
                'html': ''
            }
        })]

        state2.update_interaction_id('ItemSelectionInput')
        state2.update_interaction_customization_args(customization_args_dict2)
        state2.update_next_content_id_index(2)
        state2.update_interaction_answer_groups(state_answer_group_list2)
        state2.update_interaction_solution(solution2)
        state2.update_interaction_hints(hint_list2)

        exp_services.save_new_exploration(self.albert_id, exploration)
        rights_manager.publish_exploration(owner, self.VALID_EXP_ID)

        # Start ItemSelectionInteractionOneOff job on sample exploration.
        job_id = (
            interaction_jobs_one_off
            .RuleInputToCustomizationArgsMappingOneOffJob.create_new())
        (
            interaction_jobs_one_off
            .RuleInputToCustomizationArgsMappingOneOffJob.enqueue(job_id))
        self.process_and_flush_pending_mapreduce_tasks()

        actual_output = (
            interaction_jobs_one_off
            .RuleInputToCustomizationArgsMappingOneOffJob.get_output(job_id))
        expected_output = [(
            u'[u\'exp_id0\', [u"<ItemSelectionInput Answer> State: State2, '
            'Invalid Values: [\'<p>This is value3 for DragAndDropSort</p>\']"'
            ', u"<ItemSelectionInput Rule> State: State2, '
            'Answer Group Index: 0, Invalid Values: [u\'<p>This is value3 '
            'for ItemSelection</p>\']", u"<ItemSelectionInput Answer> State: '
            'State1, Invalid Values: [\'<p>This is value2 for '
            'DragAndDropSort</p>\']"]]'
        )]

        self.assertEqual(actual_output, expected_output)
Exemplo n.º 4
0
    def test_exp_state_pairs_are_produced_only_for_desired_interactions(self):
        """Checks (exp, state) pairs are produced only for
        desired interactions.
        """
        exploration = exp_domain.Exploration.create_default_exploration(
            self.VALID_EXP_ID, title='title', category='category')

        exploration.add_states(['State1', 'State2'])

        state1 = exploration.states['State1']
        state2 = exploration.states['State2']

        customization_args_dict1 = {
            'choices': {'value': [{
                'html': '<p>This is value1 for ItemSelection</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for ItemSelection</p>',
                'content_id': 'ca_choices_1'
            }]},
            'minAllowableSelectionCount': {'value': 0},
            'maxAllowableSelectionCount': {'value': 1}
        }

        state_answer_group_list1 = [state_domain.AnswerGroup(
            state_domain.Outcome(
                'Introduction', state_domain.SubtitledHtml(
                    'feedback', '<p>Outcome for state1</p>'),
                False, [], None, None),
            [
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value1 for ItemSelection</p>']
                    }),
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value2 for ItemSelection</p>']
                    })
            ],
            [],
            None
        )]

        state1.update_interaction_id('ItemSelectionInput')
        state1.update_interaction_customization_args(customization_args_dict1)
        state1.update_next_content_id_index(2)
        state1.update_interaction_answer_groups(state_answer_group_list1)
        exp_services.save_new_exploration(self.albert_id, exploration)

        # Start ItemSelectionInteractionOneOff job on sample exploration.
        job_id = (
            interaction_jobs_one_off
            .ItemSelectionInteractionOneOffJob.create_new())
        interaction_jobs_one_off.ItemSelectionInteractionOneOffJob.enqueue(
            job_id)
        self.process_and_flush_pending_mapreduce_tasks()

        actual_output = (
            interaction_jobs_one_off
            .ItemSelectionInteractionOneOffJob.get_output(job_id))
        self.assertEqual(actual_output, [])

        customization_args_dict2 = {
            'choices': {'value': [{
                'html': '<p>This is value1 for ItemSelection</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for ItemSelection</p>',
                'content_id': 'ca_choices_1'
            }]},
            'minAllowableSelectionCount': {'value': 0},
            'maxAllowableSelectionCount': {'value': 1}
        }

        state_answer_group_list2 = [state_domain.AnswerGroup(
            state_domain.Outcome(
                'State1', state_domain.SubtitledHtml(
                    'feedback', '<p>Outcome for state2</p>'),
                False, [], None, None),
            [
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value1 for ItemSelection</p>']
                    }),
                state_domain.RuleSpec(
                    'Equals',
                    {
                        'x': ['<p>This is value3 for ItemSelection</p>']
                    })
            ],
            [],
            None
        )]

        state2.update_interaction_id('ItemSelectionInput')
        state2.update_interaction_customization_args(customization_args_dict2)
        state2.update_next_content_id_index(2)
        state2.update_interaction_answer_groups(state_answer_group_list2)

        exp_services.save_new_exploration(self.albert_id, exploration)

        # Start ItemSelectionInteractionOneOff job on sample exploration.
        job_id = (
            interaction_jobs_one_off
            .ItemSelectionInteractionOneOffJob.create_new())
        interaction_jobs_one_off.ItemSelectionInteractionOneOffJob.enqueue(
            job_id)
        self.process_and_flush_pending_mapreduce_tasks()

        actual_output = (
            interaction_jobs_one_off
            .ItemSelectionInteractionOneOffJob.get_output(job_id))
        expected_output = [(
            u'[u\'exp_id0\', '
            u'[u\'State2: <p>This is value3 for ItemSelection</p>\']]'
        )]
        self.assertEqual(actual_output, expected_output)
Exemplo n.º 5
0
    def test_exp_state_pairs_are_produced_only_for_desired_interactions(self):
        """Checks output pairs are produced only for
        desired interactions.
        """
        exploration = exp_domain.Exploration.create_default_exploration(
            self.VALID_EXP_ID, title='title', category='category')

        exploration.add_states(['State1', 'State2'])

        state1 = exploration.states['State1']
        state2 = exploration.states['State2']

        customization_args_dict1 = {
            'choices': {'value': [{
                'html': '<p>This is value1 for MultipleChoiceInput</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for MultipleChoiceInput</p>',
                'content_id': 'ca_choices_1'
            }]},
            'showChoicesInShuffledOrder': {'value': True}
        }
        state_answer_group_list1 = [state_domain.AnswerGroup(
            state_domain.Outcome(
                'Introduction', state_domain.SubtitledHtml(
                    'feedback', '<p>Outcome for state1</p>'),
                False, [], None, None),
            [
                state_domain.RuleSpec(
                    'Equals', {'x': '1'})
            ],
            [],
            None
        )]

        state1.update_interaction_id('MultipleChoiceInput')
        state1.update_interaction_customization_args(customization_args_dict1)
        state1.update_next_content_id_index(2)
        state1.update_interaction_answer_groups(state_answer_group_list1)
        exp_services.save_new_exploration(self.albert_id, exploration)

        # Start MultipleChoiceInteractionOneOffJob job on sample exploration.
        job_id = (
            interaction_jobs_one_off
            .MultipleChoiceInteractionOneOffJob.create_new())
        interaction_jobs_one_off.MultipleChoiceInteractionOneOffJob.enqueue(
            job_id)
        self.process_and_flush_pending_mapreduce_tasks()

        actual_output = (
            interaction_jobs_one_off
            .MultipleChoiceInteractionOneOffJob.get_output(job_id))
        self.assertEqual(actual_output, [])

        customization_args_dict2 = {
            'choices': {'value': [{
                'html': '<p>This is value1 for MultipleChoiceInput</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for MultipleChoiceInput</p>',
                'content_id': 'ca_choices_1'
            }, {
                'html': '<p>This is value3 for MultipleChoiceInput</p>',
                'content_id': 'ca_choices_2'
            }, {
                'html': '<p>This is value4 for MultipleChoiceInput</p>',
                'content_id': 'ca_choices_3'
            }]},
            'showChoicesInShuffledOrder': {'value': True}
        }

        state_answer_group_list2 = [state_domain.AnswerGroup(
            state_domain.Outcome(
                'State1', state_domain.SubtitledHtml(
                    'feedback', '<p>Outcome for state2</p>'),
                False, [], None, None),
            [
                state_domain.RuleSpec('Equals', {'x': '0'}),
                state_domain.RuleSpec(
                    'Equals', {'x': '9007199254740991'})
            ],
            [],
            None
        )]

        state2.update_interaction_id('MultipleChoiceInput')
        state2.update_interaction_customization_args(customization_args_dict2)
        state2.update_next_content_id_index(4)
        state2.update_interaction_answer_groups(state_answer_group_list2)

        exp_services.save_new_exploration(self.albert_id, exploration)

        # Start MultipleChoiceInteractionOneOffJob job on sample exploration.
        job_id = (
            interaction_jobs_one_off
            .MultipleChoiceInteractionOneOffJob.create_new())
        interaction_jobs_one_off.MultipleChoiceInteractionOneOffJob.enqueue(
            job_id)
        self.process_and_flush_pending_mapreduce_tasks()

        actual_output = (
            interaction_jobs_one_off
            .MultipleChoiceInteractionOneOffJob.get_output(job_id))
        expected_output = [(
            u'[u\'exp_id0\', '
            u'[u\'State name: State2, AnswerGroup: 0, Rule: 1 is invalid.' +
            '(Indices here are 0-indexed.)\']]'
        )]
        self.assertEqual(actual_output, expected_output)
Exemplo n.º 6
0
    def test_exp_state_pairs_are_produced_only_for_desired_interactions(self):
        """Checks output pairs are produced only for
        desired interactions.
        """
        owner = user_services.get_user_actions_info(self.albert_id)
        exploration = exp_domain.Exploration.create_default_exploration(
            self.VALID_EXP_ID, title='title', category='category')

        exploration.add_states(['State1', 'State2'])

        state1 = exploration.states['State1']
        state2 = exploration.states['State2']

        customization_args_dict1 = {
            'choices': {'value': [{
                'html': '<p>This is value1 for DragAndDropSortInput</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for DragAndDropSortInput</p>',
                'content_id': 'ca_choices_1'
            }]},
            'allowMultipleItemsInSamePosition': {'value': True}
        }
        state_answer_group_list1 = [state_domain.AnswerGroup(
            state_domain.Outcome(
                'Introduction', state_domain.SubtitledHtml(
                    'feedback1', '<p>Outcome for state1</p>'),
                False, [], None, None),
            [
                state_domain.RuleSpec(
                    'IsEqualToOrdering',
                    {
                        'x': [['a'], ['b']]
                    })
            ],
            [],
            None
        )]

        customization_args_dict2 = {
            'choices': {'value': [{
                'html': '<p>This is value1 for DragAndDropSortInput</p>',
                'content_id': 'ca_choices_0'
            }, {
                'html': '<p>This is value2 for DragAndDropSortInput</p>',
                'content_id': 'ca_choices_1'
            }]},
            'allowMultipleItemsInSamePosition': {'value': True}
        }
        state_answer_group_list2 = [
            state_domain.AnswerGroup(
                state_domain.Outcome(
                    'State1', state_domain.SubtitledHtml(
                        'feedback', '<p>Outcome for state2</p>'),
                    False, [], None, None),
                [
                    state_domain.RuleSpec(
                        'IsEqualToOrderingWithOneItemAtIncorrectPosition',
                        {
                            'x': []
                        }),
                    state_domain.RuleSpec(
                        'IsEqualToOrdering',
                        {
                            'x': [['a']]
                        }),
                    state_domain.RuleSpec(
                        'HasElementXBeforeElementY',
                        {
                            'x': '',
                            'y': ''
                        }),
                    state_domain.RuleSpec(
                        'IsEqualToOrdering',
                        {
                            'x': []
                        })
                ],
                [],
                None
            ),
            state_domain.AnswerGroup(
                state_domain.Outcome(
                    'Introduction', state_domain.SubtitledHtml(
                        'feedback2', '<p>Outcome for state1</p>'),
                    False, [], None, None),
                [
                    state_domain.RuleSpec(
                        'HasElementXAtPositionY',
                        {
                            'x': '',
                            'y': 1
                        }),
                    state_domain.RuleSpec(
                        'HasElementXAtPositionY',
                        {
                            'x': 'a',
                            'y': 2
                        })
                ],
                [],
                None
            )
        ]

        state1.update_interaction_id('DragAndDropSortInput')
        state1.update_interaction_customization_args(customization_args_dict1)
        state1.update_next_content_id_index(2)
        state1.update_interaction_answer_groups(state_answer_group_list1)
        exp_services.save_new_exploration(self.albert_id, exploration)
        rights_manager.publish_exploration(owner, self.VALID_EXP_ID)

        # Start DragAndDropSortInputInteractionOneOffJob on sample exploration.
        job_id = (
            interaction_jobs_one_off.DragAndDropSortInputInteractionOneOffJob
            .create_new())
        (
            interaction_jobs_one_off
            .DragAndDropSortInputInteractionOneOffJob.enqueue(job_id))
        self.process_and_flush_pending_mapreduce_tasks()

        actual_output = (
            interaction_jobs_one_off.DragAndDropSortInputInteractionOneOffJob
            .get_output(job_id))
        self.assertEqual(actual_output, [])

        state2.update_interaction_id('DragAndDropSortInput')
        state2.update_interaction_customization_args(customization_args_dict2)
        state2.update_next_content_id_index(2)
        state2.update_interaction_answer_groups(state_answer_group_list2)

        exp_services.save_new_exploration(self.albert_id, exploration)
        rights_manager.publish_exploration(owner, self.VALID_EXP_ID)

        # Start DragAndDropSortInputInteractionOneOffJob on sample exploration.
        job_id = (
            interaction_jobs_one_off.DragAndDropSortInputInteractionOneOffJob
            .create_new())
        (
            interaction_jobs_one_off
            .DragAndDropSortInputInteractionOneOffJob.enqueue(job_id))
        self.process_and_flush_pending_mapreduce_tasks()

        actual_output = (
            interaction_jobs_one_off.DragAndDropSortInputInteractionOneOffJob
            .get_output(job_id))
        expected_output = [(
            u'[u\'exp_id0\', [u"[u\'State name: State2, AnswerGroup: 0, Rule '
            'input x in rule with index 0 is empty. \', u\'State name: State2,'
            ' AnswerGroup: 0, Rule input y in rule with index 2 is empty. \', '
            'u\'State name: State2, AnswerGroup: 0, Rule input x in rule with '
            'index 2 is empty. \', u\'State name: State2, AnswerGroup: 0, Rule'
            ' input x in rule with index 3 is empty. \', u\'State name: State2'
            ', AnswerGroup: 1, Rule input x in rule with index 0 is empty. \']'
            '"]]'
        )]
        self.assertEqual(actual_output, expected_output)

        rights_manager.unpublish_exploration(self.admin, self.VALID_EXP_ID)
        # Start DragAndDropSortInputInteractionOneOffJob on private
        # exploration.
        job_id = (
            interaction_jobs_one_off.DragAndDropSortInputInteractionOneOffJob
            .create_new())
        (
            interaction_jobs_one_off
            .DragAndDropSortInputInteractionOneOffJob.enqueue(job_id))
        self.process_and_flush_pending_mapreduce_tasks()
        actual_output = (
            interaction_jobs_one_off.DragAndDropSortInputInteractionOneOffJob
            .get_output(job_id))
        self.assertEqual(actual_output, [])