Exemplo n.º 1
0
def test_query_time_series_pages():
    client = QueryServiceClient(credentials=credentials.AnonymousCredentials, )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.query_time_series),
                           "__call__") as call:
        # Set the response to a series of pages.
        call.side_effect = (
            metric_service.QueryTimeSeriesResponse(
                time_series_data=[
                    metric.TimeSeriesData(),
                    metric.TimeSeriesData(),
                    metric.TimeSeriesData(),
                ],
                next_page_token="abc",
            ),
            metric_service.QueryTimeSeriesResponse(
                time_series_data=[],
                next_page_token="def",
            ),
            metric_service.QueryTimeSeriesResponse(
                time_series_data=[
                    metric.TimeSeriesData(),
                ],
                next_page_token="ghi",
            ),
            metric_service.QueryTimeSeriesResponse(time_series_data=[
                metric.TimeSeriesData(),
                metric.TimeSeriesData(),
            ], ),
            RuntimeError,
        )
        pages = list(client.query_time_series(request={}).pages)
        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
            assert page_.raw_page.next_page_token == token
Exemplo n.º 2
0
async def test_query_time_series_field_headers_async():
    client = QueryServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Any value that is part of the HTTP/1.1 URI should be sent as
    # a field header. Set these to a non-empty value.
    request = metric_service.QueryTimeSeriesRequest()
    request.name = "name/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.query_time_series),
                           "__call__") as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            metric_service.QueryTimeSeriesResponse())

        await client.query_time_series(request)

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

    # Establish that the field header was sent.
    _, _, kw = call.mock_calls[0]
    assert (
        "x-goog-request-params",
        "name=name/value",
    ) in kw["metadata"]
Exemplo n.º 3
0
async def test_query_time_series_async(
        transport: str = "grpc_asyncio",
        request_type=metric_service.QueryTimeSeriesRequest):
    client = QueryServiceAsyncClient(
        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 = request_type()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.query_time_series),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            metric_service.QueryTimeSeriesResponse(
                next_page_token="next_page_token_value", ))

        response = await client.query_time_series(request)

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

        assert args[0] == metric_service.QueryTimeSeriesRequest()

    # Establish that the response is the type that we expect.
    assert isinstance(response, pagers.QueryTimeSeriesAsyncPager)

    assert response.next_page_token == "next_page_token_value"
Exemplo n.º 4
0
async def test_query_time_series_async_pager():
    client = QueryServiceAsyncClient(
        credentials=credentials.AnonymousCredentials, )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
            type(client.transport.query_time_series),
            "__call__",
            new_callable=mock.AsyncMock,
    ) as call:
        # Set the response to a series of pages.
        call.side_effect = (
            metric_service.QueryTimeSeriesResponse(
                time_series_data=[
                    metric.TimeSeriesData(),
                    metric.TimeSeriesData(),
                    metric.TimeSeriesData(),
                ],
                next_page_token="abc",
            ),
            metric_service.QueryTimeSeriesResponse(
                time_series_data=[],
                next_page_token="def",
            ),
            metric_service.QueryTimeSeriesResponse(
                time_series_data=[
                    metric.TimeSeriesData(),
                ],
                next_page_token="ghi",
            ),
            metric_service.QueryTimeSeriesResponse(time_series_data=[
                metric.TimeSeriesData(),
                metric.TimeSeriesData(),
            ], ),
            RuntimeError,
        )
        async_pager = await client.query_time_series(request={}, )
        assert async_pager.next_page_token == "abc"
        responses = []
        async for response in async_pager:
            responses.append(response)

        assert len(responses) == 6
        assert all(isinstance(i, metric.TimeSeriesData) for i in responses)
Exemplo n.º 5
0
def test_query_time_series_pager():
    client = QueryServiceClient(credentials=credentials.AnonymousCredentials, )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.query_time_series),
                           "__call__") as call:
        # Set the response to a series of pages.
        call.side_effect = (
            metric_service.QueryTimeSeriesResponse(
                time_series_data=[
                    metric.TimeSeriesData(),
                    metric.TimeSeriesData(),
                    metric.TimeSeriesData(),
                ],
                next_page_token="abc",
            ),
            metric_service.QueryTimeSeriesResponse(
                time_series_data=[],
                next_page_token="def",
            ),
            metric_service.QueryTimeSeriesResponse(
                time_series_data=[
                    metric.TimeSeriesData(),
                ],
                next_page_token="ghi",
            ),
            metric_service.QueryTimeSeriesResponse(time_series_data=[
                metric.TimeSeriesData(),
                metric.TimeSeriesData(),
            ], ),
            RuntimeError,
        )

        metadata = ()
        metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata(
            (("name", ""), )), )
        pager = client.query_time_series(request={})

        assert pager._metadata == metadata

        results = [i for i in pager]
        assert len(results) == 6
        assert all(isinstance(i, metric.TimeSeriesData) for i in results)