def test_accept_suggestion_and_send_email_to_author(self): enable_recording_of_scores_swap = self.swap( feconf, 'ENABLE_RECORDING_OF_SCORES', True) send_suggestion_review_related_emails_swap = self.swap( feconf, 'SEND_SUGGESTION_REVIEW_RELATED_EMAILS', True) change_list = [ exp_domain.ExplorationChange({ 'cmd': exp_domain.CMD_ADD_STATE, 'state_name': 'state 1', }) ] exp_services.update_exploration(self.author_id, self.target_id, change_list, 'Add state.') new_suggestion_content = state_domain.SubtitledHtml( 'content', 'new suggestion content html').to_dict() change_dict = { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'state 1', 'new_value': new_suggestion_content } suggestion_services.create_suggestion( suggestion_models.SUGGESTION_TYPE_EDIT_STATE_CONTENT, suggestion_models.TARGET_TYPE_EXPLORATION, self.target_id, self.target_version_at_submission, self.author_id, change_dict, 'test description', self.reviewer_id) suggestion = suggestion_services.query_suggestions([ ('author_id', self.author_id), ('target_id', self.target_id) ])[0] self.assertEqual(suggestion.status, suggestion_models.STATUS_IN_REVIEW) self.assertFalse( suggestion_services.check_if_email_has_been_sent_to_user( self.author_id, suggestion.score_category)) suggestion_services.increment_score_for_user(self.author_id, suggestion.score_category, 10) with enable_recording_of_scores_swap, ( send_suggestion_review_related_emails_swap): suggestion_services.accept_suggestion(suggestion, self.reviewer_id, self.COMMIT_MESSAGE, 'review message') suggestion = suggestion_services.query_suggestions([ ('author_id', self.author_id), ('target_id', self.target_id) ])[0] self.assertEqual(suggestion.status, suggestion_models.STATUS_ACCEPTED) self.assertTrue( suggestion_services.check_if_email_has_been_sent_to_user( self.author_id, suggestion.score_category))
def test_check_if_email_has_been_sent_to_user(self): suggestion_services.create_new_user_contribution_scoring_model( self.user_a_id, 'category_a', 15) self.assertFalse( suggestion_services.check_if_email_has_been_sent_to_user( self.user_a_id, 'category_a')) suggestion_services.mark_email_has_been_sent_to_user( self.user_a_id, 'category_a') self.assertTrue( suggestion_services.check_if_email_has_been_sent_to_user( self.user_a_id, 'category_a'))
def test_email_is_not_sent_to_unregistered_user(self): suggestion_services.create_suggestion( suggestion_models.SUGGESTION_TYPE_EDIT_STATE_CONTENT, suggestion_models.TARGET_TYPE_EXPLORATION, self.target_id, self.target_version_at_submission, self.author_id, self.change, 'test description', self.reviewer_id) suggestion = suggestion_services.query_suggestions([ ('author_id', self.author_id), ('target_id', self.target_id) ])[0] self.assertFalse( suggestion_services.check_if_email_has_been_sent_to_user( 'unregistered_user_id', suggestion.score_category))