| Dan Albert | b406033 | 2015-01-12 16:23:53 -0800 | [diff] [blame] | 1 | import mock | 
| Dan Albert | ad248b7 | 2015-01-12 12:25:31 -0800 | [diff] [blame] | 2 | import unittest | 
|  | 3 |  | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 4 | import presubmit | 
|  | 5 |  | 
| Dan Albert | ad248b7 | 2015-01-12 12:25:31 -0800 | [diff] [blame] | 6 |  | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 7 | class TestShouldSkipBuild(unittest.TestCase): | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 8 | @mock.patch('presubmit.contains_bionicbb') | 
|  | 9 | @mock.patch('presubmit.contains_cleanspec') | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 10 | @mock.patch('gerrit.get_commit') | 
|  | 11 | def test_accepts_googlers(self, mock_commit, *other_checks): | 
|  | 12 | mock_commit.return_value = { | 
|  | 13 | 'committer': {'email': 'googler@google.com'} | 
|  | 14 | } | 
|  | 15 |  | 
|  | 16 | for other_check in other_checks: | 
|  | 17 | other_check.return_value = False | 
|  | 18 |  | 
| Dan Albert | b406033 | 2015-01-12 16:23:53 -0800 | [diff] [blame] | 19 | for message_type in ('newchange', 'newpatchset', 'comment'): | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 20 | self.assertFalse(presubmit.should_skip_build({ | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 21 | 'MessageType': message_type, | 
|  | 22 | 'Change-Id': '', | 
|  | 23 | 'PatchSet': '', | 
|  | 24 | })) | 
| Dan Albert | ad248b7 | 2015-01-12 12:25:31 -0800 | [diff] [blame] | 25 |  | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 26 | @mock.patch('presubmit.contains_bionicbb') | 
|  | 27 | @mock.patch('presubmit.contains_cleanspec') | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 28 | @mock.patch('gerrit.get_commit') | 
|  | 29 | def test_rejects_googlish_domains(self, mock_commit, *other_checks): | 
|  | 30 | mock_commit.return_value = { | 
|  | 31 | 'committer': {'email': 'fakegoogler@google.com.fake.com'} | 
|  | 32 | } | 
| Dan Albert | ad248b7 | 2015-01-12 12:25:31 -0800 | [diff] [blame] | 33 |  | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 34 | for other_check in other_checks: | 
|  | 35 | other_check.return_value = False | 
|  | 36 |  | 
| Dan Albert | b406033 | 2015-01-12 16:23:53 -0800 | [diff] [blame] | 37 | for message_type in ('newchange', 'newpatchset', 'comment'): | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 38 | self.assertTrue(presubmit.should_skip_build({ | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 39 | 'MessageType': message_type, | 
|  | 40 | 'Change-Id': '', | 
|  | 41 | 'PatchSet': '', | 
|  | 42 | })) | 
| Dan Albert | b406033 | 2015-01-12 16:23:53 -0800 | [diff] [blame] | 43 |  | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 44 | @mock.patch('presubmit.contains_bionicbb') | 
|  | 45 | @mock.patch('presubmit.contains_cleanspec') | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 46 | @mock.patch('gerrit.get_commit') | 
|  | 47 | def test_rejects_non_googlers(self, mock_commit, *other_checks): | 
|  | 48 | mock_commit.return_value = { | 
|  | 49 | 'committer': {'email': 'johndoe@example.com'} | 
|  | 50 | } | 
| Dan Albert | b406033 | 2015-01-12 16:23:53 -0800 | [diff] [blame] | 51 |  | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 52 | for other_check in other_checks: | 
|  | 53 | other_check.return_value = False | 
| Dan Albert | b406033 | 2015-01-12 16:23:53 -0800 | [diff] [blame] | 54 |  | 
| Dan Albert | b406033 | 2015-01-12 16:23:53 -0800 | [diff] [blame] | 55 | for message_type in ('newchange', 'newpatchset', 'comment'): | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 56 | self.assertTrue(presubmit.should_skip_build({ | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 57 | 'MessageType': message_type, | 
|  | 58 | 'Change-Id': '', | 
|  | 59 | 'PatchSet': '', | 
|  | 60 | })) | 
| Dan Albert | b406033 | 2015-01-12 16:23:53 -0800 | [diff] [blame] | 61 |  | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 62 | @mock.patch('presubmit.contains_bionicbb') | 
|  | 63 | @mock.patch('presubmit.is_untrusted_committer') | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 64 | @mock.patch('gerrit.get_files_for_revision') | 
|  | 65 | def test_skips_cleanspecs(self, mock_files, *other_checks): | 
|  | 66 | mock_files.return_value = ['foo/CleanSpec.mk'] | 
|  | 67 | for other_check in other_checks: | 
|  | 68 | other_check.return_value = False | 
|  | 69 |  | 
|  | 70 | for message_type in ('newchange', 'newpatchset', 'comment'): | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 71 | self.assertTrue(presubmit.should_skip_build({ | 
| Dan Albert | dadac10 | 2015-04-06 12:43:55 -0700 | [diff] [blame] | 72 | 'MessageType': message_type, | 
|  | 73 | 'Change-Id': '', | 
|  | 74 | 'PatchSet': '', | 
|  | 75 | })) | 
| Dan Albert | ad248b7 | 2015-01-12 12:25:31 -0800 | [diff] [blame] | 76 |  | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 77 | @mock.patch('presubmit.contains_cleanspec') | 
|  | 78 | @mock.patch('presubmit.is_untrusted_committer') | 
| Dan Albert | d032378 | 2015-04-09 17:18:53 -0700 | [diff] [blame] | 79 | @mock.patch('gerrit.get_files_for_revision') | 
|  | 80 | def test_skips_bionicbb(self, mock_files, *other_checks): | 
|  | 81 | mock_files.return_value = ['tools/bionicbb/common.sh'] | 
|  | 82 | for other_check in other_checks: | 
|  | 83 | other_check.return_value = False | 
|  | 84 |  | 
|  | 85 | for message_type in ('newchange', 'newpatchset', 'comment'): | 
| Dan Albert | d3fe4f1 | 2015-04-17 13:01:29 -0700 | [diff] [blame] | 86 | self.assertTrue(presubmit.should_skip_build({ | 
| Dan Albert | d032378 | 2015-04-09 17:18:53 -0700 | [diff] [blame] | 87 | 'MessageType': message_type, | 
|  | 88 | 'Change-Id': '', | 
|  | 89 | 'PatchSet': '', | 
|  | 90 | })) | 
|  | 91 |  | 
| Dan Albert | ad248b7 | 2015-01-12 12:25:31 -0800 | [diff] [blame] | 92 |  | 
|  | 93 | if __name__ == '__main__': | 
|  | 94 | unittest.main() |