Example #1
0
    def test_update_topic(self):
        # Setup Expected Response
        name = "name3373707"
        expected_response = {"name": name}
        expected_response = pubsub_pb2.Topic(**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 = publisher_client.PublisherClient()

        # Setup Request
        topic = {}
        update_mask = {}

        response = client.update_topic(topic, update_mask)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.UpdateTopicRequest(
            topic=topic, update_mask=update_mask)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Example #2
0
    def update_topic(self,
                     topic,
                     update_mask,
                     retry=google.api_core.gapic_v1.method.DEFAULT,
                     timeout=google.api_core.gapic_v1.method.DEFAULT):
        """
        Updates an existing topic. Note that certain properties of a topic are not
        modifiable.  Options settings follow the style guide:
        NOTE:  The style guide requires body: \"topic\" instead of body: \"*\".
        Keeping the latter for internal consistency in V1, however it should be
        corrected in V2.  See
        https://cloud.google.com/apis/design/standard_methods#update for details.

        Example:
            >>> from google.cloud import pubsub_v1
            >>>
            >>> client = pubsub_v1.PublisherClient()
            >>>
            >>> topic = {}
            >>> update_mask = {}
            >>>
            >>> response = client.update_topic(topic, update_mask)

        Args:
            topic (Union[dict, ~google.cloud.pubsub_v1.types.Topic]): The topic to update.
                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.pubsub_v1.types.Topic`
            update_mask (Union[dict, ~google.cloud.pubsub_v1.types.FieldMask]): Indicates which fields in the provided topic to update.
                Must be specified and non-empty.
                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.pubsub_v1.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.

        Returns:
            A :class:`~google.cloud.pubsub_v1.types.Topic` 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.
        """
        request = pubsub_pb2.UpdateTopicRequest(topic=topic,
                                                update_mask=update_mask)
        return self._update_topic(request, retry=retry, timeout=timeout)
    def test_update_topic(self):
        # Setup Expected Response
        name = 'name3373707'
        expected_response = {'name': name}
        expected_response = pubsub_pb2.Topic(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = publisher_client.PublisherClient(channel=channel)

        # Setup Request
        topic = {}
        update_mask = {}

        response = client.update_topic(topic, update_mask)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.UpdateTopicRequest(
            topic=topic, update_mask=update_mask)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Example #4
0
    def update_topic(self,
                     topic,
                     update_mask,
                     retry=google.api_core.gapic_v1.method.DEFAULT,
                     timeout=google.api_core.gapic_v1.method.DEFAULT,
                     metadata=None):
        """
        Updates an existing topic. Note that certain properties of a
        topic are not modifiable.

        Example:
            >>> from google.cloud import pubsub_v1
            >>>
            >>> client = pubsub_v1.PublisherClient()
            >>>
            >>> # TODO: Initialize `topic`:
            >>> topic = {}
            >>>
            >>> # TODO: Initialize `update_mask`:
            >>> update_mask = {}
            >>>
            >>> response = client.update_topic(topic, update_mask)

        Args:
            topic (Union[dict, ~google.cloud.pubsub_v1.types.Topic]): The updated topic object.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.pubsub_v1.types.Topic`
            update_mask (Union[dict, ~google.cloud.pubsub_v1.types.FieldMask]): Indicates which fields in the provided topic to update. Must be
                specified and non-empty. Note that if ``update_mask`` contains
                "message\_storage\_policy" then the new value will be determined based
                on the policy configured at the project or organization level. The
                ``message_storage_policy`` must not be set in the ``topic`` provided
                above.

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

        request = pubsub_pb2.UpdateTopicRequest(
            topic=topic,
            update_mask=update_mask,
        )
        return self._inner_api_calls['update_topic'](request,
                                                     retry=retry,
                                                     timeout=timeout,
                                                     metadata=metadata)