core/tests/components/person/conftest.py

53 lines
1.5 KiB
Python

"""The tests for the person component."""
import logging
from typing import Any
import pytest
from homeassistant.components import person
from homeassistant.components.person import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import collection
from homeassistant.setup import async_setup_component
from tests.common import MockUser
DEVICE_TRACKER = "device_tracker.test_tracker"
DEVICE_TRACKER_2 = "device_tracker.test_tracker_2"
@pytest.fixture
def storage_collection(hass: HomeAssistant) -> person.PersonStorageCollection:
"""Return an empty storage collection."""
id_manager = collection.IDManager()
return person.PersonStorageCollection(
person.PersonStore(hass, person.STORAGE_VERSION, person.STORAGE_KEY),
id_manager,
collection.YamlCollection(
logging.getLogger(f"{person.__name__}.yaml_collection"), id_manager
),
)
@pytest.fixture
def storage_setup(
hass: HomeAssistant, hass_storage: dict[str, Any], hass_admin_user: MockUser
) -> None:
"""Storage setup."""
hass_storage[DOMAIN] = {
"key": DOMAIN,
"version": 1,
"data": {
"persons": [
{
"id": "1234",
"name": "tracked person",
"user_id": hass_admin_user.id,
"device_trackers": [DEVICE_TRACKER],
}
]
},
}
assert hass.loop.run_until_complete(async_setup_component(hass, DOMAIN, {}))