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 test_create_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 parent = "parent-995424086" feed_id = "feedId-976011428" feed = {} response = client.create_feed(parent, feed_id, feed) assert expected_response == response assert len(channel.requests) == 1 expected_request = asset_service_pb2.CreateFeedRequest(parent=parent, feed_id=feed_id, feed=feed) actual_request = channel.requests[0][1] assert expected_request == actual_request
def create_feed(project_id, feed_id, asset_names, topic): # [START asset_quickstart_create_feed] from google.cloud import asset_v1p2beta1 from google.cloud.asset_v1p2beta1.proto import asset_service_pb2 # TODO project_id = 'Your Google Cloud Project ID' # TODO feed_id = 'Feed ID you want to create' # TODO asset_names = 'List of asset names the feed listen to' # TODO topic = "Topic name of the feed" client = asset_v1p2beta1.AssetServiceClient() parent = "projects/{}".format(project_id) feed = asset_service_pb2.Feed() feed.asset_names.extend(asset_names) feed.feed_output_config.pubsub_destination.topic = topic response = client.create_feed(parent, feed_id, feed) print('feed: {}'.format(response))
def update_feed(feed_name, topic): # [START asset_quickstart_update_feed] from google.cloud import asset_v1p2beta1 from google.cloud.asset_v1p2beta1.proto import asset_service_pb2 from google.protobuf import field_mask_pb2 # TODO feed_name = 'Feed Name you want to update' # TODO topic = "Topic name you want to update with" client = asset_v1p2beta1.AssetServiceClient() feed = asset_service_pb2.Feed() feed.name = feed_name feed.feed_output_config.pubsub_destination.topic = topic update_mask = field_mask_pb2.FieldMask() # In this example, we update topic of the feed update_mask.paths.append("feed_output_config.pubsub_destination.topic") response = client.update_feed(feed, update_mask) print('updated_feed: {}'.format(response))
def test_get_feed(self): # Setup Expected Response name_2 = "name2-1052831874" expected_response = {"name": name_2} 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 name = client.feed_path("[PROJECT]", "[FEED]") response = client.get_feed(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = asset_service_pb2.GetFeedRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request