forked from LBRYCommunity/lbry-sdk
Adds pre-formatted file_list
method to testcase, fixes file_list tests
This commit is contained in:
parent
ad8772e191
commit
69c0cefe5e
2 changed files with 32 additions and 40 deletions
|
@ -278,6 +278,9 @@ class CommandTestCase(IntegrationTestCase):
|
||||||
async def claim_search(self, **kwargs):
|
async def claim_search(self, **kwargs):
|
||||||
return (await self.out(self.daemon.jsonrpc_claim_search(**kwargs)))['items']
|
return (await self.out(self.daemon.jsonrpc_claim_search(**kwargs)))['items']
|
||||||
|
|
||||||
|
def file_list(self, *args, **kwargs):
|
||||||
|
return self.sout(self.daemon.jsonrpc_file_list(*args, **kwargs))['items']
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_claim_id(tx):
|
def get_claim_id(tx):
|
||||||
return tx['outputs'][0]['claim_id']
|
return tx['outputs'][0]['claim_id']
|
||||||
|
|
|
@ -11,6 +11,12 @@ class FileCommands(CommandTestCase):
|
||||||
|
|
||||||
VERBOSITY = logging.WARN
|
VERBOSITY = logging.WARN
|
||||||
|
|
||||||
|
async def create_streams_in_range(self, *args, **kwargs):
|
||||||
|
self.stream_claim_ids = []
|
||||||
|
for i in range(*args, **kwargs):
|
||||||
|
t = await self.stream_create(f'Stream_{i}', '0.00001', b'This is a stream')
|
||||||
|
self.stream_claim_ids.append(t['outputs'][0]['claim_id'])
|
||||||
|
|
||||||
async def test_file_management(self):
|
async def test_file_management(self):
|
||||||
await self.stream_create('foo', '0.01')
|
await self.stream_create('foo', '0.01')
|
||||||
await self.stream_create('foo2', '0.01')
|
await self.stream_create('foo2', '0.01')
|
||||||
|
@ -161,53 +167,36 @@ class FileCommands(CommandTestCase):
|
||||||
self.assertEqual(file_list[0].stream_claim_info.claim.stream.description, claim.stream.description)
|
self.assertEqual(file_list[0].stream_claim_info.claim.stream.description, claim.stream.description)
|
||||||
|
|
||||||
async def test_file_list_paginated_output(self):
|
async def test_file_list_paginated_output(self):
|
||||||
# Make sure that without both page params, file_list returns a normal list
|
await self.create_streams_in_range(0, 20)
|
||||||
file_list = self.daemon.jsonrpc_file_list()['items']
|
|
||||||
self.assertIsInstance(file_list, list)
|
|
||||||
|
|
||||||
# Should paginate
|
page = self.file_list(page_size=20)
|
||||||
file_list = self.daemon.jsonrpc_file_list(page=1)
|
page_claim_ids = [item['claim_id'] for item in page]
|
||||||
self.assertIsInstance(file_list, dict)
|
self.assertListEqual(page_claim_ids, self.stream_claim_ids)
|
||||||
|
|
||||||
# Also should paginate
|
page = self.file_list(page_size=6)
|
||||||
file_list = self.daemon.jsonrpc_file_list(page_size=212312)
|
page_claim_ids = [item['claim_id'] for item in page]
|
||||||
self.assertIsInstance(file_list, dict)
|
self.assertListEqual(page_claim_ids, self.stream_claim_ids[:6])
|
||||||
|
|
||||||
# Definitely should paginate
|
page = self.file_list(page_size=6, page=2)
|
||||||
file_list = self.daemon.jsonrpc_file_list(page=1, page_size=50)
|
page_claim_ids = [item['claim_id'] for item in page]
|
||||||
self.assertIsInstance(file_list, dict)
|
self.assertListEqual(page_claim_ids, self.stream_claim_ids[6:12])
|
||||||
|
|
||||||
# Test to make sure the paginated output exists when using page, page_size
|
out_of_bounds = self.file_list(page=5, page_size=6)
|
||||||
self.assertIn('items', file_list)
|
self.assertEqual(out_of_bounds, [])
|
||||||
self.assertIn('page', file_list)
|
|
||||||
self.assertIn('page_size', file_list)
|
|
||||||
self.assertIn('total_items', file_list)
|
|
||||||
self.assertIn('total_pages', file_list)
|
|
||||||
|
|
||||||
# The list should be inside the paginated output
|
complete = self.daemon.jsonrpc_file_list()
|
||||||
self.assertIsInstance(file_list['items'], list)
|
self.assertEqual(complete['total_pages'], 1)
|
||||||
self.assertLessEqual(len(file_list['items']), 50)
|
self.assertEqual(complete['total_items'], 20)
|
||||||
|
|
||||||
# Create 5 files to list
|
page = self.daemon.jsonrpc_file_list(page_size=10, page=1)
|
||||||
stream1 = await self.stream_create('file1', '0.01', b'house up on a hill')
|
self.assertEqual(page['total_pages'], 2)
|
||||||
stream2 = await self.stream_create('file2', '0.01', b'moon is lying still')
|
self.assertEqual(page['total_items'], 20)
|
||||||
stream3 = await self.stream_create('file3', '0.01', b'shadows of the trees')
|
self.assertEqual(page['page'], 1)
|
||||||
stream4 = await self.stream_create('file4', '0.01', b'witnessing the wild breeze')
|
|
||||||
stream5 = await self.stream_create('file5', '0.01', b'come on baby run with me')
|
|
||||||
|
|
||||||
# Without page parameters, this should be a paginated list with default page & length
|
full = self.sout(self.daemon.jsonrpc_file_list(page_size=20, page=1))
|
||||||
file_list = self.daemon.jsonrpc_file_list()
|
page1 = self.file_list(page=1, page_size=10)
|
||||||
self.assertIsInstance(file_list, dict)
|
page2 = self.file_list(page=2, page_size=10)
|
||||||
self.assertIs(file_list['total_items'], 5)
|
self.assertEqual(page1 + page2, full['items'])
|
||||||
|
|
||||||
# relist a subset of the file list
|
|
||||||
file_list_page = self.daemon.jsonrpc_file_list(page=1, page_size=3)
|
|
||||||
self.assertEqual(file_list_page['total_items'], len(file_list))
|
|
||||||
self.assertEqual(len(file_list_page['items']), 3)
|
|
||||||
|
|
||||||
# Make sure the second page contains the other 2 files
|
|
||||||
file_list_page = self.daemon.jsonrpc_file_list(page=2, page_size=3)
|
|
||||||
self.assertEqual(len(file_list_page['items']), 2)
|
|
||||||
|
|
||||||
async def test_download_different_timeouts(self):
|
async def test_download_different_timeouts(self):
|
||||||
tx = await self.stream_create('foo', '0.01')
|
tx = await self.stream_create('foo', '0.01')
|
||||||
|
|
Loading…
Reference in a new issue