def test_list_profiles(self): # Setup Expected Response next_page_token = "" profiles_element = {} profiles = [profiles_element] expected_response = { "next_page_token": next_page_token, "profiles": profiles } expected_response = profile_service_pb2.ListProfilesResponse( **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 = talent_v4beta1.ProfileServiceClient() # Setup Request parent = client.tenant_path("[PROJECT]", "[TENANT]") paged_list_response = client.list_profiles(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.profiles[0] == resources[0] assert len(channel.requests) == 1 expected_request = profile_service_pb2.ListProfilesRequest( parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def list_profiles( self, parent, filter_=None, page_size=None, read_mask=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ Lists profiles by filter. The order is unspecified. Example: >>> from google.cloud import talent_v4beta1 >>> >>> client = talent_v4beta1.ProfileServiceClient() >>> >>> parent = client.tenant_path('[PROJECT]', '[TENANT]') >>> >>> # Iterate over all results >>> for element in client.list_profiles(parent): ... # process element ... pass >>> >>> >>> # Alternatively: >>> >>> # Iterate over results one page at a time >>> for page in client.list_profiles(parent).pages: ... for element in page: ... # process element ... pass Args: parent (str): Required. The resource name of the tenant under which the profile is created. The format is "projects/{project\_id}/tenants/{tenant\_id}". For example, "projects/foo/tenants/bar". filter_ (str): The filter string specifies the profiles to be enumerated. Supported operator: =, AND The field(s) eligible for filtering are: - ``externalId`` - ``groupId`` externalId and groupId cannot be specified at the same time. If both externalId and groupId are provided, the API will return a bad request error. Sample Query: - externalId = "externalId-1" - groupId = "groupId-1" page_size (int): The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page. read_mask (Union[dict, ~google.cloud.talent_v4beta1.types.FieldMask]): A field mask to specify the profile fields to be listed in response. All fields are listed if it is unset. Valid values are: - name If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.talent_v4beta1.types.FieldMask` retry (Optional[google.api_core.retry.Retry]): A retry object used to retry requests. If ``None`` is specified, requests will be retried using a default configuration. 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.api_core.page_iterator.PageIterator` instance. An iterable of :class:`~google.cloud.talent_v4beta1.types.Profile` instances. You can also iterate over the pages of the response using its `pages` property. 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 "list_profiles" not in self._inner_api_calls: self._inner_api_calls[ "list_profiles" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.list_profiles, default_retry=self._method_configs["ListProfiles"].retry, default_timeout=self._method_configs["ListProfiles"].timeout, client_info=self._client_info, ) request = profile_service_pb2.ListProfilesRequest( parent=parent, filter=filter_, page_size=page_size, read_mask=read_mask ) if metadata is None: metadata = [] metadata = list(metadata) try: routing_header = [("parent", parent)] except AttributeError: pass else: routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata( routing_header ) metadata.append(routing_metadata) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( self._inner_api_calls["list_profiles"], retry=retry, timeout=timeout, metadata=metadata, ), request=request, items_field="profiles", request_token_field="page_token", response_token_field="next_page_token", ) return iterator
def list_profiles( self, parent, page_size=None, field_mask=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ Lists profiles by filter. The order is unspecified. Example: >>> from google.cloud import talent_v4beta1 >>> >>> client = talent_v4beta1.ProfileServiceClient() >>> >>> parent = client.tenant_path('[PROJECT]', '[TENANT]') >>> >>> # Iterate over all results >>> for element in client.list_profiles(parent): ... # process element ... pass >>> >>> >>> # Alternatively: >>> >>> # Iterate over results one page at a time >>> for page in client.list_profiles(parent).pages: ... for element in page: ... # process element ... pass Args: parent (str): Required. The resource name of the tenant under which the job is created. The format is "projects/{project\_id}/tenants/{tenant\_id}", for example, "projects/api-test-project/tenants/foo". page_size (int): The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page. field_mask (Union[dict, ~google.cloud.talent_v4beta1.types.FieldMask]): Optional. A field mask to specify the profile fields to be listed in response. All fields are listed if it is unset. Valid values are: - name If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.talent_v4beta1.types.FieldMask` 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.gax.PageIterator` instance. By default, this is an iterable of :class:`~google.cloud.talent_v4beta1.types.Profile` instances. This object can also be configured to iterate over the pages of the response through the `options` parameter. 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 "list_profiles" not in self._inner_api_calls: self._inner_api_calls[ "list_profiles" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.list_profiles, default_retry=self._method_configs["ListProfiles"].retry, default_timeout=self._method_configs["ListProfiles"].timeout, client_info=self._client_info, ) request = profile_service_pb2.ListProfilesRequest( parent=parent, page_size=page_size, field_mask=field_mask ) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( self._inner_api_calls["list_profiles"], retry=retry, timeout=timeout, metadata=metadata, ), request=request, items_field="profiles", request_token_field="page_token", response_token_field="next_page_token", ) return iterator