summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Fried <efried@us.ibm.com>2018-02-16 10:36:47 -0600
committerJohn L. Villalovos <openstack.org@sodarock.com>2018-02-17 11:35:31 -0800
commitfc4041f6a305bd7bee76ad0700d665d87205f208 (patch)
tree5ba6c7d7bf24a471de6f68b04ec35fd91646277c
parent01e1a0f979095debfbb6a5576646c428cc923cb7 (diff)
Test Gerrit message filtering
Enhance the tests introduced in [1] to exercise the filtering logic in the Gerrit class. [1] https://review.openstack.org/#/c/545128/ Change-Id: Ib4ecd9e7ee233378f25d585f016ba1448b9e8797
Notes
Notes (review): Code-Review+2: Clark Boylan <cboylan@sapwetik.org> Code-Review+1: John L. Villalovos <openstack.org@sodarock.com> Code-Review+2: Paul Belanger <pabelanger@redhat.com> Workflow+1: Paul Belanger <pabelanger@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 19 Feb 2018 18:31:16 +0000 Reviewed-on: https://review.openstack.org/545381 Project: openstack-infra/gerritbot Branch: refs/heads/master
-rw-r--r--gerritbot/tests/unit/test_bot.py69
1 files changed, 55 insertions, 14 deletions
diff --git a/gerritbot/tests/unit/test_bot.py b/gerritbot/tests/unit/test_bot.py
index c2b67ad..b516f8b 100644
--- a/gerritbot/tests/unit/test_bot.py
+++ b/gerritbot/tests/unit/test_bot.py
@@ -37,11 +37,14 @@ openstack-infra:
37 events: 37 events:
38 - patchset-created 38 - patchset-created
39 - change-merged 39 - change-merged
40 - comment-added
41 - ref-updated
40 - x-vrif-minus-2 42 - x-vrif-minus-2
41 - x-vrif-plus-2 43 - x-vrif-plus-2
42 - x-crvw-minus-2 44 - x-crvw-minus-2
43 - x-crvw-plus-2 45 - x-crvw-plus-2
44 projects: 46 projects:
47 - openstack/gerritbot
45 - openstack/nova 48 - openstack/nova
46 - openstack/swift 49 - openstack/swift
47 branches: 50 branches:
@@ -74,7 +77,9 @@ class ChannelConfigTestCase(testtools.TestCase):
74 self.assertEqual( 77 self.assertEqual(
75 { 78 {
76 'change-merged': expected_channels, 79 'change-merged': expected_channels,
80 'comment-added': {'#openstack-infra'},
77 'patchset-created': expected_channels, 81 'patchset-created': expected_channels,
82 'ref-updated': {'#openstack-infra'},
78 'x-crvw-minus-2': expected_channels, 83 'x-crvw-minus-2': expected_channels,
79 'x-crvw-plus-2': expected_channels, 84 'x-crvw-plus-2': expected_channels,
80 'x-vrif-minus-2': expected_channels, 85 'x-vrif-minus-2': expected_channels,
@@ -87,6 +92,7 @@ class ChannelConfigTestCase(testtools.TestCase):
87 expected_channels = {'#openstack-dev', '#openstack-infra'} 92 expected_channels = {'#openstack-dev', '#openstack-infra'}
88 self.assertEqual( 93 self.assertEqual(
89 { 94 {
95 'openstack/gerritbot': {'#openstack-infra'},
90 'openstack/nova': expected_channels, 96 'openstack/nova': expected_channels,
91 'openstack/swift': expected_channels, 97 'openstack/swift': expected_channels,
92 }, 98 },
@@ -143,9 +149,7 @@ class GerritTestCase(testtools.TestCase):
143 149
144 } 150 }
145 151
146 def test_patchset_created(self): 152 def _validate_patchset_created(self):
147 self.gerrit.patchset_created(self.channel, self.sample_data)
148
149 self.assertEqual(1, len(self.ircbot.messages)) 153 self.assertEqual(1, len(self.ircbot.messages))
150 message = self.ircbot.messages[0] 154 message = self.ircbot.messages[0]
151 self.assertEqual(self.channel, message.channel) 155 self.assertEqual(self.channel, message.channel)
@@ -154,18 +158,30 @@ class GerritTestCase(testtools.TestCase):
154 'unit tests https://review.openstack.org/123456', 158 'unit tests https://review.openstack.org/123456',
155 message.msg) 159 message.msg)
156 160
157 def test_ref_updated(self): 161 def test_patchset_created(self):
158 self.gerrit.ref_updated(self.channel, self.sample_data) 162 self.gerrit.patchset_created(self.channel, self.sample_data)
163 self._validate_patchset_created()
164
165 def test__read_patchset_created(self):
166 self.gerrit._read(dict(self.sample_data, type='patchset-created'))
167 self._validate_patchset_created()
159 168
169 def _validate_ref_updated(self):
160 self.assertEqual(1, len(self.ircbot.messages)) 170 self.assertEqual(1, len(self.ircbot.messages))
161 message = self.ircbot.messages[0] 171 message = self.ircbot.messages[0]
162 self.assertEqual(self.channel, message.channel) 172 self.assertEqual(self.channel, message.channel)
163 self.assertEqual('elmo tagged project openstack/gerritbot with pike', 173 self.assertEqual('elmo tagged project openstack/gerritbot with pike',
164 message.msg) 174 message.msg)
165 175
166 def test_change_merged(self): 176 def test_ref_updated(self):
167 self.gerrit.change_merged(self.channel, self.sample_data) 177 self.gerrit.ref_updated(self.channel, self.sample_data)
178 self._validate_ref_updated()
168 179
180 def test__read_ref_updated(self):
181 self.gerrit._read(dict(self.sample_data, type='ref-updated'))
182 self._validate_ref_updated()
183
184 def _validate_change_merged(self):
169 self.assertEqual(1, len(self.ircbot.messages)) 185 self.assertEqual(1, len(self.ircbot.messages))
170 message = self.ircbot.messages[0] 186 message = self.ircbot.messages[0]
171 self.assertEqual(self.channel, message.channel) 187 self.assertEqual(self.channel, message.channel)
@@ -174,9 +190,15 @@ class GerritTestCase(testtools.TestCase):
174 'https://review.openstack.org/123456', 190 'https://review.openstack.org/123456',
175 message.msg) 191 message.msg)
176 192
177 def test_comment_added(self): 193 def test_change_merged(self):
178 self.gerrit.comment_added(self.channel, self.sample_data) 194 self.gerrit.change_merged(self.channel, self.sample_data)
195 self._validate_change_merged()
196
197 def test__read_change_merged(self):
198 self.gerrit._read(dict(self.sample_data, type='change-merged'))
199 self._validate_change_merged()
179 200
201 def _validate_comment_added(self):
180 self.assertEqual(1, len(self.ircbot.messages)) 202 self.assertEqual(1, len(self.ircbot.messages))
181 message = self.ircbot.messages[0] 203 message = self.ircbot.messages[0]
182 self.assertEqual(self.channel, message.channel) 204 self.assertEqual(self.channel, message.channel)
@@ -186,13 +208,15 @@ class GerritTestCase(testtools.TestCase):
186 'https://review.openstack.org/123456', 208 'https://review.openstack.org/123456',
187 message.msg) 209 message.msg)
188 210
189 def test_comment_added_vrif(self): 211 def test_comment_added(self):
190 self.sample_data['approvals'] = [{
191 'type': 'VRIF',
192 'value': '-2',
193 }]
194 self.gerrit.comment_added(self.channel, self.sample_data) 212 self.gerrit.comment_added(self.channel, self.sample_data)
213 self._validate_comment_added()
214
215 def test__read_comment_added(self):
216 self.gerrit._read(dict(self.sample_data, type='comment-added'))
217 self._validate_comment_added()
195 218
219 def _validate_comment_added_vrif(self):
196 self.assertEqual(2, len(self.ircbot.messages)) 220 self.assertEqual(2, len(self.ircbot.messages))
197 221
198 # The test function 'test_comment_added()' verifies that index 0 is 222 # The test function 'test_comment_added()' verifies that index 0 is
@@ -203,3 +227,20 @@ class GerritTestCase(testtools.TestCase):
203 'Verification of a change to openstack/gerritbot failed: ' 227 'Verification of a change to openstack/gerritbot failed: '
204 'More unit tests https://review.openstack.org/123456', 228 'More unit tests https://review.openstack.org/123456',
205 message.msg) 229 message.msg)
230
231 def test_comment_added_vrif(self):
232 self.gerrit.comment_added(
233 self.channel,
234 dict(self.sample_data, approvals=[{
235 'type': 'VRIF',
236 'value': '-2',
237 }]))
238 self._validate_comment_added_vrif()
239
240 def test__read_comment_added_vrif(self):
241 self.gerrit._read(
242 dict(self.sample_data, type='comment-added', approvals=[{
243 'type': 'VRIF',
244 'value': '-2',
245 }]))
246 self._validate_comment_added_vrif()