blob: c3458ac460b3ffcddd9283b3b30191721b9a4c5a [file] [log] [blame]
Joshua Hesketh352264b2015-08-11 23:42:08 +10001# 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
15import logging
16import testtools
17
18import zuul.connection.gerrit
19
Joshua Heskethacccffc2015-03-31 23:38:17 +110020from tests.base import ZuulTestCase
21
Joshua Hesketh352264b2015-08-11 23:42:08 +100022
23class TestGerritConnection(testtools.TestCase):
24 log = logging.getLogger("zuul.test_connection")
25
26 def test_driver_name(self):
27 self.assertEqual('gerrit',
28 zuul.connection.gerrit.GerritConnection.driver_name)
Joshua Heskethacccffc2015-03-31 23:38:17 +110029
30
31class TestConnections(ZuulTestCase):
32 def setup_config(self, config_file='zuul-connections-same-gerrit.conf'):
33 super(TestConnections, self).setup_config(config_file)
34
35 def test_multiple_connections(self):
36 "Test multiple connections to the one gerrit"
37
38 A = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'A')
39 self.fake_review_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
40
41 self.waitUntilSettled()
42
43 self.assertEqual(len(A.patchsets[-1]['approvals']), 1)
44 self.assertEqual(A.patchsets[-1]['approvals'][0]['type'], 'VRFY')
45 self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '1')
46 self.assertEqual(A.patchsets[-1]['approvals'][0]['by']['username'],
47 'jenkins')
48
49 B = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'B')
50 self.worker.addFailTest('project-test2', B)
51 self.fake_review_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
52
53 self.waitUntilSettled()
54
55 self.assertEqual(len(B.patchsets[-1]['approvals']), 1)
56 self.assertEqual(B.patchsets[-1]['approvals'][0]['type'], 'VRFY')
57 self.assertEqual(B.patchsets[-1]['approvals'][0]['value'], '-1')
58 self.assertEqual(B.patchsets[-1]['approvals'][0]['by']['username'],
59 'civoter')
60
61
62class TestMultipleGerrits(ZuulTestCase):
63 def setup_config(self,
64 config_file='zuul-connections-multiple-gerrits.conf'):
65 super(TestMultipleGerrits, self).setup_config(config_file)
66 self.config.set(
67 'zuul', 'layout_config',
68 'layout-connections-multiple-gerrits.yaml')
69
70 def test_multiple_project_separate_gerrits(self):
71 self.worker.hold_jobs_in_build = True
72
73 A = self.fake_another_gerrit.addFakeChange(
74 'org/project', 'master', 'A')
75 self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
76
77 self.waitUntilSettled()
78
79 self.assertEqual(1, len(self.builds))
80 self.assertEqual('project-another-gerrit', self.builds[0].name)
81 self.assertTrue(self.job_has_changes(self.builds[0], A))
82
83 self.worker.hold_jobs_in_build = False
84 self.worker.release()
85 self.waitUntilSettled()