def test_report_error_event(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = report_errors_service_client.ReportErrorsServiceClient() # Mock request project_name = client.project_path('[PROJECT]') event = report_errors_service_pb2.ReportedErrorEvent() # Mock response expected_response = report_errors_service_pb2.ReportErrorEventResponse( ) grpc_stub.ReportErrorEvent.return_value = expected_response response = client.report_error_event(project_name, event) self.assertEqual(expected_response, response) grpc_stub.ReportErrorEvent.assert_called_once() args, kwargs = grpc_stub.ReportErrorEvent.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = report_errors_service_pb2.ReportErrorEventRequest( project_name=project_name, event=event) self.assertEqual(expected_request, actual_request)
def report_error_event(self, error_report): """Uses the GAX client to report the error. :type error_report: dict :param error_report: payload of the error report formatted according to https://cloud.google.com/error-reporting/docs/formatting-error-messages This object should be built using Use :meth:~`google.cloud.error_reporting.client._build_error_report` """ project_name = self._gax_api.project_path(self._project) error_report_payload = report_errors_service_pb2.ReportedErrorEvent() ParseDict(error_report, error_report_payload) self._gax_api.report_error_event(project_name, error_report_payload)
def test_report_error_event_exception(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = report_errors_service_client.ReportErrorsServiceClient() # Mock request project_name = client.project_path('[PROJECT]') event = report_errors_service_pb2.ReportedErrorEvent() # Mock exception response grpc_stub.ReportErrorEvent.side_effect = CustomException() self.assertRaises(errors.GaxError, client.report_error_event, project_name, event)
def test_report_error_event(self): from google.cloud.proto.devtools.clouderrorreporting.v1beta1 import ( report_errors_service_pb2) gax_api = mock.Mock(spec=['project_path', 'report_error_event']) gax_client_wrapper = self._make_one(gax_api, self.PROJECT) error_report = { 'message': 'The cabs are here.', } gax_client_wrapper.report_error_event(error_report) gax_api.project_path.assert_called_once_with(self.PROJECT) project_name = gax_api.project_path.return_value error_pb = report_errors_service_pb2.ReportedErrorEvent( message=error_report['message'], ) gax_api.report_error_event.assert_called_once_with( project_name, error_pb)