예제 #1
0
    def test_update_feed(self):
        # Setup Expected Response
        name = "name3373707"
        expected_response = {"name": name}
        expected_response = asset_service_pb2.Feed(**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 = asset_v1p2beta1.AssetServiceClient()

        # Setup Request
        feed = {}
        update_mask = {}

        response = client.update_feed(feed, update_mask)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = asset_service_pb2.UpdateFeedRequest(
            feed=feed, update_mask=update_mask)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def update_feed(
        self,
        feed,
        update_mask,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Updates an asset feed configuration.

        Example:
            >>> from google.cloud import asset_v1p2beta1
            >>>
            >>> client = asset_v1p2beta1.AssetServiceClient()
            >>>
            >>> # TODO: Initialize `feed`:
            >>> feed = {}
            >>>
            >>> # TODO: Initialize `update_mask`:
            >>> update_mask = {}
            >>>
            >>> response = client.update_feed(feed, update_mask)

        Args:
            feed (Union[dict, ~google.cloud.asset_v1p2beta1.types.Feed]): The new values of feed details. It must match an existing feed and the
                field ``name`` must be in the format of:
                projects/project\_number/feeds/feed\_id or
                folders/folder\_number/feeds/feed\_id or
                organizations/organization\_number/feeds/feed\_id.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.asset_v1p2beta1.types.Feed`
            update_mask (Union[dict, ~google.cloud.asset_v1p2beta1.types.FieldMask]): Only updates the ``feed`` fields indicated by this mask. The field mask
                must not be empty, and it must not contain fields that are immutable or
                only set by the server.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.asset_v1p2beta1.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.cloud.asset_v1p2beta1.types.Feed` 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 "update_feed" not in self._inner_api_calls:
            self._inner_api_calls[
                "update_feed"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.update_feed,
                    default_retry=self._method_configs["UpdateFeed"].retry,
                    default_timeout=self._method_configs["UpdateFeed"].timeout,
                    client_info=self._client_info,
                )

        request = asset_service_pb2.UpdateFeedRequest(feed=feed,
                                                      update_mask=update_mask)
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("feed.name", feed.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["update_feed"](request,
                                                    retry=retry,
                                                    timeout=timeout,
                                                    metadata=metadata)
예제 #3
0
    def update_feed(
        self,
        feed,
        update_mask,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Updates an asset feed configuration.

        Example:
            >>> from google.cloud import asset_v1p2beta1
            >>>
            >>> client = asset_v1p2beta1.AssetServiceClient()
            >>>
            >>> # TODO: Initialize `feed`:
            >>> feed = {}
            >>>
            >>> # TODO: Initialize `update_mask`:
            >>> update_mask = {}
            >>>
            >>> response = client.update_feed(feed, update_mask)

        Args:
            feed (Union[dict, ~google.cloud.asset_v1p2beta1.types.Feed]): A URL/resource name that uniquely identifies the type of the
                serialized protocol buffer message. This string must contain at least
                one "/" character. The last segment of the URL's path must represent the
                fully qualified name of the type (as in
                ``path/google.protobuf.Duration``). The name should be in a canonical
                form (e.g., leading "." is not accepted).

                In practice, teams usually precompile into the binary all types that
                they expect it to use in the context of Any. However, for URLs which use
                the scheme ``http``, ``https``, or no scheme, one can optionally set up
                a type server that maps type URLs to message definitions as follows:

                -  If no scheme is provided, ``https`` is assumed.
                -  An HTTP GET on the URL must yield a ``google.protobuf.Type`` value in
                   binary format, or produce an error.
                -  Applications are allowed to cache lookup results based on the URL, or
                   have them precompiled into a binary to avoid any lookup. Therefore,
                   binary compatibility needs to be preserved on changes to types. (Use
                   versioned type names to manage breaking changes.)

                Note: this functionality is not currently available in the official
                protobuf release, and it is not used for type URLs beginning with
                type.googleapis.com.

                Schemes other than ``http``, ``https`` (or the empty scheme) might be
                used with implementation specific semantics.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.asset_v1p2beta1.types.Feed`
            update_mask (Union[dict, ~google.cloud.asset_v1p2beta1.types.FieldMask]): The REST URL for accessing the resource. An HTTP GET operation using
                this URL returns the resource itself. Example:
                ``https://cloudresourcemanager.googleapis.com/v1/projects/my-project-123``.
                It will be left unspecified for resources without a REST API.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.asset_v1p2beta1.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.cloud.asset_v1p2beta1.types.Feed` 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 "update_feed" not in self._inner_api_calls:
            self._inner_api_calls[
                "update_feed"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.update_feed,
                    default_retry=self._method_configs["UpdateFeed"].retry,
                    default_timeout=self._method_configs["UpdateFeed"].timeout,
                    client_info=self._client_info,
                )

        request = asset_service_pb2.UpdateFeedRequest(feed=feed,
                                                      update_mask=update_mask)
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("feed.name", feed.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["update_feed"](request,
                                                    retry=retry,
                                                    timeout=timeout,
                                                    metadata=metadata)