OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Unit tests for gcl.py.""" | 6 """Unit tests for gcl.py.""" |
7 | 7 |
8 # pylint: disable=E1103,E1101,E1120 | 8 # pylint: disable=E1103,E1101,E1120 |
9 | 9 |
10 import os | 10 import os |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 change_info.issue = 1 | 46 change_info.issue = 1 |
47 change_info.patchset = 0 | 47 change_info.patchset = 0 |
48 change_info.description = 'deescription' | 48 change_info.description = 'deescription' |
49 change_info.files = files | 49 change_info.files = files |
50 change_info.GetFiles = lambda : change_info.files | 50 change_info.GetFiles = lambda : change_info.files |
51 change_info.GetIssueDescription = lambda : change_info.description | 51 change_info.GetIssueDescription = lambda : change_info.description |
52 change_info.GetFileNames = lambda : [f[1] for f in change_info.files] | 52 change_info.GetFileNames = lambda : [f[1] for f in change_info.files] |
53 change_info.GetLocalRoot = lambda : 'proout' | 53 change_info.GetLocalRoot = lambda : 'proout' |
54 change_info.patch = None | 54 change_info.patch = None |
55 change_info.rietveld = 'https://my_server' | 55 change_info.rietveld = 'https://my_server' |
56 change_info.reviewers = None | |
57 change_info._closed = False | 56 change_info._closed = False |
58 change_info._deleted = False | 57 change_info._deleted = False |
59 change_info._comments_added = [] | 58 change_info._comments_added = [] |
60 | 59 |
61 class RpcServer(object): | 60 class RpcServer(object): |
62 # pylint: disable=R0201,W0613 | 61 # pylint: disable=R0201,W0613 |
63 def get_issue_properties(self, issue, messages): | 62 def get_issue_properties(self, issue, messages): |
64 return { 'patchsets': [1337] } | 63 return { 'patchsets': [1337] } |
65 change_info.RpcServer = RpcServer | 64 change_info.RpcServer = RpcServer |
66 | 65 |
(...skipping 28 matching lines...) Expand all Loading... |
95 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings', | 94 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings', |
96 'CMDstatus', 'CMDtry', 'CMDupload', | 95 'CMDstatus', 'CMDtry', 'CMDupload', |
97 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', | 96 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', |
98 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', | 97 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', |
99 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', | 98 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', |
100 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', | 99 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', |
101 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', | 100 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', |
102 'GetCodeReviewSetting', 'GetFilesNotInCL', 'GetInfoDir', | 101 'GetCodeReviewSetting', 'GetFilesNotInCL', 'GetInfoDir', |
103 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', | 102 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', |
104 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', | 103 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', |
105 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 'REVIEWERS_REGEX', | 104 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', |
106 'RunShell', 'RunShellWithReturnCode', 'SVN', | 105 'RunShell', 'RunShellWithReturnCode', 'SVN', |
107 'TryChange', 'UnknownFiles', 'Warn', | 106 'TryChange', 'UnknownFiles', 'Warn', |
108 'attrs', 'breakpad', 'defer_attributes', 'fix_encoding', | 107 'attrs', 'breakpad', 'defer_attributes', 'fix_encoding', |
109 'gclient_utils', 'json', 'main', 'need_change', 'need_change_and_args', | 108 'gclient_utils', 'git_cl', 'json', 'main', 'need_change', |
110 'no_args', 'optparse', 'os', 'presubmit_support', 'random', 're', | 109 'need_change_and_args', 'no_args', 'optparse', 'os', |
111 'rietveld', | 110 'presubmit_support', 'random', 're', 'rietveld', |
112 'string', 'subprocess2', 'sys', 'tempfile', 'time', | 111 'string', 'subprocess2', 'sys', 'tempfile', 'time', |
113 'upload', 'urllib2', | 112 'upload', 'urllib2', |
114 ] | 113 ] |
115 # If this test fails, you should add the relevant test. | 114 # If this test fails, you should add the relevant test. |
116 self.compareMembers(gcl, members) | 115 self.compareMembers(gcl, members) |
117 | 116 |
118 def testIsSVNMoved(self): | 117 def testIsSVNMoved(self): |
119 # TODO(maruel): TEST ME | 118 # TODO(maruel): TEST ME |
120 pass | 119 pass |
121 | 120 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 class ChangeInfoUnittest(GclTestsBase): | 185 class ChangeInfoUnittest(GclTestsBase): |
187 def setUp(self): | 186 def setUp(self): |
188 GclTestsBase.setUp(self) | 187 GclTestsBase.setUp(self) |
189 self.mox.StubOutWithMock(gcl, 'GetChangelistInfoFile') | 188 self.mox.StubOutWithMock(gcl, 'GetChangelistInfoFile') |
190 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') | 189 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') |
191 | 190 |
192 def testChangeInfoMembers(self): | 191 def testChangeInfoMembers(self): |
193 self.mox.ReplayAll() | 192 self.mox.ReplayAll() |
194 members = [ | 193 members = [ |
195 'AddComment', 'CloseIssue', 'Delete', 'Exists', 'GetFiles', | 194 'AddComment', 'CloseIssue', 'Delete', 'Exists', 'GetFiles', |
196 'GetFileNames', 'GetLocalRoot', 'GetIssueDescription', 'Load', | 195 'GetFileNames', 'GetLocalRoot', |
| 196 'Load', |
197 'MissingTests', 'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', | 197 'MissingTests', 'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', |
198 'SendToRietveld', | 198 'SendToRietveld', |
199 'SEPARATOR', | 199 'SEPARATOR', |
200 'UpdateRietveldDescription', | 200 'UpdateDescriptionFromIssue', 'UpdateRietveldDescription', |
201 'description', 'issue', 'name', | 201 'append_footer', |
202 'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld', | 202 'description', 'force_description', 'get_reviewers', 'issue', 'name', |
| 203 'needs_upload', 'patch', 'patchset', 'rietveld', |
203 ] | 204 ] |
204 # If this test fails, you should add the relevant test. | 205 # If this test fails, you should add the relevant test. |
205 self.compareMembers( | 206 self.compareMembers( |
206 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo', False), | 207 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo', False), |
207 members) | 208 members) |
208 | 209 |
209 def testChangeInfoBase(self): | 210 def testChangeInfoBase(self): |
210 files = [('M', 'foo'), ('A', 'bar')] | 211 files = [('M', 'foo'), ('A', 'bar')] |
211 self.mox.ReplayAll() | 212 self.mox.ReplayAll() |
212 o = gcl.ChangeInfo( | 213 o = gcl.ChangeInfo( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 change_info.files = [('A', 'aa'), ('M', 'bb')] | 316 change_info.files = [('A', 'aa'), ('M', 'bb')] |
316 change_info.patch = None | 317 change_info.patch = None |
317 change_info.rietveld = 'https://my_server' | 318 change_info.rietveld = 'https://my_server' |
318 files = [item[1] for item in change_info.files] | 319 files = [item[1] for item in change_info.files] |
319 output = presubmit_support.PresubmitOutput() | 320 output = presubmit_support.PresubmitOutput() |
320 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 321 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
321 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 322 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
322 gcl.os.getcwd().AndReturn('somewhere') | 323 gcl.os.getcwd().AndReturn('somewhere') |
323 change_info.GetFiles().AndReturn(change_info.files) | 324 change_info.GetFiles().AndReturn(change_info.files) |
324 gcl.os.chdir('proout') | 325 gcl.os.chdir('proout') |
| 326 change_info.get_reviewers().AndReturn('foo@bar.com') |
325 change_info.GetFileNames().AndReturn(files) | 327 change_info.GetFileNames().AndReturn(files) |
326 gcl.GenerateDiff(files) | 328 gcl.GenerateDiff(files) |
327 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 329 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', |
328 '-r', 'georges@example.com', | 330 '-r', 'georges@example.com', |
329 '--issue=1', '--title= '], | 331 '--issue=1', '--title= '], |
330 change_info.patch).AndReturn(("1", | 332 change_info.patch).AndReturn(("1", |
331 "2")) | 333 "2")) |
332 change_info.GetLocalRoot().AndReturn('proout') | 334 change_info.GetLocalRoot().AndReturn('proout') |
333 change_info.Save() | 335 change_info.Save() |
334 change_info.PrimeLint() | 336 change_info.PrimeLint() |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 451 |
450 def testReviewersInDescription(self): | 452 def testReviewersInDescription(self): |
451 change_info = self.mox.CreateMock(gcl.ChangeInfo) | 453 change_info = self.mox.CreateMock(gcl.ChangeInfo) |
452 change_info.name = 'naame' | 454 change_info.name = 'naame' |
453 change_info.issue = 1 | 455 change_info.issue = 1 |
454 change_info.patchset = 0 | 456 change_info.patchset = 0 |
455 change_info.description = 'deescription\n\nR=georges@example.com', | 457 change_info.description = 'deescription\n\nR=georges@example.com', |
456 change_info.files = [('A', 'aa'), ('M', 'bb')] | 458 change_info.files = [('A', 'aa'), ('M', 'bb')] |
457 change_info.patch = None | 459 change_info.patch = None |
458 change_info.rietveld = 'https://my_server' | 460 change_info.rietveld = 'https://my_server' |
459 change_info.reviewers = ['georges@example.com'] | |
460 files = [item[1] for item in change_info.files] | 461 files = [item[1] for item in change_info.files] |
461 output = presubmit_support.PresubmitOutput() | 462 output = presubmit_support.PresubmitOutput() |
462 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 463 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
463 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 464 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
464 gcl.os.getcwd().AndReturn('somewhere') | 465 gcl.os.getcwd().AndReturn('somewhere') |
465 change_info.GetFiles().AndReturn(change_info.files) | 466 change_info.GetFiles().AndReturn(change_info.files) |
| 467 change_info.get_reviewers().AndReturn(['georges@example.com']) |
466 change_info.GetFileNames().AndReturn(files) | 468 change_info.GetFileNames().AndReturn(files) |
467 change_info.GetLocalRoot().AndReturn('proout') | 469 change_info.GetLocalRoot().AndReturn('proout') |
468 gcl.os.chdir('proout') | 470 gcl.os.chdir('proout') |
469 gcl.GenerateDiff(files) | 471 gcl.GenerateDiff(files) |
470 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 472 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', |
471 '--reviewers=georges@example.com', | 473 '--reviewers=georges@example.com', |
472 '--issue=1', '--title= '], | 474 '--issue=1', '--title= '], |
473 change_info.patch).AndReturn(("1", "2")) | 475 change_info.patch).AndReturn(("1", "2")) |
474 change_info.Save() | 476 change_info.Save() |
475 change_info.PrimeLint() | 477 change_info.PrimeLint() |
(...skipping 17 matching lines...) Expand all Loading... |
493 output.reviewers = ['foo@example.com', 'bar@example.com'] | 495 output.reviewers = ['foo@example.com', 'bar@example.com'] |
494 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 496 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
495 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 497 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
496 gcl.os.getcwd().AndReturn('somewhere') | 498 gcl.os.getcwd().AndReturn('somewhere') |
497 gcl.os.chdir('proout') | 499 gcl.os.chdir('proout') |
498 gcl.GenerateDiff(change_info.GetFileNames()) | 500 gcl.GenerateDiff(change_info.GetFileNames()) |
499 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 501 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', |
500 '--reviewers=foo@example.com,bar@example.com', | 502 '--reviewers=foo@example.com,bar@example.com', |
501 '--issue=1', '--title= '], | 503 '--issue=1', '--title= '], |
502 change_info.patch).AndReturn(("1", "2")) | 504 change_info.patch).AndReturn(("1", "2")) |
| 505 change_info.get_reviewers().AndReturn(['foo@example.com,bar@example.com']) |
503 change_info.Save() | 506 change_info.Save() |
504 change_info.PrimeLint() | 507 change_info.PrimeLint() |
505 gcl.os.chdir('somewhere') | 508 gcl.os.chdir('somewhere') |
506 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" | 509 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" |
507 " submit a try. ***") | 510 " submit a try. ***") |
508 gcl.sys.stdout.write("\n") | 511 gcl.sys.stdout.write("\n") |
509 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) | 512 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) |
510 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True | 513 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True |
511 ).AndReturn(change_info) | 514 ).AndReturn(change_info) |
512 self.mox.ReplayAll() | 515 self.mox.ReplayAll() |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 self.mox.ReplayAll() | 568 self.mox.ReplayAll() |
566 | 569 |
567 retval = gcl.CMDcommit(['naame']) | 570 retval = gcl.CMDcommit(['naame']) |
568 | 571 |
569 self.assertEquals(retval, 1) | 572 self.assertEquals(retval, 1) |
570 | 573 |
571 def testPresubmitSucceeds(self): | 574 def testPresubmitSucceeds(self): |
572 change_info = self.mockLoad() | 575 change_info = self.mockLoad() |
573 self.mockPresubmit(change_info, fail=False) | 576 self.mockPresubmit(change_info, fail=False) |
574 self.mockCommit( | 577 self.mockCommit( |
575 change_info, 'deescription\nReview URL: https://my_server/1', '') | 578 change_info, 'deescription\n\nReview URL: https://my_server/1', '') |
| 579 change_info.UpdateDescriptionFromIssue() |
576 self.mox.ReplayAll() | 580 self.mox.ReplayAll() |
577 | 581 |
578 retval = gcl.CMDcommit(['naame']) | 582 retval = gcl.CMDcommit(['naame']) |
579 | 583 |
580 self.assertEquals(retval, 0) | 584 self.assertEquals(retval, 0) |
581 self.assertEquals(change_info.description, 'deescription') | 585 self.assertEquals(change_info.description, 'deescription') |
582 # pylint: disable=W0212 | 586 # pylint: disable=W0212 |
583 self.assertFalse(change_info._deleted) | 587 self.assertFalse(change_info._deleted) |
584 self.assertFalse(change_info._closed) | 588 self.assertFalse(change_info._closed) |
585 | 589 |
586 def testPresubmitSucceedsWithCommittedMessage(self): | 590 def testPresubmitSucceedsWithCommittedMessage(self): |
587 change_info = self.mockLoad() | 591 change_info = self.mockLoad() |
588 self.mockPresubmit(change_info, fail=False) | 592 self.mockPresubmit(change_info, fail=False) |
589 self.mockCommit( | 593 self.mockCommit( |
590 change_info, 'deescription\nReview URL: https://my_server/1', | 594 change_info, |
| 595 'deescription\n\nReview URL: https://my_server/1', |
591 '\nCommitted revision 12345') | 596 '\nCommitted revision 12345') |
592 | 597 change_info.UpdateDescriptionFromIssue() |
| 598 change_info.append_footer('Committed: http://view/12345') |
593 self.mox.ReplayAll() | 599 self.mox.ReplayAll() |
594 | 600 |
595 retval = gcl.CMDcommit(['naame']) | 601 retval = gcl.CMDcommit(['naame']) |
596 self.assertEquals(retval, 0) | 602 self.assertEquals(retval, 0) |
597 self.assertEquals(change_info.description, | 603 # This is because append_footer is mocked. |
598 'deescription\n\nCommitted: http://view/12345') | 604 self.assertEquals(change_info.description, 'deescription') |
599 # pylint: disable=W0212 | 605 # pylint: disable=W0212 |
600 self.assertTrue(change_info._deleted) | 606 self.assertTrue(change_info._deleted) |
601 self.assertTrue(change_info._closed) | 607 self.assertTrue(change_info._closed) |
602 self.assertEqual( | 608 self.assertEqual( |
603 change_info._comments_added, | 609 change_info._comments_added, |
604 ["Committed patchset #1 manually as r12345 (presubmit successful)."]) | 610 ["Committed patchset #1 manually as r12345 (presubmit successful)."]) |
605 | 611 |
606 | 612 |
607 if __name__ == '__main__': | 613 if __name__ == '__main__': |
608 import unittest | 614 import unittest |
609 unittest.main() | 615 unittest.main() |
OLD | NEW |