コード例 #1
0
async def test_patch_traces_flattened_async():
    client = TraceServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.patch_traces),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = None

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.patch_traces(
            project_id="project_id_value",
            traces=trace.Traces(
                traces=[trace.Trace(project_id="project_id_value")]),
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0].project_id == "project_id_value"

        assert args[0].traces == trace.Traces(
            traces=[trace.Trace(project_id="project_id_value")])
コード例 #2
0
def test_get_trace_flattened():
    client = TraceServiceClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._transport.get_trace),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = trace.Trace()

        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        client.get_trace(
            project_id="project_id_value",
            trace_id="trace_id_value",
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls) == 1
        _, args, _ = call.mock_calls[0]

        assert args[0].project_id == "project_id_value"

        assert args[0].trace_id == "trace_id_value"
コード例 #3
0
async def test_get_trace_async(transport: str = "grpc_asyncio"):
    client = TraceServiceAsyncClient(
        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 = trace.GetTraceRequest()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.get_trace),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            trace.Trace(
                project_id="project_id_value",
                trace_id="trace_id_value",
            ))

        response = await client.get_trace(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 response is the type that we expect.
    assert isinstance(response, trace.Trace)

    assert response.project_id == "project_id_value"

    assert response.trace_id == "trace_id_value"
コード例 #4
0
def test_list_traces_pages():
    client = TraceServiceClient(credentials=credentials.AnonymousCredentials, )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._transport.list_traces),
                           "__call__") as call:
        # Set the response to a series of pages.
        call.side_effect = (
            trace.ListTracesResponse(
                traces=[
                    trace.Trace(),
                    trace.Trace(),
                    trace.Trace(),
                ],
                next_page_token="abc",
            ),
            trace.ListTracesResponse(
                traces=[],
                next_page_token="def",
            ),
            trace.ListTracesResponse(
                traces=[
                    trace.Trace(),
                ],
                next_page_token="ghi",
            ),
            trace.ListTracesResponse(traces=[
                trace.Trace(),
                trace.Trace(),
            ], ),
            RuntimeError,
        )
        pages = list(client.list_traces(request={}).pages)
        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
            assert page_.raw_page.next_page_token == token
コード例 #5
0
async def test_patch_traces_flattened_error_async():
    client = TraceServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Attempting to call a method with both a request object and flattened
    # fields is an error.
    with pytest.raises(ValueError):
        await client.patch_traces(
            trace.PatchTracesRequest(),
            project_id="project_id_value",
            traces=trace.Traces(
                traces=[trace.Trace(project_id="project_id_value")]),
        )
コード例 #6
0
async def test_list_traces_async_pager():
    client = TraceServiceAsyncClient(
        credentials=credentials.AnonymousCredentials, )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
            type(client._client._transport.list_traces),
            "__call__",
            new_callable=mock.AsyncMock,
    ) as call:
        # Set the response to a series of pages.
        call.side_effect = (
            trace.ListTracesResponse(
                traces=[
                    trace.Trace(),
                    trace.Trace(),
                    trace.Trace(),
                ],
                next_page_token="abc",
            ),
            trace.ListTracesResponse(
                traces=[],
                next_page_token="def",
            ),
            trace.ListTracesResponse(
                traces=[
                    trace.Trace(),
                ],
                next_page_token="ghi",
            ),
            trace.ListTracesResponse(traces=[
                trace.Trace(),
                trace.Trace(),
            ], ),
            RuntimeError,
        )
        async_pager = await client.list_traces(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, trace.Trace) for i in responses)
コード例 #7
0
def test_list_traces_pager():
    client = TraceServiceClient(credentials=credentials.AnonymousCredentials, )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._transport.list_traces),
                           "__call__") as call:
        # Set the response to a series of pages.
        call.side_effect = (
            trace.ListTracesResponse(
                traces=[
                    trace.Trace(),
                    trace.Trace(),
                    trace.Trace(),
                ],
                next_page_token="abc",
            ),
            trace.ListTracesResponse(
                traces=[],
                next_page_token="def",
            ),
            trace.ListTracesResponse(
                traces=[
                    trace.Trace(),
                ],
                next_page_token="ghi",
            ),
            trace.ListTracesResponse(traces=[
                trace.Trace(),
                trace.Trace(),
            ], ),
            RuntimeError,
        )

        metadata = ()
        pager = client.list_traces(request={})

        assert pager._metadata == metadata

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