~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_status_listener.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:
24
24
 
25
25
from contrib.testing.testcase import FakeMainTestCase
26
26
from ubuntuone.syncdaemon import status_listener
27
 
from ubuntuone.syncdaemon.volume_manager import Share
 
27
from ubuntuone.syncdaemon.volume_manager import Share, UDF
28
28
 
29
29
 
30
30
class GetListenerTestCase(TestCase):
39
39
        self.assertIsInstance(listener, status_listener.StatusListener)
40
40
        self.assertEqual(listener.fsm, fsm)
41
41
        self.assertEqual(listener.vm, vm)
42
 
        self.assertNotEqual(listener.aggregator, None)
 
42
        self.assertNotEqual(listener.status_frontend, None)
43
43
 
44
44
    def test_zeitgeist_not_installed_returns_none(self):
45
45
        """get_listener returns None if status reporting is disabled."""
76
76
    return listener
77
77
 
78
78
 
79
 
class FakeStatusAggregator(object):
80
 
    """A fake status aggregator."""
 
79
class FakeStatusFrontend(object):
 
80
    """A fake status frontend."""
81
81
 
82
82
    def __init__(self):
83
83
        """Initialize this instance."""
99
99
    def setUp(self):
100
100
        """Initialize this instance."""
101
101
        super(StatusListenerTestCase, self).setUp()
102
 
        self.aggregator = FakeStatusAggregator()
 
102
        self.status_frontend = FakeStatusFrontend()
103
103
        self.listener = status_listener.StatusListener(self.fs, self.vm,
104
 
                                                       self.aggregator)
 
104
                                                       self.status_frontend)
105
105
        self.event_q.subscribe(self.listener)
106
106
 
107
107
    def _listen_for(self, *args, **kwargs):
120
120
        public_url = 'http://example.com/foo.mp3'
121
121
 
122
122
        share_path = os.path.join(self.shares_dir, 'share')
123
 
        self.main.vm.add_share(Share(path=share_path, volume_id='share',
124
 
                               other_username='other username'))
 
123
        yield self.main.vm.add_share(Share(path=share_path, volume_id='share',
 
124
                                           other_username='other username'))
125
125
        path = os.path.join(share_path, "foo.mp3")
126
126
        self.main.fs.create(path, str(share_id))
127
127
        self.main.fs.set_node_id(path, str(node_id))
133
133
                               is_public=is_public, public_url=public_url)
134
134
        yield d
135
135
        call = ("file_published", (public_url,), {})
136
 
        self.assertIn(call, self.aggregator.call_log)
 
136
        self.assertIn(call, self.status_frontend.call_log)
137
137
 
138
138
    @defer.inlineCallbacks
139
139
    def test_unpublish_url_is_forwarded(self):
144
144
        public_url = 'http://example.com/foo.mp3'
145
145
 
146
146
        share_path = os.path.join(self.shares_dir, 'share')
147
 
        self.main.vm.add_share(Share(path=share_path, volume_id='share',
148
 
                               other_username='other username'))
 
147
        yield self.main.vm.add_share(Share(path=share_path, volume_id='share',
 
148
                                           other_username='other username'))
149
149
        path = os.path.join(share_path, "foo.mp3")
150
150
        self.main.fs.create(path, str(share_id))
151
151
        self.main.fs.set_node_id(path, str(node_id))
157
157
                               is_public=is_public, public_url=public_url)
158
158
        yield d
159
159
        call = ("file_unpublished", (public_url,), {})
160
 
        self.assertIn(call, self.aggregator.call_log)
 
160
        self.assertIn(call, self.status_frontend.call_log)
 
161
 
 
162
 
 
163
class FakeTransfer(object):
 
164
    """A fake action queue command."""
 
165
 
 
166
 
 
167
class QueueChangedStatusTestCase(StatusListenerTestCase):
 
168
    """Queue changed events are passed to the status object."""
 
169
 
 
170
    @defer.inlineCallbacks
 
171
    def test_download_added_is_forwarded(self):
 
172
        """A Download added event is forwarded."""
 
173
        self.patch(status_listener.action_queue, "Download", FakeTransfer)
 
174
        fake_command = FakeTransfer()
 
175
 
 
176
        d = defer.Deferred()
 
177
        self._listen_for('SYS_QUEUE_ADDED', d.callback)
 
178
        self.main.event_q.push('SYS_QUEUE_ADDED', command=fake_command)
 
179
        yield d
 
180
 
 
181
        call = ("download_started", (fake_command,), {})
 
182
        self.assertIn(call, self.status_frontend.call_log)
 
183
 
 
184
    @defer.inlineCallbacks
 
185
    def test_download_removed_is_forwarded(self):
 
186
        """A Download removed event is forwarded."""
 
187
        self.patch(status_listener.action_queue, "Download", FakeTransfer)
 
188
        fake_command = FakeTransfer()
 
189
 
 
190
        d = defer.Deferred()
 
191
        self._listen_for('SYS_QUEUE_REMOVED', d.callback)
 
192
        self.main.event_q.push('SYS_QUEUE_REMOVED', command=fake_command)
 
193
        yield d
 
194
 
 
195
        call = ("download_finished", (fake_command,), {})
 
196
        self.assertIn(call, self.status_frontend.call_log)
 
197
 
 
198
    @defer.inlineCallbacks
 
199
    def test_upload_added_is_forwarded(self):
 
200
        """A Upload added event is forwarded."""
 
201
        self.patch(status_listener.action_queue, "Upload", FakeTransfer)
 
202
        fake_command = FakeTransfer()
 
203
 
 
204
        d = defer.Deferred()
 
205
        self._listen_for('SYS_QUEUE_ADDED', d.callback)
 
206
        self.main.event_q.push('SYS_QUEUE_ADDED', command=fake_command)
 
207
        yield d
 
208
 
 
209
        call = ("upload_started", (fake_command,), {})
 
210
        self.assertIn(call, self.status_frontend.call_log)
 
211
 
 
212
    @defer.inlineCallbacks
 
213
    def test_upload_removed_is_forwarded(self):
 
214
        """A Upload removed event is forwarded."""
 
215
        self.patch(status_listener.action_queue, "Upload", FakeTransfer)
 
216
        fake_command = FakeTransfer()
 
217
 
 
218
        d = defer.Deferred()
 
219
        self._listen_for('SYS_QUEUE_REMOVED', d.callback)
 
220
        self.main.event_q.push('SYS_QUEUE_REMOVED', command=fake_command)
 
221
        yield d
 
222
 
 
223
        call = ("upload_finished", (fake_command,), {})
 
224
        self.assertIn(call, self.status_frontend.call_log)
 
225
 
 
226
    @defer.inlineCallbacks
 
227
    def test_queue_added_is_forwarded(self):
 
228
        """A misc queue added event is forwarded."""
 
229
        fake_command = object()
 
230
 
 
231
        d = defer.Deferred()
 
232
        self._listen_for('SYS_QUEUE_ADDED', d.callback)
 
233
        self.main.event_q.push('SYS_QUEUE_ADDED', command=fake_command)
 
234
        yield d
 
235
 
 
236
        call = ("queue_added", (fake_command,), {})
 
237
        self.assertIn(call, self.status_frontend.call_log)
 
238
 
 
239
    @defer.inlineCallbacks
 
240
    def test_queue_removed_is_forwarded(self):
 
241
        """A queue removed event is forwarded."""
 
242
        fake_command = object()
 
243
 
 
244
        d = defer.Deferred()
 
245
        self._listen_for('SYS_QUEUE_REMOVED', d.callback)
 
246
        self.main.event_q.push('SYS_QUEUE_REMOVED', command=fake_command)
 
247
        yield d
 
248
 
 
249
        call = ("queue_removed", (fake_command,), {})
 
250
        self.assertIn(call, self.status_frontend.call_log)
 
251
 
 
252
    @defer.inlineCallbacks
 
253
    def test_queue_done_is_forwarded(self):
 
254
        """A queue done event is forwarded."""
 
255
        d = defer.Deferred()
 
256
        self._listen_for('SYS_QUEUE_DONE', d.callback)
 
257
        self.main.event_q.push('SYS_QUEUE_DONE')
 
258
        yield d
 
259
 
 
260
        call = ("queue_done", (), {})
 
261
        self.assertIn(call, self.status_frontend.call_log)
 
262
 
 
263
 
 
264
class NewVolumesStatusTestCase(StatusListenerTestCase):
 
265
    """New volumes events are passed to the status object."""
 
266
 
 
267
    @defer.inlineCallbacks
 
268
    def test_new_unsubscribed_share_is_forwarded(self):
 
269
        """A new unsubscribed share event is forwarded."""
 
270
        SHARE_ID = "fake share id"
 
271
        d = defer.Deferred()
 
272
        share = Share(volume_id=SHARE_ID)
 
273
        yield self.main.vm.add_share(share)
 
274
        self._listen_for('VM_SHARE_CREATED', d.callback)
 
275
        self.main.event_q.push('VM_SHARE_CREATED', share_id=share)
 
276
        yield d
 
277
        call = ("new_share_available", (share,), {})
 
278
        self.assertIn(call, self.status_frontend.call_log)
 
279
 
 
280
    @defer.inlineCallbacks
 
281
    def test_new_unsubscribed_udf_is_forwarded(self):
 
282
        """A new unsubscribed udf event is forwarded."""
 
283
        d = defer.Deferred()
 
284
        udf = UDF()
 
285
        self._listen_for('VM_UDF_CREATED', d.callback)
 
286
        self.main.event_q.push('VM_UDF_CREATED', udf=udf)
 
287
        yield d
 
288
        call = ("new_udf_available", (udf,), {})
 
289
        self.assertIn(call, self.status_frontend.call_log)
 
290
 
 
291
 
 
292
class NetworkEventStatusTestCase(StatusListenerTestCase):
 
293
    """The connection to the server is lost and restored."""
 
294
 
 
295
    @defer.inlineCallbacks
 
296
    def test_connection_lost(self):
 
297
        """The connection to the server is lost."""
 
298
        d = defer.Deferred()
 
299
        self._listen_for('SYS_CONNECTION_LOST', d.callback)
 
300
        self.main.event_q.push('SYS_CONNECTION_LOST')
 
301
        yield d
 
302
        call = ("server_connection_lost", (), {})
 
303
        self.assertIn(call, self.status_frontend.call_log)
 
304
 
 
305
    @defer.inlineCallbacks
 
306
    def test_connection_made_is_forwarded(self):
 
307
        """The connection to the server is made."""
 
308
        d = defer.Deferred()
 
309
        self._listen_for('SYS_CONNECTION_MADE', d.callback)
 
310
        self.main.event_q.push('SYS_CONNECTION_MADE')
 
311
        yield d
 
312
        call = ("server_connection_made", (), {})
 
313
        self.assertIn(call, self.status_frontend.call_log)