def test_list_monitored_resource_descriptors(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = logging_service_v2_client.LoggingServiceV2Client() # Mock response next_page_token = '' resource_descriptors_element = monitored_resource_pb2.MonitoredResourceDescriptor( ) resource_descriptors = [resource_descriptors_element] expected_response = logging_pb2.ListMonitoredResourceDescriptorsResponse( next_page_token=next_page_token, resource_descriptors=resource_descriptors) grpc_stub.ListMonitoredResourceDescriptors.return_value = expected_response paged_list_response = client.list_monitored_resource_descriptors() resources = list(paged_list_response) self.assertEqual(1, len(resources)) self.assertEqual(expected_response.resource_descriptors[0], resources[0]) grpc_stub.ListMonitoredResourceDescriptors.assert_called_once() args, kwargs = grpc_stub.ListMonitoredResourceDescriptors.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = logging_pb2.ListMonitoredResourceDescriptorsRequest( ) self.assertEqual(expected_request, actual_request)
def test_get_monitored_resource_descriptor(self): # Setup Expected Response name_2 = "name2-1052831874" type_ = "type3575610" display_name = "displayName1615086568" description = "description-1724546052" expected_response = { "name": name_2, "type": type_, "display_name": display_name, "description": description, } expected_response = monitored_resource_pb2.MonitoredResourceDescriptor( **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 = monitoring_v3.MetricServiceClient() # Setup Request name = client.monitored_resource_descriptor_path( "[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]") response = client.get_monitored_resource_descriptor(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = metric_service_pb2.GetMonitoredResourceDescriptorRequest( name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_monitored_resource_descriptor(self): # Setup Expected Response name_2 = 'name2-1052831874' type_ = 'type3575610' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'name': name_2, 'type': type_, 'display_name': display_name, 'description': description } expected_response = monitored_resource_pb2.MonitoredResourceDescriptor( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = monitoring_v3.MetricServiceClient(channel=channel) # Setup Request name = client.monitored_resource_descriptor_path( '[PROJECT]', '[MONITORED_RESOURCE_DESCRIPTOR]') response = client.get_monitored_resource_descriptor(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = metric_service_pb2.GetMonitoredResourceDescriptorRequest( name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request