Files
core/tests/components/open_router/test_conversation.py
2025-07-16 10:55:28 +02:00

53 lines
1.6 KiB
Python

"""Tests for the OpenRouter integration."""
from unittest.mock import AsyncMock
from freezegun import freeze_time
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components import conversation
from homeassistant.core import Context, HomeAssistant
from homeassistant.helpers import area_registry as ar, device_registry as dr, intent
from . import setup_integration
from tests.common import MockConfigEntry
from tests.components.conversation import MockChatLog, mock_chat_log # noqa: F401
@pytest.fixture(autouse=True)
def freeze_the_time():
"""Freeze the time."""
with freeze_time("2024-05-24 12:00:00", tz_offset=0):
yield
async def test_default_prompt(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
area_registry: ar.AreaRegistry,
device_registry: dr.DeviceRegistry,
snapshot: SnapshotAssertion,
mock_openai_client: AsyncMock,
mock_chat_log: MockChatLog, # noqa: F811
) -> None:
"""Test that the default prompt works."""
await setup_integration(hass, mock_config_entry)
result = await conversation.async_converse(
hass,
"hello",
mock_chat_log.conversation_id,
Context(),
agent_id="conversation.gpt_3_5_turbo",
)
assert result.response.response_type == intent.IntentResponseType.ACTION_DONE
assert mock_chat_log.content[1:] == snapshot
call = mock_openai_client.chat.completions.create.call_args_list[0][1]
assert call["model"] == "gpt-3.5-turbo"
assert call["extra_headers"] == {
"HTTP-Referer": "https://www.home-assistant.io/integrations/open_router",
"X-Title": "Home Assistant",
}