def test_accept_suggestion_that_has_already_been_handled(self): exception_message = 'Suggestion has already been accepted/rejected' with self.swap(constants, 'ENABLE_GENERALIZED_FEEDBACK_THREADS', False): with self.swap(exp_services, '_is_suggestion_handled', self._return_true): with self.assertRaisesRegexp(Exception, exception_message): exp_services.accept_suggestion(self.editor_id, self.THREAD_ID2, self.EXP_ID2, self.COMMIT_MESSAGE, False)
def test_accept_suggestion_empty_commit_message(self): with self.swap(constants, 'ENABLE_GENERALIZED_FEEDBACK_THREADS', False): with self.assertRaisesRegexp(Exception, 'Commit message cannot be empty.'): exp_services.accept_suggestion(self.editor_id, self.THREAD_ID2, self.EXP_ID2, self.EMPTY_COMMIT_MESSAGE, False) thread = feedback_models.FeedbackThreadModel.get(self.THREAD_ID2) self.assertEqual(thread.status, feedback_models.STATUS_CHOICES_OPEN)
def put(self, exploration_id, thread_id): action = self.payload.get('action') if action == self._ACCEPT_ACTION: exp_services.accept_suggestion( self.user_id, thread_id, exploration_id, self.payload.get('commit_message'), self.payload.get('audio_update_required')) elif action == self._REJECT_ACTION: exp_services.reject_suggestion(self.user_id, thread_id) else: raise self.InvalidInputException('Invalid action.') self.render_json(self.values)
def put(self, exploration_id, thread_id): action = self.payload.get('action') if action == self._ACCEPT_ACTION: exp_services.accept_suggestion( self.user_id, thread_id, exploration_id, self.payload.get('commit_message')) elif action == self._REJECT_ACTION: exp_services.reject_suggestion( self.user_id, thread_id, exploration_id) else: raise self.InvalidInputException('Invalid action.') self.render_json(self.values)
def test_accept_suggestion_invalid_suggestion(self): with self.swap(constants, 'ENABLE_GENERALIZED_FEEDBACK_THREADS', False): with self.swap(exp_services, '_is_suggestion_valid', self._return_false): with self.assertRaisesRegexp( Exception, 'Invalid suggestion: The state for which it was made ' 'has been removed/renamed.'): exp_services.accept_suggestion(self.editor_id, self.THREAD_ID2, self.EXP_ID2, self.COMMIT_MESSAGE, False) thread = feedback_models.FeedbackThreadModel.get(self.THREAD_ID2) self.assertEqual(thread.status, feedback_models.STATUS_CHOICES_OPEN)
def test_accept_suggestion_valid_suggestion(self): with self.swap(constants, 'ENABLE_GENERALIZED_FEEDBACK_THREADS', False): with self.swap(exp_services, '_is_suggestion_valid', self._return_true): with self.swap(exp_services, 'update_exploration', self._check_commit_message): exp_services.accept_suggestion(self.editor_id, self.THREAD_ID1, self.EXP_ID1, self.COMMIT_MESSAGE, False) thread = feedback_models.FeedbackThreadModel.get(self.THREAD_ID1) thread_messages = feedback_services.get_messages(self.THREAD_ID1) last_message = thread_messages[len(thread_messages) - 1] self.assertEqual(thread.status, feedback_models.STATUS_CHOICES_FIXED) self.assertEqual(last_message.text, 'Suggestion accepted.')