mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Improve type hints in iqvia tests (#121506)
This commit is contained in:
parent
148803460b
commit
b048ad8afe
@ -1,18 +1,23 @@
|
|||||||
"""Define test fixtures for IQVIA."""
|
"""Define test fixtures for IQVIA."""
|
||||||
|
|
||||||
import json
|
from collections.abc import AsyncGenerator
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.iqvia.const import CONF_ZIP_CODE, DOMAIN
|
from homeassistant.components.iqvia.const import CONF_ZIP_CODE, DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
from homeassistant.util.json import JsonObjectType
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="config_entry")
|
@pytest.fixture(name="config_entry")
|
||||||
def config_entry_fixture(hass, config):
|
def config_entry_fixture(
|
||||||
|
hass: HomeAssistant, config: dict[str, Any]
|
||||||
|
) -> MockConfigEntry:
|
||||||
"""Define a config entry fixture."""
|
"""Define a config entry fixture."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
@ -25,7 +30,7 @@ def config_entry_fixture(hass, config):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="config")
|
@pytest.fixture(name="config")
|
||||||
def config_fixture(hass):
|
def config_fixture() -> dict[str, Any]:
|
||||||
"""Define a config entry data fixture."""
|
"""Define a config entry data fixture."""
|
||||||
return {
|
return {
|
||||||
CONF_ZIP_CODE: "12345",
|
CONF_ZIP_CODE: "12345",
|
||||||
@ -33,59 +38,59 @@ def config_fixture(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="data_allergy_forecast", scope="package")
|
@pytest.fixture(name="data_allergy_forecast", scope="package")
|
||||||
def data_allergy_forecast_fixture():
|
def data_allergy_forecast_fixture() -> JsonObjectType:
|
||||||
"""Define allergy forecast data."""
|
"""Define allergy forecast data."""
|
||||||
return json.loads(load_fixture("allergy_forecast_data.json", "iqvia"))
|
return load_json_object_fixture("allergy_forecast_data.json", "iqvia")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="data_allergy_index", scope="package")
|
@pytest.fixture(name="data_allergy_index", scope="package")
|
||||||
def data_allergy_index_fixture():
|
def data_allergy_index_fixture() -> JsonObjectType:
|
||||||
"""Define allergy index data."""
|
"""Define allergy index data."""
|
||||||
return json.loads(load_fixture("allergy_index_data.json", "iqvia"))
|
return load_json_object_fixture("allergy_index_data.json", "iqvia")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="data_allergy_outlook", scope="package")
|
@pytest.fixture(name="data_allergy_outlook", scope="package")
|
||||||
def data_allergy_outlook_fixture():
|
def data_allergy_outlook_fixture() -> JsonObjectType:
|
||||||
"""Define allergy outlook data."""
|
"""Define allergy outlook data."""
|
||||||
return json.loads(load_fixture("allergy_outlook_data.json", "iqvia"))
|
return load_json_object_fixture("allergy_outlook_data.json", "iqvia")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="data_asthma_forecast", scope="package")
|
@pytest.fixture(name="data_asthma_forecast", scope="package")
|
||||||
def data_asthma_forecast_fixture():
|
def data_asthma_forecast_fixture() -> JsonObjectType:
|
||||||
"""Define asthma forecast data."""
|
"""Define asthma forecast data."""
|
||||||
return json.loads(load_fixture("asthma_forecast_data.json", "iqvia"))
|
return load_json_object_fixture("asthma_forecast_data.json", "iqvia")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="data_asthma_index", scope="package")
|
@pytest.fixture(name="data_asthma_index", scope="package")
|
||||||
def data_asthma_index_fixture():
|
def data_asthma_index_fixture() -> JsonObjectType:
|
||||||
"""Define asthma index data."""
|
"""Define asthma index data."""
|
||||||
return json.loads(load_fixture("asthma_index_data.json", "iqvia"))
|
return load_json_object_fixture("asthma_index_data.json", "iqvia")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="data_disease_forecast", scope="package")
|
@pytest.fixture(name="data_disease_forecast", scope="package")
|
||||||
def data_disease_forecast_fixture():
|
def data_disease_forecast_fixture() -> JsonObjectType:
|
||||||
"""Define disease forecast data."""
|
"""Define disease forecast data."""
|
||||||
return json.loads(load_fixture("disease_forecast_data.json", "iqvia"))
|
return load_json_object_fixture("disease_forecast_data.json", "iqvia")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="data_disease_index", scope="package")
|
@pytest.fixture(name="data_disease_index", scope="package")
|
||||||
def data_disease_index_fixture():
|
def data_disease_index_fixture() -> JsonObjectType:
|
||||||
"""Define disease index data."""
|
"""Define disease index data."""
|
||||||
return json.loads(load_fixture("disease_index_data.json", "iqvia"))
|
return load_json_object_fixture("disease_index_data.json", "iqvia")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="setup_iqvia")
|
@pytest.fixture(name="setup_iqvia")
|
||||||
async def setup_iqvia_fixture(
|
async def setup_iqvia_fixture(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
config,
|
config: dict[str, Any],
|
||||||
data_allergy_forecast,
|
data_allergy_forecast: JsonObjectType,
|
||||||
data_allergy_index,
|
data_allergy_index: JsonObjectType,
|
||||||
data_allergy_outlook,
|
data_allergy_outlook: JsonObjectType,
|
||||||
data_asthma_forecast,
|
data_asthma_forecast: JsonObjectType,
|
||||||
data_asthma_index,
|
data_asthma_index: JsonObjectType,
|
||||||
data_disease_forecast,
|
data_disease_forecast: JsonObjectType,
|
||||||
data_disease_index,
|
data_disease_index: JsonObjectType,
|
||||||
):
|
) -> AsyncGenerator[None]:
|
||||||
"""Define a fixture to set up IQVIA."""
|
"""Define a fixture to set up IQVIA."""
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
"""Define tests for the IQVIA config flow."""
|
"""Define tests for the IQVIA config flow."""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.iqvia import CONF_ZIP_CODE, DOMAIN
|
from homeassistant.components.iqvia import CONF_ZIP_CODE, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
|
|
||||||
async def test_duplicate_error(hass: HomeAssistant, config, config_entry) -> None:
|
@pytest.mark.usefixtures("config_entry")
|
||||||
|
async def test_duplicate_error(hass: HomeAssistant, config: dict[str, Any]) -> None:
|
||||||
"""Test that errors are shown when duplicates are added."""
|
"""Test that errors are shown when duplicates are added."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}, data=config
|
DOMAIN, context={"source": SOURCE_USER}, data=config
|
||||||
@ -33,7 +38,8 @@ async def test_show_form(hass: HomeAssistant) -> None:
|
|||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
|
|
||||||
async def test_step_user(hass: HomeAssistant, config, setup_iqvia) -> None:
|
@pytest.mark.usefixtures("setup_iqvia")
|
||||||
|
async def test_step_user(hass: HomeAssistant, config: dict[str, Any]) -> None:
|
||||||
"""Test that the user step works (without MFA)."""
|
"""Test that the user step works (without MFA)."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}, data=config
|
DOMAIN, context={"source": SOURCE_USER}, data=config
|
||||||
|
@ -4,15 +4,16 @@ from syrupy import SnapshotAssertion
|
|||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
from tests.typing import ClientSessionGenerator
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_diagnostics(
|
async def test_entry_diagnostics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
setup_iqvia,
|
setup_iqvia: None, # Needs to be injected after config_entry
|
||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test config entry diagnostics."""
|
"""Test config entry diagnostics."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user