Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: dashboard/dashboard/issue_tracker_service_test.py

Issue 2162963002: [polymer] Merge of master into polymer10-migration (Closed) Base URL: git@github.com:catapult-project/catapult.git@polymer10-migration
Patch Set: Merge polymer10-migration int polymer10-merge Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dashboard/dashboard/issue_tracker_service.py ('k') | dashboard/dashboard/start_try_job.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import mock 6 import mock
7 import unittest 7 import unittest
8 8
9 from apiclient import errors 9 from apiclient import errors
10 10
11 from dashboard import issue_tracker_service 11 from dashboard import issue_tracker_service
12 from dashboard import testing_common 12 from dashboard import testing_common
13 13
14 14
15 @mock.patch('issue_tracker_service.discovery.build', mock.MagicMock()) 15 @mock.patch('issue_tracker_service.discovery.build', mock.MagicMock())
16 class IssueTrackerServiceTest(testing_common.TestCase): 16 class IssueTrackerServiceTest(testing_common.TestCase):
17 17
18 def testAddBugComment_Basic(self): 18 def testAddBugComment_Basic(self):
19 service = issue_tracker_service.IssueTrackerService() 19 service = issue_tracker_service.IssueTrackerService()
20 service._MakeCommentRequest = mock.Mock() 20 service._MakeCommentRequest = mock.Mock()
21 self.assertTrue(service.AddBugComment(12345, 'The comment')) 21 self.assertTrue(service.AddBugComment(12345, 'The comment'))
22 self.assertEqual(1, service._MakeCommentRequest.call_count) 22 self.assertEqual(1, service._MakeCommentRequest.call_count)
23 service._MakeCommentRequest.assert_called_with( 23 service._MakeCommentRequest.assert_called_with(
24 12345, {'updates': {}, 'content': 'The comment'}) 24 12345, {'updates': {}, 'content': 'The comment'}, send_email=True)
25 25
26 def testAddBugComment_WithNoBug_ReturnsFalse(self): 26 def testAddBugComment_WithNoBug_ReturnsFalse(self):
27 service = issue_tracker_service.IssueTrackerService() 27 service = issue_tracker_service.IssueTrackerService()
28 service._MakeCommentRequest = mock.Mock() 28 service._MakeCommentRequest = mock.Mock()
29 self.assertFalse(service.AddBugComment(None, 'Some comment')) 29 self.assertFalse(service.AddBugComment(None, 'Some comment'))
30 self.assertFalse(service.AddBugComment(-1, 'Some comment')) 30 self.assertFalse(service.AddBugComment(-1, 'Some comment'))
31 31
32 def testAddBugComment_WithOptionalParameters(self): 32 def testAddBugComment_WithOptionalParameters(self):
33 service = issue_tracker_service.IssueTrackerService() 33 service = issue_tracker_service.IssueTrackerService()
34 service._MakeCommentRequest = mock.Mock() 34 service._MakeCommentRequest = mock.Mock()
35 self.assertTrue(service.AddBugComment( 35 self.assertTrue(service.AddBugComment(
36 12345, 'Some other comment', status='Fixed', 36 12345, 'Some other comment', status='Fixed',
37 labels=['Foo'], cc_list=['someone@chromium.org'])) 37 labels=['Foo'], cc_list=['someone@chromium.org']))
38 self.assertEqual(1, service._MakeCommentRequest.call_count) 38 self.assertEqual(1, service._MakeCommentRequest.call_count)
39 service._MakeCommentRequest.assert_called_with( 39 service._MakeCommentRequest.assert_called_with(
40 12345, 40 12345,
41 { 41 {
42 'updates': { 42 'updates': {
43 'status': 'Fixed', 43 'status': 'Fixed',
44 'cc': ['someone@chromium.org'], 44 'cc': ['someone@chromium.org'],
45 'labels': ['Foo'], 45 'labels': ['Foo'],
46 }, 46 },
47 'content': 'Some other comment' 47 'content': 'Some other comment'
48 }) 48 },
49 send_email=True)
49 50
50 def testAddBugComment_MergeBug(self): 51 def testAddBugComment_MergeBug(self):
51 service = issue_tracker_service.IssueTrackerService() 52 service = issue_tracker_service.IssueTrackerService()
52 service._MakeCommentRequest = mock.Mock() 53 service._MakeCommentRequest = mock.Mock()
53 self.assertTrue(service.AddBugComment(12345, 'Dupe', merge_issue=54321)) 54 self.assertTrue(service.AddBugComment(12345, 'Dupe', merge_issue=54321))
54 self.assertEqual(1, service._MakeCommentRequest.call_count) 55 self.assertEqual(1, service._MakeCommentRequest.call_count)
55 service._MakeCommentRequest.assert_called_with( 56 service._MakeCommentRequest.assert_called_with(
56 12345, 57 12345,
57 { 58 {
58 'updates': { 59 'updates': {
59 'status': 'Duplicate', 60 'status': 'Duplicate',
60 'mergedInto': 54321, 61 'mergedInto': 54321,
61 }, 62 },
62 'content': 'Dupe' 63 'content': 'Dupe'
63 }) 64 },
65 send_email=True)
64 66
65 @mock.patch('logging.error') 67 @mock.patch('logging.error')
66 def testAddBugComment_Error(self, mock_logging_error): 68 def testAddBugComment_Error(self, mock_logging_error):
67 service = issue_tracker_service.IssueTrackerService() 69 service = issue_tracker_service.IssueTrackerService()
68 service._ExecuteRequest = mock.Mock(return_value=None) 70 service._ExecuteRequest = mock.Mock(return_value=None)
69 self.assertFalse(service.AddBugComment(12345, 'My bug comment')) 71 self.assertFalse(service.AddBugComment(12345, 'My bug comment'))
70 self.assertEqual(1, service._ExecuteRequest.call_count) 72 self.assertEqual(1, service._ExecuteRequest.call_count)
71 self.assertEqual(1, mock_logging_error.call_count) 73 self.assertEqual(1, mock_logging_error.call_count)
72 74
73 def testNewBug_Success_NewBugReturnsId(self): 75 def testNewBug_Success_NewBugReturnsId(self):
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 service._ExecuteRequest = mock.Mock(side_effect=errors.HttpError( 122 service._ExecuteRequest = mock.Mock(side_effect=errors.HttpError(
121 mock.Mock(return_value={'status': 403}), json.dumps(error_content))) 123 mock.Mock(return_value={'status': 403}), json.dumps(error_content)))
122 comment_posted = service.AddBugComment(12345, 'The comment', 124 comment_posted = service.AddBugComment(12345, 'The comment',
123 owner='test@chromium.org') 125 owner='test@chromium.org')
124 self.assertEqual(1, service._ExecuteRequest.call_count) 126 self.assertEqual(1, service._ExecuteRequest.call_count)
125 self.assertEqual(True, comment_posted) 127 self.assertEqual(True, comment_posted)
126 128
127 129
128 if __name__ == '__main__': 130 if __name__ == '__main__':
129 unittest.main() 131 unittest.main()
OLDNEW
« no previous file with comments | « dashboard/dashboard/issue_tracker_service.py ('k') | dashboard/dashboard/start_try_job.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698