blob: f2bdece0a7b2524c2c3d9ff07ad1966825cec0dc [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
Jamie Lennoxff3e0b92016-11-23 10:38:25 +110019from unittest import skip
James E. Blair9c17dbf2014-06-23 14:21:58 -070020
21from tests.base import ZuulTestCase
22
23logging.basicConfig(level=logging.DEBUG,
24 format='%(asctime)s %(name)-32s '
25 '%(levelname)-8s %(message)s')
26
27
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110028class TestRequirementsApprovalNewerThan(ZuulTestCase):
29 """Requirements with a newer-than comment requirement"""
James E. Blair9c17dbf2014-06-23 14:21:58 -070030
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110031 tenant_config_file = 'config/requirements/newer-than/main.yaml'
32
James E. Blair9c17dbf2014-06-23 14:21:58 -070033 def test_pipeline_require_approval_newer_than(self):
34 "Test pipeline requirement: approval newer than"
35 return self._test_require_approval_newer_than('org/project1',
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110036 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070037
38 def test_trigger_require_approval_newer_than(self):
39 "Test trigger requirement: approval newer than"
40 return self._test_require_approval_newer_than('org/project2',
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110041 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070042
43 def _test_require_approval_newer_than(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -070044 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
45 # A comment event that we will keep submitting to trigger
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110046 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -070047 self.fake_gerrit.addEvent(comment)
48 self.waitUntilSettled()
49 # No +1 from Jenkins so should not be enqueued
50 self.assertEqual(len(self.history), 0)
51
52 # Add a too-old +1, should not be enqueued
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110053 A.addApproval('verified', 1, username='jenkins',
Joshua Hesketh642824b2014-07-01 17:54:59 +100054 granted_on=time.time() - 72 * 60 * 60)
James E. Blair9c17dbf2014-06-23 14:21:58 -070055 self.fake_gerrit.addEvent(comment)
56 self.waitUntilSettled()
57 self.assertEqual(len(self.history), 0)
58
59 # Add a recent +1
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110060 self.fake_gerrit.addEvent(A.addApproval('verified', 1,
61 username='jenkins'))
James E. Blair9c17dbf2014-06-23 14:21:58 -070062 self.fake_gerrit.addEvent(comment)
63 self.waitUntilSettled()
64 self.assertEqual(len(self.history), 1)
65 self.assertEqual(self.history[0].name, job)
66
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110067
Jamie Lennox8faa71e2016-11-23 14:33:52 +110068class TestRequirementsApprovalOlderThan(ZuulTestCase):
69 """Requirements with a older-than comment requirement"""
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110070
Jamie Lennox8faa71e2016-11-23 14:33:52 +110071 tenant_config_file = 'config/requirements/older-than/main.yaml'
Jamie Lennoxb59a73f2016-11-23 14:27:18 +110072
James E. Blair9c17dbf2014-06-23 14:21:58 -070073 def test_pipeline_require_approval_older_than(self):
74 "Test pipeline requirement: approval older than"
75 return self._test_require_approval_older_than('org/project1',
Jamie Lennox8faa71e2016-11-23 14:33:52 +110076 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070077
78 def test_trigger_require_approval_older_than(self):
79 "Test trigger requirement: approval older than"
80 return self._test_require_approval_older_than('org/project2',
Jamie Lennox8faa71e2016-11-23 14:33:52 +110081 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -070082
83 def _test_require_approval_older_than(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -070084 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
85 # A comment event that we will keep submitting to trigger
Jamie Lennox8faa71e2016-11-23 14:33:52 +110086 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -070087 self.fake_gerrit.addEvent(comment)
88 self.waitUntilSettled()
89 # No +1 from Jenkins so should not be enqueued
90 self.assertEqual(len(self.history), 0)
91
92 # Add a recent +1 which should not be enqueued
Jamie Lennox8faa71e2016-11-23 14:33:52 +110093 A.addApproval('verified', 1)
James E. Blair9c17dbf2014-06-23 14:21:58 -070094 self.fake_gerrit.addEvent(comment)
95 self.waitUntilSettled()
96 self.assertEqual(len(self.history), 0)
97
98 # Add an old +1 which should be enqueued
Jamie Lennox8faa71e2016-11-23 14:33:52 +110099 A.addApproval('verified', 1, username='jenkins',
Joshua Hesketh642824b2014-07-01 17:54:59 +1000100 granted_on=time.time() - 72 * 60 * 60)
James E. Blair9c17dbf2014-06-23 14:21:58 -0700101 self.fake_gerrit.addEvent(comment)
102 self.waitUntilSettled()
103 self.assertEqual(len(self.history), 1)
104 self.assertEqual(self.history[0].name, job)
105
Jamie Lennox8faa71e2016-11-23 14:33:52 +1100106
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100107class TestRequirementsUserName(ZuulTestCase):
108 """Requirements with a username requirement"""
Jamie Lennox8faa71e2016-11-23 14:33:52 +1100109
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100110 tenant_config_file = 'config/requirements/username/main.yaml'
Jamie Lennox8faa71e2016-11-23 14:33:52 +1100111
James E. Blair9c17dbf2014-06-23 14:21:58 -0700112 def test_pipeline_require_approval_username(self):
113 "Test pipeline requirement: approval username"
114 return self._test_require_approval_username('org/project1',
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100115 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700116
117 def test_trigger_require_approval_username(self):
118 "Test trigger requirement: approval username"
119 return self._test_require_approval_username('org/project2',
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100120 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700121
122 def _test_require_approval_username(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700123 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
124 # A comment event that we will keep submitting to trigger
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100125 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700126 self.fake_gerrit.addEvent(comment)
127 self.waitUntilSettled()
128 # No approval from Jenkins so should not be enqueued
129 self.assertEqual(len(self.history), 0)
130
131 # Add an approval from Jenkins
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100132 A.addApproval('verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700133 self.fake_gerrit.addEvent(comment)
134 self.waitUntilSettled()
135 self.assertEqual(len(self.history), 1)
136 self.assertEqual(self.history[0].name, job)
137
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100138
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100139class TestRequirementsEmail(ZuulTestCase):
140 """Requirements with a email requirement"""
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100141
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100142 tenant_config_file = 'config/requirements/email/main.yaml'
Jamie Lennoxdb3b4e02016-11-23 14:36:12 +1100143
James E. Blair9c17dbf2014-06-23 14:21:58 -0700144 def test_pipeline_require_approval_email(self):
145 "Test pipeline requirement: approval email"
146 return self._test_require_approval_email('org/project1',
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100147 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700148
149 def test_trigger_require_approval_email(self):
150 "Test trigger requirement: approval email"
151 return self._test_require_approval_email('org/project2',
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100152 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700153
154 def _test_require_approval_email(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700155 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
156 # A comment event that we will keep submitting to trigger
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100157 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700158 self.fake_gerrit.addEvent(comment)
159 self.waitUntilSettled()
160 # No approval from Jenkins so should not be enqueued
161 self.assertEqual(len(self.history), 0)
162
163 # Add an approval from Jenkins
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100164 A.addApproval('verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700165 self.fake_gerrit.addEvent(comment)
166 self.waitUntilSettled()
167 self.assertEqual(len(self.history), 1)
168 self.assertEqual(self.history[0].name, job)
169
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100170
Jamie Lennox8ce65582016-11-23 15:20:39 +1100171class TestRequirementsVote1(ZuulTestCase):
172 """Requirements with a voting requirement"""
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100173
Jamie Lennox8ce65582016-11-23 15:20:39 +1100174 tenant_config_file = 'config/requirements/vote1/main.yaml'
Jamie Lennox90cb6b92016-11-23 14:37:19 +1100175
James E. Blair9c17dbf2014-06-23 14:21:58 -0700176 def test_pipeline_require_approval_vote1(self):
177 "Test pipeline requirement: approval vote with one value"
178 return self._test_require_approval_vote1('org/project1',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100179 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700180
181 def test_trigger_require_approval_vote1(self):
182 "Test trigger requirement: approval vote with one value"
183 return self._test_require_approval_vote1('org/project2',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100184 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700185
186 def _test_require_approval_vote1(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700187 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
188 # A comment event that we will keep submitting to trigger
Jamie Lennox8ce65582016-11-23 15:20:39 +1100189 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700190 self.fake_gerrit.addEvent(comment)
191 self.waitUntilSettled()
192 # No approval from Jenkins so should not be enqueued
193 self.assertEqual(len(self.history), 0)
194
195 # A -1 from jenkins should not cause it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100196 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), 0)
200
201 # A +1 should allow it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100202 A.addApproval('verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700203 self.fake_gerrit.addEvent(comment)
204 self.waitUntilSettled()
205 self.assertEqual(len(self.history), 1)
206 self.assertEqual(self.history[0].name, job)
207
Jamie Lennox8ce65582016-11-23 15:20:39 +1100208
209class TestRequirementsVote2(ZuulTestCase):
210 """Requirements with a voting requirement"""
211
212 tenant_config_file = 'config/requirements/vote2/main.yaml'
213
James E. Blair9c17dbf2014-06-23 14:21:58 -0700214 def test_pipeline_require_approval_vote2(self):
215 "Test pipeline requirement: approval vote with two values"
216 return self._test_require_approval_vote2('org/project1',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100217 'project1-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700218
219 def test_trigger_require_approval_vote2(self):
220 "Test trigger requirement: approval vote with two values"
221 return self._test_require_approval_vote2('org/project2',
Jamie Lennox8ce65582016-11-23 15:20:39 +1100222 'project2-job')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700223
224 def _test_require_approval_vote2(self, project, job):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700225 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
226 # A comment event that we will keep submitting to trigger
Jamie Lennox8ce65582016-11-23 15:20:39 +1100227 comment = A.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700228 self.fake_gerrit.addEvent(comment)
229 self.waitUntilSettled()
230 # No approval from Jenkins so should not be enqueued
231 self.assertEqual(len(self.history), 0)
232
233 # A -1 from jenkins should not cause it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100234 A.addApproval('verified', -1, 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
239 # A -2 from jenkins should not cause it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100240 A.addApproval('verified', -2, 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), 0)
244
Joshua Hesketh642824b2014-07-01 17:54:59 +1000245 # A +1 from jenkins should allow it to be enqueued
Jamie Lennox8ce65582016-11-23 15:20:39 +1100246 A.addApproval('verified', 1, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700247 self.fake_gerrit.addEvent(comment)
248 self.waitUntilSettled()
249 self.assertEqual(len(self.history), 1)
250 self.assertEqual(self.history[0].name, job)
251
252 # A +2 should allow it to be enqueued
253 B = self.fake_gerrit.addFakeChange(project, 'master', 'B')
254 # A comment event that we will keep submitting to trigger
Jamie Lennox8ce65582016-11-23 15:20:39 +1100255 comment = B.addApproval('code-review', 2, username='nobody')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700256 self.fake_gerrit.addEvent(comment)
257 self.waitUntilSettled()
258 self.assertEqual(len(self.history), 1)
259
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
320class TestRequirements(ZuulTestCase):
321 """Test pipeline and trigger requirements"""
322
323 tenant_config_file = 'config/requirements/main.yaml'
324
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.
James E. Blairf84026c2015-12-08 16:11:46 -0800328 self.updateConfigLayout(
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000329 'tests/fixtures/layout-requirement-reject-username.yaml')
330 self.sched.reconfigure(self.config)
331 self.registerJobs()
332
333 # add in a change with no comments
334 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
335 self.waitUntilSettled()
336 self.assertEqual(len(self.history), 0)
337
338 # add in a comment that will trigger
339 self.fake_gerrit.addEvent(A.addApproval('CRVW', 1,
340 username='reviewer'))
341 self.waitUntilSettled()
342 self.assertEqual(len(self.history), 1)
343 self.assertEqual(self.history[0].name, job)
344
345 # add in a comment from jenkins user which shouldn't trigger
346 self.fake_gerrit.addEvent(A.addApproval('VRFY', 1, username='jenkins'))
347 self.waitUntilSettled()
348 self.assertEqual(len(self.history), 1)
349
350 # Check future reviews also won't trigger as a 'jenkins' user has
351 # commented previously
352 self.fake_gerrit.addEvent(A.addApproval('CRVW', 1,
353 username='reviewer'))
354 self.waitUntilSettled()
355 self.assertEqual(len(self.history), 1)
356
Jamie Lennoxff3e0b92016-11-23 10:38:25 +1100357 @skip("Disabled for early v3 development")
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000358 def test_pipeline_reject_username(self):
359 "Test negative pipeline requirement: no comment from jenkins"
360 return self._test_require_reject_username('org/project1',
361 'project1-pipeline')
362
Jamie Lennoxff3e0b92016-11-23 10:38:25 +1100363 @skip("Disabled for early v3 development")
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000364 def test_trigger_reject_username(self):
365 "Test negative trigger requirement: no comment from jenkins"
366 return self._test_require_reject_username('org/project2',
367 'project2-trigger')
368
369 def _test_require_reject(self, project, job):
370 "Test no approval matches a reject param"
James E. Blairf84026c2015-12-08 16:11:46 -0800371 self.updateConfigLayout(
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000372 'tests/fixtures/layout-requirement-reject.yaml')
373 self.sched.reconfigure(self.config)
374 self.registerJobs()
375
376 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
377 self.waitUntilSettled()
378 self.assertEqual(len(self.history), 0)
379
380 # First positive vote should not queue until jenkins has +1'd
381 comment = A.addApproval('VRFY', 1, username='reviewer_a')
382 self.fake_gerrit.addEvent(comment)
383 self.waitUntilSettled()
384 self.assertEqual(len(self.history), 0)
385
386 # Jenkins should put in a +1 which will also queue
387 comment = A.addApproval('VRFY', 1, username='jenkins')
388 self.fake_gerrit.addEvent(comment)
389 self.waitUntilSettled()
390 self.assertEqual(len(self.history), 1)
391 self.assertEqual(self.history[0].name, job)
392
393 # Negative vote should not queue
394 comment = A.addApproval('VRFY', -1, username='reviewer_b')
395 self.fake_gerrit.addEvent(comment)
396 self.waitUntilSettled()
397 self.assertEqual(len(self.history), 1)
398
399 # Future approvals should do nothing
400 comment = A.addApproval('VRFY', 1, username='reviewer_c')
401 self.fake_gerrit.addEvent(comment)
402 self.waitUntilSettled()
403 self.assertEqual(len(self.history), 1)
404
405 # Change/update negative vote should queue
406 comment = A.addApproval('VRFY', 1, username='reviewer_b')
407 self.fake_gerrit.addEvent(comment)
408 self.waitUntilSettled()
409 self.assertEqual(len(self.history), 2)
410 self.assertEqual(self.history[1].name, job)
411
412 # Future approvals should also queue
413 comment = A.addApproval('VRFY', 1, username='reviewer_d')
414 self.fake_gerrit.addEvent(comment)
415 self.waitUntilSettled()
416 self.assertEqual(len(self.history), 3)
417 self.assertEqual(self.history[2].name, job)
418
Jamie Lennoxff3e0b92016-11-23 10:38:25 +1100419 @skip("Disabled for early v3 development")
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000420 def test_pipeline_require_reject(self):
421 "Test pipeline requirement: rejections absent"
422 return self._test_require_reject('org/project1', 'project1-pipeline')
423
Jamie Lennoxff3e0b92016-11-23 10:38:25 +1100424 @skip("Disabled for early v3 development")
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000425 def test_trigger_require_reject(self):
426 "Test trigger requirement: rejections absent"
427 return self._test_require_reject('org/project2', 'project2-trigger')