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