blob: eecb5faf628dc3632aacfc582a19bb9530f5f3c6 [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
251 # A +2 should allow it to be enqueued
252 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
Jamie Lennox8ce65582016-11-23 15:20:39 +1100259 B.addApproval('verified', 2, username='jenkins')
James E. Blair9c17dbf2014-06-23 14:21:58 -0700260 self.fake_gerrit.addEvent(comment)
261 self.waitUntilSettled()
262 self.assertEqual(len(self.history), 2)
263 self.assertEqual(self.history[1].name, job)
264
Jamie Lennox8ce65582016-11-23 15:20:39 +1100265
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100266class TestRequirementsState(ZuulTestCase):
267 """Requirements with simple state requirement"""
Jamie Lennox8ce65582016-11-23 15:20:39 +1100268
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100269 tenant_config_file = 'config/requirements/state/main.yaml'
Jamie Lennox8ce65582016-11-23 15:20:39 +1100270
James E. Blair9c17dbf2014-06-23 14:21:58 -0700271 def test_pipeline_require_current_patchset(self):
James E. Blair9c17dbf2014-06-23 14:21:58 -0700272 # Create two patchsets and let their tests settle out. Then
273 # comment on first patchset and check that no additional
274 # jobs are run.
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100275 A = self.fake_gerrit.addFakeChange('current-project', 'master', 'A')
276 self.fake_gerrit.addEvent(A.addApproval('code-review', 1))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700277 self.waitUntilSettled()
278 A.addPatchset()
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100279 self.fake_gerrit.addEvent(A.addApproval('code-review', 1))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700280 self.waitUntilSettled()
281
282 self.assertEqual(len(self.history), 2) # one job for each ps
283 self.fake_gerrit.addEvent(A.getChangeCommentEvent(1))
284 self.waitUntilSettled()
285
286 # Assert no new jobs ran after event for old patchset.
287 self.assertEqual(len(self.history), 2)
288
289 # Make sure the same event on a new PS will trigger
290 self.fake_gerrit.addEvent(A.getChangeCommentEvent(2))
291 self.waitUntilSettled()
292 self.assertEqual(len(self.history), 3)
293
294 def test_pipeline_require_open(self):
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100295 A = self.fake_gerrit.addFakeChange('open-project', 'master', 'A',
James E. Blair9c17dbf2014-06-23 14:21:58 -0700296 status='MERGED')
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100297 self.fake_gerrit.addEvent(A.addApproval('code-review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700298 self.waitUntilSettled()
299 self.assertEqual(len(self.history), 0)
300
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100301 B = self.fake_gerrit.addFakeChange('open-project', 'master', 'B')
302 self.fake_gerrit.addEvent(B.addApproval('code-review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700303 self.waitUntilSettled()
304 self.assertEqual(len(self.history), 1)
305
306 def test_pipeline_require_status(self):
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100307 A = self.fake_gerrit.addFakeChange('status-project', 'master', 'A',
James E. Blair9c17dbf2014-06-23 14:21:58 -0700308 status='MERGED')
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100309 self.fake_gerrit.addEvent(A.addApproval('code-review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700310 self.waitUntilSettled()
311 self.assertEqual(len(self.history), 0)
312
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100313 B = self.fake_gerrit.addFakeChange('status-project', 'master', 'B')
314 self.fake_gerrit.addEvent(B.addApproval('code-review', 2))
James E. Blair9c17dbf2014-06-23 14:21:58 -0700315 self.waitUntilSettled()
316 self.assertEqual(len(self.history), 1)
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000317
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100318
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100319class TestRequirementsRejectUsername(ZuulTestCase):
320 """Requirements with reject username requirement"""
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100321
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100322 tenant_config_file = 'config/requirements/reject-username/main.yaml'
Jamie Lennoxd62939f2016-11-23 15:53:49 +1100323
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000324 def _test_require_reject_username(self, project, job):
325 "Test negative username's match"
326 # Should only trigger if Jenkins hasn't voted.
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000327 # add in a change with no comments
328 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
329 self.waitUntilSettled()
330 self.assertEqual(len(self.history), 0)
331
332 # add in a comment that will trigger
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100333 self.fake_gerrit.addEvent(A.addApproval('code-review', 1,
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000334 username='reviewer'))
335 self.waitUntilSettled()
336 self.assertEqual(len(self.history), 1)
337 self.assertEqual(self.history[0].name, job)
338
339 # add in a comment from jenkins user which shouldn't trigger
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100340 self.fake_gerrit.addEvent(A.addApproval('verified', 1,
341 username='jenkins'))
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000342 self.waitUntilSettled()
343 self.assertEqual(len(self.history), 1)
344
345 # Check future reviews also won't trigger as a 'jenkins' user has
346 # commented previously
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100347 self.fake_gerrit.addEvent(A.addApproval('code-review', 1,
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000348 username='reviewer'))
349 self.waitUntilSettled()
350 self.assertEqual(len(self.history), 1)
351
352 def test_pipeline_reject_username(self):
353 "Test negative pipeline requirement: no comment from jenkins"
354 return self._test_require_reject_username('org/project1',
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100355 'project1-job')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000356
357 def test_trigger_reject_username(self):
358 "Test negative trigger requirement: no comment from jenkins"
359 return self._test_require_reject_username('org/project2',
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100360 'project2-job')
361
362
363class TestRequirementsReject(ZuulTestCase):
364 """Requirements with reject requirement"""
365
366 tenant_config_file = 'config/requirements/reject/main.yaml'
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000367
368 def _test_require_reject(self, project, job):
369 "Test no approval matches a reject param"
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000370 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
371 self.waitUntilSettled()
372 self.assertEqual(len(self.history), 0)
373
374 # First positive vote should not queue until jenkins has +1'd
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100375 comment = A.addApproval('verified', 1, username='reviewer_a')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000376 self.fake_gerrit.addEvent(comment)
377 self.waitUntilSettled()
378 self.assertEqual(len(self.history), 0)
379
380 # Jenkins should put in a +1 which will also queue
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100381 comment = A.addApproval('verified', 1, username='jenkins')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000382 self.fake_gerrit.addEvent(comment)
383 self.waitUntilSettled()
384 self.assertEqual(len(self.history), 1)
385 self.assertEqual(self.history[0].name, job)
386
387 # Negative vote should not queue
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100388 comment = A.addApproval('verified', -1, username='reviewer_b')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000389 self.fake_gerrit.addEvent(comment)
390 self.waitUntilSettled()
391 self.assertEqual(len(self.history), 1)
392
393 # Future approvals should do nothing
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100394 comment = A.addApproval('verified', 1, username='reviewer_c')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000395 self.fake_gerrit.addEvent(comment)
396 self.waitUntilSettled()
397 self.assertEqual(len(self.history), 1)
398
399 # Change/update negative vote should queue
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100400 comment = A.addApproval('verified', 1, username='reviewer_b')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000401 self.fake_gerrit.addEvent(comment)
402 self.waitUntilSettled()
403 self.assertEqual(len(self.history), 2)
404 self.assertEqual(self.history[1].name, job)
405
406 # Future approvals should also queue
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100407 comment = A.addApproval('verified', 1, username='reviewer_d')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000408 self.fake_gerrit.addEvent(comment)
409 self.waitUntilSettled()
410 self.assertEqual(len(self.history), 3)
411 self.assertEqual(self.history[2].name, job)
412
413 def test_pipeline_require_reject(self):
414 "Test pipeline requirement: rejections absent"
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100415 return self._test_require_reject('org/project1', 'project1-job')
Joshua Hesketh66c8e522014-06-26 15:30:08 +1000416
417 def test_trigger_require_reject(self):
418 "Test trigger requirement: rejections absent"
Jamie Lennoxd981b7d2016-11-23 16:05:12 +1100419 return self._test_require_reject('org/project2', 'project2-job')