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 git_cl.py.""" | 6 """Unit tests for git_cl.py.""" |
7 | 7 |
8 import os | 8 import os |
9 import StringIO | 9 import StringIO |
| 10 import stat |
10 import sys | 11 import sys |
11 import unittest | 12 import unittest |
12 | 13 |
13 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 14 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
14 | 15 |
15 from testing_support.auto_stub import TestCase | 16 from testing_support.auto_stub import TestCase |
16 | 17 |
17 import git_cl | 18 import git_cl |
18 import subprocess2 | 19 import subprocess2 |
19 | 20 |
(...skipping 15 matching lines...) Expand all Loading... |
35 | 36 |
36 | 37 |
37 class WatchlistsMock(object): | 38 class WatchlistsMock(object): |
38 def __init__(self, _): | 39 def __init__(self, _): |
39 pass | 40 pass |
40 @staticmethod | 41 @staticmethod |
41 def GetWatchersForPaths(_): | 42 def GetWatchersForPaths(_): |
42 return ['joe@example.com'] | 43 return ['joe@example.com'] |
43 | 44 |
44 | 45 |
| 46 class CodereviewSettingsFileMock(object): |
| 47 def __init__(self): |
| 48 pass |
| 49 def read(self): |
| 50 return ("CODE_REVIEW_SERVER: gerrit.chromium.org\n" + |
| 51 "GERRIT_HOST: gerrit.chromium.org\n" + |
| 52 "GERRIT_PORT: 29418\n") |
| 53 |
| 54 |
45 class TestGitCl(TestCase): | 55 class TestGitCl(TestCase): |
46 def setUp(self): | 56 def setUp(self): |
47 super(TestGitCl, self).setUp() | 57 super(TestGitCl, self).setUp() |
48 self.calls = [] | 58 self.calls = [] |
49 self._calls_done = 0 | 59 self._calls_done = 0 |
50 self.mock(subprocess2, 'call', self._mocked_call) | 60 self.mock(subprocess2, 'call', self._mocked_call) |
51 self.mock(subprocess2, 'check_call', self._mocked_call) | 61 self.mock(subprocess2, 'check_call', self._mocked_call) |
52 self.mock(subprocess2, 'check_output', self._mocked_call) | 62 self.mock(subprocess2, 'check_output', self._mocked_call) |
53 self.mock(subprocess2, 'communicate', self._mocked_call) | 63 self.mock(subprocess2, 'communicate', self._mocked_call) |
54 self.mock(subprocess2, 'Popen', self._mocked_call) | 64 self.mock(subprocess2, 'Popen', self._mocked_call) |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 'desc\n\nBUG=\nTEST=\n', | 396 'desc\n\nBUG=\nTEST=\n', |
387 ['foo@example.com']) | 397 ['foo@example.com']) |
388 | 398 |
389 def test_gerrit_reviewer_multiple(self): | 399 def test_gerrit_reviewer_multiple(self): |
390 self._run_gerrit_reviewer_test( | 400 self._run_gerrit_reviewer_test( |
391 [], | 401 [], |
392 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n', | 402 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n', |
393 ['reviewer@example.com', 'another@example.com']) | 403 ['reviewer@example.com', 'another@example.com']) |
394 | 404 |
395 | 405 |
| 406 def test_config_gerrit_download_hook(self): |
| 407 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) |
| 408 def ParseCodereviewSettingsContent(content): |
| 409 keyvals = {} |
| 410 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' |
| 411 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' |
| 412 keyvals['GERRIT_PORT'] = '29418' |
| 413 return keyvals |
| 414 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', |
| 415 ParseCodereviewSettingsContent) |
| 416 self.mock(git_cl.os, 'access', self._mocked_call) |
| 417 self.mock(git_cl.os, 'chmod', self._mocked_call) |
| 418 def AbsPath(path): |
| 419 if not path.startswith('/'): |
| 420 return os.path.join('/usr/local/src', path) |
| 421 return path |
| 422 self.mock(git_cl.os.path, 'abspath', AbsPath) |
| 423 def Exists(path): |
| 424 if path == '/usr/local/src/.git/hooks/commit-msg': |
| 425 return False |
| 426 # others paths, such as /usr/share/locale/.... |
| 427 return True |
| 428 self.mock(git_cl.os.path, 'exists', Exists) |
| 429 self.mock(git_cl.urllib, 'urlretrieve', self._mocked_call) |
| 430 self.calls = [ |
| 431 ((['git', 'config', 'rietveld.server', 'gerrit.chromium.org'],), ''), |
| 432 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), |
| 433 ((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), ''), |
| 434 ((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), ''), |
| 435 ((['git', 'config', 'gerrit.host', 'gerrit.chromium.org'],), ''), |
| 436 ((['git', 'config', 'gerrit.port', '29418'],), ''), |
| 437 ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), |
| 438 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), |
| 439 ''), |
| 440 ((['git', 'config', 'rietveld.cc'],), ''), |
| 441 (('CC list:',), ''), |
| 442 ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
| 443 (('Tree status URL:',), ''), |
| 444 ((['git', 'config', 'rietveld.viewvc-url'],), ''), |
| 445 (('ViewVC URL:',), ''), |
| 446 ((['git', 'config', 'gerrit.host'],), 'gerrit.chromium.org'), |
| 447 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 448 (('/usr/local/src/.git/hooks/commit-msg', os.X_OK,), False), |
| 449 (('https://gerrit.chromium.org/tools/hooks/commit-msg', |
| 450 '/usr/local/src/.git/hooks/commit-msg',), ''), |
| 451 (('/usr/local/src/.git/hooks/commit-msg', |
| 452 stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), '') |
| 453 ] |
| 454 git_cl.main(['config']) |
| 455 |
| 456 |
396 if __name__ == '__main__': | 457 if __name__ == '__main__': |
397 unittest.main() | 458 unittest.main() |
OLD | NEW |