blob: ff39fd74c56f3b73ab88af2cf25c56296f1eafb2 [file] [log] [blame]
James E. Blair9c17dbf2014-06-23 14:21:58 -07001#!/usr/bin/env python
2
3# Copyright 2012-2014 Hewlett-Packard Development Company, L.P.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
James E. Blair9c17dbf2014-06-23 14:21:58 -070017import time
18
19from tests.base import ZuulTestCase
20
James E. Blair9c17dbf2014-06-23 14:21:58 -070021
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110022class TestRequirementsApprovalNewerThan(ZuulTestCase):
23 """Requirements with a newer-than comment requirement"""
James E. Blair9c17dbf2014-06-23 14:21:58 -070024
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110025 tenant_config_file = 'config/requirements/newer-than/main.yaml'
26
James E. Blair9c17dbf2014-06-23 14:21:58 -070027 def test_pipeline_require_approval_newer_than(self):
28 "Test pipeline requirement: approval newer than"
29 return self._test_require_approval_newer_than('org/project1',
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110030 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070031
32 def test_trigger_require_approval_newer_than(self):
33 "Test trigger requirement: approval newer than"
34 return self._test_require_approval_newer_than('org/project2',
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110035 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070036
37 def _test_require_approval_newer_than(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -070038 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
39 # A comment event that we will keep submitting to trigger
Tobias Henkelbf24fd12017-07-27 06:13:07 +020040 comment = A.addApproval('Code-Review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -070041 self.fake_gerrit.addEvent(comment)
42 self.waitUntilSettled()
43 # No +1 from Jenkins so should not be enqueued
44 self.assertEqual(len(self.history), 0)
45
46 # Add a too-old +1, should not be enqueued
Tobias Henkelbf24fd12017-07-27 06:13:07 +020047 A.addApproval('Verified', 1, username='jenkins',
Joshua Hesketh642824b2014-07-01 17:54:59 +100048 granted_on=time.time() - 72 * 60 * 60)
James E. Blair9c17dbf2014-06-23 14:21:58 -070049 self.fake_gerrit.addEvent(comment)
50 self.waitUntilSettled()
51 self.assertEqual(len(self.history), 0)
52
53 # Add a recent +1
Tobias Henkelbf24fd12017-07-27 06:13:07 +020054 self.fake_gerrit.addEvent(A.addApproval('Verified', 1,
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110055 username='jenkins'))
James E. Blair9c17dbf2014-06-23 14:21:58 -070056 self.fake_gerrit.addEvent(comment)
57 self.waitUntilSettled()
58 self.assertEqual(len(self.history), 1)
59 self.assertEqual(self.history[0].name, job)
60
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110061
Jamie Lennox8faa71e2016-11-23 14:33:52 +110062class TestRequirementsApprovalOlderThan(ZuulTestCase):
63 """Requirements with a older-than comment requirement"""
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110064
Jamie Lennox8faa71e2016-11-23 14:33:52 +110065 tenant_config_file = 'config/requirements/older-than/main.yaml'
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110066
James E. Blair9c17dbf2014-06-23 14:21:58 -070067 def test_pipeline_require_approval_older_than(self):
68 "Test pipeline requirement: approval older than"
69 return self._test_require_approval_older_than('org/project1',
Jamie Lennox8faa71e2016-11-23 14:33:52 +110070 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070071
72 def test_trigger_require_approval_older_than(self):
73 "Test trigger requirement: approval older than"
74 return self._test_require_approval_older_than('org/project2',
Jamie Lennox8faa71e2016-11-23 14:33:52 +110075 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070076
77 def _test_require_approval_older_than(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -070078 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
79 # A comment event that we will keep submitting to trigger
Tobias Henkelbf24fd12017-07-27 06:13:07 +020080 comment = A.addApproval('Code-Review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -070081 self.fake_gerrit.addEvent(comment)
82 self.waitUntilSettled()
83 # No +1 from Jenkins so should not be enqueued
84 self.assertEqual(len(self.history), 0)
85
86 # Add a recent +1 which should not be enqueued
Tobias Henkelbf24fd12017-07-27 06:13:07 +020087 A.addApproval('Verified', 1)
James E. Blair9c17dbf2014-06-23 14:21:58 -070088 self.fake_gerrit.addEvent(comment)
89 self.waitUntilSettled()
90 self.assertEqual(len(self.history), 0)
91
92 # Add an old +1 which should be enqueued
Tobias Henkelbf24fd12017-07-27 06:13:07 +020093 A.addApproval('Verified', 1, username='jenkins',
Joshua Hesketh642824b2014-07-01 17:54:59 +100094 granted_on=time.time() - 72 * 60 * 60)
James E. Blair9c17dbf2014-06-23 14:21:58 -070095 self.fake_gerrit.addEvent(comment)
96 self.waitUntilSettled()
97 self.assertEqual(len(self.history), 1)
98 self.assertEqual(self.history[0].name, job)
99
Jamie Lennox8faa71e2016-11-23 14:33:52 +1100100
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100101class TestRequirementsUserName(ZuulTestCase):
102 """Requirements with a username requirement"""
Jamie Lennox8faa71e2016-11-23 14:33:52 +1100103
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100104 tenant_config_file = 'config/requirements/username/main.yaml'
Jamie Lennox8faa71e2016-11-23 14:33:52 +1100105
James E. Blair9c17dbf2014-06-23 14:21:58 -0700106 def test_pipeline_require_approval_username(self):
107 "Test pipeline requirement: approval username"
108 return self._test_require_approval_username('org/project1',
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100109 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700110
111 def test_trigger_require_approval_username(self):
112 "Test trigger requirement: approval username"
113 return self._test_require_approval_username('org/project2',
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100114 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700115
116 def _test_require_approval_username(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700117 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
118 # A comment event that we will keep submitting to trigger
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200119 comment = A.addApproval('Code-Review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700120 self.fake_gerrit.addEvent(comment)
121 self.waitUntilSettled()
122 # No approval from Jenkins so should not be enqueued
123 self.assertEqual(len(self.history), 0)
124
125 # Add an approval from Jenkins
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200126 A.addApproval('Verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700127 self.fake_gerrit.addEvent(comment)
128 self.waitUntilSettled()
129 self.assertEqual(len(self.history), 1)
130 self.assertEqual(self.history[0].name, job)
131
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100132
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100133class TestRequirementsEmail(ZuulTestCase):
134 """Requirements with a email requirement"""
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100135
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100136 tenant_config_file = 'config/requirements/email/main.yaml'
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100137
James E. Blair9c17dbf2014-06-23 14:21:58 -0700138 def test_pipeline_require_approval_email(self):
139 "Test pipeline requirement: approval email"
140 return self._test_require_approval_email('org/project1',
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100141 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700142
143 def test_trigger_require_approval_email(self):
144 "Test trigger requirement: approval email"
145 return self._test_require_approval_email('org/project2',
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100146 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700147
148 def _test_require_approval_email(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700149 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
150 # A comment event that we will keep submitting to trigger
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200151 comment = A.addApproval('Code-Review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700152 self.fake_gerrit.addEvent(comment)
153 self.waitUntilSettled()
154 # No approval from Jenkins so should not be enqueued
155 self.assertEqual(len(self.history), 0)
156
157 # Add an approval from Jenkins
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200158 A.addApproval('Verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700159 self.fake_gerrit.addEvent(comment)
160 self.waitUntilSettled()
161 self.assertEqual(len(self.history), 1)
162 self.assertEqual(self.history[0].name, job)
163
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100164
Jamie Lennox8ce65582016-11-23 15:20:39 +1100165class TestRequirementsVote1(ZuulTestCase):
166 """Requirements with a voting requirement"""
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100167
Jamie Lennox8ce65582016-11-23 15:20:39 +1100168 tenant_config_file = 'config/requirements/vote1/main.yaml'
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100169
James E. Blair9c17dbf2014-06-23 14:21:58 -0700170 def test_pipeline_require_approval_vote1(self):
171 "Test pipeline requirement: approval vote with one value"
172 return self._test_require_approval_vote1('org/project1',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100173 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700174
175 def test_trigger_require_approval_vote1(self):
176 "Test trigger requirement: approval vote with one value"
177 return self._test_require_approval_vote1('org/project2',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100178 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700179
180 def _test_require_approval_vote1(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700181 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
182 # A comment event that we will keep submitting to trigger
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200183 comment = A.addApproval('Code-Review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700184 self.fake_gerrit.addEvent(comment)
185 self.waitUntilSettled()
186 # No approval from Jenkins so should not be enqueued
187 self.assertEqual(len(self.history), 0)
188
189 # A -1 from jenkins should not cause it to be enqueued
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200190 A.addApproval('Verified', -1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700191 self.fake_gerrit.addEvent(comment)
192 self.waitUntilSettled()
193 self.assertEqual(len(self.history), 0)
194
195 # A +1 should allow it to be enqueued
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200196 A.addApproval('Verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700197 self.fake_gerrit.addEvent(comment)
198 self.waitUntilSettled()
199 self.assertEqual(len(self.history), 1)
200 self.assertEqual(self.history[0].name, job)
201
Jamie Lennox8ce65582016-11-23 15:20:39 +1100202
203class TestRequirementsVote2(ZuulTestCase):
204 """Requirements with a voting requirement"""
205
206 tenant_config_file = 'config/requirements/vote2/main.yaml'
207
James E. Blair9c17dbf2014-06-23 14:21:58 -0700208 def test_pipeline_require_approval_vote2(self):
209 "Test pipeline requirement: approval vote with two values"
210 return self._test_require_approval_vote2('org/project1',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100211 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700212
213 def test_trigger_require_approval_vote2(self):
214 "Test trigger requirement: approval vote with two values"
215 return self._test_require_approval_vote2('org/project2',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100216 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700217
218 def _test_require_approval_vote2(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700219 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
220 # A comment event that we will keep submitting to trigger
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200221 comment = A.addApproval('Code-Review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700222 self.fake_gerrit.addEvent(comment)
223 self.waitUntilSettled()
224 # No approval from Jenkins so should not be enqueued
225 self.assertEqual(len(self.history), 0)
226
227 # A -1 from jenkins should not cause it to be enqueued
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200228 A.addApproval('Verified', -1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700229 self.fake_gerrit.addEvent(comment)
230 self.waitUntilSettled()
231 self.assertEqual(len(self.history), 0)
232
233 # A -2 from jenkins should not cause it to be enqueued
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200234 A.addApproval('Verified', -2, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700235 self.fake_gerrit.addEvent(comment)
236 self.waitUntilSettled()
237 self.assertEqual(len(self.history), 0)
238
Joshua Hesketh642824b2014-07-01 17:54:59 +1000239 # A +1 from jenkins should allow it to be enqueued
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200240 A.addApproval('Verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700241 self.fake_gerrit.addEvent(comment)
242 self.waitUntilSettled()
243 self.assertEqual(len(self.history), 1)
244 self.assertEqual(self.history[0].name, job)
245
Jesse Keating2dfc6512017-01-19 14:31:44 -0800246 # A +2 from nobody should not cause it to be enqueued
James E. Blair9c17dbf2014-06-23 14:21:58 -0700247 B = self.fake_gerrit.addFakeChange(project, 'master', 'B')
248 # A comment event that we will keep submitting to trigger
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200249 comment = B.addApproval('Code-Review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700250 self.fake_gerrit.addEvent(comment)
251 self.waitUntilSettled()
252 self.assertEqual(len(self.history), 1)
253
Jesse Keating2dfc6512017-01-19 14:31:44 -0800254 # A +2 from jenkins should allow it to be enqueued
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200255 B.addApproval('Verified', 2, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700256 self.fake_gerrit.addEvent(comment)
257 self.waitUntilSettled()
258 self.assertEqual(len(self.history), 2)
259 self.assertEqual(self.history[1].name, job)
260
Jamie Lennox8ce65582016-11-23 15:20:39 +1100261
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100262class TestRequirementsState(ZuulTestCase):
263 """Requirements with simple state requirement"""
Jamie Lennox8ce65582016-11-23 15:20:39 +1100264
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100265 tenant_config_file = 'config/requirements/state/main.yaml'
Jamie Lennox8ce65582016-11-23 15:20:39 +1100266
James E. Blair9c17dbf2014-06-23 14:21:58 -0700267 def test_pipeline_require_current_patchset(self):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700268 # Create two patchsets and let their tests settle out. Then
269 # comment on first patchset and check that no additional
270 # jobs are run.
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100271 A = self.fake_gerrit.addFakeChange('current-project', 'master', 'A')
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200272 self.fake_gerrit.addEvent(A.addApproval('Code-Review', 1))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700273 self.waitUntilSettled()
274 A.addPatchset()
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200275 self.fake_gerrit.addEvent(A.addApproval('Code-Review', 1))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700276 self.waitUntilSettled()
277
278 self.assertEqual(len(self.history), 2) # one job for each ps
279 self.fake_gerrit.addEvent(A.getChangeCommentEvent(1))
280 self.waitUntilSettled()
281
282 # Assert no new jobs ran after event for old patchset.
283 self.assertEqual(len(self.history), 2)
284
285 # Make sure the same event on a new PS will trigger
286 self.fake_gerrit.addEvent(A.getChangeCommentEvent(2))
287 self.waitUntilSettled()
288 self.assertEqual(len(self.history), 3)
289
290 def test_pipeline_require_open(self):
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100291 A = self.fake_gerrit.addFakeChange('open-project', 'master', 'A',
James E. Blair9c17dbf2014-06-23 14:21:58 -0700292 status='MERGED')
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200293 self.fake_gerrit.addEvent(A.addApproval('Code-Review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700294 self.waitUntilSettled()
295 self.assertEqual(len(self.history), 0)
296
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100297 B = self.fake_gerrit.addFakeChange('open-project', 'master', 'B')
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200298 self.fake_gerrit.addEvent(B.addApproval('Code-Review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700299 self.waitUntilSettled()
300 self.assertEqual(len(self.history), 1)
301
302 def test_pipeline_require_status(self):
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100303 A = self.fake_gerrit.addFakeChange('status-project', 'master', 'A',
James E. Blair9c17dbf2014-06-23 14:21:58 -0700304 status='MERGED')
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200305 self.fake_gerrit.addEvent(A.addApproval('Code-Review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700306 self.waitUntilSettled()
307 self.assertEqual(len(self.history), 0)
308
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100309 B = self.fake_gerrit.addFakeChange('status-project', 'master', 'B')
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200310 self.fake_gerrit.addEvent(B.addApproval('Code-Review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700311 self.waitUntilSettled()
312 self.assertEqual(len(self.history), 1)
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000313
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100314
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100315class TestRequirementsRejectUsername(ZuulTestCase):
316 """Requirements with reject username requirement"""
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100317
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100318 tenant_config_file = 'config/requirements/reject-username/main.yaml'
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100319
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000320 def _test_require_reject_username(self, project, job):
321 "Test negative username's match"
322 # Should only trigger if Jenkins hasn't voted.
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000323 # add in a change with no comments
324 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
325 self.waitUntilSettled()
326 self.assertEqual(len(self.history), 0)
327
328 # add in a comment that will trigger
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200329 self.fake_gerrit.addEvent(A.addApproval('Code-Review', 1,
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000330 username='reviewer'))
331 self.waitUntilSettled()
332 self.assertEqual(len(self.history), 1)
333 self.assertEqual(self.history[0].name, job)
334
335 # add in a comment from jenkins user which shouldn't trigger
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200336 self.fake_gerrit.addEvent(A.addApproval('Verified', 1,
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100337 username='jenkins'))
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000338 self.waitUntilSettled()
339 self.assertEqual(len(self.history), 1)
340
341 # Check future reviews also won't trigger as a 'jenkins' user has
342 # commented previously
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200343 self.fake_gerrit.addEvent(A.addApproval('Code-Review', 1,
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000344 username='reviewer'))
345 self.waitUntilSettled()
346 self.assertEqual(len(self.history), 1)
347
348 def test_pipeline_reject_username(self):
349 "Test negative pipeline requirement: no comment from jenkins"
350 return self._test_require_reject_username('org/project1',
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100351 'project1-job')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000352
353 def test_trigger_reject_username(self):
354 "Test negative trigger requirement: no comment from jenkins"
355 return self._test_require_reject_username('org/project2',
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100356 'project2-job')
357
358
359class TestRequirementsReject(ZuulTestCase):
360 """Requirements with reject requirement"""
361
362 tenant_config_file = 'config/requirements/reject/main.yaml'
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000363
364 def _test_require_reject(self, project, job):
365 "Test no approval matches a reject param"
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000366 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
367 self.waitUntilSettled()
368 self.assertEqual(len(self.history), 0)
369
370 # First positive vote should not queue until jenkins has +1'd
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200371 comment = A.addApproval('Verified', 1, username='reviewer_a')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000372 self.fake_gerrit.addEvent(comment)
373 self.waitUntilSettled()
374 self.assertEqual(len(self.history), 0)
375
376 # Jenkins should put in a +1 which will also queue
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200377 comment = A.addApproval('Verified', 1, username='jenkins')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000378 self.fake_gerrit.addEvent(comment)
379 self.waitUntilSettled()
380 self.assertEqual(len(self.history), 1)
381 self.assertEqual(self.history[0].name, job)
382
383 # Negative vote should not queue
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200384 comment = A.addApproval('Verified', -1, username='reviewer_b')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000385 self.fake_gerrit.addEvent(comment)
386 self.waitUntilSettled()
387 self.assertEqual(len(self.history), 1)
388
389 # Future approvals should do nothing
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200390 comment = A.addApproval('Verified', 1, username='reviewer_c')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000391 self.fake_gerrit.addEvent(comment)
392 self.waitUntilSettled()
393 self.assertEqual(len(self.history), 1)
394
395 # Change/update negative vote should queue
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200396 comment = A.addApproval('Verified', 1, username='reviewer_b')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000397 self.fake_gerrit.addEvent(comment)
398 self.waitUntilSettled()
399 self.assertEqual(len(self.history), 2)
400 self.assertEqual(self.history[1].name, job)
401
402 # Future approvals should also queue
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200403 comment = A.addApproval('Verified', 1, username='reviewer_d')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000404 self.fake_gerrit.addEvent(comment)
405 self.waitUntilSettled()
406 self.assertEqual(len(self.history), 3)
407 self.assertEqual(self.history[2].name, job)
408
409 def test_pipeline_require_reject(self):
410 "Test pipeline requirement: rejections absent"
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100411 return self._test_require_reject('org/project1', 'project1-job')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000412
413 def test_trigger_require_reject(self):
414 "Test trigger requirement: rejections absent"
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100415 return self._test_require_reject('org/project2', 'project2-job')