def test_search_uris(self): # Setup Expected Response expected_response = {} expected_response = webrisk_pb2.SearchUrisResponse(**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 = webrisk_v1beta1.WebRiskServiceV1Beta1Client() # Setup Request uri = "uri116076" threat_types = [] response = client.search_uris(uri, threat_types) assert expected_response == response assert len(channel.requests) == 1 expected_request = webrisk_pb2.SearchUrisRequest( uri=uri, threat_types=threat_types ) actual_request = channel.requests[0][1] assert expected_request == actual_request
def search_uris( self, uri, threat_types, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ This method is used to check whether a URI is on a given threatList. Example: >>> from google.cloud import webrisk_v1beta1 >>> from google.cloud.webrisk_v1beta1 import enums >>> >>> client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() >>> >>> # TODO: Initialize `uri`: >>> uri = '' >>> >>> # TODO: Initialize `threat_types`: >>> threat_types = [] >>> >>> response = client.search_uris(uri, threat_types) Args: uri (str): The URI to be checked for matches. threat_types (list[~google.cloud.webrisk_v1beta1.types.ThreatType]): Required. The ThreatLists to search in. 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.webrisk_v1beta1.types.SearchUrisResponse` 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 "search_uris" not in self._inner_api_calls: self._inner_api_calls[ "search_uris"] = google.api_core.gapic_v1.method.wrap_method( self.transport.search_uris, default_retry=self._method_configs["SearchUris"].retry, default_timeout=self._method_configs["SearchUris"].timeout, client_info=self._client_info, ) request = webrisk_pb2.SearchUrisRequest(uri=uri, threat_types=threat_types) return self._inner_api_calls["search_uris"](request, retry=retry, timeout=timeout, metadata=metadata)