def test_get_sink(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = config_service_v2_client.ConfigServiceV2Client() # Mock request sink_name = client.sink_path('[PROJECT]', '[SINK]') # Mock response name = 'name3373707' destination = 'destination-1429847026' filter_ = 'filter-1274492040' writer_identity = 'writerIdentity775638794' expected_response = logging_config_pb2.LogSink( name=name, destination=destination, filter=filter_, writer_identity=writer_identity) grpc_stub.GetSink.return_value = expected_response response = client.get_sink(sink_name) self.assertEqual(expected_response, response) grpc_stub.GetSink.assert_called_once() args, kwargs = grpc_stub.GetSink.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = logging_config_pb2.GetSinkRequest( sink_name=sink_name) self.assertEqual(expected_request, actual_request)
def test_list_sinks(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = config_service_v2_client.ConfigServiceV2Client() # Mock request parent = client.project_path('[PROJECT]') # Mock response next_page_token = '' sinks_element = logging_config_pb2.LogSink() sinks = [sinks_element] expected_response = logging_config_pb2.ListSinksResponse( next_page_token=next_page_token, sinks=sinks) grpc_stub.ListSinks.return_value = expected_response paged_list_response = client.list_sinks(parent) resources = list(paged_list_response) self.assertEqual(1, len(resources)) self.assertEqual(expected_response.sinks[0], resources[0]) grpc_stub.ListSinks.assert_called_once() args, kwargs = grpc_stub.ListSinks.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = logging_config_pb2.ListSinksRequest(parent=parent) self.assertEqual(expected_request, actual_request)
def test_delete_sink_exception(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = config_service_v2_client.ConfigServiceV2Client() # Mock request sink_name = client.sink_path('[PROJECT]', '[SINK]') # Mock exception response grpc_stub.DeleteSink.side_effect = CustomException() self.assertRaises(errors.GaxError, client.delete_sink, sink_name)
def test_list_sinks_exception(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = config_service_v2_client.ConfigServiceV2Client() # Mock request parent = client.project_path('[PROJECT]') # Mock exception response grpc_stub.ListSinks.side_effect = CustomException() paged_list_response = client.list_sinks(parent) self.assertRaises(errors.GaxError, list, paged_list_response)
def test_create_sink_exception(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = config_service_v2_client.ConfigServiceV2Client() # Mock request parent = client.project_path('[PROJECT]') sink = logging_config_pb2.LogSink() # Mock exception response grpc_stub.CreateSink.side_effect = CustomException() self.assertRaises(errors.GaxError, client.create_sink, parent, sink)
def test_delete_sink(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = config_service_v2_client.ConfigServiceV2Client() # Mock request sink_name = client.sink_path('[PROJECT]', '[SINK]') client.delete_sink(sink_name) grpc_stub.DeleteSink.assert_called_once() args, kwargs = grpc_stub.DeleteSink.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = logging_config_pb2.DeleteSinkRequest( sink_name=sink_name) self.assertEqual(expected_request, actual_request)