diff --git a/lbry/torrent/torrent_manager.py b/lbry/torrent/torrent_manager.py index b4b52bdb0..96d4d50a1 100644 --- a/lbry/torrent/torrent_manager.py +++ b/lbry/torrent/torrent_manager.py @@ -104,6 +104,10 @@ class TorrentSource(ManagedDownloadSource): def completed(self): return self.torrent_session.is_completed(self.identifier) + @property + def status(self): + return self.STATUS_FINISHED if self.completed else self.STATUS_RUNNING + async def stream_file(self, request): log.info("stream torrent to browser for lbry://%s#%s (btih %s...)", self.claim_name, self.claim_id, self.identifier[:6]) diff --git a/tests/integration/datanetwork/test_file_commands.py b/tests/integration/datanetwork/test_file_commands.py index 7c1178f0e..c76172c95 100644 --- a/tests/integration/datanetwork/test_file_commands.py +++ b/tests/integration/datanetwork/test_file_commands.py @@ -82,16 +82,23 @@ class FileCommands(CommandTestCase): # second call, see its there and move on self.assertNotIn('error', await self.out(self.daemon.jsonrpc_get('torrent'))) self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1) + self.assertIn(btih, self.client_session._handles) + + # stream over streaming API (full range of the largest file) + await self.assert_torrent_streaming_works(btih) + + # check json encoder fields for torrent sources file = (await self.out(self.daemon.jsonrpc_file_list()))['items'][0] self.assertEqual(btih, file['metadata']['source']['bt_infohash']) self.assertAlmostEqual(time.time(), file['added_on'], delta=2) self.assertEqual("application/octet-stream", file['mime_type']) self.assertEqual("tmp1", file['suggested_file_name']) self.assertEqual("tmp1", file['stream_name']) - self.assertIn(btih, self.client_session._handles) - - # stream over streaming API (full range of the largest file) - await self.assert_torrent_streaming_works(btih) + self.assertTrue(file['completed']) + self.assertGreater(file['total_bytes_lower_bound'], 0) + self.assertEqual(file['total_bytes_lower_bound'], file['total_bytes']) + self.assertEqual(file['total_bytes'], file['written_bytes']) + self.assertEqual('finished', file['status']) tx, new_btih = await self.initialize_torrent(tx) self.assertNotEqual(btih, new_btih)