Exemplo n.º 1
0
def test_list_users(transport: str = 'grpc'):
    client = IdentityClient(
        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 = identity.ListUsersRequest()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._transport.list_users),
                           '__call__') as call:
        # Designate an appropriate return value for the call.
        call.return_value = identity.ListUsersResponse(
            next_page_token='next_page_token_value', )
        response = client.list_users(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.ListUsersPager)
    assert response.next_page_token == 'next_page_token_value'
Exemplo n.º 2
0
def test_list_users_pager():
    client = IdentityClient(
        credentials=credentials.AnonymousCredentials,
    )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
            type(client._transport.list_users),
            '__call__') as call:
        # Set the response to a series of pages.
        call.side_effect = (
            identity.ListUsersResponse(
                users=[
                    identity.User(),
                    identity.User(),
                    identity.User(),
                ],
                next_page_token='abc',
            ),
            identity.ListUsersResponse(
                users=[],
                next_page_token='def',
            ),
            identity.ListUsersResponse(
                users=[
                    identity.User(),
                ],
                next_page_token='ghi',
            ),
            identity.ListUsersResponse(
                users=[
                    identity.User(),
                    identity.User(),
                ],
            ),
            RuntimeError,
        )
        results = [i for i in client.list_users(
            request={},
        )]
        assert len(results) == 6
        assert all([isinstance(i, identity.User)
                    for i in results])
Exemplo n.º 3
0
def test_list_users_pages():
    client = IdentityClient(
        credentials=credentials.AnonymousCredentials,
    )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
            type(client._transport.list_users),
            '__call__') as call:
        # Set the response to a series of pages.
        call.side_effect = (
            identity.ListUsersResponse(
                users=[
                    identity.User(),
                    identity.User(),
                    identity.User(),
                ],
                next_page_token='abc',
            ),
            identity.ListUsersResponse(
                users=[],
                next_page_token='def',
            ),
            identity.ListUsersResponse(
                users=[
                    identity.User(),
                ],
                next_page_token='ghi',
            ),
            identity.ListUsersResponse(
                users=[
                    identity.User(),
                    identity.User(),
                ],
            ),
            RuntimeError,
        )
        pages = list(client.list_users(request={}).pages)
        for page, token in zip(pages, ['abc','def','ghi', '']):
            assert page.raw_page.next_page_token == token