def CreateIssueWithIssueGenerator(issue_generator): """Creates a new issue with a given issue generator. Args: issue_generator: A FlakyTestIssueGenerator object. Returns: The id of the newly created issue. """ issue_info = { 'status': issue_generator.GetStatus(), 'summary': issue_generator.GetSummary(), 'description': issue_generator.GetDescription(), 'projectId': issue_generator.GetMonorailProject(), 'labels': issue_generator.GetLabels(), 'components': issue_generator.GetComponents() } field_value = issue_generator.GetFlakyTestCustomizedField() if field_value: issue_info['fieldValues'] = [field_value] issue = Issue(issue_info) issue.owner = issue_generator.GetAutoAssignOwner() issue_id = CreateBug(issue, issue_generator.GetMonorailProject()) if issue_id: issue_generator.OnIssueCreated() return issue_id
def testGetIssuesClosedWithinAWeek(self, mock_api, _): expected_issue = Issue({ 'status': 'Fixed', 'summary': 'summary', 'description': 'description', 'projectId': 'chromium', 'labels': [], 'fieldValues': [], 'closed': '2019-01-29T02:00:00' }) monorail_issues = [ expected_issue, Issue({ 'status': 'Fixed', 'summary': 'summary', 'description': 'description', 'projectId': 'chromium', 'labels': [], 'fieldValues': [], 'closed': '2019-01-20T02:00:00' }), Issue({ 'status': 'Available', 'summary': 'summary', 'description': 'description', 'projectId': 'chromium', 'labels': [], 'fieldValues': [], 'state': 'open' }) ] mock_api.return_value.getIssues.return_value = monorail_issues self.assertEqual([expected_issue], monorail_util.GetIssuesClosedWithinAWeek( 'query', 'chromium'))
def testMergeDuplicateIssues(self, mocked_update_bug): duplicate_issue = Issue({'status': 'Available', 'id': '12344'}) merged_issue = Issue({'status': 'Available', 'id': '12345'}) monorail_util.MergeDuplicateIssues(duplicate_issue, merged_issue, 'comment') self.assertEqual('Duplicate', duplicate_issue.status) self.assertEqual('12345', duplicate_issue.merged_into) mocked_update_bug.assert_called_once_with(duplicate_issue, 'comment')
def testMergeOrSplitFlakeIssueByCulpritIssueAlreadyMerged( self, mocked_get_issue, mocked_merge_issues, _): # Culprit's flake issue 12344 was already merged into 12346. # Incoming flake issue's id is 12345 and is expected to be merged as well. project = 'chromium' merged_bug_id = 12344 open_bug_id = 12345 destination_bug_id = 12346 revision = 'r1000' commit_position = 1000 flake_issue = FlakeIssue.Create(project, open_bug_id) flake_issue.put() destination_issue = FlakeIssue.Create(project, destination_bug_id) destination_issue.put() culprit_flake_issue = FlakeIssue.Create(project, merged_bug_id) culprit_flake_issue.status = 'Merged' culprit_flake_issue.merge_destination_key = destination_issue.key culprit_flake_issue.put() flake_culprit = FlakeCulprit.Create(project, revision, commit_position) flake_culprit.flake_issue_key = culprit_flake_issue.key flake_culprit.put() flake_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(open_bug_id) }) destination_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(destination_bug_id) }) mocked_get_issue.side_effect = [ destination_monorail_issue, flake_monorail_issue, ] (duplicate, destination) = flake_analysis_actions.MergeOrSplitFlakeIssueByCulprit( flake_issue.key, flake_culprit.key) mocked_merge_issues.assert_called_once_with( flake_monorail_issue, destination_monorail_issue, mock.ANY) flake_issue = flake_issue.key.get() self.assertEqual(flake_issue.key, duplicate) self.assertEqual(destination_issue.key, destination) self.assertEqual(destination_issue.key, flake_issue.merge_destination_key)
def testMergeOrSplitFlakeIssueByCulpritMergeIntoManuallyCreated( self, mocked_get_issue, mocked_merge_issues, _): project = 'chromium' duplicate_bug_id = 12344 manually_created_bug_id = 12345 revision = 'r1000' commit_position = 1000 flake_issue = FlakeIssue.Create(project, manually_created_bug_id) flake_issue.status = 'Assigned' flake_issue.put() culprit_flake_issue = FlakeIssue.Create(project, duplicate_bug_id) culprit_flake_issue.put() flake_culprit = FlakeCulprit.Create(project, revision, commit_position) flake_culprit.flake_issue_key = culprit_flake_issue.key flake_culprit.put() # Even though the flake issue associated with the culprit was identified # first, the incoming flake issue was manually created. Merge into the # manually created one. flake_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(manually_created_bug_id) }) culprit_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(duplicate_bug_id) }) mocked_get_issue.side_effect = [ culprit_monorail_issue, flake_monorail_issue ] (duplicate, destination) = flake_analysis_actions.MergeOrSplitFlakeIssueByCulprit( flake_issue.key, flake_culprit.key) mocked_merge_issues.assert_called_once_with(culprit_monorail_issue, flake_monorail_issue, mock.ANY) flake_culprit = flake_culprit.key.get() flake_issue = flake_issue.key.get() culprit_flake_issue = culprit_flake_issue.key.get() self.assertEqual(culprit_flake_issue.key, duplicate) self.assertEqual(flake_issue.key, destination) self.assertEqual(flake_issue.flake_culprit_key, flake_culprit.key) self.assertEqual(flake_issue.key, culprit_flake_issue.merge_destination_key)
def testMergeOrSplitFlakeIssueByCulpritIssueClosed(self, mocked_get_issue, mocked_merge_issues, *_): project = 'chromium' closed_bug_id = 12344 open_bug_id = 12345 revision = 'r1000' commit_position = 1000 flake_issue = FlakeIssue.Create(project, open_bug_id) flake_issue.put() culprit_flake_issue = FlakeIssue.Create(project, closed_bug_id) culprit_flake_issue.status = 'Fixed' culprit_flake_issue.last_updated_time_in_monorail = datetime( 2019, 1, 1) culprit_flake_issue.put() flake_culprit = FlakeCulprit.Create(project, revision, commit_position) flake_culprit.flake_issue_key = culprit_flake_issue.key flake_culprit.put() # Even though the flake issue associated with the culprit was identified # first, it has been closed. FlakeCulprit should have its flake issue # updated to the incoming one. flake_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(open_bug_id) }) culprit_monorail_issue = Issue({ 'status': 'Fixed', 'projectId': 'chromium', 'id': str(closed_bug_id) }) mocked_get_issue.side_effect = [ culprit_monorail_issue, flake_monorail_issue ] (duplicate, destination) = flake_analysis_actions.MergeOrSplitFlakeIssueByCulprit( flake_issue.key, flake_culprit.key) mocked_merge_issues.assert_not_called() flake_culprit = flake_culprit.key.get() self.assertIsNone(duplicate) self.assertIsNone(destination) self.assertIsNone(flake_issue.merge_destination_key) self.assertEqual(flake_issue.key, flake_culprit.flake_issue_key)
def testUpdateIssueWithIssueGeneratorReopen(self, mock_create_bug_fn, mock_update_bug_fn, mock_get_merged_issue): issue_id = 12345 issue = Issue({ 'status': 'Fixed', 'summary': 'summary', 'description': 'description', 'projectId': 'chromium', 'labels': [], 'fieldValues': [], 'state': 'open', 'owner': { 'name': '*****@*****.**' } }) mock_get_merged_issue.return_value = issue test_issue_generator = TestIssueGenerator() monorail_util.UpdateIssueWithIssueGenerator( issue_id=issue_id, issue_generator=test_issue_generator, reopen=True) self.assertFalse(mock_create_bug_fn.called) mock_update_bug_fn.assert_called_once_with( issue, 'comment without previous tracking bug id.', 'chromium') issue = mock_update_bug_fn.call_args_list[0][0][0] self.assertEqual(['label1'], issue.labels) self.assertEqual(1, len(issue.field_values)) self.assertEqual('Flaky-Test', issue.field_values[0].to_dict()['fieldName']) self.assertEqual('suite.test', issue.field_values[0].to_dict()['fieldValue']) self.assertEqual('Assigned', issue.status)
def testGetMergedDestinationIssueWithMergeInCircle(self, mock_api): issue = Issue({'id': 12345, 'mergedInto': {'issueId': 56789}}) another_issue = Issue({'id': 56789, 'mergedInto': {'issueId': 12345}}) def _return_issue(issue_id): if issue_id == 12345: return issue if issue_id == 56789: return another_issue return None mock_api.return_value.getIssue.side_effect = _return_issue self.assertEqual(issue, monorail_util.GetMergedDestinationIssueForId(12345))
def testCreateBug(self, mock_api): summary = 'test summary' description = 'test description' project_id = 'proj' issue = Issue({ 'status': 'Available', 'summary': summary, 'description': description, 'projectId': 'chromium', 'state': 'open', }) monorail_util.CreateBug(issue, project_id=project_id)
def testGetMonorailIssueForIssueId(self, mocked_issue_tracker_api): issue = Issue({ 'status': 'Available', 'summary': 'summary', 'description': 'description', 'projectId': 'chromium', 'labels': [], 'fieldValues': [], 'state': 'open', 'id': '12345' }) mocked_issue_tracker_api.return_value.getIssue.return_value = issue self.assertEqual( issue, monorail_util.GetMonorailIssueForIssueId(12345, 'chromium'))
def testCreateBug(self, mock_api): summary = 'test summary' description = 'test description' project_id = 'proj' issue = Issue({ 'status': 'Available', 'summary': summary, 'description': description, 'projectId': 'chromium', 'state': 'open', }) monorail_util.CreateBug(issue, project_id=project_id) mock_api.assert_called_once_with(project_id, use_staging=False) mock_api.return_value.create.assert_called_once_with(issue)
def testUpdateMonorailBugWithCulprit(self, mock_update, mock_comments, mock_get_issue, *_): project = 'chromium' bug_id = 12345 step_name = 's' test_name = 't' label = 'l' flake_issue = FlakeIssue.Create(project, bug_id) flake_issue.put() flake = Flake.Create(project, step_name, test_name, label) flake.flake_issue_key = flake_issue.key flake.put() analysis = MasterFlakeAnalysis.Create('m', 'b', 123, 's', 't') analysis.flake_key = flake.key analysis.put() mock_comments.return_value = [ Comment({ 'author': { 'name': '*****@*****.**' }, 'content': '', 'published': None, 'id': '12345', }), ] mock_get_issue.return_value = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(bug_id), 'state': 'open' }) flake_analysis_actions.UpdateMonorailBugWithCulprit( analysis.key.urlsafe()) mock_update.assert_called_once_with(bug_id, mock.ANY) self.assertIsNotNone( flake_issue.last_updated_time_with_analysis_results)
def testPostCommentOnMonorailBug(self, mock_update_bug_fn, mock_get_merged_issue): issue_id = 12345 issue = Issue({ 'status': 'Available', 'summary': 'summary', 'description': 'description', 'projectId': 'chromium', 'labels': [], 'fieldValues': [], 'state': 'open', }) mock_get_merged_issue.return_value = issue test_issue_generator = TestIssueGenerator() monorail_util.PostCommentOnMonorailBug( issue_id=issue_id, issue_generator=test_issue_generator, comment='Random comment') mock_update_bug_fn.assert_called_once_with(issue, 'Random comment', 'chromium')
def testUpdateIssueWithIssueGeneratorAndRestoreSheriffLabel( self, mock_create_bug_fn, mock_update_bug_fn, mock_get_merged_issue, _): issue_id = 12345 issue = Issue({ 'status': 'Available', 'summary': 'summary', 'description': 'description', 'projectId': 'chromium', 'labels': [], 'fieldValues': [], 'state': 'open', }) mock_get_merged_issue.return_value = issue test_issue_generator = TestIssueGenerator() monorail_util.UpdateIssueWithIssueGenerator( issue_id=issue_id, issue_generator=test_issue_generator) self.assertFalse(mock_create_bug_fn.called) self.assertTrue(mock_update_bug_fn.called) self.assertEqual(['label1', 'Sheriff-Chromium'], issue.labels)
def testUpdateIssueWithIssueGeneratorWithPreviousTrackingId( self, mock_create_bug_fn, mock_update_bug_fn, mock_get_merged_issue): issue_id = 12345 issue = Issue({ 'status': 'Available', 'summary': 'summary', 'description': 'description', 'projectId': 'chromium', 'labels': [], 'fieldValues': [], 'state': 'open', }) mock_get_merged_issue.return_value = issue test_issue_generator = TestIssueGenerator() test_issue_generator.SetPreviousTrackingBugId(56789) monorail_util.UpdateIssueWithIssueGenerator( issue_id=issue_id, issue_generator=test_issue_generator) self.assertFalse(mock_create_bug_fn.called) mock_update_bug_fn.assert_called_once_with( issue, 'comment with previous tracking bug id: 56789.', 'chromium')
def testGetMergedDestinationIssueWithoutMergeInto(self, mock_api): issue = Issue({'id': 12345}) mock_api.return_value.getIssue.return_value = issue self.assertEqual(issue, monorail_util.GetMergedDestinationIssueForId(12345))