def _traces_mapping_to_pb(traces_mapping):
    """Convert a trace dict to protobuf.

    :type traces_mapping: dict
    :param traces_mapping: A trace mapping.

    :rtype: class:`google.cloud.proto.devtools.cloudtrace.v1.trace_pb2.Traces`
    :returns: The converted protobuf type traces.
    """
    traces_pb = trace_pb2.Traces()
    ParseDict(traces_mapping, traces_pb)
    return traces_pb
    def test_patch_traces_exception(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = trace_service_client.TraceServiceClient()

        # Mock request
        project_id = 'projectId-1969970175'
        traces = trace_pb2.Traces()

        # Mock exception response
        grpc_stub.PatchTraces.side_effect = CustomException()

        self.assertRaises(errors.GaxError, client.patch_traces, project_id,
                          traces)
    def test_patch_traces(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = trace_service_client.TraceServiceClient()

        # Mock request
        project_id = 'projectId-1969970175'
        traces = trace_pb2.Traces()

        client.patch_traces(project_id, traces)

        grpc_stub.PatchTraces.assert_called_once()
        args, kwargs = grpc_stub.PatchTraces.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = trace_pb2.PatchTracesRequest(project_id=project_id,
                                                        traces=traces)
        self.assertEqual(expected_request, actual_request)