blob: b36cbad59ad4b2ce471119e4567e70152e2246c4 [file] [log] [blame]
Dan Albertb4060332015-01-12 16:23:53 -08001import mock
Dan Albertad248b72015-01-12 12:25:31 -08002import unittest
3
Dan Albertd3fe4f12015-04-17 13:01:29 -07004import presubmit
5
Dan Albertad248b72015-01-12 12:25:31 -08006
Dan Albertdadac102015-04-06 12:43:55 -07007class TestShouldSkipBuild(unittest.TestCase):
Dan Albertd3fe4f12015-04-17 13:01:29 -07008 @mock.patch('presubmit.contains_bionicbb')
9 @mock.patch('presubmit.contains_cleanspec')
Dan Albertdadac102015-04-06 12:43:55 -070010 @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 Albertb4060332015-01-12 16:23:53 -080019 for message_type in ('newchange', 'newpatchset', 'comment'):
Dan Albertd3fe4f12015-04-17 13:01:29 -070020 self.assertFalse(presubmit.should_skip_build({
Dan Albertdadac102015-04-06 12:43:55 -070021 'MessageType': message_type,
22 'Change-Id': '',
23 'PatchSet': '',
24 }))
Dan Albertad248b72015-01-12 12:25:31 -080025
Dan Albertd3fe4f12015-04-17 13:01:29 -070026 @mock.patch('presubmit.contains_bionicbb')
27 @mock.patch('presubmit.contains_cleanspec')
Dan Albertdadac102015-04-06 12:43:55 -070028 @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 Albertad248b72015-01-12 12:25:31 -080033
Dan Albertdadac102015-04-06 12:43:55 -070034 for other_check in other_checks:
35 other_check.return_value = False
36
Dan Albertb4060332015-01-12 16:23:53 -080037 for message_type in ('newchange', 'newpatchset', 'comment'):
Dan Albertd3fe4f12015-04-17 13:01:29 -070038 self.assertTrue(presubmit.should_skip_build({
Dan Albertdadac102015-04-06 12:43:55 -070039 'MessageType': message_type,
40 'Change-Id': '',
41 'PatchSet': '',
42 }))
Dan Albertb4060332015-01-12 16:23:53 -080043
Dan Albertd3fe4f12015-04-17 13:01:29 -070044 @mock.patch('presubmit.contains_bionicbb')
45 @mock.patch('presubmit.contains_cleanspec')
Dan Albertdadac102015-04-06 12:43:55 -070046 @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 Albertb4060332015-01-12 16:23:53 -080051
Dan Albertdadac102015-04-06 12:43:55 -070052 for other_check in other_checks:
53 other_check.return_value = False
Dan Albertb4060332015-01-12 16:23:53 -080054
Dan Albertb4060332015-01-12 16:23:53 -080055 for message_type in ('newchange', 'newpatchset', 'comment'):
Dan Albertd3fe4f12015-04-17 13:01:29 -070056 self.assertTrue(presubmit.should_skip_build({
Dan Albertdadac102015-04-06 12:43:55 -070057 'MessageType': message_type,
58 'Change-Id': '',
59 'PatchSet': '',
60 }))
Dan Albertb4060332015-01-12 16:23:53 -080061
Dan Albertd3fe4f12015-04-17 13:01:29 -070062 @mock.patch('presubmit.contains_bionicbb')
63 @mock.patch('presubmit.is_untrusted_committer')
Dan Albertdadac102015-04-06 12:43:55 -070064 @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 Albertd3fe4f12015-04-17 13:01:29 -070071 self.assertTrue(presubmit.should_skip_build({
Dan Albertdadac102015-04-06 12:43:55 -070072 'MessageType': message_type,
73 'Change-Id': '',
74 'PatchSet': '',
75 }))
Dan Albertad248b72015-01-12 12:25:31 -080076
Dan Albertd3fe4f12015-04-17 13:01:29 -070077 @mock.patch('presubmit.contains_cleanspec')
78 @mock.patch('presubmit.is_untrusted_committer')
Dan Albertd0323782015-04-09 17:18:53 -070079 @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 Albertd3fe4f12015-04-17 13:01:29 -070086 self.assertTrue(presubmit.should_skip_build({
Dan Albertd0323782015-04-09 17:18:53 -070087 'MessageType': message_type,
88 'Change-Id': '',
89 'PatchSet': '',
90 }))
91
Dan Albertad248b72015-01-12 12:25:31 -080092
93if __name__ == '__main__':
94 unittest.main()