def test_list_sinks(self): # Setup Expected Response next_page_token = "" sinks_element = {} sinks = [sinks_element] expected_response = { "next_page_token": next_page_token, "sinks": sinks } expected_response = logging_config_pb2.ListSinksResponse( **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 = logging_v2.ConfigServiceV2Client() # Setup Request parent = client.project_path("[PROJECT]") paged_list_response = client.list_sinks(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.sinks[0] == resources[0] assert len(channel.requests) == 1 expected_request = logging_config_pb2.ListSinksRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_sinks(self): # Setup Expected Response next_page_token = '' sinks_element = {} sinks = [sinks_element] expected_response = { 'next_page_token': next_page_token, 'sinks': sinks } expected_response = logging_config_pb2.ListSinksResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = logging_v2.ConfigServiceV2Client(channel=channel) # Setup Request parent = client.project_path('[PROJECT]') paged_list_response = client.list_sinks(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.sinks[0] == resources[0] assert len(channel.requests) == 1 expected_request = logging_config_pb2.ListSinksRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_sinks(self): channel, api = self.make_sinks_api() sink_msg = logging_config_pb2.LogSink( name=self.SINK_PATH, destination=self.DESTINATION_URI, filter=FILTER ) channel.ListSinks.response = logging_config_pb2.ListSinksResponse( sinks=[sink_msg] ) result = api.list_sinks(PROJECT) sinks = list(result) # Check the response assert len(sinks) == 1 sink = sinks[0] assert isinstance(sink, google.cloud.logging.sink.Sink) assert sink.name == self.SINK_PATH assert sink.destination == self.DESTINATION_URI assert sink.filter_ == FILTER # Check the request assert len(channel.ListSinks.requests) == 1 request = channel.ListSinks.requests[0] assert request.parent == PROJECT_PATH
def test_list_sinks_with_options(self): channel, api = self.make_sinks_api() channel.ListSinks.response = logging_config_pb2.ListSinksResponse(sinks=[]) result = api.list_sinks(PROJECT, page_size=42, page_token="token") list(result) # Check the request assert len(channel.ListSinks.requests) == 1 request = channel.ListSinks.requests[0] assert request.parent == "projects/%s" % PROJECT assert request.page_size == 42 assert request.page_token == "token"