예제 #1
0
def test_list_traces_flattened_error():
    client = TraceServiceClient(
        credentials=credentials.AnonymousCredentials(), )

    # Attempting to call a method with both a request object and flattened
    # fields is an error.
    with pytest.raises(ValueError):
        client.list_traces(
            trace.ListTracesRequest(),
            project_id="project_id_value",
        )
예제 #2
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
예제 #3
0
def test_list_traces(transport: str = "grpc",
                     request_type=trace.ListTracesRequest):
    client = TraceServiceClient(
        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.list_traces),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = trace.ListTracesResponse(
            next_page_token="next_page_token_value", )

        response = client.list_traces(request)

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

        assert args[0] == trace.ListTracesRequest()

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

    assert response.next_page_token == "next_page_token_value"
예제 #4
0
def test_list_traces_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.list_traces),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = trace.ListTracesResponse()

        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        client.list_traces(project_id="project_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"
예제 #5
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)