diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index a8ebdea74..2e8efe967 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -837,37 +837,8 @@ class Daemon(metaclass=JSONRPCServerType): --file_name= : (str) specified name for the downloaded file --timeout= : (int) download timeout in number of seconds - Returns: - (dict) Dictionary containing information about the stream - { - 'completed': (bool) true if download is completed, - 'file_name': (str) name of file, - 'download_directory': (str) download directory, - 'points_paid': (float) credit paid to download file, - 'stopped': (bool) true if download is stopped, - 'stream_hash': (str) stream hash of file, - 'stream_name': (str) stream name , - 'suggested_file_name': (str) suggested file name, - 'sd_hash': (str) sd hash of file, - 'download_path': (str) download path of file, - 'mime_type': (str) mime type of file, - 'key': (str) key attached to file, - 'total_bytes': (int) file size in bytes, - 'written_bytes': (int) written size in bytes, - 'blobs_completed': (int) number of fully downloaded blobs, - 'blobs_in_stream': (int) total blobs on stream, - 'status': (str) downloader status, - 'claim_id': (str) claim id, - 'outpoint': (str) claim outpoint string, - 'txid': (str) claim txid, - 'nout': (int) claim nout, - 'metadata': (dict) claim metadata, - 'channel_claim_id': (str) None if claim is not signed - 'channel_name': (str) None if claim is not signed - 'claim_name': (str) claim name - } + Returns: {File} """ - try: stream = await self.stream_manager.download_stream_from_uri( uri, self.exchange_rate_manager, file_name, timeout @@ -877,8 +848,7 @@ class Daemon(metaclass=JSONRPCServerType): except Exception as e: log.warning("Error downloading %s: %s", uri, str(e)) return {"error": str(e)} - else: - return stream.as_dict() + return stream SETTINGS_DOC = """ Settings management. diff --git a/lbrynet/testcase.py b/lbrynet/testcase.py index cf89236af..aaa273ec6 100644 --- a/lbrynet/testcase.py +++ b/lbrynet/testcase.py @@ -153,10 +153,13 @@ class CommandTestCase(IntegrationTestCase): return self.blockchain._cli_cmnd('claimname', name, value, amount) async def out(self, awaitable): - """ Converts Daemon API call results (dictionary) - to JSON and then back to a dictionary. """ + """ Serializes lbrynet API results to JSON then loads and returns it as dictionary. """ return json.loads(jsonrpc_dumps_pretty(await awaitable, ledger=self.ledger))['result'] + def sout(self, value): + """ Synchronous version of `out` method. """ + return json.loads(jsonrpc_dumps_pretty(value, ledger=self.ledger))['result'] + async def stream_create(self, name='hovercraft', bid='1.0', data=b'hi!', confirm=True, **kwargs): with tempfile.NamedTemporaryFile() as file: file.write(data) diff --git a/tests/integration/test_chris45.py b/tests/integration/test_chris45.py index 27d5b398d..f1774ca46 100644 --- a/tests/integration/test_chris45.py +++ b/tests/integration/test_chris45.py @@ -97,7 +97,7 @@ class EpicAdventuresOfChris45(CommandTestCase): # Amidst all this Chris receives a call from his friend Ramsey # who says that it is of utmost urgency that Chris transfer him # 1 LBC to which Chris readily obliges - ramsey_account_id = (await self.daemon.jsonrpc_account_create("Ramsey"))['id'] + ramsey_account_id = (await self.out(self.daemon.jsonrpc_account_create("Ramsey")))['id'] ramsey_address = await self.daemon.jsonrpc_address_unused(ramsey_account_id) result = await self.out(self.daemon.jsonrpc_account_send('1.0', ramsey_address)) self.assertIn("txid", result) diff --git a/tests/integration/test_claim_commands.py b/tests/integration/test_claim_commands.py index 3765e1eed..1467f9683 100644 --- a/tests/integration/test_claim_commands.py +++ b/tests/integration/test_claim_commands.py @@ -137,7 +137,7 @@ class ChannelCommands(CommandTestCase): ) # send channel to someone else - new_account = await self.daemon.jsonrpc_account_create('second account') + new_account = await self.out(self.daemon.jsonrpc_account_create('second account')) account2_id, account2 = new_account['id'], self.daemon.get_account_or_error(new_account['id']) # before sending @@ -222,7 +222,7 @@ class StreamCommands(CommandTestCase): async def test_publishing_checks_all_accounts_for_channel(self): account1_id, account1 = self.account.id, self.account - new_account = await self.daemon.jsonrpc_account_create('second account') + new_account = await self.out(self.daemon.jsonrpc_account_create('second account')) account2_id, account2 = new_account['id'], self.daemon.get_account_or_error(new_account['id']) await self.out(self.channel_create('@spam', '1.0')) @@ -342,7 +342,7 @@ class StreamCommands(CommandTestCase): self.assertEqual(txo['value']['stream'], fixed_values) # send claim to someone else - new_account = await self.daemon.jsonrpc_account_create('second account') + new_account = await self.out(self.daemon.jsonrpc_account_create('second account')) account2_id, account2 = new_account['id'], self.daemon.get_account_or_error(new_account['id']) # before sending @@ -655,7 +655,7 @@ class SupportCommands(CommandTestCase): async def test_regular_supports_and_tip_supports(self): # account2 will be used to send tips and supports to account1 - account2_id = (await self.daemon.jsonrpc_account_create('second account'))['id'] + account2_id = (await self.out(self.daemon.jsonrpc_account_create('second account')))['id'] account2 = self.daemon.get_account_or_error(account2_id) # send account2 5 LBC out of the 10 LBC in account1 diff --git a/tests/integration/test_file_commands.py b/tests/integration/test_file_commands.py index c30ce7584..f0e40e1a1 100644 --- a/tests/integration/test_file_commands.py +++ b/tests/integration/test_file_commands.py @@ -14,7 +14,7 @@ class FileCommands(CommandTestCase): await self.stream_create('foo', '0.01') await self.stream_create('foo2', '0.01') - file1, file2 = self.daemon.jsonrpc_file_list('claim_name') + file1, file2 = self.sout(self.daemon.jsonrpc_file_list('claim_name')) self.assertEqual(file1['claim_name'], 'foo') self.assertEqual(file2['claim_name'], 'foo2') @@ -44,12 +44,12 @@ class FileCommands(CommandTestCase): self.assertEquals('Failed to download sd blob %s within timeout' % sd_hash, resp['error']) async def wait_files_to_complete(self): - while self.daemon.jsonrpc_file_list(status='running'): + while self.sout(self.daemon.jsonrpc_file_list(status='running')): await asyncio.sleep(0.01) async def test_filename_conflicts_management_on_resume_download(self): await self.stream_create('foo', '0.01', data=bytes([0] * (1 << 23))) - file_info = self.daemon.jsonrpc_file_list()[0] + file_info = self.sout(self.daemon.jsonrpc_file_list())[0] original_path = os.path.join(self.daemon.conf.download_dir, file_info['file_name']) await self.daemon.jsonrpc_file_delete(claim_name='foo') await self.daemon.jsonrpc_get('lbry://foo') @@ -60,7 +60,7 @@ class FileCommands(CommandTestCase): await asyncio.wait_for(self.wait_files_to_complete(), timeout=5) # if this hangs, file didnt get set completed # check that internal state got through up to the file list API downloader = self.daemon.stream_manager.get_stream_by_stream_hash(file_info['stream_hash']).downloader - file_info = self.daemon.jsonrpc_file_list()[0] + file_info = self.sout(self.daemon.jsonrpc_file_list())[0] self.assertEqual(downloader.output_file_name, file_info['file_name']) # checks if what the API shows is what he have at the very internal level. self.assertEqual(downloader.output_path, file_info['download_path']) @@ -71,7 +71,7 @@ class FileCommands(CommandTestCase): async def test_incomplete_downloads_erases_output_file_on_stop(self): tx = await self.stream_create('foo', '0.01') sd_hash = tx['outputs'][0]['value']['stream']['sd_hash'] - file_info = self.daemon.jsonrpc_file_list()[0] + file_info = self.sout(self.daemon.jsonrpc_file_list())[0] await self.daemon.jsonrpc_file_delete(claim_name='foo') blobs = await self.server_storage.get_blobs_for_stream( await self.server_storage.get_stream_hash_for_sd_hash(sd_hash) @@ -110,7 +110,7 @@ class FileCommands(CommandTestCase): resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2) self.assertNotIn('error', resp) self.assertEqual(len(self.daemon.jsonrpc_file_list()), 1) - self.assertEqual('running', self.daemon.jsonrpc_file_list()[0]['status']) + self.assertEqual('running', self.sout(self.daemon.jsonrpc_file_list())[0]['status']) await self.daemon.jsonrpc_file_set_status('stop', claim_name='foo') # recover blobs @@ -122,7 +122,7 @@ class FileCommands(CommandTestCase): await self.daemon.jsonrpc_file_set_status('start', claim_name='foo') await asyncio.wait_for(self.wait_files_to_complete(), timeout=5) - file_info = self.daemon.jsonrpc_file_list()[0] + file_info = self.sout(self.daemon.jsonrpc_file_list())[0] self.assertEqual(file_info['blobs_completed'], file_info['blobs_in_stream']) self.assertEqual('finished', file_info['status'])