예제 #1
0
    def test_reject_suggestion_handled_suggestion_failure(self):
        with self.swap(feedback_models.FeedbackThreadModel,
                       'generate_new_thread_id', self.generate_thread_id):
            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_cmd, self.score_category, 'test description',
                self.assigned_reviewer_id, self.reviewer_id)
        suggestion = suggestion_services.get_suggestion_by_id(
            self.suggestion_id)

        suggestion.status = suggestion_models.STATUS_ACCEPTED
        suggestion_services._update_suggestion(suggestion)  # pylint: disable=protected-access
        with self.assertRaisesRegexp(
                Exception,
                'The suggestion has already been accepted/rejected.'):
            suggestion_services.reject_suggestion(suggestion, self.reviewer_id,
                                                  'reject review message')

        suggestion = suggestion_services.get_suggestion_by_id(
            self.suggestion_id)
        self.assertEqual(suggestion.status, suggestion_models.STATUS_ACCEPTED)

        suggestion.status = suggestion_models.STATUS_REJECTED
        suggestion_services._update_suggestion(suggestion)  # pylint: disable=protected-access

        with self.assertRaisesRegexp(
                Exception,
                'The suggestion has already been accepted/rejected.'):
            suggestion_services.reject_suggestion(suggestion, self.reviewer_id,
                                                  'reject review message')
        suggestion = suggestion_services.get_suggestion_by_id(
            self.suggestion_id)
        self.assertEqual(suggestion.status, suggestion_models.STATUS_REJECTED)
예제 #2
0
    def test_accept_suggestion_invalid_suggestion_failure(self):
        with self.swap(feedback_models.GeneralFeedbackThreadModel,
                       'generate_new_thread_id',
                       self.mock_generate_new_thread_id):
            with self.swap(exp_fetchers, 'get_exploration_by_id',
                           self.mock_get_exploration_by_id):
                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.get_suggestion_by_id(
            self.suggestion_id)

        # Invalidating the suggestion.
        suggestion.score_category = 'invalid_score_category'
        with self.assertRaisesRegexp(
                utils.ValidationError,
                'Expected score_category to be of the form '
                'score_type.score_sub_type, received '
                'invalid_score_category'):
            suggestion_services._update_suggestion(suggestion)  # pylint: disable=protected-access

        suggestion = suggestion_services.get_suggestion_by_id(
            self.suggestion_id)
    def test_accept_suggestion_handled_suggestion_failure(self):
        with self.swap(feedback_models.GeneralFeedbackThreadModel,
                       'generate_new_thread_id', self.generate_thread_id):
            with self.swap(exp_services, 'get_exploration_by_id',
                           self.mock_get_exploration_by_id):
                with self.swap(feconf, 'ENABLE_GENERALIZED_FEEDBACK_THREADS',
                               True):
                    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.get_suggestion_by_id(
            self.suggestion_id)

        suggestion.status = suggestion_models.STATUS_ACCEPTED
        suggestion_services._update_suggestion(suggestion)  # pylint: disable=protected-access
        with self.assertRaisesRegexp(
                Exception,
                'The suggestion has already been accepted/rejected.'):
            with self.swap(feconf, 'ENABLE_GENERALIZED_FEEDBACK_THREADS',
                           True):
                suggestion_services.accept_suggestion(suggestion,
                                                      self.reviewer_id,
                                                      self.COMMIT_MESSAGE,
                                                      None)
        suggestion = suggestion_services.get_suggestion_by_id(
            self.suggestion_id)

        self.assertEqual(suggestion.status, suggestion_models.STATUS_ACCEPTED)
        suggestion.status = suggestion_models.STATUS_REJECTED
        suggestion_services._update_suggestion(suggestion)  # pylint: disable=protected-access

        with self.assertRaisesRegexp(
                Exception,
                'The suggestion has already been accepted/rejected.'):
            with self.swap(feconf, 'ENABLE_GENERALIZED_FEEDBACK_THREADS',
                           True):
                suggestion_services.accept_suggestion(suggestion,
                                                      self.reviewer_id,
                                                      self.COMMIT_MESSAGE,
                                                      None)
        suggestion = suggestion_services.get_suggestion_by_id(
            self.suggestion_id)
        self.assertEqual(suggestion.status, suggestion_models.STATUS_REJECTED)