Browse Source

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
tags/0.4.0
Eric Fried 1 year ago
parent
commit
fc4041f6a3
1 changed files with 55 additions and 14 deletions
  1. 55
    14
      gerritbot/tests/unit/test_bot.py

+ 55
- 14
gerritbot/tests/unit/test_bot.py View File

@@ -37,11 +37,14 @@ openstack-infra:
37 37
     events:
38 38
       - patchset-created
39 39
       - change-merged
40
+      - comment-added
41
+      - ref-updated
40 42
       - x-vrif-minus-2
41 43
       - x-vrif-plus-2
42 44
       - x-crvw-minus-2
43 45
       - x-crvw-plus-2
44 46
     projects:
47
+      - openstack/gerritbot
45 48
       - openstack/nova
46 49
       - openstack/swift
47 50
     branches:
@@ -74,7 +77,9 @@ class ChannelConfigTestCase(testtools.TestCase):
74 77
         self.assertEqual(
75 78
             {
76 79
                 'change-merged': expected_channels,
80
+                'comment-added': {'#openstack-infra'},
77 81
                 'patchset-created': expected_channels,
82
+                'ref-updated': {'#openstack-infra'},
78 83
                 'x-crvw-minus-2': expected_channels,
79 84
                 'x-crvw-plus-2': expected_channels,
80 85
                 'x-vrif-minus-2': expected_channels,
@@ -87,6 +92,7 @@ class ChannelConfigTestCase(testtools.TestCase):
87 92
         expected_channels = {'#openstack-dev', '#openstack-infra'}
88 93
         self.assertEqual(
89 94
             {
95
+                'openstack/gerritbot': {'#openstack-infra'},
90 96
                 'openstack/nova': expected_channels,
91 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):
147
-        self.gerrit.patchset_created(self.channel, self.sample_data)
148
-
152
+    def _validate_patchset_created(self):
149 153
         self.assertEqual(1, len(self.ircbot.messages))
150 154
         message = self.ircbot.messages[0]
151 155
         self.assertEqual(self.channel, message.channel)
@@ -154,18 +158,30 @@ class GerritTestCase(testtools.TestCase):
154 158
             'unit tests  https://review.openstack.org/123456',
155 159
             message.msg)
156 160
 
157
-    def test_ref_updated(self):
158
-        self.gerrit.ref_updated(self.channel, self.sample_data)
161
+    def test_patchset_created(self):
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 170
         self.assertEqual(1, len(self.ircbot.messages))
161 171
         message = self.ircbot.messages[0]
162 172
         self.assertEqual(self.channel, message.channel)
163 173
         self.assertEqual('elmo tagged project openstack/gerritbot with pike',
164 174
                          message.msg)
165 175
 
166
-    def test_change_merged(self):
167
-        self.gerrit.change_merged(self.channel, self.sample_data)
176
+    def test_ref_updated(self):
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 185
         self.assertEqual(1, len(self.ircbot.messages))
170 186
         message = self.ircbot.messages[0]
171 187
         self.assertEqual(self.channel, message.channel)
@@ -174,9 +190,15 @@ class GerritTestCase(testtools.TestCase):
174 190
             'https://review.openstack.org/123456',
175 191
             message.msg)
176 192
 
177
-    def test_comment_added(self):
178
-        self.gerrit.comment_added(self.channel, self.sample_data)
193
+    def test_change_merged(self):
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 202
         self.assertEqual(1, len(self.ircbot.messages))
181 203
         message = self.ircbot.messages[0]
182 204
         self.assertEqual(self.channel, message.channel)
@@ -186,13 +208,15 @@ class GerritTestCase(testtools.TestCase):
186 208
             'https://review.openstack.org/123456',
187 209
             message.msg)
188 210
 
189
-    def test_comment_added_vrif(self):
190
-        self.sample_data['approvals'] = [{
191
-            'type': 'VRIF',
192
-            'value': '-2',
193
-        }]
211
+    def test_comment_added(self):
194 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 220
         self.assertEqual(2, len(self.ircbot.messages))
197 221
 
198 222
         # The test function 'test_comment_added()' verifies that index 0 is
@@ -203,3 +227,20 @@ class GerritTestCase(testtools.TestCase):
203 227
             'Verification of a change to openstack/gerritbot failed: '
204 228
             'More unit tests  https://review.openstack.org/123456',
205 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()

Loading…
Cancel
Save