Skip to content

Commit f9df6a6

Browse files
Add tests for the public order book extension
Signed-off-by: camille-bouvy-frequenz <[email protected]>
1 parent 47a17cd commit f9df6a6

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

tests/test_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,21 @@ def test_update_gridpool_order_with_invalid_params( # pylint: disable=too-many-
460460
valid_until=valid_until,
461461
)
462462
)
463+
464+
465+
async def test_receive_public_order_book(
466+
set_up: SetupParams,
467+
) -> None:
468+
"""Test the method receiving public order book."""
469+
set_up.client.receive_public_order_book(
470+
delivery_period=set_up.delivery_period,
471+
delivery_area=set_up.delivery_area,
472+
side=set_up.side,
473+
)
474+
await asyncio.sleep(0)
475+
476+
set_up.mock_stub.ReceivePublicOrderBookStream.assert_called_once()
477+
args, _ = set_up.mock_stub.ReceivePublicOrderBookStream.call_args
478+
assert args[0].filter.delivery_period == set_up.delivery_period.to_pb()
479+
assert args[0].filter.delivery_area == set_up.delivery_area.to_pb()
480+
assert args[0].filter.side == set_up.side.to_pb()

tests/test_types.py

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
MarketSide,
2929
Order,
3030
OrderDetail,
31+
OrderExecutionOption,
3132
OrderState,
3233
OrderType,
3334
Power,
3435
Price,
36+
PublicOrder,
37+
PublicOrderBookFilter,
3538
PublicTrade,
3639
PublicTradeFilter,
3740
StateDetail,
@@ -172,7 +175,53 @@
172175
quantity=power_pb2.Power(mw=decimal_pb2.Decimal(value="5.00")),
173176
state=electricity_trading_pb2.TradeState.TRADE_STATE_ACTIVE,
174177
)
175-
178+
PUBLIC_ORDER = PublicOrder(
179+
public_order_id=42,
180+
delivery_area=DeliveryArea(code="XYZ", code_type=EnergyMarketCodeType.EUROPE_EIC),
181+
delivery_period=DeliveryPeriod(start=START_TIME, duration=timedelta(minutes=15)),
182+
side=MarketSide.BUY,
183+
price=Price(amount=Decimal("100.00"), currency=Currency.EUR),
184+
quantity=Power(mw=Decimal("5.00")),
185+
execution_option=OrderExecutionOption.AON,
186+
create_time=CREATE_TIME,
187+
update_time=MODIFICATION_TIME,
188+
)
189+
PUBLIC_ORDER_PB = electricity_trading_pb2.PublicOrderBookRecord(
190+
id=42,
191+
delivery_area=delivery_area_pb2.DeliveryArea(
192+
code="XYZ",
193+
code_type=delivery_area_pb2.EnergyMarketCodeType.ENERGY_MARKET_CODE_TYPE_EUROPE_EIC,
194+
),
195+
delivery_period=delivery_duration_pb2.DeliveryPeriod(
196+
start=START_TIME_PB,
197+
duration=delivery_duration_pb2.DeliveryDuration.DELIVERY_DURATION_15,
198+
),
199+
side=electricity_trading_pb2.MarketSide.MARKET_SIDE_BUY,
200+
price=price_pb2.Price(
201+
amount=decimal_pb2.Decimal(value="100.00"),
202+
currency=price_pb2.Price.Currency.CURRENCY_EUR,
203+
),
204+
quantity=power_pb2.Power(mw=decimal_pb2.Decimal(value="5.00")),
205+
execution_option=electricity_trading_pb2.OrderExecutionOption.ORDER_EXECUTION_OPTION_AON,
206+
create_time=CREATE_TIME_PB,
207+
update_time=MODIFICATION_TIME_PB,
208+
)
209+
PUBLIC_ORDER_BOOK_FILTER = PublicOrderBookFilter(
210+
delivery_area=DeliveryArea(code="XYZ", code_type=EnergyMarketCodeType.EUROPE_EIC),
211+
delivery_period=DeliveryPeriod(start=START_TIME, duration=timedelta(minutes=15)),
212+
side=MarketSide.SELL,
213+
)
214+
PUBLIC_ORDER_BOOK_FILTER_PB = electricity_trading_pb2.PublicOrderBookFilter(
215+
delivery_area=delivery_area_pb2.DeliveryArea(
216+
code="XYZ",
217+
code_type=delivery_area_pb2.EnergyMarketCodeType.ENERGY_MARKET_CODE_TYPE_EUROPE_EIC,
218+
),
219+
delivery_period=delivery_duration_pb2.DeliveryPeriod(
220+
start=START_TIME_PB,
221+
duration=delivery_duration_pb2.DeliveryDuration.DELIVERY_DURATION_15,
222+
),
223+
side=electricity_trading_pb2.MarketSide.MARKET_SIDE_SELL,
224+
)
176225
GRIDPOOL_ORDER_FILTER = GridpoolOrderFilter(
177226
order_states=[OrderState.ACTIVE, OrderState.CANCELED],
178227
side=MarketSide.BUY,
@@ -653,3 +702,39 @@ def test_update_order_to_pb_with_empty_values() -> None:
653702
# Make sure all attributes are None
654703
non_none_attrs = converted_update_order.ListFields()
655704
assert len(non_none_attrs) == 0
705+
706+
707+
def test_public_order_to_pb() -> None:
708+
"""Test the client public order type conversion to protobuf."""
709+
assert_conversion_to_pb(
710+
original=PUBLIC_ORDER,
711+
expected_pb=PUBLIC_ORDER_PB,
712+
assert_func=assert_equal,
713+
)
714+
715+
716+
def test_public_order_from_pb() -> None:
717+
"""Test the client public order type conversion from protobuf."""
718+
assert_conversion_from_pb(
719+
original_pb=PUBLIC_ORDER_PB,
720+
expected=PUBLIC_ORDER,
721+
assert_func=assert_equal,
722+
)
723+
724+
725+
def test_public_order_book_filter_to_pb() -> None:
726+
"""Test the client public order book filter type conversion to protobuf."""
727+
assert_conversion_to_pb(
728+
original=PUBLIC_ORDER_BOOK_FILTER,
729+
expected_pb=PUBLIC_ORDER_BOOK_FILTER_PB,
730+
assert_func=assert_equal,
731+
)
732+
733+
734+
def test_public_order_book_filter_from_pb() -> None:
735+
"""Test the client public order book filter type conversion from protobuf."""
736+
assert_conversion_from_pb(
737+
original_pb=PUBLIC_ORDER_BOOK_FILTER_PB,
738+
expected=PUBLIC_ORDER_BOOK_FILTER,
739+
assert_func=assert_equal,
740+
)

0 commit comments

Comments
 (0)