File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -498,6 +498,29 @@ def test_order_detail_from_pb() -> None:
498498 )
499499
500500
501+ def test_order_detail_from_pb_missing_fields () -> None :
502+ """Test the client order detail type conversion from protobuf with missing fields."""
503+ # Missing price
504+ od_pb1 = electricity_trading_pb2 .OrderDetail ()
505+ od_pb1 .CopyFrom (ORDER_DETAIL_PB )
506+ od_pb1 .order .ClearField ("price" )
507+ # Not allowed for active orders
508+ with pytest .raises (ValueError ):
509+ OrderDetail .from_pb (od_pb1 )
510+ # But allowed for canceled orders
511+ od_pb1 .state_detail .state = electricity_trading_pb2 .OrderState .ORDER_STATE_CANCELED
512+ OrderDetail .from_pb (od_pb1 )
513+
514+ # Missing quantity (same logic as above)
515+ od_pb2 = electricity_trading_pb2 .OrderDetail ()
516+ od_pb2 .CopyFrom (ORDER_DETAIL_PB )
517+ od_pb2 .order .ClearField ("quantity" )
518+ with pytest .raises (ValueError ):
519+ OrderDetail .from_pb (od_pb2 )
520+ od_pb2 .state_detail .state = electricity_trading_pb2 .OrderState .ORDER_STATE_CANCELED
521+ OrderDetail .from_pb (od_pb2 )
522+
523+
501524def test_order_detail_no_timezone_error () -> None :
502525 """Test that an order detail with inputs with no timezone raises a ValueError."""
503526 with pytest .raises (ValueError ):
You can’t perform that action at this time.
0 commit comments