def update_subscription(self, subscription, update_mask, options=None): """ Updates an existing subscription. Note that certain properties of a subscription, such as its topic, are not modifiable. Example: >>> from google.cloud.gapic.pubsub.v1 import subscriber_client >>> from google.cloud.proto.pubsub.v1 import pubsub_pb2 >>> from google.protobuf import field_mask_pb2 >>> client = subscriber_client.SubscriberClient() >>> subscription = pubsub_pb2.Subscription() >>> update_mask = field_mask_pb2.FieldMask() >>> response = client.update_subscription(subscription, update_mask) Args: subscription (:class:`google.cloud.proto.pubsub.v1.pubsub_pb2.Subscription`): The updated subscription object. update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Indicates which fields in the provided subscription to update. Must be specified and non-empty. options (:class:`google.gax.CallOptions`): Overrides the default settings for this call, e.g, timeout, retries etc. Returns: A :class:`google.cloud.proto.pubsub.v1.pubsub_pb2.Subscription` instance. Raises: :exc:`google.gax.errors.GaxError` if the RPC is aborted. :exc:`ValueError` if the parameters are invalid. """ # Create the request object. request = pubsub_pb2.UpdateSubscriptionRequest( subscription=subscription, update_mask=update_mask) return self._update_subscription(request, options)
def test_update_subscription(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = subscriber_client.SubscriberClient() # Mock request subscription = pubsub_pb2.Subscription() update_mask = field_mask_pb2.FieldMask() # Mock response name = 'name3373707' topic = 'topic110546223' ack_deadline_seconds = 2135351438 retain_acked_messages = False expected_response = pubsub_pb2.Subscription( name=name, topic=topic, ack_deadline_seconds=ack_deadline_seconds, retain_acked_messages=retain_acked_messages) grpc_stub.UpdateSubscription.return_value = expected_response response = client.update_subscription(subscription, update_mask) self.assertEqual(expected_response, response) grpc_stub.UpdateSubscription.assert_called_once() args, kwargs = grpc_stub.UpdateSubscription.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = pubsub_pb2.UpdateSubscriptionRequest( subscription=subscription, update_mask=update_mask) self.assertEqual(expected_request, actual_request)