build 059.11: add runtime command models
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
# app/tests/unit/market_data/acquisition/runtime/test_runtime_commands.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import FrozenInstanceError
|
||||
|
||||
import pytest
|
||||
|
||||
from src.market_data.acquisition.runtime.runtime_commands import (
|
||||
ConnectCommand,
|
||||
DisconnectCommand,
|
||||
SendBinaryCommand,
|
||||
SendTextCommand,
|
||||
SubscribeCommand,
|
||||
UnsubscribeCommand,
|
||||
)
|
||||
from src.market_data.acquisition.runtime.transport_messages import (
|
||||
TransportBinaryMessage,
|
||||
TransportTextMessage,
|
||||
)
|
||||
|
||||
|
||||
def test_connect_command_is_marker_command() -> None:
|
||||
assert ConnectCommand() == ConnectCommand()
|
||||
|
||||
|
||||
def test_disconnect_command_is_marker_command() -> None:
|
||||
assert DisconnectCommand() == DisconnectCommand()
|
||||
|
||||
|
||||
def test_subscribe_command_contains_subscription_key_and_text_message() -> None:
|
||||
message = TransportTextMessage(payload='{"action":"subscribe"}')
|
||||
command = SubscribeCommand(
|
||||
subscription_key="quotes:BTCUSDT",
|
||||
message=message,
|
||||
)
|
||||
|
||||
assert command.subscription_key == "quotes:BTCUSDT"
|
||||
assert command.message is message
|
||||
|
||||
|
||||
def test_subscribe_command_supports_binary_message() -> None:
|
||||
message = TransportBinaryMessage(payload=b"\x01\x02")
|
||||
command = SubscribeCommand(
|
||||
subscription_key="binary:market-data",
|
||||
message=message,
|
||||
)
|
||||
|
||||
assert command.message is message
|
||||
|
||||
|
||||
def test_unsubscribe_command_contains_subscription_key_and_message() -> None:
|
||||
message = TransportTextMessage(payload='{"action":"unsubscribe"}')
|
||||
command = UnsubscribeCommand(
|
||||
subscription_key="quotes:BTCUSDT",
|
||||
message=message,
|
||||
)
|
||||
|
||||
assert command.subscription_key == "quotes:BTCUSDT"
|
||||
assert command.message is message
|
||||
|
||||
|
||||
def test_send_text_command_contains_transport_text_message() -> None:
|
||||
message = TransportTextMessage(payload="ping")
|
||||
command = SendTextCommand(message=message)
|
||||
|
||||
assert command.message is message
|
||||
|
||||
|
||||
def test_send_binary_command_contains_transport_binary_message() -> None:
|
||||
message = TransportBinaryMessage(payload=b"\x00")
|
||||
command = SendBinaryCommand(message=message)
|
||||
|
||||
assert command.message is message
|
||||
|
||||
|
||||
def test_subscribe_command_is_immutable() -> None:
|
||||
command = SubscribeCommand(
|
||||
subscription_key="quotes:BTCUSDT",
|
||||
message=TransportTextMessage(payload="subscribe"),
|
||||
)
|
||||
|
||||
with pytest.raises(FrozenInstanceError):
|
||||
setattr(command, "subscription_key", "quotes:ETHUSDT")
|
||||
|
||||
|
||||
def test_send_text_command_is_immutable() -> None:
|
||||
command = SendTextCommand(
|
||||
message=TransportTextMessage(payload="ping"),
|
||||
)
|
||||
|
||||
with pytest.raises(FrozenInstanceError):
|
||||
setattr(
|
||||
command,
|
||||
"message",
|
||||
TransportTextMessage(payload="pong"),
|
||||
)
|
||||
Reference in New Issue
Block a user