chore: adjust message/command structure and write unit tests
ref: N25B-205
This commit is contained in:
@@ -4,7 +4,7 @@ import json
|
||||
import pytest
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from control_backend.agents.ri_command_agent import RICommandAgent
|
||||
from control_backend.schemas.message import Message
|
||||
from control_backend.schemas.ri_message import SpeechCommand
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_setup_bind(monkeypatch):
|
||||
@@ -41,7 +41,7 @@ async def test_setup_connect(monkeypatch):
|
||||
fake_socket.connect.assert_any_call("tcp://localhost:5555")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_commands_behaviour_valid_message(caplog):
|
||||
async def test_send_commands_behaviour_valid_message():
|
||||
"""Test behaviour with valid JSON message"""
|
||||
fake_socket = AsyncMock()
|
||||
message_dict = {"message": "hello"}
|
||||
@@ -55,12 +55,14 @@ async def test_send_commands_behaviour_valid_message(caplog):
|
||||
behaviour = agent.SendCommandsBehaviour()
|
||||
behaviour.agent = agent
|
||||
|
||||
with caplog.at_level("INFO"):
|
||||
with patch('control_backend.agents.ri_command_agent.SpeechCommand') as MockSpeechCommand:
|
||||
mock_message = MagicMock()
|
||||
MockSpeechCommand.model_validate.return_value = mock_message
|
||||
|
||||
await behaviour.run()
|
||||
|
||||
fake_socket.recv_multipart.assert_awaited()
|
||||
fake_socket.send_json.assert_awaited()
|
||||
assert "Received message" in caplog.text
|
||||
fake_socket.send_json.assert_awaited_with(mock_message)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_commands_behaviour_invalid_message(caplog):
|
||||
|
||||
Reference in New Issue
Block a user