def test_get_customer_id_from_invalid_resource_name(self):
     """Returns None for a resource_name not starting with 'customers'."""
     resource_name = f'languageConstants/{self._MOCK_CUSTOMER_ID}'
     mock_request = customer_service_pb2.GetCustomerRequest(
         resource_name=resource_name)
     interceptor = self._create_test_interceptor()
     self.assertEqual(interceptor._get_customer_id(mock_request), None)
 def test_get_customer_id_from_resource_name(self):
     """Retrieves a customer_id from a request object via resource_name."""
     resource_name = f'customers/{self._MOCK_CUSTOMER_ID}'
     mock_request = customer_service_pb2.GetCustomerRequest(
         resource_name=resource_name)
     interceptor = self._create_test_interceptor()
     self.assertEqual(interceptor._get_customer_id(mock_request),
                      self._MOCK_CUSTOMER_ID)
    def get_customer(self,
                     resource_name,
                     retry=google.api_core.gapic_v1.method.DEFAULT,
                     timeout=google.api_core.gapic_v1.method.DEFAULT,
                     metadata=None):
        """
        Returns the requested customer in full detail.

        Args:
            resource_name (str): Required. The resource name of the customer to fetch.
            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.ads.googleads_v3.types.Customer` 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_customer' not in self._inner_api_calls:
            self._inner_api_calls[
                'get_customer'] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.get_customer,
                    default_retry=self._method_configs['GetCustomer'].retry,
                    default_timeout=self._method_configs['GetCustomer'].
                    timeout,
                    client_info=self._client_info,
                )

        request = customer_service_pb2.GetCustomerRequest(
            resource_name=resource_name, )
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [('resource_name', resource_name)]
        except AttributeError:
            pass
        else:
            routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
                routing_header)
            metadata.append(routing_metadata)

        return self._inner_api_calls['get_customer'](request,
                                                     retry=retry,
                                                     timeout=timeout,
                                                     metadata=metadata)