def test_get_trace(self):
        # Setup Expected Response
        project_id_2 = 'projectId2939242356'
        trace_id_2 = 'traceId2987826376'
        expected_response = {
            'project_id': project_id_2,
            'trace_id': trace_id_2
        }
        expected_response = trace_pb2.Trace(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = trace_v1.TraceServiceClient(channel=channel)

        # Setup Request
        project_id = 'projectId-1969970175'
        trace_id = 'traceId1270300245'

        response = client.get_trace(project_id, trace_id)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = trace_pb2.GetTraceRequest(project_id=project_id,
                                                     trace_id=trace_id)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def get_trace(self,
                  project_id,
                  trace_id,
                  retry=google.api_core.gapic_v1.method.DEFAULT,
                  timeout=google.api_core.gapic_v1.method.DEFAULT,
                  metadata=None):
        """
        Gets a single trace by its ID.

        Example:
            >>> from google.cloud import trace_v1
            >>>
            >>> client = trace_v1.TraceServiceClient()
            >>>
            >>> # TODO: Initialize `project_id`:
            >>> project_id = ''
            >>>
            >>> # TODO: Initialize `trace_id`:
            >>> trace_id = ''
            >>>
            >>> response = client.get_trace(project_id, trace_id)

        Args:
            project_id (str): ID of the Cloud project where the trace data is stored.
            trace_id (str): ID of the trace to return.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.trace_v1.types.Trace` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if 'get_trace' not in self._inner_api_calls:
            self._inner_api_calls[
                'get_trace'] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.get_trace,
                    default_retry=self._method_configs['GetTrace'].retry,
                    default_timeout=self._method_configs['GetTrace'].timeout,
                    client_info=self._client_info,
                )

        request = trace_pb2.GetTraceRequest(
            project_id=project_id,
            trace_id=trace_id,
        )
        return self._inner_api_calls['get_trace'](
            request, retry=retry, timeout=timeout, metadata=metadata)
    def test_get_trace(self):
        # Setup Expected Response
        project_id_2 = "projectId2939242356"
        trace_id_2 = "traceId2987826376"
        expected_response = {
            "project_id": project_id_2,
            "trace_id": trace_id_2
        }
        expected_response = trace_pb2.Trace(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = trace_v1.TraceServiceClient()

        # Setup Request
        project_id = "projectId-1969970175"
        trace_id = "traceId1270300245"

        response = client.get_trace(project_id, trace_id)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = trace_pb2.GetTraceRequest(project_id=project_id,
                                                     trace_id=trace_id)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemplo n.º 4
0
    def get_trace(self,
                  project_id,
                  trace_id,
                  retry=google.api_core.gapic_v1.method.DEFAULT,
                  timeout=google.api_core.gapic_v1.method.DEFAULT):
        """
        Gets a single trace by its ID.

        Example:
            >>> from google.cloud import trace_v1
            >>>
            >>> client = trace_v1.TraceServiceClient()
            >>>
            >>> project_id = ''
            >>> trace_id = ''
            >>>
            >>> response = client.get_trace(project_id, trace_id)

        Args:
            project_id (str): ID of the Cloud project where the trace data is stored.
            trace_id (str): ID of the trace to return.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.

        Returns:
            A :class:`~google.cloud.trace_v1.types.Trace` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        request = trace_pb2.GetTraceRequest(project_id=project_id,
                                            trace_id=trace_id)
        return self._get_trace(request, retry=retry, timeout=timeout)