From ad8772e1914cf7021dda46e8dd4fac6fba83b362 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Mon, 14 Oct 2019 13:40:46 -0400 Subject: [PATCH] Replaces .get with bracket notation dictionary access --- lbry/tests/integration/test_claim_commands.py | 20 +++--- lbry/tests/integration/test_file_commands.py | 54 +++++++-------- lbry/tests/integration/test_streaming.py | 66 +++++++++---------- lbry/tests/unit/lbrynet_daemon/test_Daemon.py | 30 ++++----- 4 files changed, 85 insertions(+), 85 deletions(-) diff --git a/lbry/tests/integration/test_claim_commands.py b/lbry/tests/integration/test_claim_commands.py index 2bec1a6d9..4cebc2c06 100644 --- a/lbry/tests/integration/test_claim_commands.py +++ b/lbry/tests/integration/test_claim_commands.py @@ -672,14 +672,14 @@ class StreamCommands(ClaimTestCase): tx = await self.out(self.stream_create(title='created')) txo = tx['outputs'][0] claim_id, expected = txo['claim_id'], txo['value'] - files = self.sout(self.daemon.jsonrpc_file_list()).get('items') + files = self.sout(self.daemon.jsonrpc_file_list())['items'] self.assertEqual(1, len(files)) self.assertEqual(tx['txid'], files[0]['txid']) self.assertEqual(expected, files[0]['metadata']) # update with metadata-only changes tx = await self.out(self.stream_update(claim_id, title='update 1')) - files = self.sout(self.daemon.jsonrpc_file_list()).get('items') + files = self.sout(self.daemon.jsonrpc_file_list())['items'] expected['title'] = 'update 1' self.assertEqual(1, len(files)) self.assertEqual(tx['txid'], files[0]['txid']) @@ -688,7 +688,7 @@ class StreamCommands(ClaimTestCase): # update with new data tx = await self.out(self.stream_update(claim_id, title='update 2', data=b'updated data')) expected = tx['outputs'][0]['value'] - files = self.sout(self.daemon.jsonrpc_file_list()).get('items') + files = self.sout(self.daemon.jsonrpc_file_list())['items'] self.assertEqual(1, len(files)) self.assertEqual(tx['txid'], files[0]['txid']) self.assertEqual(expected, files[0]['metadata']) @@ -1055,10 +1055,10 @@ class StreamCommands(ClaimTestCase): self.assertEqual(txs[0]['value'], '0.0') self.assertEqual(txs[0]['fee'], '-0.020107') await self.assertBalance(self.account, '7.479893') - self.assertEqual(1, self.daemon.jsonrpc_file_list().get('total_items')) + self.assertEqual(1, self.daemon.jsonrpc_file_list()['total_items']) await self.daemon.jsonrpc_file_delete(delete_all=True) - self.assertEqual(0, self.daemon.jsonrpc_file_list().get('total_items')) + self.assertEqual(0, self.daemon.jsonrpc_file_list()['total_items']) await self.stream_update(claim_id, bid='1.0') # updates previous claim txs = (await self.out(self.daemon.jsonrpc_transaction_list()))['items'] @@ -1100,12 +1100,12 @@ class StreamCommands(ClaimTestCase): file.flush() tx1 = await self.publish('foo', bid='1.0', file_path=file.name) - self.assertEqual(1, self.daemon.jsonrpc_file_list().get('total_items')) + self.assertEqual(1, self.daemon.jsonrpc_file_list()['total_items']) # doesn't error on missing arguments when doing an update stream tx2 = await self.publish('foo', tags='updated') - self.assertEqual(1, self.daemon.jsonrpc_file_list().get('total_items')) + self.assertEqual(1, self.daemon.jsonrpc_file_list()['total_items']) self.assertEqual(self.get_claim_id(tx1), self.get_claim_id(tx2)) # update conflict with two claims of the same name @@ -1113,14 +1113,14 @@ class StreamCommands(ClaimTestCase): with self.assertRaisesRegex(Exception, "There are 2 claims for 'foo'"): await self.daemon.jsonrpc_publish('foo') - self.assertEqual(2, self.daemon.jsonrpc_file_list().get('total_items')) + self.assertEqual(2, self.daemon.jsonrpc_file_list()['total_items']) # abandon duplicate stream await self.stream_abandon(self.get_claim_id(tx3)) # publish to a channel await self.channel_create('@abc') tx3 = await self.publish('foo', channel_name='@abc') - self.assertEqual(2, self.daemon.jsonrpc_file_list().get('total_items')) + self.assertEqual(2, self.daemon.jsonrpc_file_list()['total_items']) r = await self.resolve('lbry://@abc/foo') self.assertEqual( r['lbry://@abc/foo']['claim_id'], @@ -1129,7 +1129,7 @@ class StreamCommands(ClaimTestCase): # publishing again clears channel tx4 = await self.publish('foo', languages='uk-UA', tags=['Anime', 'anime ']) - self.assertEqual(2, self.daemon.jsonrpc_file_list().get('total_items')) + self.assertEqual(2, self.daemon.jsonrpc_file_list()['total_items']) r = await self.resolve('lbry://foo') claim = r['lbry://foo'] self.assertEqual(claim['txid'], tx4['outputs'][0]['txid']) diff --git a/lbry/tests/integration/test_file_commands.py b/lbry/tests/integration/test_file_commands.py index 597c83250..02778a503 100644 --- a/lbry/tests/integration/test_file_commands.py +++ b/lbry/tests/integration/test_file_commands.py @@ -15,23 +15,23 @@ class FileCommands(CommandTestCase): await self.stream_create('foo', '0.01') await self.stream_create('foo2', '0.01') - file1, file2 = self.sout(self.daemon.jsonrpc_file_list('claim_name')).get('items') + file1, file2 = self.sout(self.daemon.jsonrpc_file_list('claim_name'))['items'] self.assertEqual(file1['claim_name'], 'foo') self.assertEqual(file2['claim_name'], 'foo2') await self.daemon.jsonrpc_file_delete(claim_name='foo') - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 1) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 1) await self.daemon.jsonrpc_file_delete(claim_name='foo2') - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 0) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 0) await self.daemon.jsonrpc_get('lbry://foo') - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 1) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 1) async def test_announces(self): # announces on publish self.assertEqual(await self.daemon.storage.get_blobs_to_announce(), []) await self.stream_create('foo', '0.01') - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertSetEqual( set(await self.daemon.storage.get_blobs_to_announce()), {stream.sd_hash, stream.descriptor.blobs[0].blob_hash} @@ -120,14 +120,14 @@ class FileCommands(CommandTestCase): async def test_file_list_fields(self): await self.stream_create('foo', '0.01') - file_list = self.sout(self.daemon.jsonrpc_file_list()).get('items') + file_list = self.sout(self.daemon.jsonrpc_file_list())['items'] self.assertEqual( file_list[0]['timestamp'], None ) self.assertEqual(file_list[0]['confirmations'], -1) await self.daemon.jsonrpc_resolve('foo') - file_list = self.sout(self.daemon.jsonrpc_file_list()).get('items') + file_list = self.sout(self.daemon.jsonrpc_file_list())['items'] self.assertEqual( file_list[0]['timestamp'], self.ledger.headers[file_list[0]['height']]['timestamp'] @@ -157,12 +157,12 @@ class FileCommands(CommandTestCase): claim.stream.description = "fix typos, fix the world" await self.blockchain_update_name(txid, hexlify(claim.to_bytes()).decode(), '0.01') await self.daemon.jsonrpc_resolve('lbry://bar') - file_list = self.daemon.jsonrpc_file_list().get('items') + file_list = self.daemon.jsonrpc_file_list()['items'] self.assertEqual(file_list[0].stream_claim_info.claim.stream.description, claim.stream.description) async def test_file_list_paginated_output(self): # Make sure that without both page params, file_list returns a normal list - file_list = self.daemon.jsonrpc_file_list().get('items') + file_list = self.daemon.jsonrpc_file_list()['items'] self.assertIsInstance(file_list, list) # Should paginate @@ -198,7 +198,7 @@ class FileCommands(CommandTestCase): # Without page parameters, this should be a paginated list with default page & length file_list = self.daemon.jsonrpc_file_list() self.assertIsInstance(file_list, dict) - self.assertIs(file_list.get('total_items'), 5) + self.assertIs(file_list['total_items'], 5) # relist a subset of the file list file_list_page = self.daemon.jsonrpc_file_list(page=1, page_size=3) @@ -227,12 +227,12 @@ class FileCommands(CommandTestCase): self.assertEqual('Failed to download sd blob %s within timeout' % sd_hash, resp['error']) async def wait_files_to_complete(self): - while self.sout(self.daemon.jsonrpc_file_list(status='running')).get('items'): + while self.sout(self.daemon.jsonrpc_file_list(status='running'))['items']: 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.sout(self.daemon.jsonrpc_file_list()).get('items')[0] + file_info = self.sout(self.daemon.jsonrpc_file_list())['items'][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') @@ -243,7 +243,7 @@ class FileCommands(CommandTestCase): await asyncio.wait_for(self.wait_files_to_complete(), timeout=5) # if this hangs, file didn't get set completed # check that internal state got through up to the file list API stream = self.daemon.stream_manager.get_stream_by_stream_hash(file_info['stream_hash']) - file_info = self.sout(self.daemon.jsonrpc_file_list().get('items')[0]) + file_info = self.sout(self.daemon.jsonrpc_file_list()['items'][0]) self.assertEqual(stream.file_name, file_info['file_name']) # checks if what the API shows is what he have at the very internal level. self.assertEqual(stream.full_path, file_info['download_path']) @@ -251,7 +251,7 @@ class FileCommands(CommandTestCase): async def test_incomplete_downloads_erases_output_file_on_stop(self): tx = await self.stream_create('foo', '0.01', data=b'deadbeef' * 1000000) sd_hash = tx['outputs'][0]['value']['source']['sd_hash'] - file_info = self.sout(self.daemon.jsonrpc_file_list()).get('items')[0] + file_info = self.sout(self.daemon.jsonrpc_file_list())['items'][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) @@ -291,8 +291,8 @@ class FileCommands(CommandTestCase): # start the download resp = await self.out(self.daemon.jsonrpc_get('lbry://foo', timeout=2)) self.assertNotIn('error', resp) - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 1) - self.assertEqual('running', self.sout(self.daemon.jsonrpc_file_list()).get('items')[0]['status']) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 1) + self.assertEqual('running', self.sout(self.daemon.jsonrpc_file_list())['items'][0]['status']) await self.daemon.jsonrpc_file_set_status('stop', claim_name='foo') # recover blobs @@ -304,7 +304,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.sout(self.daemon.jsonrpc_file_list()).get('items')[0] + file_info = self.sout(self.daemon.jsonrpc_file_list())['items'][0] self.assertEqual(file_info['blobs_completed'], file_info['blobs_in_stream']) self.assertEqual('finished', file_info['status']) @@ -339,7 +339,7 @@ class FileCommands(CommandTestCase): await self.daemon.jsonrpc_file_delete(claim_name='expensive') response = await self.out(self.daemon.jsonrpc_get('lbry://expensive')) self.assertEqual(response['error'], 'fee of 11.00000 exceeds max available balance') - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 0) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 0) # FAIL: beyond maximum key fee await self.stream_create( @@ -348,7 +348,7 @@ class FileCommands(CommandTestCase): ) await self.daemon.jsonrpc_file_delete(claim_name='maxkey') response = await self.out(self.daemon.jsonrpc_get('lbry://maxkey')) - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 0) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 0) self.assertEqual(response['error'], 'fee of 111.00000 exceeds max configured to allow of 50.00000') # PASS: purchase is successful @@ -362,7 +362,7 @@ class FileCommands(CommandTestCase): raw_content_fee = response.content_fee.raw await self.ledger.wait(response.content_fee) await self.assertBalance(self.account, '8.925555') - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 1) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 1) await asyncio.wait_for(self.wait_files_to_complete(), timeout=1) @@ -378,8 +378,8 @@ class FileCommands(CommandTestCase): self.daemon.stream_manager.stop() await self.daemon.stream_manager.start() - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 1) - self.assertEqual(self.daemon.jsonrpc_file_list().get('items')[0].content_fee.raw, raw_content_fee) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 1) + self.assertEqual(self.daemon.jsonrpc_file_list()['items'][0].content_fee.raw, raw_content_fee) await self.daemon.jsonrpc_file_delete(claim_name='icanpay') # PASS: no fee address --> use the claim address to pay @@ -390,12 +390,12 @@ class FileCommands(CommandTestCase): tx, fee_amount='2.0', fee_currency='LBC', claim_address=target_address ) await self.daemon.jsonrpc_file_delete(claim_name='nofeeaddress') - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 0) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 0) response = await self.out(self.daemon.jsonrpc_get('lbry://nofeeaddress')) - self.assertIsNone(self.daemon.jsonrpc_file_list().get('items')[0].stream_claim_info.claim.stream.fee.address) + self.assertIsNone(self.daemon.jsonrpc_file_list()['items'][0].stream_claim_info.claim.stream.fee.address) self.assertIsNotNone(response['content_fee']) - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 1) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 1) self.assertEqual(response['content_fee']['outputs'][0]['amount'], '2.0') self.assertEqual(response['content_fee']['outputs'][0]['address'], target_address) @@ -416,7 +416,7 @@ class FileCommands(CommandTestCase): # Assert the file downloads await asyncio.wait_for(self.wait_files_to_complete(), timeout=1) - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 1) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 1) # Assert the transaction is recorded to the blockchain starting_balance = await self.blockchain.get_balance() @@ -435,7 +435,7 @@ class FileCommands(CommandTestCase): await self.__raw_value_update_no_fee_amount(tx, target_address) await self.daemon.jsonrpc_file_delete(claim_name='nullfee') response = await self.daemon.jsonrpc_get('lbry://nullfee') - self.assertEqual(self.daemon.jsonrpc_file_list().get('total_items'), 1) + self.assertEqual(self.daemon.jsonrpc_file_list()['total_items'], 1) self.assertIsNone(response.content_fee) self.assertTrue(response.stream_claim_info.claim.stream.has_fee) self.assertDictEqual( diff --git a/lbry/tests/integration/test_streaming.py b/lbry/tests/integration/test_streaming.py index 0522a1eb7..a390247ab 100644 --- a/lbry/tests/integration/test_streaming.py +++ b/lbry/tests/integration/test_streaming.py @@ -32,7 +32,7 @@ class RangeRequests(CommandTestCase): await self.stream_create('foo', '0.01', data=self.data, file_size=file_size) if save_blobs: self.assertTrue(len(os.listdir(self.daemon.blob_manager.blob_dir)) > 1) - await self.daemon.jsonrpc_file_list().get('items')[0].fully_reflected.wait() + await self.daemon.jsonrpc_file_list()['items'][0].fully_reflected.wait() await self.daemon.jsonrpc_file_delete(delete_from_download_dir=True, claim_name='foo') self.assertEqual(0, len(os.listdir(self.daemon.blob_manager.blob_dir))) # await self._restart_stream_manager() @@ -40,7 +40,7 @@ class RangeRequests(CommandTestCase): site = aiohttp.web.TCPSite(self.daemon.streaming_runner, self.daemon.conf.streaming_host, self.daemon.conf.streaming_port) await site.start() - self.assertListEqual(self.daemon.jsonrpc_file_list().get('items'), []) + self.assertListEqual(self.daemon.jsonrpc_file_list()['items'], []) async def _test_range_requests(self): name = 'foo' @@ -127,7 +127,7 @@ class RangeRequests(CommandTestCase): await self._setup_stream(self.data) await self._test_range_requests() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path)) self.assertIsNone(stream.download_directory) self.assertIsNone(stream.full_path) @@ -136,7 +136,7 @@ class RangeRequests(CommandTestCase): # test that repeated range requests do not create duplicate files for _ in range(3): await self._test_range_requests() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path)) self.assertIsNone(stream.download_directory) self.assertIsNone(stream.full_path) @@ -152,13 +152,13 @@ class RangeRequests(CommandTestCase): self.assertEqual( len(files_in_download_dir), len(current_files_in_download_dir) ) - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path)) self.assertIsNone(stream.download_directory) self.assertIsNone(stream.full_path) await self._test_range_requests() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path)) self.assertIsNone(stream.download_directory) self.assertIsNone(stream.full_path) @@ -171,7 +171,7 @@ class RangeRequests(CommandTestCase): self.data = get_random_bytes((MAX_BLOB_SIZE - 1) * 4) await self._setup_stream(self.data, save_blobs=False) await self._test_range_requests() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertIsNone(stream.download_directory) self.assertIsNone(stream.full_path) files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir))) @@ -179,7 +179,7 @@ class RangeRequests(CommandTestCase): # test that repeated range requests do not create duplicate files for _ in range(3): await self._test_range_requests() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertIsNone(stream.download_directory) self.assertIsNone(stream.full_path) current_files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir))) @@ -194,12 +194,12 @@ class RangeRequests(CommandTestCase): self.assertEqual( len(files_in_download_dir), len(current_files_in_download_dir) ) - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertIsNone(stream.download_directory) self.assertIsNone(stream.full_path) await self._test_range_requests() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertIsNone(stream.download_directory) self.assertIsNone(stream.full_path) current_files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir))) @@ -212,7 +212,7 @@ class RangeRequests(CommandTestCase): await self._setup_stream(self.data, save_files=True) await self._test_range_requests() - streams = self.daemon.jsonrpc_file_list().get('items') + streams = self.daemon.jsonrpc_file_list()['items'] self.assertEqual(1, len(streams)) stream = streams[0] self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path)) @@ -223,7 +223,7 @@ class RangeRequests(CommandTestCase): for _ in range(3): await self._test_range_requests() - streams = self.daemon.jsonrpc_file_list().get('items') + streams = self.daemon.jsonrpc_file_list()['items'] self.assertEqual(1, len(streams)) stream = streams[0] self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path)) @@ -240,7 +240,7 @@ class RangeRequests(CommandTestCase): self.assertEqual( len(files_in_download_dir), len(current_files_in_download_dir) ) - streams = self.daemon.jsonrpc_file_list().get('items') + streams = self.daemon.jsonrpc_file_list()['items'] self.assertEqual(1, len(streams)) stream = streams[0] self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path)) @@ -248,7 +248,7 @@ class RangeRequests(CommandTestCase): self.assertTrue(os.path.isfile(stream.full_path)) await self._test_range_requests() - streams = self.daemon.jsonrpc_file_list().get('items') + streams = self.daemon.jsonrpc_file_list()['items'] self.assertEqual(1, len(streams)) stream = streams[0] self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path)) @@ -267,7 +267,7 @@ class RangeRequests(CommandTestCase): self.daemon.conf.save_blobs = False await self._test_range_requests() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertTrue(os.path.isdir(stream.download_directory)) self.assertTrue(os.path.isfile(stream.full_path)) full_path = stream.full_path @@ -275,7 +275,7 @@ class RangeRequests(CommandTestCase): for _ in range(3): await self._test_range_requests() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertTrue(os.path.isdir(stream.download_directory)) self.assertTrue(os.path.isfile(stream.full_path)) current_files_in_download_dir = list(os.scandir(os.path.dirname(full_path))) @@ -288,14 +288,14 @@ class RangeRequests(CommandTestCase): self.assertEqual( len(files_in_download_dir), len(current_files_in_download_dir) ) - streams = self.daemon.jsonrpc_file_list().get('items') + streams = self.daemon.jsonrpc_file_list()['items'] self.assertEqual(1, len(streams)) stream = streams[0] self.assertTrue(os.path.isdir(stream.download_directory)) self.assertTrue(os.path.isfile(stream.full_path)) await self._test_range_requests() - streams = self.daemon.jsonrpc_file_list().get('items') + streams = self.daemon.jsonrpc_file_list()['items'] self.assertEqual(1, len(streams)) stream = streams[0] self.assertTrue(os.path.isdir(stream.download_directory)) @@ -311,31 +311,31 @@ class RangeRequests(CommandTestCase): async def test_switch_save_blobs_while_running(self): await self.test_streaming_only_without_blobs() self.daemon.conf.save_blobs = True - blobs_in_stream = self.daemon.jsonrpc_file_list().get('items')[0].blobs_in_stream - sd_hash = self.daemon.jsonrpc_file_list().get('items')[0].sd_hash + blobs_in_stream = self.daemon.jsonrpc_file_list()['items'][0].blobs_in_stream + sd_hash = self.daemon.jsonrpc_file_list()['items'][0].sd_hash start_file_count = len(os.listdir(self.daemon.blob_manager.blob_dir)) await self._test_range_requests() self.assertEqual(start_file_count + blobs_in_stream, len(os.listdir(self.daemon.blob_manager.blob_dir))) - self.assertEqual(0, self.daemon.jsonrpc_file_list().get('items')[0].blobs_remaining) + self.assertEqual(0, self.daemon.jsonrpc_file_list()['items'][0].blobs_remaining) # switch back self.daemon.conf.save_blobs = False await self._test_range_requests() self.assertEqual(start_file_count + blobs_in_stream, len(os.listdir(self.daemon.blob_manager.blob_dir))) - self.assertEqual(0, self.daemon.jsonrpc_file_list().get('items')[0].blobs_remaining) + self.assertEqual(0, self.daemon.jsonrpc_file_list()['items'][0].blobs_remaining) await self.daemon.jsonrpc_file_delete(delete_from_download_dir=True, sd_hash=sd_hash) self.assertEqual(start_file_count, len(os.listdir(self.daemon.blob_manager.blob_dir))) await self._test_range_requests() self.assertEqual(start_file_count, len(os.listdir(self.daemon.blob_manager.blob_dir))) - self.assertEqual(blobs_in_stream, self.daemon.jsonrpc_file_list().get('items')[0].blobs_remaining) + self.assertEqual(blobs_in_stream, self.daemon.jsonrpc_file_list()['items'][0].blobs_remaining) async def test_file_save_streaming_only_save_blobs(self): await self.test_streaming_only_with_blobs() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertIsNone(stream.full_path) self.server.stop_server() await self.daemon.jsonrpc_file_save('test', self.daemon.conf.data_dir) - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertIsNotNone(stream.full_path) await stream.finished_writing.wait() with open(stream.full_path, 'rb') as f: @@ -344,18 +344,18 @@ class RangeRequests(CommandTestCase): async def test_file_save_stop_before_finished_streaming_only(self, wait_for_start_writing=False): await self.test_streaming_only_with_blobs() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertIsNone(stream.full_path) self.server.stop_server() await self.daemon.jsonrpc_file_save('test', self.daemon.conf.data_dir) - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] path = stream.full_path self.assertIsNotNone(path) if wait_for_start_writing: await stream.started_writing.wait() self.assertTrue(os.path.isfile(path)) await self._restart_stream_manager() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertIsNotNone(stream.full_path) self.assertFalse(os.path.isfile(path)) if wait_for_start_writing: @@ -367,10 +367,10 @@ class RangeRequests(CommandTestCase): async def test_file_save_streaming_only_dont_save_blobs(self): await self.test_streaming_only_without_blobs() - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] self.assertIsNone(stream.full_path) await self.daemon.jsonrpc_file_save('test', self.daemon.conf.data_dir) - stream = self.daemon.jsonrpc_file_list().get('items')[0] + stream = self.daemon.jsonrpc_file_list()['items'][0] await stream.finished_writing.wait() with open(stream.full_path, 'rb') as f: self.assertEqual(self.data, f.read()) @@ -398,7 +398,7 @@ class RangeRequestsLRUCache(CommandTestCase): self.daemon.conf.save_blobs = False self.daemon.conf.save_files = False await self.stream_create('foo', '0.01', data=self.data, file_size=0) - await self.daemon.jsonrpc_file_list().get('items')[0].fully_reflected.wait() + await self.daemon.jsonrpc_file_list()['items'][0].fully_reflected.wait() await self.daemon.jsonrpc_file_delete(delete_from_download_dir=True, claim_name='foo') self.assertEqual(0, len(os.listdir(self.daemon.blob_manager.blob_dir))) @@ -406,10 +406,10 @@ class RangeRequestsLRUCache(CommandTestCase): site = aiohttp.web.TCPSite(self.daemon.streaming_runner, self.daemon.conf.streaming_host, self.daemon.conf.streaming_port) await site.start() - self.assertListEqual(self.daemon.jsonrpc_file_list().get('items'), []) + self.assertListEqual(self.daemon.jsonrpc_file_list()['items'], []) await self._request_stream() - self.assertEqual(1, self.daemon.jsonrpc_file_list().get('total_items')) + self.assertEqual(1, self.daemon.jsonrpc_file_list()['total_items']) self.server.stop_server() # running with cache size 0 gets through without errors without diff --git a/lbry/tests/unit/lbrynet_daemon/test_Daemon.py b/lbry/tests/unit/lbrynet_daemon/test_Daemon.py index c87a93b5d..8669aac20 100644 --- a/lbry/tests/unit/lbrynet_daemon/test_Daemon.py +++ b/lbry/tests/unit/lbrynet_daemon/test_Daemon.py @@ -135,32 +135,32 @@ class TestFileListSorting(unittest.TestCase): def test_sort_by_points_paid_no_direction_specified(self): sort_options = ['points_paid'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertEqual(self.test_points_paid, [f['points_paid'] for f in file_list]) def test_sort_by_points_paid_ascending(self): sort_options = ['points_paid,asc'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertEqual(self.test_points_paid, [f['points_paid'] for f in file_list]) def test_sort_by_points_paid_descending(self): sort_options = ['points_paid, desc'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertEqual(list(reversed(self.test_points_paid)), [f['points_paid'] for f in file_list]) def test_sort_by_file_name_no_direction_specified(self): sort_options = ['file_name'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertEqual(self.test_file_names, [f['file_name'] for f in file_list]) def test_sort_by_file_name_ascending(self): sort_options = ['file_name,\nasc'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertEqual(self.test_file_names, [f['file_name'] for f in file_list]) def test_sort_by_file_name_descending(self): sort_options = ['\tfile_name,\n\tdesc'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertEqual(list(reversed(self.test_file_names)), [f['file_name'] for f in file_list]) def test_sort_by_multiple_criteria(self): @@ -179,48 +179,48 @@ class TestFileListSorting(unittest.TestCase): format_result = lambda f: f"file_name={f['file_name']}, points_paid={f['points_paid']}" sort_options = ['file_name,asc', 'points_paid,desc'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertEqual(expected, [format_result(r) for r in file_list]) # Check that the list is not sorted as expected when sorted only by file_name. sort_options = ['file_name,asc'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertNotEqual(expected, [format_result(r) for r in file_list]) # Check that the list is not sorted as expected when sorted only by points_paid. sort_options = ['points_paid,desc'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertNotEqual(expected, [format_result(r) for r in file_list]) # Check that the list is not sorted as expected when not sorted at all. - file_list = yield f2d(self.test_daemon.jsonrpc_file_list().get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list()['items']) self.assertNotEqual(expected, [format_result(r) for r in file_list]) def test_sort_by_nested_field(self): extract_authors = lambda file_list: [f['metadata']['author'] for f in file_list] sort_options = ['metadata.author'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertEqual(self.test_authors, extract_authors(file_list)) # Check that the list matches the expected in reverse when sorting in descending order. sort_options = ['metadata.author,desc'] - file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) self.assertEqual(list(reversed(self.test_authors)), extract_authors(file_list)) # Check that the list is not sorted as expected when not sorted at all. - file_list = yield f2d(self.test_daemon.jsonrpc_file_list().get('items')) + file_list = yield f2d(self.test_daemon.jsonrpc_file_list()['items']) self.assertNotEqual(self.test_authors, extract_authors(file_list)) def test_invalid_sort_produces_meaningful_errors(self): sort_options = ['meta.author'] expected_message = "Failed to get 'meta.author', key 'meta' was not found." with self.assertRaisesRegex(Exception, expected_message): - yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) sort_options = ['metadata.foo.bar'] expected_message = "Failed to get 'metadata.foo.bar', key 'foo' was not found." with self.assertRaisesRegex(Exception, expected_message): - yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options).get('items')) + yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options)['items']) @staticmethod def _get_fake_lbry_files():