summaryrefslogtreecommitdiffstats
path: root/tools/bionicbb/test_tasks.py
blob: b36cbad59ad4b2ce471119e4567e70152e2246c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import mock
import unittest

import presubmit


class TestShouldSkipBuild(unittest.TestCase):
    @mock.patch('presubmit.contains_bionicbb')
    @mock.patch('presubmit.contains_cleanspec')
    @mock.patch('gerrit.get_commit')
    def test_accepts_googlers(self, mock_commit, *other_checks):
        mock_commit.return_value = {
            'committer': {'email': 'googler@google.com'}
        }

        for other_check in other_checks:
            other_check.return_value = False

        for message_type in ('newchange', 'newpatchset', 'comment'):
            self.assertFalse(presubmit.should_skip_build({
                'MessageType': message_type,
                'Change-Id': '',
                'PatchSet': '',
            }))

    @mock.patch('presubmit.contains_bionicbb')
    @mock.patch('presubmit.contains_cleanspec')
    @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

        for message_type in ('newchange', 'newpatchset', 'comment'):
            self.assertTrue(presubmit.should_skip_build({
                'MessageType': message_type,
                'Change-Id': '',
                'PatchSet': '',
            }))

    @mock.patch('presubmit.contains_bionicbb')
    @mock.patch('presubmit.contains_cleanspec')
    @mock.patch('gerrit.get_commit')
    def test_rejects_non_googlers(self, mock_commit, *other_checks):
        mock_commit.return_value = {
            'committer': {'email': 'johndoe@example.com'}
        }

        for other_check in other_checks:
            other_check.return_value = False

        for message_type in ('newchange', 'newpatchset', 'comment'):
            self.assertTrue(presubmit.should_skip_build({
                'MessageType': message_type,
                'Change-Id': '',
                'PatchSet': '',
            }))

    @mock.patch('presubmit.contains_bionicbb')
    @mock.patch('presubmit.is_untrusted_committer')
    @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

        for message_type in ('newchange', 'newpatchset', 'comment'):
            self.assertTrue(presubmit.should_skip_build({
                'MessageType': message_type,
                'Change-Id': '',
                'PatchSet': '',
            }))

    @mock.patch('presubmit.contains_cleanspec')
    @mock.patch('presubmit.is_untrusted_committer')
    @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'):
            self.assertTrue(presubmit.should_skip_build({
                'MessageType': message_type,
                'Change-Id': '',
                'PatchSet': '',
            }))


if __name__ == '__main__':
    unittest.main()