James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 1 | #!/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 | |
| 17 | import logging |
| 18 | import time |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 19 | from unittest import skip |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 20 | |
| 21 | from tests.base import ZuulTestCase |
| 22 | |
| 23 | logging.basicConfig(level=logging.DEBUG, |
| 24 | format='%(asctime)s %(name)-32s ' |
| 25 | '%(levelname)-8s %(message)s') |
| 26 | |
| 27 | |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 28 | class TestRequirementsApprovalNewerThan(ZuulTestCase): |
| 29 | """Requirements with a newer-than comment requirement""" |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 30 | |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 31 | tenant_config_file = 'config/requirements/newer-than/main.yaml' |
| 32 | |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 33 | 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 Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 36 | 'project1-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 37 | |
| 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 Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 41 | 'project2-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 42 | |
| 43 | def _test_require_approval_newer_than(self, project, job): |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 44 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 45 | # A comment event that we will keep submitting to trigger |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 46 | comment = A.addApproval('code-review', 2, username='nobody') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 47 | 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 Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 53 | A.addApproval('verified', 1, username='jenkins', |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 54 | granted_on=time.time() - 72 * 60 * 60) |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 55 | self.fake_gerrit.addEvent(comment) |
| 56 | self.waitUntilSettled() |
| 57 | self.assertEqual(len(self.history), 0) |
| 58 | |
| 59 | # Add a recent +1 |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 60 | self.fake_gerrit.addEvent(A.addApproval('verified', 1, |
| 61 | username='jenkins')) |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 62 | 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 Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 67 | |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame^] | 68 | class TestRequirementsApprovalOlderThan(ZuulTestCase): |
| 69 | """Requirements with a older-than comment requirement""" |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 70 | |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame^] | 71 | tenant_config_file = 'config/requirements/older-than/main.yaml' |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 72 | |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 73 | 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 Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame^] | 76 | 'project1-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 77 | |
| 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 Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame^] | 81 | 'project2-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 82 | |
| 83 | def _test_require_approval_older_than(self, project, job): |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 84 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 85 | # A comment event that we will keep submitting to trigger |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame^] | 86 | comment = A.addApproval('code-review', 2, username='nobody') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 87 | 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 Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame^] | 93 | A.addApproval('verified', 1) |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 94 | 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 Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame^] | 99 | A.addApproval('verified', 1, username='jenkins', |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 100 | granted_on=time.time() - 72 * 60 * 60) |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 101 | 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 Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame^] | 106 | |
| 107 | class TestRequirements(ZuulTestCase): |
| 108 | """Test pipeline and trigger requirements""" |
| 109 | |
| 110 | tenant_config_file = 'config/requirements/main.yaml' |
| 111 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 112 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 113 | def test_pipeline_require_approval_username(self): |
| 114 | "Test pipeline requirement: approval username" |
| 115 | return self._test_require_approval_username('org/project1', |
| 116 | 'project1-pipeline') |
| 117 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 118 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 119 | def test_trigger_require_approval_username(self): |
| 120 | "Test trigger requirement: approval username" |
| 121 | return self._test_require_approval_username('org/project2', |
| 122 | 'project2-trigger') |
| 123 | |
| 124 | def _test_require_approval_username(self, project, job): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 125 | self.updateConfigLayout( |
| 126 | 'tests/fixtures/layout-requirement-username.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 127 | self.sched.reconfigure(self.config) |
| 128 | self.registerJobs() |
| 129 | |
| 130 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 131 | # A comment event that we will keep submitting to trigger |
| 132 | comment = A.addApproval('CRVW', 2, username='nobody') |
| 133 | self.fake_gerrit.addEvent(comment) |
| 134 | self.waitUntilSettled() |
| 135 | # No approval from Jenkins so should not be enqueued |
| 136 | self.assertEqual(len(self.history), 0) |
| 137 | |
| 138 | # Add an approval from Jenkins |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 139 | A.addApproval('VRFY', 1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 140 | self.fake_gerrit.addEvent(comment) |
| 141 | self.waitUntilSettled() |
| 142 | self.assertEqual(len(self.history), 1) |
| 143 | self.assertEqual(self.history[0].name, job) |
| 144 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 145 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 146 | def test_pipeline_require_approval_email(self): |
| 147 | "Test pipeline requirement: approval email" |
| 148 | return self._test_require_approval_email('org/project1', |
| 149 | 'project1-pipeline') |
| 150 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 151 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 152 | def test_trigger_require_approval_email(self): |
| 153 | "Test trigger requirement: approval email" |
| 154 | return self._test_require_approval_email('org/project2', |
| 155 | 'project2-trigger') |
| 156 | |
| 157 | def _test_require_approval_email(self, project, job): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 158 | self.updateConfigLayout( |
| 159 | 'tests/fixtures/layout-requirement-email.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 160 | self.sched.reconfigure(self.config) |
| 161 | self.registerJobs() |
| 162 | |
| 163 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 164 | # A comment event that we will keep submitting to trigger |
| 165 | comment = A.addApproval('CRVW', 2, username='nobody') |
| 166 | self.fake_gerrit.addEvent(comment) |
| 167 | self.waitUntilSettled() |
| 168 | # No approval from Jenkins so should not be enqueued |
| 169 | self.assertEqual(len(self.history), 0) |
| 170 | |
| 171 | # Add an approval from Jenkins |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 172 | A.addApproval('VRFY', 1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 173 | self.fake_gerrit.addEvent(comment) |
| 174 | self.waitUntilSettled() |
| 175 | self.assertEqual(len(self.history), 1) |
| 176 | self.assertEqual(self.history[0].name, job) |
| 177 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 178 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 179 | def test_pipeline_require_approval_vote1(self): |
| 180 | "Test pipeline requirement: approval vote with one value" |
| 181 | return self._test_require_approval_vote1('org/project1', |
| 182 | 'project1-pipeline') |
| 183 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 184 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 185 | def test_trigger_require_approval_vote1(self): |
| 186 | "Test trigger requirement: approval vote with one value" |
| 187 | return self._test_require_approval_vote1('org/project2', |
| 188 | 'project2-trigger') |
| 189 | |
| 190 | def _test_require_approval_vote1(self, project, job): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 191 | self.updateConfigLayout( |
| 192 | 'tests/fixtures/layout-requirement-vote1.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 193 | self.sched.reconfigure(self.config) |
| 194 | self.registerJobs() |
| 195 | |
| 196 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 197 | # A comment event that we will keep submitting to trigger |
| 198 | comment = A.addApproval('CRVW', 2, username='nobody') |
| 199 | self.fake_gerrit.addEvent(comment) |
| 200 | self.waitUntilSettled() |
| 201 | # No approval from Jenkins so should not be enqueued |
| 202 | self.assertEqual(len(self.history), 0) |
| 203 | |
| 204 | # A -1 from jenkins should not cause it to be enqueued |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 205 | A.addApproval('VRFY', -1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 206 | self.fake_gerrit.addEvent(comment) |
| 207 | self.waitUntilSettled() |
| 208 | self.assertEqual(len(self.history), 0) |
| 209 | |
| 210 | # A +1 should allow it to be enqueued |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 211 | A.addApproval('VRFY', 1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 212 | self.fake_gerrit.addEvent(comment) |
| 213 | self.waitUntilSettled() |
| 214 | self.assertEqual(len(self.history), 1) |
| 215 | self.assertEqual(self.history[0].name, job) |
| 216 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 217 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 218 | def test_pipeline_require_approval_vote2(self): |
| 219 | "Test pipeline requirement: approval vote with two values" |
| 220 | return self._test_require_approval_vote2('org/project1', |
| 221 | 'project1-pipeline') |
| 222 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 223 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 224 | def test_trigger_require_approval_vote2(self): |
| 225 | "Test trigger requirement: approval vote with two values" |
| 226 | return self._test_require_approval_vote2('org/project2', |
| 227 | 'project2-trigger') |
| 228 | |
| 229 | def _test_require_approval_vote2(self, project, job): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 230 | self.updateConfigLayout( |
| 231 | 'tests/fixtures/layout-requirement-vote2.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 232 | self.sched.reconfigure(self.config) |
| 233 | self.registerJobs() |
| 234 | |
| 235 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 236 | # A comment event that we will keep submitting to trigger |
| 237 | comment = A.addApproval('CRVW', 2, username='nobody') |
| 238 | self.fake_gerrit.addEvent(comment) |
| 239 | self.waitUntilSettled() |
| 240 | # No approval from Jenkins so should not be enqueued |
| 241 | self.assertEqual(len(self.history), 0) |
| 242 | |
| 243 | # A -1 from jenkins should not cause it to be enqueued |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 244 | A.addApproval('VRFY', -1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 245 | self.fake_gerrit.addEvent(comment) |
| 246 | self.waitUntilSettled() |
| 247 | self.assertEqual(len(self.history), 0) |
| 248 | |
| 249 | # A -2 from jenkins should not cause it to be enqueued |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 250 | A.addApproval('VRFY', -2, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 251 | self.fake_gerrit.addEvent(comment) |
| 252 | self.waitUntilSettled() |
| 253 | self.assertEqual(len(self.history), 0) |
| 254 | |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 255 | # A +1 from jenkins should allow it to be enqueued |
| 256 | A.addApproval('VRFY', 1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 257 | self.fake_gerrit.addEvent(comment) |
| 258 | self.waitUntilSettled() |
| 259 | self.assertEqual(len(self.history), 1) |
| 260 | self.assertEqual(self.history[0].name, job) |
| 261 | |
| 262 | # A +2 should allow it to be enqueued |
| 263 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 264 | # A comment event that we will keep submitting to trigger |
| 265 | comment = B.addApproval('CRVW', 2, username='nobody') |
| 266 | self.fake_gerrit.addEvent(comment) |
| 267 | self.waitUntilSettled() |
| 268 | self.assertEqual(len(self.history), 1) |
| 269 | |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 270 | B.addApproval('VRFY', 2, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 271 | self.fake_gerrit.addEvent(comment) |
| 272 | self.waitUntilSettled() |
| 273 | self.assertEqual(len(self.history), 2) |
| 274 | self.assertEqual(self.history[1].name, job) |
| 275 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 276 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 277 | def test_pipeline_require_current_patchset(self): |
| 278 | "Test pipeline requirement: current-patchset" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 279 | self.updateConfigLayout( |
| 280 | 'tests/fixtures/layout-requirement-current-patchset.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 281 | self.sched.reconfigure(self.config) |
| 282 | self.registerJobs() |
| 283 | # Create two patchsets and let their tests settle out. Then |
| 284 | # comment on first patchset and check that no additional |
| 285 | # jobs are run. |
| 286 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 287 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 1)) |
| 288 | self.waitUntilSettled() |
| 289 | A.addPatchset() |
| 290 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 1)) |
| 291 | self.waitUntilSettled() |
| 292 | |
| 293 | self.assertEqual(len(self.history), 2) # one job for each ps |
| 294 | self.fake_gerrit.addEvent(A.getChangeCommentEvent(1)) |
| 295 | self.waitUntilSettled() |
| 296 | |
| 297 | # Assert no new jobs ran after event for old patchset. |
| 298 | self.assertEqual(len(self.history), 2) |
| 299 | |
| 300 | # Make sure the same event on a new PS will trigger |
| 301 | self.fake_gerrit.addEvent(A.getChangeCommentEvent(2)) |
| 302 | self.waitUntilSettled() |
| 303 | self.assertEqual(len(self.history), 3) |
| 304 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 305 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 306 | def test_pipeline_require_open(self): |
| 307 | "Test pipeline requirement: open" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 308 | self.updateConfigLayout( |
| 309 | 'tests/fixtures/layout-requirement-open.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 310 | self.sched.reconfigure(self.config) |
| 311 | self.registerJobs() |
| 312 | |
| 313 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 314 | status='MERGED') |
| 315 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 2)) |
| 316 | self.waitUntilSettled() |
| 317 | self.assertEqual(len(self.history), 0) |
| 318 | |
| 319 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 320 | self.fake_gerrit.addEvent(B.addApproval('CRVW', 2)) |
| 321 | self.waitUntilSettled() |
| 322 | self.assertEqual(len(self.history), 1) |
| 323 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 324 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 325 | def test_pipeline_require_status(self): |
| 326 | "Test pipeline requirement: status" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 327 | self.updateConfigLayout( |
| 328 | 'tests/fixtures/layout-requirement-status.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 329 | self.sched.reconfigure(self.config) |
| 330 | self.registerJobs() |
| 331 | |
| 332 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 333 | status='MERGED') |
| 334 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 2)) |
| 335 | self.waitUntilSettled() |
| 336 | self.assertEqual(len(self.history), 0) |
| 337 | |
| 338 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 339 | self.fake_gerrit.addEvent(B.addApproval('CRVW', 2)) |
| 340 | self.waitUntilSettled() |
| 341 | self.assertEqual(len(self.history), 1) |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 342 | |
| 343 | def _test_require_reject_username(self, project, job): |
| 344 | "Test negative username's match" |
| 345 | # Should only trigger if Jenkins hasn't voted. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 346 | self.updateConfigLayout( |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 347 | 'tests/fixtures/layout-requirement-reject-username.yaml') |
| 348 | self.sched.reconfigure(self.config) |
| 349 | self.registerJobs() |
| 350 | |
| 351 | # add in a change with no comments |
| 352 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 353 | self.waitUntilSettled() |
| 354 | self.assertEqual(len(self.history), 0) |
| 355 | |
| 356 | # add in a comment that will trigger |
| 357 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 1, |
| 358 | username='reviewer')) |
| 359 | self.waitUntilSettled() |
| 360 | self.assertEqual(len(self.history), 1) |
| 361 | self.assertEqual(self.history[0].name, job) |
| 362 | |
| 363 | # add in a comment from jenkins user which shouldn't trigger |
| 364 | self.fake_gerrit.addEvent(A.addApproval('VRFY', 1, username='jenkins')) |
| 365 | self.waitUntilSettled() |
| 366 | self.assertEqual(len(self.history), 1) |
| 367 | |
| 368 | # Check future reviews also won't trigger as a 'jenkins' user has |
| 369 | # commented previously |
| 370 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 1, |
| 371 | username='reviewer')) |
| 372 | self.waitUntilSettled() |
| 373 | self.assertEqual(len(self.history), 1) |
| 374 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 375 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 376 | def test_pipeline_reject_username(self): |
| 377 | "Test negative pipeline requirement: no comment from jenkins" |
| 378 | return self._test_require_reject_username('org/project1', |
| 379 | 'project1-pipeline') |
| 380 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 381 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 382 | def test_trigger_reject_username(self): |
| 383 | "Test negative trigger requirement: no comment from jenkins" |
| 384 | return self._test_require_reject_username('org/project2', |
| 385 | 'project2-trigger') |
| 386 | |
| 387 | def _test_require_reject(self, project, job): |
| 388 | "Test no approval matches a reject param" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 389 | self.updateConfigLayout( |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 390 | 'tests/fixtures/layout-requirement-reject.yaml') |
| 391 | self.sched.reconfigure(self.config) |
| 392 | self.registerJobs() |
| 393 | |
| 394 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 395 | self.waitUntilSettled() |
| 396 | self.assertEqual(len(self.history), 0) |
| 397 | |
| 398 | # First positive vote should not queue until jenkins has +1'd |
| 399 | comment = A.addApproval('VRFY', 1, username='reviewer_a') |
| 400 | self.fake_gerrit.addEvent(comment) |
| 401 | self.waitUntilSettled() |
| 402 | self.assertEqual(len(self.history), 0) |
| 403 | |
| 404 | # Jenkins should put in a +1 which will also queue |
| 405 | comment = A.addApproval('VRFY', 1, username='jenkins') |
| 406 | self.fake_gerrit.addEvent(comment) |
| 407 | self.waitUntilSettled() |
| 408 | self.assertEqual(len(self.history), 1) |
| 409 | self.assertEqual(self.history[0].name, job) |
| 410 | |
| 411 | # Negative vote should not queue |
| 412 | comment = A.addApproval('VRFY', -1, username='reviewer_b') |
| 413 | self.fake_gerrit.addEvent(comment) |
| 414 | self.waitUntilSettled() |
| 415 | self.assertEqual(len(self.history), 1) |
| 416 | |
| 417 | # Future approvals should do nothing |
| 418 | comment = A.addApproval('VRFY', 1, username='reviewer_c') |
| 419 | self.fake_gerrit.addEvent(comment) |
| 420 | self.waitUntilSettled() |
| 421 | self.assertEqual(len(self.history), 1) |
| 422 | |
| 423 | # Change/update negative vote should queue |
| 424 | comment = A.addApproval('VRFY', 1, username='reviewer_b') |
| 425 | self.fake_gerrit.addEvent(comment) |
| 426 | self.waitUntilSettled() |
| 427 | self.assertEqual(len(self.history), 2) |
| 428 | self.assertEqual(self.history[1].name, job) |
| 429 | |
| 430 | # Future approvals should also queue |
| 431 | comment = A.addApproval('VRFY', 1, username='reviewer_d') |
| 432 | self.fake_gerrit.addEvent(comment) |
| 433 | self.waitUntilSettled() |
| 434 | self.assertEqual(len(self.history), 3) |
| 435 | self.assertEqual(self.history[2].name, job) |
| 436 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 437 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 438 | def test_pipeline_require_reject(self): |
| 439 | "Test pipeline requirement: rejections absent" |
| 440 | return self._test_require_reject('org/project1', 'project1-pipeline') |
| 441 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 442 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 443 | def test_trigger_require_reject(self): |
| 444 | "Test trigger requirement: rejections absent" |
| 445 | return self._test_require_reject('org/project2', 'project2-trigger') |