fix status for completed torrents

This commit is contained in:
Victor Shyba 2022-10-28 01:26:35 -03:00
parent 31c6e0e835
commit 651348f6e0
2 changed files with 15 additions and 4 deletions

View file

@ -104,6 +104,10 @@ class TorrentSource(ManagedDownloadSource):
def completed(self): def completed(self):
return self.torrent_session.is_completed(self.identifier) 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): async def stream_file(self, request):
log.info("stream torrent to browser for lbry://%s#%s (btih %s...)", self.claim_name, self.claim_id, log.info("stream torrent to browser for lbry://%s#%s (btih %s...)", self.claim_name, self.claim_id,
self.identifier[:6]) self.identifier[:6])

View file

@ -82,16 +82,23 @@ class FileCommands(CommandTestCase):
# second call, see its there and move on # second call, see its there and move on
self.assertNotIn('error', await self.out(self.daemon.jsonrpc_get('torrent'))) self.assertNotIn('error', await self.out(self.daemon.jsonrpc_get('torrent')))
self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1) 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] file = (await self.out(self.daemon.jsonrpc_file_list()))['items'][0]
self.assertEqual(btih, file['metadata']['source']['bt_infohash']) self.assertEqual(btih, file['metadata']['source']['bt_infohash'])
self.assertAlmostEqual(time.time(), file['added_on'], delta=2) self.assertAlmostEqual(time.time(), file['added_on'], delta=2)
self.assertEqual("application/octet-stream", file['mime_type']) self.assertEqual("application/octet-stream", file['mime_type'])
self.assertEqual("tmp1", file['suggested_file_name']) self.assertEqual("tmp1", file['suggested_file_name'])
self.assertEqual("tmp1", file['stream_name']) self.assertEqual("tmp1", file['stream_name'])
self.assertIn(btih, self.client_session._handles) self.assertTrue(file['completed'])
self.assertGreater(file['total_bytes_lower_bound'], 0)
# stream over streaming API (full range of the largest file) self.assertEqual(file['total_bytes_lower_bound'], file['total_bytes'])
await self.assert_torrent_streaming_works(btih) self.assertEqual(file['total_bytes'], file['written_bytes'])
self.assertEqual('finished', file['status'])
tx, new_btih = await self.initialize_torrent(tx) tx, new_btih = await self.initialize_torrent(tx)
self.assertNotEqual(btih, new_btih) self.assertNotEqual(btih, new_btih)