def test_complete_query(self): # Setup Expected Response expected_response = {} expected_response = completion_service_pb2.CompleteQueryResponse( **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.CompletionClient() # Setup Request parent = client.tenant_path("[PROJECT]", "[TENANT]") query = "query107944136" page_size = 883849137 response = client.complete_query(parent, query, page_size) assert expected_response == response assert len(channel.requests) == 1 expected_request = completion_service_pb2.CompleteQueryRequest( parent=parent, query=query, page_size=page_size) actual_request = channel.requests[0][1] assert expected_request == actual_request
def complete_query( self, parent, query, page_size, language_codes=None, company=None, scope=None, type_=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ Completes the specified prefix with keyword suggestions. Intended for use by a job search auto-complete search box. Example: >>> from google.cloud import talent_v4beta1 >>> >>> client = talent_v4beta1.CompletionClient() >>> >>> parent = client.tenant_path('[PROJECT]', '[TENANT]') >>> >>> # TODO: Initialize `query`: >>> query = '' >>> >>> # TODO: Initialize `page_size`: >>> page_size = 0 >>> >>> response = client.complete_query(parent, query, page_size) Args: parent (str): Required. Resource name of tenant the completion is performed within. The format is "projects/{project\_id}/tenants/{tenant\_id}", for example, "projects/api-test-project/tenant/foo". Tenant id is optional and the default tenant is used if unspecified, for example, "projects/api-test-project". query (str): Required. The query used to generate suggestions. The maximum number of allowed characters is 255. page_size (int): Required. Completion result count. The maximum allowed page size is 10. language_codes (list[str]): Optional. The list of languages of the query. This is the BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see `Tags for Identifying Languages <https://tools.ietf.org/html/bcp47>`__. For ``CompletionType.JOB_TITLE`` type, only open jobs with the same ``language_codes`` are returned. For ``CompletionType.COMPANY_NAME`` type, only companies having open jobs with the same ``language_codes`` are returned. For ``CompletionType.COMBINED`` type, only open jobs with the same ``language_codes`` or companies having open jobs with the same ``language_codes`` are returned. The maximum number of allowed characters is 255. company (str): Optional. If provided, restricts completion to specified company. The format is "projects/{project\_id}/tenants/{tenant\_id}/companies/{company\_id}", for example, "projects/api-test-project/tenants/foo/companies/bar". Tenant id is optional and the default tenant is used if unspecified, for example, "projects/api-test-project/companies/bar". scope (~google.cloud.talent_v4beta1.types.CompletionScope): Optional. The scope of the completion. The defaults is ``CompletionScope.PUBLIC``. type_ (~google.cloud.talent_v4beta1.types.CompletionType): Optional. The completion topic. The default is ``CompletionType.COMBINED``. 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.talent_v4beta1.types.CompleteQueryResponse` 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 "complete_query" not in self._inner_api_calls: self._inner_api_calls[ "complete_query" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.complete_query, default_retry=self._method_configs["CompleteQuery"].retry, default_timeout=self._method_configs["CompleteQuery"].timeout, client_info=self._client_info, ) request = completion_service_pb2.CompleteQueryRequest( parent=parent, query=query, page_size=page_size, language_codes=language_codes, company=company, scope=scope, type=type_, ) 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) return self._inner_api_calls["complete_query"]( request, retry=retry, timeout=timeout, metadata=metadata )