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('content', 'old content').to_dict() self.old_content_ids_to_audio_translations = { 'content': { self.TRANSLATION_LANGUAGE_CODE: exp_domain.AudioTranslation('filename.mp3', 20, False).to_dict() }, 'default_outcome': {} } # Create content in State A with a single audio subtitle. exploration.states['State 1'].update_content(self.old_content) exploration.states['State 1'].update_content_ids_to_audio_translations( self.old_content_ids_to_audio_translations) 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('content', 'new content').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
def test_feedback_threads_with_suggestions(self): with self.swap(feconf, 'ENABLE_GENERALIZED_FEEDBACK_THREADS', True): new_content = exp_domain.SubtitledHtml( 'content', 'new content html').to_dict() change_cmd = { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'State 1', 'new_value': new_content } suggestion_services.create_suggestion( suggestion_models.SUGGESTION_TYPE_EDIT_STATE_CONTENT, suggestion_models.TARGET_TYPE_EXPLORATION, self.EXP_ID, 1, self.user_id, change_cmd, 'sample description', None) with self.swap(constants, 'USE_NEW_SUGGESTION_FRAMEWORK', True): response = self.get_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID)) self.assertEquals(response['feedback_thread_dicts'], []) expected_thread_dict = { 'original_author_username': self.USER_USERNAME, 'status': feedback_models.STATUS_CHOICES_OPEN, 'subject': 'sample description' } self.assertDictContainsSubset( expected_thread_dict, response['suggestion_thread_dicts'][0]) thread_id = ( response['suggestion_thread_dicts'][0]['thread_id']) response = self.get_json( '%s/%s' % (feconf.FEEDBACK_THREAD_URL_PREFIX, thread_id)) expected_suggestion_dict = { 'suggestion_type': (suggestion_models.SUGGESTION_TYPE_EDIT_STATE_CONTENT), 'target_type': suggestion_models.TARGET_TYPE_EXPLORATION, 'target_id': self.EXP_ID, 'status': suggestion_models.STATUS_IN_REVIEW, 'author_name': self.USER_USERNAME } self.assertDictContainsSubset(expected_suggestion_dict, response['suggestion'])
def setUp(self): super(SuggestionMigrationOneOffJobTest, 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.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.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='Algebra', 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 1']) self.old_content = exp_domain.SubtitledHtml('content', 'old content').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)
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()
def setUp(self): super(SuggestionUnitTests, self).setUp() self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) 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.AUTHOR_EMAIL_2, 'author2') self.signup(self.NORMAL_USER_EMAIL, 'normalUser') 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.author_id_2 = self.get_user_id_from_email(self.AUTHOR_EMAIL_2) self.reviewer_id = self.editor_id self.set_admins([self.ADMIN_USERNAME]) self.editor = user_services.UserActionsInfo(self.editor_id) # Login and create exploration and suggestions. self.login(self.EDITOR_EMAIL) exploration = ( self.save_new_linear_exp_with_state_names_and_interactions( self.EXP_ID, self.editor_id, ['State 1', 'State 2', 'State 3'], ['TextInput'], category='Algebra')) self.old_content = exp_domain.SubtitledHtml( 'content', 'old content html').to_dict() exploration.states['State 1'].update_content(self.old_content) exploration.states['State 2'].update_content(self.old_content) exploration.states['State 3'].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( 'content', 'new content html').to_dict() self.logout() with self.swap(constants, 'ENABLE_GENERALIZED_FEEDBACK_THREADS', True): self.login(self.AUTHOR_EMAIL) response = self.testapp.get('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/' % feconf.GENERAL_SUGGESTION_URL_PREFIX, { 'suggestion_type': (suggestion_models.SUGGESTION_TYPE_EDIT_STATE_CONTENT), 'target_type': (suggestion_models.TARGET_TYPE_EXPLORATION), 'target_id': 'exp1', 'target_version_at_submission': exploration.version, 'change': { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'State 1', 'old_value': self.old_content, 'new_value': self.new_content }, 'description': 'change to state 1', 'final_reviewer_id': self.reviewer_id, }, csrf_token=csrf_token) self.logout() self.login(self.AUTHOR_EMAIL_2) response = self.testapp.get('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/' % feconf.GENERAL_SUGGESTION_URL_PREFIX, { 'suggestion_type': (suggestion_models.SUGGESTION_TYPE_EDIT_STATE_CONTENT), 'target_type': (suggestion_models.TARGET_TYPE_EXPLORATION), 'target_id': 'exp1', 'target_version_at_submission': exploration.version, 'change': { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'State 2', 'old_value': self.old_content, 'new_value': self.new_content }, 'description': 'change to state 2', 'final_reviewer_id': self.reviewer_id, }, csrf_token=csrf_token) self.post_json('%s/' % feconf.GENERAL_SUGGESTION_URL_PREFIX, { 'suggestion_type': (suggestion_models.SUGGESTION_TYPE_EDIT_STATE_CONTENT), 'target_type': (suggestion_models.TARGET_TYPE_EXPLORATION), 'target_id': 'exp1', 'target_version_at_submission': exploration.version, 'change': { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'State 3', 'old_value': self.old_content, 'new_value': self.new_content }, 'description': 'change to state 3', 'final_reviewer_id': self.reviewer_id, }, csrf_token=csrf_token) self.logout()