Skip to content

Commit 023f844

Browse files
committed
Add test for missing fields in order detail
Signed-off-by: cwasicki <[email protected]>
1 parent 139a7ba commit 023f844

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
501524
def 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):

0 commit comments

Comments
 (0)