| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import mock |
| 6 |
| 7 from issue_tracker import Issue |
| 8 |
| 9 from waterfall import post_comment_to_bug_pipeline |
| 10 from waterfall.test import wf_testcase |
| 11 |
| 12 |
| 13 class PostCommentToBugPipelineTest(wf_testcase.WaterfallTestCase): |
| 14 |
| 15 def testGetIssueWithoutMergeInto(self): |
| 16 issue_tracker = mock.Mock() |
| 17 expected_issue = Issue({}) |
| 18 issue_tracker.getIssue.return_value = expected_issue |
| 19 |
| 20 issue = post_comment_to_bug_pipeline._GetIssue(123, issue_tracker) |
| 21 self.assertEqual(expected_issue, issue) |
| 22 issue_tracker.assert_has_calls([mock.call.getIssue(123)]) |
| 23 |
| 24 def testGetIssueWithMergeInto(self): |
| 25 issue_tracker = mock.Mock() |
| 26 expected_issue = Issue({}) |
| 27 issue_tracker.getIssue.side_effect = [ |
| 28 Issue({'mergedInto': {'issueId': 234}}), |
| 29 Issue({'mergedInto': {'issueId': 345}}), |
| 30 expected_issue, |
| 31 ] |
| 32 |
| 33 issue = post_comment_to_bug_pipeline._GetIssue(123, issue_tracker) |
| 34 self.assertEqual(expected_issue, issue) |
| 35 issue_tracker.assert_has_calls( |
| 36 [mock.call.getIssue(123), mock.call.getIssue(234), |
| 37 mock.call.getIssue(345)]) |
| 38 |
| 39 @mock.patch('waterfall.post_comment_to_bug_pipeline.IssueTrackerAPI') |
| 40 def testPostCommentToBug(self, issue_tracker): |
| 41 dummy_issue = Issue({}) |
| 42 mocked_instance = mock.Mock() |
| 43 mocked_instance.getIssue.return_value = dummy_issue |
| 44 issue_tracker.return_value = mocked_instance |
| 45 pipeline = post_comment_to_bug_pipeline.PostCommentToBugPipeline() |
| 46 pipeline.run(123, 'comment', ['label']) |
| 47 issue_tracker.assert_has_calls( |
| 48 [mock.call('chromium'), |
| 49 mock.call().getIssue(123), |
| 50 mock.call().update(dummy_issue, 'comment', send_email=True)]) |
| 51 self.assertEqual(['label'], dummy_issue.labels) |
| 52 |
| 53 @mock.patch('waterfall.post_comment_to_bug_pipeline.IssueTrackerAPI') |
| 54 def testPostCommentToBugWhenDeleted(self, issue_tracker): |
| 55 mocked_instance = mock.Mock() |
| 56 mocked_instance.getIssue.return_value = None |
| 57 issue_tracker.return_value = mocked_instance |
| 58 pipeline = post_comment_to_bug_pipeline.PostCommentToBugPipeline() |
| 59 pipeline.run(123, 'comment', ['label']) |
| 60 issue_tracker.assert_has_calls( |
| 61 [mock.call('chromium'), |
| 62 mock.call().getIssue(123)]) |
| OLD | NEW |