def testAnomalyMappingForMergeIssue(self):
   # Add anomalies.
   test_keys = map(utils.TestKey, [
       'ChromiumGPU/linux-release/scrolling-benchmark/first_paint',
       'ChromiumGPU/linux-release/scrolling-benchmark/mean_frame_time'])
   anomaly.Anomaly(
       start_revision=9990, end_revision=9997, test=test_keys[0],
       median_before_anomaly=100, median_after_anomaly=200,
       sheriff=None, bug_id=12345).put()
   anomaly.Anomaly(
       start_revision=9990, end_revision=9996, test=test_keys[0],
       median_before_anomaly=100, median_after_anomaly=200,
       sheriff=None, bug_id=54321).put()
   # Map anomalies to base(dest_bug_id) bug.
   update_bug_from_rietveld._MapAnomaliesToMergeIntoBug(dest_bug_id=12345,
                                                        source_bug_id=54321)
   anomalies = anomaly.Anomaly.query(
       anomaly.Anomaly.bug_id == int(54321)).fetch()
   self.assertEqual(0, len(anomalies))
  def testGetForMergeIssue(self, mock_update_bug):
    # When there exists a bug with the same revision (commit hash),
    # mark bug as duplicate and merge current issue into that.
    try_job.TryJob(
        bug_id=12345, rietveld_issue_id=200037, rietveld_patchset_id=1,
        status='started', bot='win_perf').put()
    try_job.TryJob(
        bug_id=54321, rietveld_issue_id=200037, rietveld_patchset_id=1,
        status='started', bot='win_perf').put()

    # Create bug.
    bug_data.Bug(id=12345).put()
    bug_data.Bug(id=54321).put()
    self.testapp.get('/update_bug_from_rietveld')
    # Owners of CLs are not cc'ed for duplicate bugs and the issue should be
    # marked as duplicate.
    mock_update_bug.assert_called_with(mock.ANY,
                                       mock.ANY,
                                       cc_list=[],
                                       merge_issue='12345',
                                       labels=None)
    pending_jobs = try_job.TryJob.query().fetch()
    self.assertEqual(0, len(pending_jobs))
    # Add anomalies.
    test_keys = map(utils.TestKey, [
        'ChromiumGPU/linux-release/scrolling-benchmark/first_paint',
        'ChromiumGPU/linux-release/scrolling-benchmark/mean_frame_time'])
    anomaly.Anomaly(
        start_revision=9990, end_revision=9997, test=test_keys[0],
        median_before_anomaly=100, median_after_anomaly=200,
        sheriff=None, bug_id=12345).put()
    anomaly.Anomaly(
        start_revision=9990, end_revision=9996, test=test_keys[0],
        median_before_anomaly=100, median_after_anomaly=200,
        sheriff=None, bug_id=54321).put()
    # Map anomalies to base(dest_bug_id) bug.
    update_bug_from_rietveld._MapAnomaliesToMergeIntoBug(dest_bug_id=12345,
                                                         source_bug_id=54321)
    anomalies = anomaly.Anomaly.query(
        anomaly.Anomaly.bug_id == int(54321)).fetch()
    self.assertEqual(0, len(anomalies))