~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_eventqueue.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-11 16:18:11 UTC
  • mto: This revision was merged to the branch mainline in revision 67.
  • Revision ID: james.westby@ubuntu.com-20110211161811-n18dj9lde7dxqjzr
Tags: upstream-1.5.4
ImportĀ upstreamĀ versionĀ 1.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
        # not even an event
127
127
        self.assertRaises(TypeError, self.eq.push)
128
128
 
129
 
        # bad event
130
 
        self.assertRaises(event_queue.InvalidEventError,
131
 
                          self.eq.push, "no-such-event")
132
 
 
133
 
        # not enough or incorrect args for that event
134
 
        self.assertRaises(TypeError, self.eq.push, "FS_FILE_MOVE")
135
 
        self.assertRaises(TypeError, self.eq.push, "FS_FILE_MOVE", 1, 2, 3)
136
 
        self.assertRaises(TypeError,
137
 
                      self.eq.push, "FS_FILE_MOVE", 1, 2, path_to=3)
138
 
        self.assertRaises(TypeError,
139
 
                      self.eq.push, "FS_FILE_MOVE", 1, path_from=2, path_to=3)
140
 
 
141
 
        # all ok... args, kwargs, and mixed
142
 
        self.eq.push("FS_FILE_MOVE", 1, 2)
 
129
        # incorrect args, only kwargs supported
 
130
        self.assertRaises(TypeError, self.eq.push, "FS_FILE_MOVE", 1)
 
131
        self.assertRaises(TypeError,
 
132
                      self.eq.push, "FS_FILE_MOVE", 1, path_to=2)
 
133
 
 
134
        # ok: just kwargs
143
135
        self.eq.push("FS_FILE_MOVE", path_from=1, path_to=2)
144
 
        self.eq.push("FS_FILE_MOVE", 1, path_to=2)
145
136
 
146
137
    def test_events_kwargs(self):
147
138
        """Test that all events are defined correctly with tuples or lists.
160
151
        class Create(object):
161
152
            def __init__(self):
162
153
                self.a = None
163
 
            def handle_FS_FILE_CREATE(self, a):
164
 
                self.a = a
 
154
            def handle_FS_FILE_CREATE(self, path):
 
155
                self.a = path
165
156
 
166
157
        # it get passed!
167
158
        c = Create()
168
159
        self.eq.subscribe(c)
169
 
        self.eq.push("FS_FILE_CREATE", 1)
 
160
        self.eq.push("FS_FILE_CREATE", path=1)
170
161
        self.assertEqual(c.a, 1)
171
162
        self.eq.unsubscribe(c)
172
163
 
173
164
        # don't get what don't listen
174
165
        c = Create()
175
166
        self.eq.subscribe(c)
176
 
        self.eq.push("FS_FILE_DELETE", 1)
 
167
        self.eq.push("FS_FILE_DELETE", path=1)
177
168
        self.assertEqual(c.a, None)
178
169
        self.eq.unsubscribe(c)
179
170
 
182
173
 
183
174
        # helper class, pylint: disable-msg=C0111
184
175
        class Create(object):
185
 
            def handle_FS_FILE_CREATE(self, a, b): # it should be only 'a' here
 
176
            def handle_FS_FILE_CREATE(self, notpath): # it should be path here
186
177
                pass
187
178
 
188
179
        # it get passed!
189
180
        c = Create()
190
181
        self.eq.subscribe(c)
191
182
 
192
 
        # caught by EQ
193
 
        self.assertRaises(TypeError, self.eq.push, "FS_FILE_CREATE")
194
 
        self.assertRaises(TypeError, self.eq.push, "FS_FILE_CREATE", 1, 2)
195
 
 
196
 
        # approved by EQ, but the listener has a wrong signature
 
183
        # the listener has a wrong signature
197
184
        # this is logged as an error/exception
198
 
        self.eq.push("FS_FILE_CREATE", 1)
 
185
        self.eq.push("FS_FILE_CREATE", path=1)
199
186
        self.assertTrue(self.log_handler.check_error('FS_FILE_CREATE',
200
187
                                                     'Create object'))
201
188
 
203
190
 
204
191
    def test_log_pushing_data(self):
205
192
        """Pushed event and info should be logged."""
206
 
        self.eq.push("AQ_QUERY_ERROR", 'item', error='err')
 
193
        self.eq.push("AQ_QUERY_ERROR", item='item', error='err')
207
194
        self.assertTrue(self.log_handler.check_debug(
208
 
            "push_event: AQ_QUERY_ERROR, args:('item',), kw:{'error': 'err'}"))
 
195
                        "push_event: AQ_QUERY_ERROR, kwargs: "
 
196
                        "{'item': 'item', 'error': 'err'}"))
209
197
 
210
198
    def test_log_delete_in_info(self):
211
199
        """Pushed any deletion event should be logged in info."""
212
 
        self.eq.push("FS_DIR_DELETE", 'path')
 
200
        self.eq.push("FS_DIR_DELETE", path='path')
213
201
        self.assertTrue(self.log_handler.check_info(
214
202
                        "push_event: FS_DIR_DELETE"))
215
203
 
217
205
        """SYS_USER_CONNECT event info must not be logged."""
218
206
        self.eq.push("SYS_USER_CONNECT", access_token='foo')
219
207
        self.assertTrue(self.log_handler.check_debug(
220
 
            "push_event: SYS_USER_CONNECT, args:*, kw:*"))
 
208
            "push_event: SYS_USER_CONNECT, kwargs: *"))
221
209
 
222
210
 
223
211
class PushTestsWithCallback(BaseEQTestCase):
230
218
        d = defer.Deferred()
231
219
        # helper class, pylint: disable-msg=C0111
232
220
        class BadListener(object):
233
 
            def handle_FS_FILE_CREATE(self, a, b): # it should be only 'a' here
 
221
            def handle_FS_FILE_CREATE(self, notpath): # it should be path here
234
222
                d.callback(False)
235
223
 
236
224
        class GoodListener(object):
237
 
            def handle_FS_FILE_CREATE(self, a):
238
 
                d.callback(a)
 
225
            def handle_FS_FILE_CREATE(self, path):
 
226
                d.callback(path)
239
227
 
240
228
        bl = BadListener()
241
229
        gl = GoodListener()
248
236
            self.eq.unsubscribe(gl)
249
237
        self.addCleanup(cleanup)
250
238
 
251
 
        # caught by EQ
252
 
        self.assertRaises(TypeError, self.eq.push, "FS_FILE_CREATE")
253
 
        self.assertRaises(TypeError, self.eq.push, "FS_FILE_CREATE", 1, 2)
254
 
 
255
 
        # approved by EQ, but one listener has a wrong signature
256
 
        self.eq.push("FS_FILE_CREATE", 1)
 
239
        # one listener has a wrong signature
 
240
        self.eq.push("FS_FILE_CREATE", path=1)
257
241
        def callback(result):
258
242
            """ asserts that GoodListener was called. """
259
243
            self.assertTrue(result)
267
251
        d = defer.Deferred()
268
252
        # helper class, pylint: disable-msg=C0111
269
253
        class Listener(object):
270
 
            def handle_default(self, *args, **kwargs):
271
 
                d.callback(args)
 
254
            def handle_default(self, event, **kwargs):
 
255
                d.callback((event, kwargs))
272
256
 
273
257
        l = Listener()
274
258
        self.eq.subscribe(l)
279
263
        self.addCleanup(cleanup)
280
264
 
281
265
        # push some event and expect it'll be handled by handle_default
282
 
        self.eq.push("FS_FILE_CREATE", 1)
 
266
        self.eq.push("FS_FILE_CREATE", path=1)
283
267
        def callback(result):
284
268
            """ asserts that GoodListener was called. """
285
269
            self.assertEquals(2, len(result))
286
270
            self.assertEquals('FS_FILE_CREATE', result[0])
287
 
            self.assertEquals(1, result[1])
 
271
            self.assertEquals({'path': 1}, result[1])
288
272
 
289
273
        d.addCallback(callback)
290
274
        return d
298
282
                self.eq = eq
299
283
                self.events = []
300
284
 
301
 
            def handle_FS_FILE_CREATE(self, a):
 
285
            def handle_FS_FILE_CREATE(self, path):
302
286
                self.events.append('FS_FILE_CREATE')
303
 
                self.eq.push('FS_FILE_MOVE', a, 2)
 
287
                self.eq.push('FS_FILE_MOVE', path_from=path, path_to=2)
304
288
 
305
 
            def handle_FS_FILE_DELETE(self, a):
 
289
            def handle_FS_FILE_DELETE(self, path):
306
290
                self.events.append('FS_FILE_DELETE')
307
291
 
308
 
            def handle_FS_FILE_MOVE(self, *args):
 
292
            def handle_FS_FILE_MOVE(self, path_from, path_to):
309
293
                self.events.append('FS_FILE_MOVE')
310
294
                d.callback(True)
311
295
 
324
308
        self.addCleanup(cleanup)
325
309
 
326
310
        # push some events to unleash the event madness
327
 
        self.eq.push("FS_FILE_CREATE", 1)
328
 
        self.eq.push('FS_FILE_DELETE', 2)
 
311
        self.eq.push("FS_FILE_CREATE", path=1)
 
312
        self.eq.push('FS_FILE_DELETE', path=2)
329
313
 
330
314
        def callback(result):
331
315
            """ asserts that Listener was called in the right order"""