def setUp(self): super(SuggestionActionUnitTests, self).setUp() self.user_id = self.get_user_id_from_email(self.USER_EMAIL) self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL) user_services.create_new_user(self.user_id, self.USER_EMAIL) user_services.create_new_user(self.editor_id, self.EDITOR_EMAIL) self.signup(self.USER_EMAIL, self.USERNAME) self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) exploration = self.save_new_valid_exploration(self.EXP_ID1, self.editor_id) self.save_new_valid_exploration(self.EXP_ID2, self.editor_id) self.initial_state_name = exploration.init_state_name with self.swap(constants, 'ENABLE_GENERALIZED_FEEDBACK_THREADS', False): with self.swap(feedback_models.FeedbackThreadModel, 'generate_new_thread_id', self._generate_thread_id_1): feedback_services.create_suggestion(self.EXP_ID1, self.user_id, 3, self.initial_state_name, 'description', 'new text') with self.swap(feedback_models.FeedbackThreadModel, 'generate_new_thread_id', self._generate_thread_id_2): feedback_services.create_suggestion(self.EXP_ID2, self.user_id, 3, self.initial_state_name, 'description', 'new text')
def post(self, exploration_id): feedback_services.create_suggestion( exploration_id, self.user_id, self.payload.get('exploration_version'), self.payload.get('state_name'), self.payload.get('description'), self.payload.get('suggestion_html')) self.render_json(self.values)
def post(self, exploration_id): feedback_services.create_suggestion( exploration_id, self.user_id, self.payload.get('exploration_version'), self.payload.get('state_name'), self.payload.get('description'), self.payload.get('suggestion_content')) self.render_json(self.values)
def test_suggestion_migration_validation_one_off_job(self): exploration = exp_services.get_exploration_by_id(self.EXP_ID) for _ in range(10): feedback_services.create_suggestion(self.EXP_ID, self.author_id, exploration.version, 'State 1', 'description', 'new_value') self._run_one_off_job() output = self._run_validation_job() self.assertEqual(output[0][1], output[1][1]) self.assertEqual(output[0][1], 10)
def test_that_emails_are_sent(self): expected_email_html_body = ( 'Hi editor,<br>' 'newuser has submitted a new suggestion for your Oppia ' 'exploration, ' '<a href="https://www.oppia.org/create/A">"Title"</a>.<br>' 'You can accept or reject this suggestion by visiting the ' '<a href="https://www.oppia.org/create/A#/feedback">' 'feedback page</a> ' 'for your exploration.<br>' '<br>' 'Thanks!<br>' '- The Oppia Team<br>' '<br>' 'You can change your email preferences via the ' '<a href="https://www.example.com">Preferences</a> page.') expected_email_text_body = ( 'Hi editor,\n' 'newuser has submitted a new suggestion for your Oppia ' 'exploration, "Title".\n' 'You can accept or reject this suggestion by visiting the ' 'feedback page for your exploration.\n' '\n' 'Thanks!\n' '- The Oppia Team\n' '\n' 'You can change your email preferences via the Preferences page.') with self.can_send_emails_ctx, self.can_send_feedback_email_ctx: feedback_services.create_suggestion(self.exploration.id, self.new_user_id, self.exploration.version, 'a state', 'simple description', {'content': {}}) self.process_and_flush_pending_tasks() messages = self.mail_stub.get_sent_messages(to=self.EDITOR_EMAIL) self.assertEqual(len(messages), 1) self.assertEqual(messages[0].html.decode(), expected_email_html_body) self.assertEqual(messages[0].body.decode(), expected_email_text_body)
def test_create_and_get_suggestion(self): with self.swap(feedback_models.FeedbackThreadModel, 'generate_new_thread_id', self._generate_thread_id): feedback_services.create_suggestion( self.EXP_ID3, self.user_id, 3, 'state_name', 'description', {'old_content': {}}) suggestion = feedback_services.get_suggestion( self.EXP_ID3, self.THREAD_ID1) thread = feedback_models.FeedbackThreadModel.get( feedback_models.FeedbackThreadModel.generate_full_thread_id( self.EXP_ID3, self.THREAD_ID1)) self.assertEqual(thread.status, feedback_models.STATUS_CHOICES_OPEN) self.assertEqual(suggestion['exploration_id'], self.EXP_ID3) self.assertEqual(suggestion['author_name'], 'user123') self.assertEqual(suggestion['exploration_version'], 3) self.assertEqual(suggestion['state_name'], 'state_name') self.assertEqual(suggestion['description'], 'description') self.assertEqual(suggestion['state_content'], {'old_content': {}})
def test_that_emails_are_sent(self): expected_email_html_body = ( 'Hi editor,<br>' 'newuser has submitted a new suggestion for your Oppia ' 'exploration, ' '<a href="https://www.oppia.org/create/A">"Title"</a>.<br>' 'You can accept or reject this suggestion by visiting the ' '<a href="https://www.oppia.org/create/A#/feedback">' 'feedback page</a> ' 'for your exploration.<br>' '<br>' 'Thanks!<br>' '- The Oppia Team<br>' '<br>' 'You can change your email preferences via the ' '<a href="https://www.example.com">Preferences</a> page.') expected_email_text_body = ( 'Hi editor,\n' 'newuser has submitted a new suggestion for your Oppia ' 'exploration, "Title".\n' 'You can accept or reject this suggestion by visiting the ' 'feedback page for your exploration.\n' '\n' 'Thanks!\n' '- The Oppia Team\n' '\n' 'You can change your email preferences via the Preferences page.') with self.can_send_emails_ctx, self.can_send_feedback_email_ctx: feedback_services.create_suggestion( self.exploration.id, self.new_user_id, self.exploration.version, 'a state', 'simple description', {'content': {}}) self.process_and_flush_pending_tasks() messages = self.mail_stub.get_sent_messages(to=self.EDITOR_EMAIL) self.assertEqual(len(messages), 1) self.assertEqual( messages[0].html.decode(), expected_email_html_body) self.assertEqual( messages[0].body.decode(), expected_email_text_body)
def test_suggestion_migration_one_off_job(self): exploration = exp_services.get_exploration_by_id(self.EXP_ID) feedback_services.create_suggestion( self.EXP_ID, self.author_id, exploration.version, 'State 1', 'description', 'new_value') self._run_one_off_job() queries = [ ('target_type', suggestion_models.TARGET_TYPE_EXPLORATION), ('target_id', self.EXP_ID) ] suggestion = suggestion_models.GeneralSuggestionModel.query_suggestions( queries)[0] expected_change_cmd = { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'State 1', 'new_value': { 'html': 'new_value', 'content_id': 'content' } } self.assertEqual(suggestion.id.split('.')[0], 'exploration') self.assertEqual(suggestion.id.split('.')[1], self.EXP_ID) self.assertEqual( suggestion.suggestion_type, suggestion_models.SUGGESTION_TYPE_EDIT_STATE_CONTENT) self.assertEqual( suggestion.target_type, suggestion_models.TARGET_TYPE_EXPLORATION) self.assertEqual(suggestion.target_id, self.EXP_ID) self.assertEqual( suggestion.target_version_at_submission, exploration.version) self.assertEqual(suggestion.status, suggestion_models.STATUS_IN_REVIEW) self.assertEqual(suggestion.author_id, self.author_id) self.assertEqual(suggestion.final_reviewer_id, None) self.assertDictEqual( suggestion.change_cmd, expected_change_cmd) self.assertEqual( suggestion.score_category, 'content.' + exploration.category)
def test_create_and_get_suggestion(self): with self.swap(feedback_models.FeedbackThreadModel, 'generate_new_thread_id', self._generate_thread_id): feedback_services.create_suggestion( self.EXP_ID2, self.user_id, 3, 'state_name', 'description', {'old_content': {}}) suggestion = feedback_services.get_suggestion( self.EXP_ID2, self.THREAD_ID1) thread = feedback_models.FeedbackThreadModel.get( feedback_models.FeedbackThreadModel.generate_full_thread_id( self.EXP_ID2, self.THREAD_ID1)) expected_suggestion_dict = { 'exploration_id': self.EXP_ID2, 'author_name': 'user123', 'exploration_version': 3, 'state_name': 'state_name', 'description': 'description', 'state_content': {'old_content': {}} } self.assertEqual(thread.status, feedback_models.STATUS_CHOICES_OPEN) self.assertDictEqual(expected_suggestion_dict, suggestion.to_dict())
def test_correct_email_is_sent_for_multiple_recipients(self): rights_manager.assign_role_for_exploration( self.editor_id, self.exploration.id, self.owner_id, rights_manager.ROLE_OWNER) expected_editor_email_html_body = ( 'Hi editor,<br>' 'newuser has submitted a new suggestion for your Oppia ' 'exploration, ' '<a href="https://www.oppia.org/create/A">"Title"</a>.<br>' 'You can accept or reject this suggestion by visiting the ' '<a href="https://www.oppia.org/create/A#/feedback">' 'feedback page</a> ' 'for your exploration.<br>' '<br>' 'Thanks!<br>' '- The Oppia Team<br>' '<br>' 'You can change your email preferences via the ' '<a href="https://www.example.com">Preferences</a> page.') expected_owner_email_html_body = ( 'Hi owner,<br>' 'newuser has submitted a new suggestion for your Oppia ' 'exploration, ' '<a href="https://www.oppia.org/create/A">"Title"</a>.<br>' 'You can accept or reject this suggestion by visiting the ' '<a href="https://www.oppia.org/create/A#/feedback">' 'feedback page</a> ' 'for your exploration.<br>' '<br>' 'Thanks!<br>' '- The Oppia Team<br>' '<br>' 'You can change your email preferences via the ' '<a href="https://www.example.com">Preferences</a> page.') expected_editor_email_text_body = ( 'Hi editor,\n' 'newuser has submitted a new suggestion for your Oppia ' 'exploration, "Title".\n' 'You can accept or reject this suggestion by visiting the ' 'feedback page for your exploration.\n' '\n' 'Thanks!\n' '- The Oppia Team\n' '\n' 'You can change your email preferences via the Preferences page.') expected_owner_email_text_body = ( 'Hi owner,\n' 'newuser has submitted a new suggestion for your Oppia ' 'exploration, "Title".\n' 'You can accept or reject this suggestion by visiting the ' 'feedback page for your exploration.\n' '\n' 'Thanks!\n' '- The Oppia Team\n' '\n' 'You can change your email preferences via the Preferences page.') with self.can_send_emails_ctx, self.can_send_feedback_email_ctx: feedback_services.create_suggestion( self.exploration.id, self.new_user_id, self.exploration.version, 'a state', 'simple description', {'type': 'text', 'value': ''}) self.process_and_flush_pending_tasks() editor_messages = ( self.mail_stub.get_sent_messages(to=self.EDITOR_EMAIL)) self.assertEqual(len(editor_messages), 1) self.assertEqual( editor_messages[0].html.decode(), expected_editor_email_html_body) self.assertEqual( editor_messages[0].body.decode(), expected_editor_email_text_body) owner_messages = ( self.mail_stub.get_sent_messages(to=self.OWNER_EMAIL)) self.assertEqual(len(owner_messages), 1) self.assertEqual( owner_messages[0].html.decode(), expected_owner_email_html_body) self.assertEqual( owner_messages[0].body.decode(), expected_owner_email_text_body)