def test_show_current_transfers(self): """Test the --current_transfers output with transfers in progress.""" # create a download fake_download = FakeDownload('share_id', 'down_node_id') fake_download.deflated_size = 10 fake_download.n_bytes_read = 1 fake_download.path = "down_path" self.action_q.queue.waiting.append(fake_download) # create an upload fake_upload = FakeUpload('share_id', 'node_id') fake_upload.deflated_size = 100 fake_upload.n_bytes_written = 10 fake_upload.path = "up_path" self.action_q.queue.waiting.append(fake_upload) out = StringIO() expected = ( u"Current uploads:\n path: up_path\n deflated size: 100\n " u"bytes written: 10\nCurrent downloads:\n path: down_path\n " u"deflated size: 10\n bytes read: 1\n") result = yield self.tool.get_current_uploads() show_uploads(result, out) result = yield self.tool.get_current_downloads() show_downloads(result, out) self.assertEqual(out.getvalue(), expected)
def test_show_current_transfers_empty(self): """test the output of --current_transfers option """ out = StringIO() d = self.tool.get_current_uploads() d.addCallback(lambda result: show_uploads(result, out)) d.addCallback(lambda _: self.tool.get_current_downloads()) d.addCallback(lambda result: show_downloads(result, out)) expected = u'Current uploads: 0\nCurrent downloads: 0\n' def check(result): """check the output""" self.assertEqual(out.getvalue(), expected) d.addCallback(check) return d