blob: 1ea0b2eb3850d7c058af187be40daee77d9e2cf5 [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
17import logging
18import time
19
20from tests.base import ZuulTestCase
21
22logging.basicConfig(level=logging.DEBUG,
23 format='%(asctime)s %(name)-32s '
24 '%(levelname)-8s %(message)s')
25
26
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110027class TestRequirementsApprovalNewerThan(ZuulTestCase):
28 """Requirements with a newer-than comment requirement"""
James E. Blair9c17dbf2014-06-23 14:21:58 -070029
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110030 tenant_config_file = 'config/requirements/newer-than/main.yaml'
31
James E. Blair9c17dbf2014-06-23 14:21:58 -070032 def test_pipeline_require_approval_newer_than(self):
33 "Test pipeline requirement: approval newer than"
34 return self._test_require_approval_newer_than('org/project1',
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110035 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070036
37 def test_trigger_require_approval_newer_than(self):
38 "Test trigger requirement: approval newer than"
39 return self._test_require_approval_newer_than('org/project2',
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110040 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070041
42 def _test_require_approval_newer_than(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -070043 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
44 # A comment event that we will keep submitting to trigger
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110045 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -070046 self.fake_gerrit.addEvent(comment)
47 self.waitUntilSettled()
48 # No +1 from Jenkins so should not be enqueued
49 self.assertEqual(len(self.history), 0)
50
51 # Add a too-old +1, should not be enqueued
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110052 A.addApproval('verified', 1, username='jenkins',
Joshua Hesketh642824b2014-07-01 17:54:59 +100053 granted_on=time.time() - 72 * 60 * 60)
James E. Blair9c17dbf2014-06-23 14:21:58 -070054 self.fake_gerrit.addEvent(comment)
55 self.waitUntilSettled()
56 self.assertEqual(len(self.history), 0)
57
58 # Add a recent +1
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110059 self.fake_gerrit.addEvent(A.addApproval('verified', 1,
60 username='jenkins'))
James E. Blair9c17dbf2014-06-23 14:21:58 -070061 self.fake_gerrit.addEvent(comment)
62 self.waitUntilSettled()
63 self.assertEqual(len(self.history), 1)
64 self.assertEqual(self.history[0].name, job)
65
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110066
Jamie Lennox8faa71e2016-11-23 14:33:52 +110067class TestRequirementsApprovalOlderThan(ZuulTestCase):
68 """Requirements with a older-than comment requirement"""
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110069
Jamie Lennox8faa71e2016-11-23 14:33:52 +110070 tenant_config_file = 'config/requirements/older-than/main.yaml'
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110071
James E. Blair9c17dbf2014-06-23 14:21:58 -070072 def test_pipeline_require_approval_older_than(self):
73 "Test pipeline requirement: approval older than"
74 return self._test_require_approval_older_than('org/project1',
Jamie Lennox8faa71e2016-11-23 14:33:52 +110075 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070076
77 def test_trigger_require_approval_older_than(self):
78 "Test trigger requirement: approval older than"
79 return self._test_require_approval_older_than('org/project2',
Jamie Lennox8faa71e2016-11-23 14:33:52 +110080 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070081
82 def _test_require_approval_older_than(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -070083 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
84 # A comment event that we will keep submitting to trigger
Jamie Lennox8faa71e2016-11-23 14:33:52 +110085 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -070086 self.fake_gerrit.addEvent(comment)
87 self.waitUntilSettled()
88 # No +1 from Jenkins so should not be enqueued
89 self.assertEqual(len(self.history), 0)
90
91 # Add a recent +1 which should not be enqueued
Jamie Lennox8faa71e2016-11-23 14:33:52 +110092 A.addApproval('verified', 1)
James E. Blair9c17dbf2014-06-23 14:21:58 -070093 self.fake_gerrit.addEvent(comment)
94 self.waitUntilSettled()
95 self.assertEqual(len(self.history), 0)
96
97 # Add an old +1 which should be enqueued
Jamie Lennox8faa71e2016-11-23 14:33:52 +110098 A.addApproval('verified', 1, username='jenkins',
Joshua Hesketh642824b2014-07-01 17:54:59 +100099 granted_on=time.time() - 72 * 60 * 60)
James E. Blair9c17dbf2014-06-23 14:21:58 -0700100 self.fake_gerrit.addEvent(comment)
101 self.waitUntilSettled()
102 self.assertEqual(len(self.history), 1)
103 self.assertEqual(self.history[0].name, job)
104
Jamie Lennox8faa71e2016-11-23 14:33:52 +1100105
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100106class TestRequirementsUserName(ZuulTestCase):
107 """Requirements with a username requirement"""
Jamie Lennox8faa71e2016-11-23 14:33:52 +1100108
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100109 tenant_config_file = 'config/requirements/username/main.yaml'
Jamie Lennox8faa71e2016-11-23 14:33:52 +1100110
James E. Blair9c17dbf2014-06-23 14:21:58 -0700111 def test_pipeline_require_approval_username(self):
112 "Test pipeline requirement: approval username"
113 return self._test_require_approval_username('org/project1',
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100114 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700115
116 def test_trigger_require_approval_username(self):
117 "Test trigger requirement: approval username"
118 return self._test_require_approval_username('org/project2',
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100119 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700120
121 def _test_require_approval_username(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700122 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
123 # A comment event that we will keep submitting to trigger
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100124 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700125 self.fake_gerrit.addEvent(comment)
126 self.waitUntilSettled()
127 # No approval from Jenkins so should not be enqueued
128 self.assertEqual(len(self.history), 0)
129
130 # Add an approval from Jenkins
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100131 A.addApproval('verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700132 self.fake_gerrit.addEvent(comment)
133 self.waitUntilSettled()
134 self.assertEqual(len(self.history), 1)
135 self.assertEqual(self.history[0].name, job)
136
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100137
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100138class TestRequirementsEmail(ZuulTestCase):
139 """Requirements with a email requirement"""
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100140
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100141 tenant_config_file = 'config/requirements/email/main.yaml'
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100142
James E. Blair9c17dbf2014-06-23 14:21:58 -0700143 def test_pipeline_require_approval_email(self):
144 "Test pipeline requirement: approval email"
145 return self._test_require_approval_email('org/project1',
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100146 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700147
148 def test_trigger_require_approval_email(self):
149 "Test trigger requirement: approval email"
150 return self._test_require_approval_email('org/project2',
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100151 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700152
153 def _test_require_approval_email(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700154 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
155 # A comment event that we will keep submitting to trigger
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100156 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700157 self.fake_gerrit.addEvent(comment)
158 self.waitUntilSettled()
159 # No approval from Jenkins so should not be enqueued
160 self.assertEqual(len(self.history), 0)
161
162 # Add an approval from Jenkins
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100163 A.addApproval('verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700164 self.fake_gerrit.addEvent(comment)
165 self.waitUntilSettled()
166 self.assertEqual(len(self.history), 1)
167 self.assertEqual(self.history[0].name, job)
168
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100169
Jamie Lennox8ce65582016-11-23 15:20:39 +1100170class TestRequirementsVote1(ZuulTestCase):
171 """Requirements with a voting requirement"""
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100172
Jamie Lennox8ce65582016-11-23 15:20:39 +1100173 tenant_config_file = 'config/requirements/vote1/main.yaml'
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100174
James E. Blair9c17dbf2014-06-23 14:21:58 -0700175 def test_pipeline_require_approval_vote1(self):
176 "Test pipeline requirement: approval vote with one value"
177 return self._test_require_approval_vote1('org/project1',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100178 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700179
180 def test_trigger_require_approval_vote1(self):
181 "Test trigger requirement: approval vote with one value"
182 return self._test_require_approval_vote1('org/project2',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100183 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700184
185 def _test_require_approval_vote1(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700186 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
187 # A comment event that we will keep submitting to trigger
Jamie Lennox8ce65582016-11-23 15:20:39 +1100188 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700189 self.fake_gerrit.addEvent(comment)
190 self.waitUntilSettled()
191 # No approval from Jenkins so should not be enqueued
192 self.assertEqual(len(self.history), 0)
193
194 # A -1 from jenkins should not cause it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100195 A.addApproval('verified', -1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700196 self.fake_gerrit.addEvent(comment)
197 self.waitUntilSettled()
198 self.assertEqual(len(self.history), 0)
199
200 # A +1 should allow it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100201 A.addApproval('verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700202 self.fake_gerrit.addEvent(comment)
203 self.waitUntilSettled()
204 self.assertEqual(len(self.history), 1)
205 self.assertEqual(self.history[0].name, job)
206
Jamie Lennox8ce65582016-11-23 15:20:39 +1100207
208class TestRequirementsVote2(ZuulTestCase):
209 """Requirements with a voting requirement"""
210
211 tenant_config_file = 'config/requirements/vote2/main.yaml'
212
James E. Blair9c17dbf2014-06-23 14:21:58 -0700213 def test_pipeline_require_approval_vote2(self):
214 "Test pipeline requirement: approval vote with two values"
215 return self._test_require_approval_vote2('org/project1',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100216 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700217
218 def test_trigger_require_approval_vote2(self):
219 "Test trigger requirement: approval vote with two values"
220 return self._test_require_approval_vote2('org/project2',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100221 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700222
223 def _test_require_approval_vote2(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700224 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
225 # A comment event that we will keep submitting to trigger
Jamie Lennox8ce65582016-11-23 15:20:39 +1100226 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700227 self.fake_gerrit.addEvent(comment)
228 self.waitUntilSettled()
229 # No approval from Jenkins so should not be enqueued
230 self.assertEqual(len(self.history), 0)
231
232 # A -1 from jenkins should not cause it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100233 A.addApproval('verified', -1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700234 self.fake_gerrit.addEvent(comment)
235 self.waitUntilSettled()
236 self.assertEqual(len(self.history), 0)
237
238 # A -2 from jenkins should not cause it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100239 A.addApproval('verified', -2, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700240 self.fake_gerrit.addEvent(comment)
241 self.waitUntilSettled()
242 self.assertEqual(len(self.history), 0)
243
Joshua Hesketh642824b2014-07-01 17:54:59 +1000244 # A +1 from jenkins should allow it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100245 A.addApproval('verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700246 self.fake_gerrit.addEvent(comment)
247 self.waitUntilSettled()
248 self.assertEqual(len(self.history), 1)
249 self.assertEqual(self.history[0].name, job)
250
Jesse Keating2dfc6512017-01-19 14:31:44 -0800251 # A +2 from nobody should not cause it to be enqueued
James E. Blair9c17dbf2014-06-23 14:21:58 -0700252 B = self.fake_gerrit.addFakeChange(project, 'master', 'B')
253 # A comment event that we will keep submitting to trigger
Jamie Lennox8ce65582016-11-23 15:20:39 +1100254 comment = B.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700255 self.fake_gerrit.addEvent(comment)
256 self.waitUntilSettled()
257 self.assertEqual(len(self.history), 1)
258
Jesse Keating2dfc6512017-01-19 14:31:44 -0800259 # A +2 from jenkins should allow it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100260 B.addApproval('verified', 2, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700261 self.fake_gerrit.addEvent(comment)
262 self.waitUntilSettled()
263 self.assertEqual(len(self.history), 2)
264 self.assertEqual(self.history[1].name, job)
265
Jamie Lennox8ce65582016-11-23 15:20:39 +1100266
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100267class TestRequirementsState(ZuulTestCase):
268 """Requirements with simple state requirement"""
Jamie Lennox8ce65582016-11-23 15:20:39 +1100269
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100270 tenant_config_file = 'config/requirements/state/main.yaml'
Jamie Lennox8ce65582016-11-23 15:20:39 +1100271
James E. Blair9c17dbf2014-06-23 14:21:58 -0700272 def test_pipeline_require_current_patchset(self):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700273 # Create two patchsets and let their tests settle out. Then
274 # comment on first patchset and check that no additional
275 # jobs are run.
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100276 A = self.fake_gerrit.addFakeChange('current-project', 'master', 'A')
277 self.fake_gerrit.addEvent(A.addApproval('code-review', 1))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700278 self.waitUntilSettled()
279 A.addPatchset()
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100280 self.fake_gerrit.addEvent(A.addApproval('code-review', 1))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700281 self.waitUntilSettled()
282
283 self.assertEqual(len(self.history), 2) # one job for each ps
284 self.fake_gerrit.addEvent(A.getChangeCommentEvent(1))
285 self.waitUntilSettled()
286
287 # Assert no new jobs ran after event for old patchset.
288 self.assertEqual(len(self.history), 2)
289
290 # Make sure the same event on a new PS will trigger
291 self.fake_gerrit.addEvent(A.getChangeCommentEvent(2))
292 self.waitUntilSettled()
293 self.assertEqual(len(self.history), 3)
294
295 def test_pipeline_require_open(self):
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100296 A = self.fake_gerrit.addFakeChange('open-project', 'master', 'A',
James E. Blair9c17dbf2014-06-23 14:21:58 -0700297 status='MERGED')
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100298 self.fake_gerrit.addEvent(A.addApproval('code-review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700299 self.waitUntilSettled()
300 self.assertEqual(len(self.history), 0)
301
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100302 B = self.fake_gerrit.addFakeChange('open-project', 'master', 'B')
303 self.fake_gerrit.addEvent(B.addApproval('code-review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700304 self.waitUntilSettled()
305 self.assertEqual(len(self.history), 1)
306
307 def test_pipeline_require_status(self):
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100308 A = self.fake_gerrit.addFakeChange('status-project', 'master', 'A',
James E. Blair9c17dbf2014-06-23 14:21:58 -0700309 status='MERGED')
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100310 self.fake_gerrit.addEvent(A.addApproval('code-review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700311 self.waitUntilSettled()
312 self.assertEqual(len(self.history), 0)
313
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100314 B = self.fake_gerrit.addFakeChange('status-project', 'master', 'B')
315 self.fake_gerrit.addEvent(B.addApproval('code-review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700316 self.waitUntilSettled()
317 self.assertEqual(len(self.history), 1)
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000318
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100319
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100320class TestRequirementsRejectUsername(ZuulTestCase):
321 """Requirements with reject username requirement"""
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100322
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100323 tenant_config_file = 'config/requirements/reject-username/main.yaml'
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100324
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000325 def _test_require_reject_username(self, project, job):
326 "Test negative username's match"
327 # Should only trigger if Jenkins hasn't voted.
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000328 # add in a change with no comments
329 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
330 self.waitUntilSettled()
331 self.assertEqual(len(self.history), 0)
332
333 # add in a comment that will trigger
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100334 self.fake_gerrit.addEvent(A.addApproval('code-review', 1,
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000335 username='reviewer'))
336 self.waitUntilSettled()
337 self.assertEqual(len(self.history), 1)
338 self.assertEqual(self.history[0].name, job)
339
340 # add in a comment from jenkins user which shouldn't trigger
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100341 self.fake_gerrit.addEvent(A.addApproval('verified', 1,
342 username='jenkins'))
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000343 self.waitUntilSettled()
344 self.assertEqual(len(self.history), 1)
345
346 # Check future reviews also won't trigger as a 'jenkins' user has
347 # commented previously
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100348 self.fake_gerrit.addEvent(A.addApproval('code-review', 1,
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000349 username='reviewer'))
350 self.waitUntilSettled()
351 self.assertEqual(len(self.history), 1)
352
353 def test_pipeline_reject_username(self):
354 "Test negative pipeline requirement: no comment from jenkins"
355 return self._test_require_reject_username('org/project1',
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100356 'project1-job')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000357
358 def test_trigger_reject_username(self):
359 "Test negative trigger requirement: no comment from jenkins"
360 return self._test_require_reject_username('org/project2',
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100361 'project2-job')
362
363
364class TestRequirementsReject(ZuulTestCase):
365 """Requirements with reject requirement"""
366
367 tenant_config_file = 'config/requirements/reject/main.yaml'
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000368
369 def _test_require_reject(self, project, job):
370 "Test no approval matches a reject param"
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000371 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
372 self.waitUntilSettled()
373 self.assertEqual(len(self.history), 0)
374
375 # First positive vote should not queue until jenkins has +1'd
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100376 comment = A.addApproval('verified', 1, username='reviewer_a')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000377 self.fake_gerrit.addEvent(comment)
378 self.waitUntilSettled()
379 self.assertEqual(len(self.history), 0)
380
381 # Jenkins should put in a +1 which will also queue
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100382 comment = A.addApproval('verified', 1, username='jenkins')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000383 self.fake_gerrit.addEvent(comment)
384 self.waitUntilSettled()
385 self.assertEqual(len(self.history), 1)
386 self.assertEqual(self.history[0].name, job)
387
388 # Negative vote should not queue
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100389 comment = A.addApproval('verified', -1, username='reviewer_b')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000390 self.fake_gerrit.addEvent(comment)
391 self.waitUntilSettled()
392 self.assertEqual(len(self.history), 1)
393
394 # Future approvals should do nothing
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100395 comment = A.addApproval('verified', 1, username='reviewer_c')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000396 self.fake_gerrit.addEvent(comment)
397 self.waitUntilSettled()
398 self.assertEqual(len(self.history), 1)
399
400 # Change/update negative vote should queue
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100401 comment = A.addApproval('verified', 1, username='reviewer_b')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000402 self.fake_gerrit.addEvent(comment)
403 self.waitUntilSettled()
404 self.assertEqual(len(self.history), 2)
405 self.assertEqual(self.history[1].name, job)
406
407 # Future approvals should also queue
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100408 comment = A.addApproval('verified', 1, username='reviewer_d')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000409 self.fake_gerrit.addEvent(comment)
410 self.waitUntilSettled()
411 self.assertEqual(len(self.history), 3)
412 self.assertEqual(self.history[2].name, job)
413
414 def test_pipeline_require_reject(self):
415 "Test pipeline requirement: rejections absent"
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100416 return self._test_require_reject('org/project1', 'project1-job')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000417
418 def test_trigger_require_reject(self):
419 "Test trigger requirement: rejections absent"
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100420 return self._test_require_reject('org/project2', 'project2-job')