Example #1
0
    def test_mark_recommendation_claimed(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        description = "description-1724546052"
        recommender_subtype = "recommenderSubtype-1488504412"
        etag_2 = "etag2-1293302904"
        expected_response = {
            "name": name_2,
            "description": description,
            "recommender_subtype": recommender_subtype,
            "etag": etag_2,
        }
        expected_response = recommendation_pb2.Recommendation(
            **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 = recommender_v1.RecommenderClient()

        # Setup Request
        name = client.recommendation_path("[PROJECT]", "[LOCATION]",
                                          "[RECOMMENDER]", "[RECOMMENDATION]")
        etag = "etag3123477"

        response = client.mark_recommendation_claimed(name, etag)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = recommender_service_pb2.MarkRecommendationClaimedRequest(
            name=name, etag=etag)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Example #2
0
    def mark_recommendation_claimed(
        self,
        name,
        etag,
        state_metadata=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Marks the Recommendation State as Claimed. Users can use this method
        to indicate to the Recommender API that they are starting to apply the
        recommendation themselves. This stops the recommendation content from
        being updated. Associated insights are frozen and placed in the ACCEPTED
        state.

        MarkRecommendationClaimed can be applied to recommendations in CLAIMED,
        SUCCEEDED, FAILED, or ACTIVE state.

        Requires the recommender.*.update IAM permission for the specified
        recommender.

        Example:
            >>> from google.cloud import recommender_v1
            >>>
            >>> client = recommender_v1.RecommenderClient()
            >>>
            >>> name = client.recommendation_path('[PROJECT]', '[LOCATION]', '[RECOMMENDER]', '[RECOMMENDATION]')
            >>>
            >>> # TODO: Initialize `etag`:
            >>> etag = ''
            >>>
            >>> response = client.mark_recommendation_claimed(name, etag)

        Args:
            name (str): Required. Name of the recommendation.
            etag (str): Required. Fingerprint of the Recommendation. Provides optimistic locking.
            state_metadata (dict[str -> str]): State properties to include with this state. Overwrites any existing
                ``state_metadata``. Keys must match the regex
                ``/^[a-z0-9][a-z0-9_.-]{0,62}$/``. Values must match the regex
                ``/^[a-zA-Z0-9_./-]{0,255}$/``.
            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.recommender_v1.types.Recommendation` 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 "mark_recommendation_claimed" not in self._inner_api_calls:
            self._inner_api_calls[
                "mark_recommendation_claimed"
            ] = google.api_core.gapic_v1.method.wrap_method(
                self.transport.mark_recommendation_claimed,
                default_retry=self._method_configs["MarkRecommendationClaimed"].retry,
                default_timeout=self._method_configs[
                    "MarkRecommendationClaimed"
                ].timeout,
                client_info=self._client_info,
            )

        request = recommender_service_pb2.MarkRecommendationClaimedRequest(
            name=name, etag=etag, state_metadata=state_metadata,
        )
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("name", 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["mark_recommendation_claimed"](
            request, retry=retry, timeout=timeout, metadata=metadata
        )