2015-01-13 01:23:53 +01:00
|
|
|
import mock
|
2015-01-12 21:25:31 +01:00
|
|
|
import unittest
|
|
|
|
|
2015-04-17 22:01:29 +02:00
|
|
|
import presubmit
|
|
|
|
|
2015-01-12 21:25:31 +01:00
|
|
|
|
2015-04-06 21:43:55 +02:00
|
|
|
class TestShouldSkipBuild(unittest.TestCase):
|
2015-04-17 22:01:29 +02:00
|
|
|
@mock.patch('presubmit.contains_bionicbb')
|
|
|
|
@mock.patch('presubmit.contains_cleanspec')
|
2015-04-06 21:43:55 +02:00
|
|
|
@mock.patch('gerrit.get_commit')
|
|
|
|
def test_accepts_googlers(self, mock_commit, *other_checks):
|
|
|
|
mock_commit.return_value = {
|
|
|
|
'committer': {'email': 'googler@google.com'}
|
|
|
|
}
|
2015-01-12 21:25:31 +01:00
|
|
|
|
2015-04-06 21:43:55 +02:00
|
|
|
for other_check in other_checks:
|
|
|
|
other_check.return_value = False
|
2015-01-12 21:25:31 +01:00
|
|
|
|
2015-01-13 01:23:53 +01:00
|
|
|
for message_type in ('newchange', 'newpatchset', 'comment'):
|
2015-04-17 22:01:29 +02:00
|
|
|
self.assertFalse(presubmit.should_skip_build({
|
2015-04-06 21:43:55 +02:00
|
|
|
'MessageType': message_type,
|
|
|
|
'Change-Id': '',
|
|
|
|
'PatchSet': '',
|
|
|
|
}))
|
|
|
|
|
2015-04-17 22:01:29 +02:00
|
|
|
@mock.patch('presubmit.contains_bionicbb')
|
|
|
|
@mock.patch('presubmit.contains_cleanspec')
|
2015-04-06 21:43:55 +02:00
|
|
|
@mock.patch('gerrit.get_commit')
|
|
|
|
def test_rejects_googlish_domains(self, mock_commit, *other_checks):
|
|
|
|
mock_commit.return_value = {
|
|
|
|
'committer': {'email': 'fakegoogler@google.com.fake.com'}
|
|
|
|
}
|
|
|
|
|
|
|
|
for other_check in other_checks:
|
|
|
|
other_check.return_value = False
|
2015-01-13 01:23:53 +01:00
|
|
|
|
2015-04-06 21:43:55 +02:00
|
|
|
for message_type in ('newchange', 'newpatchset', 'comment'):
|
2015-04-17 22:01:29 +02:00
|
|
|
self.assertTrue(presubmit.should_skip_build({
|
2015-04-06 21:43:55 +02:00
|
|
|
'MessageType': message_type,
|
|
|
|
'Change-Id': '',
|
|
|
|
'PatchSet': '',
|
|
|
|
}))
|
2015-01-13 01:23:53 +01:00
|
|
|
|
2015-04-17 22:01:29 +02:00
|
|
|
@mock.patch('presubmit.contains_bionicbb')
|
|
|
|
@mock.patch('presubmit.contains_cleanspec')
|
2015-04-06 21:43:55 +02:00
|
|
|
@mock.patch('gerrit.get_commit')
|
|
|
|
def test_rejects_non_googlers(self, mock_commit, *other_checks):
|
|
|
|
mock_commit.return_value = {
|
|
|
|
'committer': {'email': 'johndoe@example.com'}
|
|
|
|
}
|
2015-01-13 01:23:53 +01:00
|
|
|
|
2015-04-06 21:43:55 +02:00
|
|
|
for other_check in other_checks:
|
|
|
|
other_check.return_value = False
|
2015-01-13 01:23:53 +01:00
|
|
|
|
|
|
|
for message_type in ('newchange', 'newpatchset', 'comment'):
|
2015-04-17 22:01:29 +02:00
|
|
|
self.assertTrue(presubmit.should_skip_build({
|
2015-04-06 21:43:55 +02:00
|
|
|
'MessageType': message_type,
|
|
|
|
'Change-Id': '',
|
|
|
|
'PatchSet': '',
|
|
|
|
}))
|
|
|
|
|
2015-04-17 22:01:29 +02:00
|
|
|
@mock.patch('presubmit.contains_bionicbb')
|
|
|
|
@mock.patch('presubmit.is_untrusted_committer')
|
2015-04-06 21:43:55 +02:00
|
|
|
@mock.patch('gerrit.get_files_for_revision')
|
|
|
|
def test_skips_cleanspecs(self, mock_files, *other_checks):
|
|
|
|
mock_files.return_value = ['foo/CleanSpec.mk']
|
|
|
|
for other_check in other_checks:
|
|
|
|
other_check.return_value = False
|
2015-01-13 01:23:53 +01:00
|
|
|
|
2015-04-06 21:43:55 +02:00
|
|
|
for message_type in ('newchange', 'newpatchset', 'comment'):
|
2015-04-17 22:01:29 +02:00
|
|
|
self.assertTrue(presubmit.should_skip_build({
|
2015-04-06 21:43:55 +02:00
|
|
|
'MessageType': message_type,
|
|
|
|
'Change-Id': '',
|
|
|
|
'PatchSet': '',
|
|
|
|
}))
|
2015-01-12 21:25:31 +01:00
|
|
|
|
2015-04-17 22:01:29 +02:00
|
|
|
@mock.patch('presubmit.contains_cleanspec')
|
|
|
|
@mock.patch('presubmit.is_untrusted_committer')
|
2015-04-10 02:18:53 +02:00
|
|
|
@mock.patch('gerrit.get_files_for_revision')
|
|
|
|
def test_skips_bionicbb(self, mock_files, *other_checks):
|
|
|
|
mock_files.return_value = ['tools/bionicbb/common.sh']
|
|
|
|
for other_check in other_checks:
|
|
|
|
other_check.return_value = False
|
|
|
|
|
|
|
|
for message_type in ('newchange', 'newpatchset', 'comment'):
|
2015-04-17 22:01:29 +02:00
|
|
|
self.assertTrue(presubmit.should_skip_build({
|
2015-04-10 02:18:53 +02:00
|
|
|
'MessageType': message_type,
|
|
|
|
'Change-Id': '',
|
|
|
|
'PatchSet': '',
|
|
|
|
}))
|
|
|
|
|
2015-01-12 21:25:31 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|