예제 #1
0
    def setUp(self):
        super(SuggestionIntegrationTests, self).setUp()
        self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.signup(self.AUTHOR_EMAIL, 'author')
        self.signup(self.ASSIGNED_REVIEWER_EMAIL, 'assignedReviewer')
        self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)
        self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)
        self.author_id = self.get_user_id_from_email(self.AUTHOR_EMAIL)
        self.reviewer_id = self.editor_id
        self.assigned_reviewer_id = self.get_user_id_from_email(
            self.ASSIGNED_REVIEWER_EMAIL)

        self.editor = user_services.UserActionsInfo(self.editor_id)

        # Login and create exploration and suggestions.
        self.login(self.EDITOR_EMAIL)

        # Create exploration.
        exploration = (
            self.save_new_linear_exp_with_state_names_and_interactions(
                self.EXP_ID,
                self.editor_id, ['State 1', 'State 2'], ['TextInput'],
                category='Algebra'))

        self.old_content = exp_domain.SubtitledHtml(
            'old content', {
                self.TRANSLATION_LANGUAGE_CODE:
                exp_domain.AudioTranslation('filename.mp3', 20, False)
            }).to_dict()

        # Create content in State A with a single audio subtitle.
        exploration.states['State 1'].update_content(self.old_content)
        exp_services._save_exploration(self.editor_id, exploration, '', [])  # pylint: disable=protected-access

        rights_manager.publish_exploration(self.editor, self.EXP_ID)
        rights_manager.assign_role_for_exploration(self.editor, self.EXP_ID,
                                                   self.owner_id,
                                                   rights_manager.ROLE_EDITOR)

        self.new_content = exp_domain.SubtitledHtml(
            'new content', {
                self.TRANSLATION_LANGUAGE_CODE:
                exp_domain.AudioTranslation('filename.mp3', 20, False)
            }).to_dict()

        self.change_cmd = {
            'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
            'property_name': exp_domain.STATE_PROPERTY_CONTENT,
            'state_name': 'State 1',
            'new_value': self.new_content
        }

        self.target_version_at_submission = exploration.version
예제 #2
0
    def setUp(self):
        super(SuggestionsIntegrationTests, self).setUp()

        # Register users.
        self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME)
        self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)
        self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)
        self.viewer_id = self.get_user_id_from_email(self.VIEWER_EMAIL)

        self.editor = user_services.UserActionsInfo(self.editor_id)

        # Login and create exploration and suggestions.
        self.login(self.EDITOR_EMAIL)

        # Create exploration.
        self.save_new_valid_exploration(
            self.EXP_ID,
            self.editor_id,
            title='Exploration for suggestions',
            category='This is just a test category',
            objective='Test a suggestion.')

        exploration = exp_services.get_exploration_by_id(self.EXP_ID)
        init_state = exploration.states[exploration.init_state_name]
        init_interaction = init_state.interaction
        init_interaction.default_outcome.dest = exploration.init_state_name
        exploration.add_states(['State A', 'State 2', 'State 3'])
        exploration.states['State A'].update_interaction_id('TextInput')
        # Create content in State A with a single audio subtitle.
        content_id = exploration.states['State A'].content.content_id
        exploration.states['State A'].update_content(
            exp_domain.SubtitledHtml(content_id, 'old content').to_dict())
        exploration.states['State A'].update_content_ids_to_audio_translations(
            {
                content_id: {
                    self.TRANSLATION_LANGUAGE_CODE:
                    exp_domain.AudioTranslation('filename.mp3', 20,
                                                False).to_dict()
                },
                'default_outcome': {}
            })
        exploration.states['State 2'].update_interaction_id('TextInput')
        exploration.states['State 3'].update_interaction_id('TextInput')
        exp_services._save_exploration(self.editor_id, exploration, '', [])  # pylint: disable=protected-access
        rights_manager.publish_exploration(self.editor, self.EXP_ID)
        rights_manager.assign_role_for_exploration(self.editor, self.EXP_ID,
                                                   self.owner_id,
                                                   rights_manager.ROLE_EDITOR)

        response = self.testapp.get('/explore/%s' % self.EXP_ID)
        csrf_token = self.get_csrf_token_from_response(response)

        # Create suggestions.
        self.post_json(
            '%s/%s' % (feconf.SUGGESTION_URL_PREFIX, self.EXP_ID), {
                'exploration_version': 3,
                'state_name': u'State A',
                'description': u'Suggestion for state A.',
                'suggestion_html': 'new accepted suggestion for state A',
            },
            csrf_token=csrf_token)
        self.post_json('%s/%s' % (feconf.SUGGESTION_URL_PREFIX, self.EXP_ID), {
            'exploration_version': 1,
            'state_name': u'State 2',
            'description': u'A new value.',
            'suggestion_html': 'some new value',
        },
                       csrf_token=csrf_token)
        self.post_json('%s/%s' % (feconf.SUGGESTION_URL_PREFIX, self.EXP_ID), {
            'exploration_version': 2,
            'state_name': u'State 3',
            'description': u'Empty suggestion',
            'suggestion_html': '',
        },
                       csrf_token=csrf_token)
        self.post_json('%s/%s' % (feconf.SUGGESTION_URL_PREFIX, self.EXP_ID), {
            'exploration_version': 2,
            'state_name': u'State A',
            'description': u'Just a space.',
            'suggestion_html': ' ',
        },
                       csrf_token=csrf_token)
        self.post_json('%s/%s' % (feconf.SUGGESTION_URL_PREFIX, self.EXP_ID), {
            'exploration_version': 1,
            'state_name': u'State 2',
            'description': u'Random characters.',
            'suggestion_html': '#!$%',
        },
                       csrf_token=csrf_token)
        self.post_json('%s/%s' % (feconf.SUGGESTION_URL_PREFIX, self.EXP_ID), {
            'exploration_version': 2,
            'state_name': u'State 3',
            'description': u'Very bizarre characters.',
            'suggestion_html': u'Ֆݓॵক',
        },
                       csrf_token=csrf_token)
        self.logout()