Improve type hints in simplisafe tests (#120303)
This commit is contained in:
parent
237f20de6c
commit
e3806d12f4
1 changed files with 33 additions and 20 deletions
|
@ -1,18 +1,20 @@
|
|||
"""Define test fixtures for SimpliSafe."""
|
||||
|
||||
import json
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from simplipy.system.v3 import SystemV3
|
||||
from typing_extensions import AsyncGenerator
|
||||
|
||||
from homeassistant.components.simplisafe.const import DOMAIN
|
||||
from homeassistant.const import CONF_CODE, CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.json import JsonObjectType
|
||||
|
||||
from .common import REFRESH_TOKEN, USER_ID, USERNAME
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||
|
||||
CODE = "12345"
|
||||
PASSWORD = "password"
|
||||
|
@ -20,7 +22,9 @@ SYSTEM_ID = 12345
|
|||
|
||||
|
||||
@pytest.fixture(name="api")
|
||||
def api_fixture(data_subscription, system_v3, websocket):
|
||||
def api_fixture(
|
||||
data_subscription: JsonObjectType, system_v3: SystemV3, websocket: Mock
|
||||
) -> Mock:
|
||||
"""Define a simplisafe-python API object."""
|
||||
return Mock(
|
||||
async_get_systems=AsyncMock(return_value={SYSTEM_ID: system_v3}),
|
||||
|
@ -32,7 +36,9 @@ def api_fixture(data_subscription, system_v3, websocket):
|
|||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def config_entry_fixture(hass, config, unique_id):
|
||||
def config_entry_fixture(
|
||||
hass: HomeAssistant, config: dict[str, str], unique_id: str
|
||||
) -> MockConfigEntry:
|
||||
"""Define a config entry."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN, unique_id=unique_id, data=config, options={CONF_CODE: "1234"}
|
||||
|
@ -42,7 +48,7 @@ def config_entry_fixture(hass, config, unique_id):
|
|||
|
||||
|
||||
@pytest.fixture(name="config")
|
||||
def config_fixture():
|
||||
def config_fixture() -> dict[str, str]:
|
||||
"""Define config entry data config."""
|
||||
return {
|
||||
CONF_TOKEN: REFRESH_TOKEN,
|
||||
|
@ -51,7 +57,7 @@ def config_fixture():
|
|||
|
||||
|
||||
@pytest.fixture(name="credentials_config")
|
||||
def credentials_config_fixture():
|
||||
def credentials_config_fixture() -> dict[str, str]:
|
||||
"""Define a username/password config."""
|
||||
return {
|
||||
CONF_USERNAME: USERNAME,
|
||||
|
@ -60,32 +66,32 @@ def credentials_config_fixture():
|
|||
|
||||
|
||||
@pytest.fixture(name="data_latest_event", scope="package")
|
||||
def data_latest_event_fixture():
|
||||
def data_latest_event_fixture() -> JsonObjectType:
|
||||
"""Define latest event data."""
|
||||
return json.loads(load_fixture("latest_event_data.json", "simplisafe"))
|
||||
return load_json_object_fixture("latest_event_data.json", "simplisafe")
|
||||
|
||||
|
||||
@pytest.fixture(name="data_sensor", scope="package")
|
||||
def data_sensor_fixture():
|
||||
def data_sensor_fixture() -> JsonObjectType:
|
||||
"""Define sensor data."""
|
||||
return json.loads(load_fixture("sensor_data.json", "simplisafe"))
|
||||
return load_json_object_fixture("sensor_data.json", "simplisafe")
|
||||
|
||||
|
||||
@pytest.fixture(name="data_settings", scope="package")
|
||||
def data_settings_fixture():
|
||||
def data_settings_fixture() -> JsonObjectType:
|
||||
"""Define settings data."""
|
||||
return json.loads(load_fixture("settings_data.json", "simplisafe"))
|
||||
return load_json_object_fixture("settings_data.json", "simplisafe")
|
||||
|
||||
|
||||
@pytest.fixture(name="data_subscription", scope="package")
|
||||
def data_subscription_fixture():
|
||||
def data_subscription_fixture() -> JsonObjectType:
|
||||
"""Define subscription data."""
|
||||
data = json.loads(load_fixture("subscription_data.json", "simplisafe"))
|
||||
data = load_json_object_fixture("subscription_data.json", "simplisafe")
|
||||
return {SYSTEM_ID: data}
|
||||
|
||||
|
||||
@pytest.fixture(name="reauth_config")
|
||||
def reauth_config_fixture():
|
||||
def reauth_config_fixture() -> dict[str, str]:
|
||||
"""Define a reauth config."""
|
||||
return {
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
|
@ -93,7 +99,9 @@ def reauth_config_fixture():
|
|||
|
||||
|
||||
@pytest.fixture(name="setup_simplisafe")
|
||||
async def setup_simplisafe_fixture(hass, api, config):
|
||||
async def setup_simplisafe_fixture(
|
||||
hass: HomeAssistant, api: Mock, config: dict[str, str]
|
||||
) -> AsyncGenerator[None]:
|
||||
"""Define a fixture to set up SimpliSafe."""
|
||||
with (
|
||||
patch(
|
||||
|
@ -122,7 +130,7 @@ async def setup_simplisafe_fixture(hass, api, config):
|
|||
|
||||
|
||||
@pytest.fixture(name="sms_config")
|
||||
def sms_config_fixture():
|
||||
def sms_config_fixture() -> dict[str, str]:
|
||||
"""Define a SMS-based two-factor authentication config."""
|
||||
return {
|
||||
CONF_CODE: CODE,
|
||||
|
@ -130,7 +138,12 @@ def sms_config_fixture():
|
|||
|
||||
|
||||
@pytest.fixture(name="system_v3")
|
||||
def system_v3_fixture(data_latest_event, data_sensor, data_settings, data_subscription):
|
||||
def system_v3_fixture(
|
||||
data_latest_event: JsonObjectType,
|
||||
data_sensor: JsonObjectType,
|
||||
data_settings: JsonObjectType,
|
||||
data_subscription: JsonObjectType,
|
||||
) -> SystemV3:
|
||||
"""Define a simplisafe-python V3 System object."""
|
||||
system = SystemV3(Mock(subscription_data=data_subscription), SYSTEM_ID)
|
||||
system.async_get_latest_event = AsyncMock(return_value=data_latest_event)
|
||||
|
@ -141,13 +154,13 @@ def system_v3_fixture(data_latest_event, data_sensor, data_settings, data_subscr
|
|||
|
||||
|
||||
@pytest.fixture(name="unique_id")
|
||||
def unique_id_fixture():
|
||||
def unique_id_fixture() -> str:
|
||||
"""Define a unique ID."""
|
||||
return USER_ID
|
||||
|
||||
|
||||
@pytest.fixture(name="websocket")
|
||||
def websocket_fixture():
|
||||
def websocket_fixture() -> Mock:
|
||||
"""Define a simplisafe-python websocket object."""
|
||||
return Mock(
|
||||
async_connect=AsyncMock(),
|
||||
|
|
Loading…
Add table
Reference in a new issue