def test_paged_expand_pager():
    client = EchoClient(credentials=credentials.AnonymousCredentials, )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._transport.paged_expand),
                           '__call__') as call:
        # Set the response to a series of pages.
        call.side_effect = (
            gs_echo.PagedExpandResponse(
                responses=[
                    gs_echo.EchoResponse(),
                    gs_echo.EchoResponse(),
                    gs_echo.EchoResponse(),
                ],
                next_page_token='abc',
            ),
            gs_echo.PagedExpandResponse(
                responses=[],
                next_page_token='def',
            ),
            gs_echo.PagedExpandResponse(
                responses=[
                    gs_echo.EchoResponse(),
                ],
                next_page_token='ghi',
            ),
            gs_echo.PagedExpandResponse(responses=[
                gs_echo.EchoResponse(),
                gs_echo.EchoResponse(),
            ], ),
            RuntimeError,
        )
        results = [i for i in client.paged_expand(request={}, )]
        assert len(results) == 6
        assert all(isinstance(i, gs_echo.EchoResponse) for i in results)
def test_paged_expand_pages():
    client = EchoClient(credentials=credentials.AnonymousCredentials, )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._transport.paged_expand),
                           '__call__') as call:
        # Set the response to a series of pages.
        call.side_effect = (
            gs_echo.PagedExpandResponse(
                responses=[
                    gs_echo.EchoResponse(),
                    gs_echo.EchoResponse(),
                    gs_echo.EchoResponse(),
                ],
                next_page_token='abc',
            ),
            gs_echo.PagedExpandResponse(
                responses=[],
                next_page_token='def',
            ),
            gs_echo.PagedExpandResponse(
                responses=[
                    gs_echo.EchoResponse(),
                ],
                next_page_token='ghi',
            ),
            gs_echo.PagedExpandResponse(responses=[
                gs_echo.EchoResponse(),
                gs_echo.EchoResponse(),
            ], ),
            RuntimeError,
        )
        pages = list(client.paged_expand(request={}).pages)
        for page, token in zip(pages, ['abc', 'def', 'ghi', '']):
            assert page.raw_page.next_page_token == token
def test_paged_expand(transport: str = 'grpc'):
    client = EchoClient(
        credentials=credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = gs_echo.PagedExpandRequest()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._transport.paged_expand),
                           '__call__') as call:
        # Designate an appropriate return value for the call.
        call.return_value = gs_echo.PagedExpandResponse(
            next_page_token='next_page_token_value', )

        response = client.paged_expand(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls) == 1
        _, args, _ = call.mock_calls[0]

        assert args[0] == request

    # Establish that the response is the type that we expect.
    assert isinstance(response, pagers.PagedExpandPager)
    assert response.next_page_token == 'next_page_token_value'