Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1 | # Copyright 2014 Rackspace Australia |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import logging |
| 16 | import testtools |
| 17 | |
| 18 | import zuul.connection.gerrit |
| 19 | |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 20 | from tests.base import ZuulTestCase |
| 21 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 22 | |
| 23 | class TestGerritConnection(testtools.TestCase): |
James E. Blair | 509cada | 2015-12-08 16:31:16 -0800 | [diff] [blame] | 24 | def setUp(self): |
| 25 | self.skip("Disabled for early v3 development") |
| 26 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 27 | log = logging.getLogger("zuul.test_connection") |
| 28 | |
| 29 | def test_driver_name(self): |
| 30 | self.assertEqual('gerrit', |
| 31 | zuul.connection.gerrit.GerritConnection.driver_name) |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 32 | |
| 33 | |
| 34 | class TestConnections(ZuulTestCase): |
James E. Blair | 509cada | 2015-12-08 16:31:16 -0800 | [diff] [blame] | 35 | def setUp(self): |
| 36 | self.skip("Disabled for early v3 development") |
| 37 | |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 38 | def setup_config(self, config_file='zuul-connections-same-gerrit.conf'): |
| 39 | super(TestConnections, self).setup_config(config_file) |
| 40 | |
| 41 | def test_multiple_connections(self): |
| 42 | "Test multiple connections to the one gerrit" |
| 43 | |
| 44 | A = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'A') |
| 45 | self.fake_review_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 46 | |
| 47 | self.waitUntilSettled() |
| 48 | |
| 49 | self.assertEqual(len(A.patchsets[-1]['approvals']), 1) |
| 50 | self.assertEqual(A.patchsets[-1]['approvals'][0]['type'], 'VRFY') |
| 51 | self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '1') |
| 52 | self.assertEqual(A.patchsets[-1]['approvals'][0]['by']['username'], |
| 53 | 'jenkins') |
| 54 | |
| 55 | B = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'B') |
| 56 | self.worker.addFailTest('project-test2', B) |
| 57 | self.fake_review_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 58 | |
| 59 | self.waitUntilSettled() |
| 60 | |
| 61 | self.assertEqual(len(B.patchsets[-1]['approvals']), 1) |
| 62 | self.assertEqual(B.patchsets[-1]['approvals'][0]['type'], 'VRFY') |
| 63 | self.assertEqual(B.patchsets[-1]['approvals'][0]['value'], '-1') |
| 64 | self.assertEqual(B.patchsets[-1]['approvals'][0]['by']['username'], |
| 65 | 'civoter') |
| 66 | |
| 67 | |
| 68 | class TestMultipleGerrits(ZuulTestCase): |
James E. Blair | 509cada | 2015-12-08 16:31:16 -0800 | [diff] [blame] | 69 | def setUp(self): |
| 70 | self.skip("Disabled for early v3 development") |
| 71 | |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 72 | def setup_config(self, |
| 73 | config_file='zuul-connections-multiple-gerrits.conf'): |
| 74 | super(TestMultipleGerrits, self).setup_config(config_file) |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 75 | self.self.updateConfigLayout( |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 76 | 'layout-connections-multiple-gerrits.yaml') |
| 77 | |
| 78 | def test_multiple_project_separate_gerrits(self): |
| 79 | self.worker.hold_jobs_in_build = True |
| 80 | |
| 81 | A = self.fake_another_gerrit.addFakeChange( |
| 82 | 'org/project', 'master', 'A') |
| 83 | self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 84 | |
| 85 | self.waitUntilSettled() |
| 86 | |
| 87 | self.assertEqual(1, len(self.builds)) |
| 88 | self.assertEqual('project-another-gerrit', self.builds[0].name) |
| 89 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 90 | |
| 91 | self.worker.hold_jobs_in_build = False |
| 92 | self.worker.release() |
| 93 | self.waitUntilSettled() |