hass-core/tests/components/notion/conftest.py

76 lines
2.3 KiB
Python
Raw Normal View History

2022-01-23 02:18:54 -07:00
"""Define fixtures for Notion tests."""
2022-01-24 08:15:45 -07:00
import json
from unittest.mock import AsyncMock, patch
2022-01-23 02:18:54 -07:00
import pytest
from homeassistant.components.notion import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.setup import async_setup_component
2022-01-24 08:15:45 -07:00
from tests.common import MockConfigEntry, load_fixture
@pytest.fixture(name="client")
def client_fixture(data_bridge, data_sensor, data_task):
"""Define a fixture for an aionotion client."""
client = AsyncMock()
client.bridge.async_all.return_value = data_bridge
client.sensor.async_all.return_value = data_sensor
client.task.async_all.return_value = data_task
return client
2022-01-23 02:18:54 -07:00
@pytest.fixture(name="config_entry")
def config_entry_fixture(hass, config):
2022-01-23 02:18:54 -07:00
"""Define a config entry fixture."""
entry = MockConfigEntry(domain=DOMAIN, unique_id=config[CONF_USERNAME], data=config)
2022-01-23 02:18:54 -07:00
entry.add_to_hass(hass)
return entry
@pytest.fixture(name="config")
def config_fixture(hass):
"""Define a config entry data fixture."""
return {
CONF_USERNAME: "user@host.com",
CONF_PASSWORD: "password123",
}
@pytest.fixture(name="data_bridge", scope="package")
2022-01-24 08:15:45 -07:00
def data_bridge_fixture():
"""Define bridge data."""
return json.loads(load_fixture("bridge_data.json", "notion"))
@pytest.fixture(name="data_sensor", scope="package")
2022-01-24 08:15:45 -07:00
def data_sensor_fixture():
"""Define sensor data."""
return json.loads(load_fixture("sensor_data.json", "notion"))
@pytest.fixture(name="data_task", scope="package")
2022-01-24 08:15:45 -07:00
def data_task_fixture():
"""Define task data."""
return json.loads(load_fixture("task_data.json", "notion"))
@pytest.fixture(name="get_client")
def get_client_fixture(client):
"""Define a fixture to mock the async_get_client method."""
return AsyncMock(return_value=client)
2022-01-23 02:18:54 -07:00
@pytest.fixture(name="setup_notion")
async def setup_notion_fixture(hass, config, get_client):
2022-01-23 02:18:54 -07:00
"""Define a fixture to set up Notion."""
with patch(
"homeassistant.components.notion.config_flow.async_get_client", get_client
), patch("homeassistant.components.notion.async_get_client", get_client), patch(
2022-01-24 08:15:45 -07:00
"homeassistant.components.notion.PLATFORMS", []
):
2022-01-23 02:18:54 -07:00
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
yield