OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
7 | 7 |
8 # pylint is too confused. | 8 # pylint is too confused. |
9 # pylint: disable=E1101,E1103,W0212,W0403 | 9 # pylint: disable=E1101,E1103,W0212,W0403 |
10 | 10 |
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 self.mox.ReplayAll() | 1860 self.mox.ReplayAll() |
1861 | 1861 |
1862 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( | 1862 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( |
1863 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) | 1863 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) |
1864 self.assertEquals(len(results), 1) | 1864 self.assertEquals(len(results), 1) |
1865 self.assertEquals(results[0].__class__, | 1865 self.assertEquals(results[0].__class__, |
1866 presubmit.OutputApi.PresubmitNotifyResult) | 1866 presubmit.OutputApi.PresubmitNotifyResult) |
1867 | 1867 |
1868 def OwnersTest(self, is_committing, tbr=False, change_tags=None, | 1868 def OwnersTest(self, is_committing, tbr=False, change_tags=None, |
1869 suggested_reviewers=None, approvers=None, | 1869 suggested_reviewers=None, approvers=None, |
1870 uncovered_files=None, expected_reviewers=None, expected_output=''): | 1870 uncovered_files=None, expected_reviewers=None, expected_output='', |
| 1871 host_url=None): |
1871 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 1872 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
1872 affected_file.LocalPath().AndReturn('foo.cc') | 1873 affected_file.LocalPath().AndReturn('foo.cc') |
1873 change = self.mox.CreateMock(presubmit.Change) | 1874 change = self.mox.CreateMock(presubmit.Change) |
1874 change.AffectedFiles(None).AndReturn([affected_file]) | 1875 change.AffectedFiles(None).AndReturn([affected_file]) |
1875 | 1876 |
1876 input_api = self.MockInputApi(change, False) | 1877 input_api = self.MockInputApi(change, False) |
| 1878 if host_url: |
| 1879 input_api.host_url = host_url |
1877 fake_db = self.mox.CreateMock(owners.Database) | 1880 fake_db = self.mox.CreateMock(owners.Database) |
1878 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) | 1881 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) |
1879 input_api.owners_db = fake_db | 1882 input_api.owners_db = fake_db |
1880 input_api.is_committing = is_committing | 1883 input_api.is_committing = is_committing |
1881 input_api.tbr = tbr | 1884 input_api.tbr = tbr |
1882 | 1885 |
1883 if is_committing and not tbr: | 1886 if is_committing and not tbr: |
1884 change.issue = '1' | 1887 change.issue = '1' |
1885 messages = list('{"sender": "' + a + '","text": "lgtm"}' for | 1888 messages = list('{"sender": "' + a + '","text": "lgtm"}' for |
1886 a in approvers) | 1889 a in approvers) |
1887 rietveld_response = ('{"owner": "john@example.com",' | 1890 rietveld_response = ('{"owner": "john@example.com",' |
1888 '"messages": [' + ','.join(messages) + ']}') | 1891 '"messages": [' + ','.join(messages) + ']}') |
1889 input_api.urllib2.urlopen( | 1892 input_api.urllib2.urlopen( |
1890 input_api.host_url + '/api/1?messages=true').AndReturn( | 1893 'http://localhost/api/1?messages=true').AndReturn( |
1891 StringIO.StringIO(rietveld_response)) | 1894 StringIO.StringIO(rietveld_response)) |
1892 input_api.json = presubmit.json | 1895 input_api.json = presubmit.json |
1893 fake_db.files_not_covered_by(set(['foo.cc']), approvers).AndReturn( | 1896 fake_db.files_not_covered_by(set(['foo.cc']), approvers).AndReturn( |
1894 uncovered_files) | 1897 uncovered_files) |
1895 elif not is_committing: | 1898 elif not is_committing: |
1896 change.tags = change_tags | 1899 change.tags = change_tags |
1897 if not change_tags.get('R'): | 1900 if not change_tags.get('R'): |
1898 fake_db.reviewers_for(set(['foo.cc'])).AndReturn(suggested_reviewers) | 1901 fake_db.reviewers_for(set(['foo.cc'])).AndReturn(suggested_reviewers) |
1899 | 1902 |
1900 self.mox.ReplayAll() | 1903 self.mox.ReplayAll() |
(...skipping 29 matching lines...) Expand all Loading... |
1930 self.OwnersTest(is_committing=True, | 1933 self.OwnersTest(is_committing=True, |
1931 approvers=set(['ben@example.com']), | 1934 approvers=set(['ben@example.com']), |
1932 uncovered_files=set()) | 1935 uncovered_files=set()) |
1933 | 1936 |
1934 def testCannedCheckOwners_TBR(self): | 1937 def testCannedCheckOwners_TBR(self): |
1935 self.OwnersTest(is_committing=True, tbr=True, | 1938 self.OwnersTest(is_committing=True, tbr=True, |
1936 approvers=set(), | 1939 approvers=set(), |
1937 uncovered_files=set(), | 1940 uncovered_files=set(), |
1938 expected_output='--tbr was specified, skipping OWNERS check\n') | 1941 expected_output='--tbr was specified, skipping OWNERS check\n') |
1939 | 1942 |
| 1943 def testCannedCheckOwners_MissingSchemeInHostURL(self): |
| 1944 self.OwnersTest(is_committing=True, |
| 1945 approvers=set(['ben@example.com']), |
| 1946 uncovered_files=set(), host_url='localhost') |
| 1947 |
| 1948 |
1940 if __name__ == '__main__': | 1949 if __name__ == '__main__': |
1941 import unittest | 1950 import unittest |
1942 unittest.main() | 1951 unittest.main() |
OLD | NEW |