def test_report_phishing(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = phishingprotection_pb2.ReportPhishingResponse(
            **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 = phishingprotection_v1beta1.PhishingProtectionServiceClient(
            )

        # Setup Request
        parent = client.project_path("[PROJECT]")
        uri = "uri116076"

        response = client.report_phishing(parent, uri)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = phishingprotection_pb2.ReportPhishingRequest(
            parent=parent, uri=uri)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Beispiel #2
0
    def report_phishing(
        self,
        parent,
        uri,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Reports a URI suspected of containing phishing content to be reviewed.
        Once the report review is completed, if its result verifies the
        existince of malicious phishing content, the site will be added the to
        `Google's Social Engineering
        lists <https://support.google.com/webmasters/answer/6350487/>`__ in
        order to protect users that could get exposed to this threat in the
        future.

        Example:
            >>> from google.cloud import phishingprotection_v1beta1
            >>>
            >>> client = phishingprotection_v1beta1.PhishingProtectionServiceClient()
            >>>
            >>> parent = client.project_path('[PROJECT]')
            >>>
            >>> # TODO: Initialize `uri`:
            >>> uri = ''
            >>>
            >>> response = client.report_phishing(parent, uri)

        Args:
            parent (str): Required. The name of the project for which the report will be created,
                in the format "projects/{project\_number}".
            uri (str): The URI that is being reported for phishing content to be analyzed.
            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.phishingprotection_v1beta1.types.ReportPhishingResponse` 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 "report_phishing" not in self._inner_api_calls:
            self._inner_api_calls[
                "report_phishing"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.report_phishing,
                    default_retry=self._method_configs["ReportPhishing"].retry,
                    default_timeout=self._method_configs["ReportPhishing"].
                    timeout,
                    client_info=self._client_info,
                )

        request = phishingprotection_pb2.ReportPhishingRequest(parent=parent,
                                                               uri=uri)
        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["report_phishing"](request,
                                                        retry=retry,
                                                        timeout=timeout,
                                                        metadata=metadata)