def test_report_error_event(self):
        project_id = os.environ["PROJECT_ID"]

        client = errorreporting_v1beta1.ReportErrorsServiceClient()
        project_name = f"projects/{project_id}"
        message = "[MESSAGE]"
        service = "[SERVICE]"
        service_context = {"service": service}
        file_path = "path/to/file.lang"
        line_number = 42
        function_name = "meaningOfLife"
        report_location = {
            "file_path": file_path,
            "line_number": line_number,
            "function_name": function_name,
        }
        context = {"report_location": report_location}
        event = {
            "message": message,
            "service_context": service_context,
            "context": context,
        }
        response = client.report_error_event(request={
            "project_name": project_name,
            "event": event
        })
示例#2
0
    def test_report_error_event(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = report_errors_service_pb2.ReportErrorEventResponse(
            **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 = errorreporting_v1beta1.ReportErrorsServiceClient()

        # Setup Request
        project_name = client.project_path("[PROJECT]")
        event = {}

        response = client.report_error_event(project_name, event)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = report_errors_service_pb2.ReportErrorEventRequest(
            project_name=project_name, event=event)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_report_error_event_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = errorreporting_v1beta1.ReportErrorsServiceClient(
            channel=channel)

        # Setup request
        project_name = client.project_path('[PROJECT]')
        event = {}

        with pytest.raises(CustomException):
            client.report_error_event(project_name, event)
示例#4
0
    def test_report_error_event_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = errorreporting_v1beta1.ReportErrorsServiceClient()

        # Setup request
        project_name = client.project_path("[PROJECT]")
        event = {}

        with pytest.raises(CustomException):
            client.report_error_event(project_name, event)
    def test_report_error_event(self):
        project_id = os.environ['PROJECT_ID']

        client = errorreporting_v1beta1.ReportErrorsServiceClient()
        project_name = client.project_path(project_id)
        message = '[MESSAGE]'
        service = '[SERVICE]'
        service_context = {'service': service}
        file_path = 'path/to/file.lang'
        line_number = 42
        function_name = 'meaningOfLife'
        report_location = {
            'file_path': file_path,
            'line_number': line_number,
            'function_name': function_name
        }
        context = {'report_location': report_location}
        event = {
            'message': message,
            'service_context': service_context,
            'context': context
        }
        response = client.report_error_event(project_name, event)
    def test_report_error_event(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = report_errors_service_pb2.ReportErrorEventResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = errorreporting_v1beta1.ReportErrorsServiceClient(
            channel=channel)

        # Setup Request
        project_name = client.project_path('[PROJECT]')
        event = {}

        response = client.report_error_event(project_name, event)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = report_errors_service_pb2.ReportErrorEventRequest(
            project_name=project_name, event=event)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request