def test_redact_content(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = dlp_service_client.DlpServiceClient() # Mock request inspect_config = dlp_pb2.InspectConfig() items = [] replace_configs = [] # Mock response expected_response = dlp_pb2.RedactContentResponse() grpc_stub.RedactContent.return_value = expected_response response = client.redact_content(inspect_config, items, replace_configs) self.assertEqual(expected_response, response) grpc_stub.RedactContent.assert_called_once() args, kwargs = grpc_stub.RedactContent.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = dlp_pb2.RedactContentRequest( inspect_config=inspect_config, items=items, replace_configs=replace_configs) self.assertEqual(expected_request, actual_request)
def test_list_root_categories(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = dlp_service_client.DlpServiceClient() # Mock request language_code = 'languageCode-412800396' # Mock response expected_response = dlp_pb2.ListRootCategoriesResponse() grpc_stub.ListRootCategories.return_value = expected_response response = client.list_root_categories(language_code) self.assertEqual(expected_response, response) grpc_stub.ListRootCategories.assert_called_once() args, kwargs = grpc_stub.ListRootCategories.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = dlp_pb2.ListRootCategoriesRequest( language_code=language_code) self.assertEqual(expected_request, actual_request)
def test_list_inspect_findings(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = dlp_service_client.DlpServiceClient() # Mock request name = client.result_path('[RESULT]') # Mock response next_page_token = 'nextPageToken-1530815211' expected_response = dlp_pb2.ListInspectFindingsResponse( next_page_token=next_page_token) grpc_stub.ListInspectFindings.return_value = expected_response response = client.list_inspect_findings(name) self.assertEqual(expected_response, response) grpc_stub.ListInspectFindings.assert_called_once() args, kwargs = grpc_stub.ListInspectFindings.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = dlp_pb2.ListInspectFindingsRequest(name=name) self.assertEqual(expected_request, actual_request)
def test_create_inspect_operation(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = dlp_service_client.DlpServiceClient() # Mock request inspect_config = dlp_pb2.InspectConfig() storage_config = storage_pb2.StorageConfig() output_config = dlp_pb2.OutputStorageConfig() # Mock response name = 'name3373707' done = True expected_response = operations_pb2.Operation(name=name, done=done) grpc_stub.CreateInspectOperation.return_value = expected_response response = client.create_inspect_operation(inspect_config, storage_config, output_config) self.assertEqual(expected_response, response) grpc_stub.CreateInspectOperation.assert_called_once() args, kwargs = grpc_stub.CreateInspectOperation.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = dlp_pb2.CreateInspectOperationRequest( inspect_config=inspect_config, storage_config=storage_config, output_config=output_config) self.assertEqual(expected_request, actual_request)
def test_list_inspect_findings_exception(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = dlp_service_client.DlpServiceClient() # Mock request name = client.result_path('[RESULT]') # Mock exception response grpc_stub.ListInspectFindings.side_effect = CustomException() self.assertRaises(errors.GaxError, client.list_inspect_findings, name)
def test_list_root_categories_exception(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = dlp_service_client.DlpServiceClient() # Mock request language_code = 'languageCode-412800396' # Mock exception response grpc_stub.ListRootCategories.side_effect = CustomException() self.assertRaises(errors.GaxError, client.list_root_categories, language_code)
def test_inspect_content_exception(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = dlp_service_client.DlpServiceClient() # Mock request inspect_config = dlp_pb2.InspectConfig() items = [] # Mock exception response grpc_stub.InspectContent.side_effect = CustomException() self.assertRaises(errors.GaxError, client.inspect_content, inspect_config, items)
def test_create_inspect_operation_exception(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = dlp_service_client.DlpServiceClient() # Mock request inspect_config = dlp_pb2.InspectConfig() storage_config = storage_pb2.StorageConfig() output_config = dlp_pb2.OutputStorageConfig() # Mock exception response grpc_stub.CreateInspectOperation.side_effect = CustomException() self.assertRaises(errors.GaxError, client.create_inspect_operation, inspect_config, storage_config, output_config)