core/tests/components/mcp/conftest.py
Allen Porter 58b4556a1d
Add the Model Context Protocol integration (#135058)
* Add the Model Context Protocol integration

* Improvements to mcp integration

* Move the API prompt constant

* Update config flow error handling

* Update test descriptions

* Update tests/components/mcp/test_config_flow.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update tests/components/mcp/test_config_flow.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Address PR feedback

* Update homeassistant/components/mcp/coordinator.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

* Move tool parsing to the coordinator

* Update session handling not to use a context manager

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2025-01-27 14:38:52 -05:00

46 lines
1.3 KiB
Python

"""Common fixtures for the Model Context Protocol tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
from homeassistant.components.mcp.const import DOMAIN
from homeassistant.const import CONF_URL
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
TEST_API_NAME = "Memory Server"
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.mcp.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture
def mock_mcp_client() -> Generator[AsyncMock]:
"""Fixture to mock the MCP client."""
with (
patch("homeassistant.components.mcp.coordinator.sse_client"),
patch("homeassistant.components.mcp.coordinator.ClientSession") as mock_session,
):
yield mock_session.return_value.__aenter__
@pytest.fixture(name="config_entry")
def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Fixture to load the integration."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_URL: "http://1.1.1.1/sse"},
title=TEST_API_NAME,
)
config_entry.add_to_hass(hass)
return config_entry