Example #1
0
    def setUp(self):
        test_helpers.patch(self, [
            'libs.access._is_domain_allowed',
            'libs.auth.get_current_user',
            'clusterfuzz._internal.config.db_config.get',
            'libs.issue_management.issue_tracker.IssueTracker.get_original_issue',
            'libs.issue_management.issue_tracker_utils.'
            'get_issue_tracker_for_testcase',
            'libs.issue_management.monorail.issue_tracker_manager.'
            'IssueTrackerManager',
        ])
        self.itm = issue_tracker_manager.IssueTrackerManager('test')
        self.itm.project_name = 'test-project'
        self.mock.get_issue_tracker_for_testcase.return_value = (
            monorail.IssueTracker(self.itm))
        self.get_issue = self.itm.get_issue

        self.email = '*****@*****.**'
        self.mock.get_current_user.return_value = auth.User(self.email)

        self.bug = issue.Issue()
        self.bug.id = 1234
        self.bug.itm = self.itm
        self.original_bug = issue.Issue()
        self.original_bug.id = 5678
        self.original_bug.itm = self.itm

        self.testcase = data_types.Testcase()

        self.mock.get.return_value = (data_types.Config(
            relax_testcase_restrictions=True))
        self.mock._is_domain_allowed.return_value = False
Example #2
0
  def test_succeed(self):
    """Update an issue."""
    bug = issue.Issue()
    bug.open = True
    itm = mock.Mock(project_name='chromium')
    itm.get_issue.return_value = bug

    self.mock.get_issue_tracker_for_testcase.return_value = (
        monorail.IssueTracker(itm))
    self.mock.get_issue_description.return_value = 'description'
    self.mock.get_issue_summary.return_value = 'summary'
    self.mock.get_stacktrace.return_value = 'stacktrace'
    self.mock.get_memory_tool_labels.return_value = ['tool']

    resp = self.app.post_json(
        '/', {
            'testcaseId': self.testcase.key.id(),
            'issueId': '2',
            'needsSummaryUpdate': 'true',
            'csrf_token': form.generate_csrf_token(),
        },
        expect_errors=True)

    self.assertEqual(200, resp.status_int)
    self.assertEqual('yes', resp.json['testcase'])

    self.assertEqual('description', bug.comment)
    self.assertEqual('summary', bug.summary)
    self.assertListEqual(['Stability-tool'], bug.labels)
    self.assertEqual('2', self.testcase.key.get().bug_information)
Example #3
0
    def test_find(self):
        """Ensure it returns correct JSON when everything is ok."""
        issue_tracker = mock.Mock()
        monorail_issue = issue.Issue()
        monorail_issue.id = 100
        issue_item = monorail.Issue(monorail_issue)
        self.mock.get_issue_tracker_for_testcase.return_value = issue_tracker
        self.mock.get_search_keywords.return_value = ['query']
        self.mock.get_similar_issues_url.return_value = 'similarurl'
        self.mock.get_similar_issues.return_value = [issue_item]
        issue_tracker.issue_url.return_value = 'issueurl'

        response = self.app.get('/?testcaseId=%d&filterType=open' %
                                self.testcase.key.id())
        self.assertEqual(response.status_int, 200)
        self.assertEqual(response.json['queryString'], 'query')
        self.assertEqual(response.json['queryUrl'], 'similarurl')
        self.assertEqual(len(response.json['items']), 1)

        self.assertEqual(response.json['items'][0]['issue']['id'],
                         issue_item.id)

        self.mock.get_issue_tracker_for_testcase.assert_has_calls(
            [mock.call(mock.ANY)])
        self.assertEqual(
            self.testcase.key.id(),
            self.mock.get_issue_tracker_for_testcase.call_args[0][0].key.id())
        self.mock.get_similar_issues.assert_has_calls(
            [mock.call(issue_tracker, mock.ANY, only_open=True)])
        self.assertEqual(self.testcase.key.id(),
                         self.mock.get_similar_issues.call_args[0][1].key.id())
Example #4
0
    def test_deny_no_access_and_no_bug_access(self):
        """Ensure it is false when user has no access and no bug access."""
        self.mock._is_domain_allowed.return_value = False
        self.get_issue.return_value = issue.Issue()

        self.testcase.bug_information = '1234'
        self.assertFalse(access.can_user_access_testcase(self.testcase))

        self.get_issue.assert_has_calls([mock.call(1234)])
Example #5
0
    def test_issue_not_open(self):
        """Issue is not open."""
        itm = mock.Mock(spec_set=issue_tracker_manager.IssueTrackerManager)
        bug = issue.Issue()
        bug.open = False

        self.mock.get_issue_tracker_for_testcase.return_value = (
            monorail.IssueTracker(itm))
        itm.get_issue.return_value = bug

        resp = self.app.post_json('/', {
            'testcaseId': self.testcase.key.id(),
            'issueId': '2',
            'needsSummaryUpdate': '',
            'csrf_token': form.generate_csrf_token(),
        },
                                  expect_errors=True)

        self.assertEqual(400, resp.status_int)
        self.assertIn('file a new issue', resp.json['message'])
        self.assertEqual('*****@*****.**', resp.json['email'])