Example #1
0
    def test_get_or_exit_tuple_none(self):
        """Ensure it raises 404 when the value is a tuple of None."""
        fn = lambda: (None, None)
        with self.assertRaises(helpers.EarlyExitException) as catched:
            helpers.get_or_exit(fn, 'not_found', 'error')

        self.assertEqual(catched.exception.status, 404)
        self.assertEqual(catched.exception.message, 'not_found')
Example #2
0
    def test_get_or_exit_other_exception(self):
        """Ensure it raises 500 when `fn` throws an unknown exception."""
        def fn():
            raise Exception('message')

        with self.assertRaises(helpers.EarlyExitException) as catched:
            helpers.get_or_exit(fn, 'not_found', 'other')

        self.assertEqual(catched.exception.status, 500)
        self.assertEqual(catched.exception.message,
                         "other (<type 'exceptions.Exception'>: message)")
Example #3
0
  def test_get_or_exit_not_found_exception(self):
    """Ensure it raises 404 when `fn` throws a recognised exception."""

    def fn():
      raise TestNotFoundException()

    with self.assertRaises(helpers.EarlyExitException) as catched:
      helpers.get_or_exit(
          fn, 'not_found', 'error', not_found_exception=TestNotFoundException)

    self.assertEqual(catched.exception.status, 404)
    self.assertEqual(str(catched.exception), 'not_found')
  def get(self, testcase_id):
    """Redirect user to the correct URL."""
    testcase = helpers.get_testcase(testcase_id)
    issue_url = helpers.get_or_exit(
        lambda: issue_tracker_utils.get_issue_url(testcase),
        'Issue tracker for testcase (id=%s) is not found.' % testcase_id,
        'Failed to get the issue tracker URL.')

    self.redirect(issue_url)
Example #5
0
  def test_get_or_exit_other_exception(self):
    """Ensure it raises 500 when `fn` throws an unknown exception."""

    def fn():
      raise Exception('message')

    with self.assertRaises(helpers.EarlyExitException) as catched:
      helpers.get_or_exit(fn, 'not_found', 'other')

    self.assertEqual(catched.exception.status, 500)

    if sys.version_info.major == 2:
      # TODO(ochang): Remove this once migrated to Python 3.
      self.assertEqual(
          str(catched.exception),
          "other (<type 'exceptions.Exception'>: message)")
    else:
      self.assertEqual(
          str(catched.exception), "other (<class 'Exception'>: message)")
Example #6
0
    def update_issue(testcase, issue_id, needs_summary_update):
        """Associate (or update) an existing issue with the testcase."""
        issue_id = helpers.cast(issue_id, int,
                                'Issue ID (%s) is not a number!' % issue_id)
        issue_tracker = helpers.get_issue_tracker_for_testcase(testcase)

        issue = helpers.get_or_exit(
            lambda: issue_tracker.get_issue(issue_id),
            'Issue (id=%d) is not found!' % issue_id,
            'Failed to get the issue (id=%s).' % issue_id, Exception)

        if not issue.is_open:
            raise helpers.EarlyExitException(
                ('The issue (%d) is already closed and further updates are not'
                 ' allowed. Please file a new issue instead!') % issue_id, 400)

        if not testcase.is_crash():
            raise helpers.EarlyExitException(
                'This is not a crash testcase, so issue update is not applicable.',
                400)

        issue_comment = data_handler.get_issue_description(
            testcase, helpers.get_user_email())
        if needs_summary_update:
            issue.title = data_handler.get_issue_summary(testcase)

        policy = issue_tracker_policy.get(issue_tracker.project)
        properties = policy.get_existing_issue_properties()
        for label in properties.labels:
            for result in issue_filer.apply_substitutions(
                    policy, label, testcase):
                issue.labels.add(result)

        issue.save(new_comment=issue_comment)

        testcase.bug_information = str(issue_id)
        testcase.put()

        data_handler.update_group_bug(testcase.group_id)

        helpers.log('Updated issue %sd' % issue_id, helpers.MODIFY_OPERATION)
Example #7
0
    def update_issue(testcase, issue_id, needs_summary_update):
        """Associate (or update) an existing issue with the testcase."""
        issue_id = helpers.cast(issue_id, int,
                                'Issue ID (%s) is not a number!' % issue_id)
        itm = helpers.get_issue_tracker_manager(testcase)

        issue = helpers.get_or_exit(
            lambda: itm.get_issue(issue_id),
            'Issue (id=%d) is not found!' % issue_id,
            'Failed to get the issue (id=%s).' % issue_id, Exception)

        if not issue.open:
            raise helpers.EarlyExitException(
                ('The issue (%d) is already closed and further updates are not'
                 ' allowed. Please file a new issue instead!') % issue_id, 400)

        # Create issue parameters.
        issue.comment = data_handler.get_issue_description(
            testcase, helpers.get_user_email())
        issue_summary = data_handler.get_issue_summary(testcase)

        # NULL states leads to unhelpful summaries, so do not update in that case.
        if needs_summary_update and testcase.crash_state != 'NULL':
            issue.summary = issue_summary

        # Add label on memory tool used.
        issue_filer.add_memory_tool_label_if_needed(issue, testcase)

        # Add view restrictions for internal job types.
        issue_filer.add_view_restrictions_if_needed(issue, testcase)

        # Don't enforce security severity label on an existing issue.

        itm.save(issue)

        testcase.bug_information = str(issue_id)
        testcase.put()

        data_handler.update_group_bug(testcase.group_id)

        helpers.log('Updated issue %sd' % issue_id, helpers.MODIFY_OPERATION)
Example #8
0
 def test_get_or_exit_valid(self):
     """Ensure it gets value."""
     fn = lambda: 'test'
     self.assertEqual(helpers.get_or_exit(fn, 'not_found', 'error'), 'test')