def test_pagination(echo): text = 'The hail in Wales falls mainly on the snails.' results = [i for i in echo.paged_expand({ 'content': text, 'page_size': 3, })] assert len(results) == 9 assert results == [showcase.EchoResponse(content=i) for i in text.split(' ')]
async def test_pagination_async(async_echo): text = 'The hail in Wales falls mainly on the snails.' results = [] async for i in await async_echo.paged_expand({ 'content': text, 'page_size': 3, }): results.append(i) assert len(results) == 9 assert results == [showcase.EchoResponse(content=i) for i in text.split(' ')]
def test_pagination_pages(echo): text = "The hail in Wales falls mainly on the snails." page_results = list(echo.paged_expand({ 'content': text, 'page_size': 3, }).pages) assert len(page_results) == 3 assert not page_results[-1].next_page_token # The monolithic surface uses a wrapper type that needs an explicit property # for a 'raw_page': we need to duplicate that interface, even though the # architecture is different. assert page_results[0].raw_page is page_results[0] results = [r for p in page_results for r in p.responses] assert results == [showcase.EchoResponse(content=i) for i in text.split(' ')]