diff --git a/tests/components/iqvia/conftest.py b/tests/components/iqvia/conftest.py index 6fb14ca4d2812..0d23b825c5a07 100644 --- a/tests/components/iqvia/conftest.py +++ b/tests/components/iqvia/conftest.py @@ -1,18 +1,23 @@ """Define test fixtures for IQVIA.""" -import json +from collections.abc import AsyncGenerator +from typing import Any from unittest.mock import patch import pytest from homeassistant.components.iqvia.const import CONF_ZIP_CODE, DOMAIN +from homeassistant.core import HomeAssistant 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") -def config_entry_fixture(hass, config): +def config_entry_fixture( + hass: HomeAssistant, config: dict[str, Any] +) -> MockConfigEntry: """Define a config entry fixture.""" entry = MockConfigEntry( domain=DOMAIN, @@ -25,7 +30,7 @@ def config_entry_fixture(hass, config): @pytest.fixture(name="config") -def config_fixture(hass): +def config_fixture() -> dict[str, Any]: """Define a config entry data fixture.""" return { CONF_ZIP_CODE: "12345", @@ -33,59 +38,59 @@ def config_fixture(hass): @pytest.fixture(name="data_allergy_forecast", scope="package") -def data_allergy_forecast_fixture(): +def data_allergy_forecast_fixture() -> JsonObjectType: """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") -def data_allergy_index_fixture(): +def data_allergy_index_fixture() -> JsonObjectType: """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") -def data_allergy_outlook_fixture(): +def data_allergy_outlook_fixture() -> JsonObjectType: """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") -def data_asthma_forecast_fixture(): +def data_asthma_forecast_fixture() -> JsonObjectType: """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") -def data_asthma_index_fixture(): +def data_asthma_index_fixture() -> JsonObjectType: """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") -def data_disease_forecast_fixture(): +def data_disease_forecast_fixture() -> JsonObjectType: """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") -def data_disease_index_fixture(): +def data_disease_index_fixture() -> JsonObjectType: """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") async def setup_iqvia_fixture( - hass, - config, - data_allergy_forecast, - data_allergy_index, - data_allergy_outlook, - data_asthma_forecast, - data_asthma_index, - data_disease_forecast, - data_disease_index, -): + hass: HomeAssistant, + config: dict[str, Any], + data_allergy_forecast: JsonObjectType, + data_allergy_index: JsonObjectType, + data_allergy_outlook: JsonObjectType, + data_asthma_forecast: JsonObjectType, + data_asthma_index: JsonObjectType, + data_disease_forecast: JsonObjectType, + data_disease_index: JsonObjectType, +) -> AsyncGenerator[None]: """Define a fixture to set up IQVIA.""" with ( patch( diff --git a/tests/components/iqvia/test_config_flow.py b/tests/components/iqvia/test_config_flow.py index 17c977a6b4cd4..22f473a3fb5ec 100644 --- a/tests/components/iqvia/test_config_flow.py +++ b/tests/components/iqvia/test_config_flow.py @@ -1,12 +1,17 @@ """Define tests for the IQVIA config flow.""" +from typing import Any + +import pytest + from homeassistant.components.iqvia import CONF_ZIP_CODE, DOMAIN from homeassistant.config_entries import SOURCE_USER from homeassistant.core import HomeAssistant 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.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=config @@ -33,7 +38,8 @@ async def test_show_form(hass: HomeAssistant) -> None: 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).""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=config diff --git a/tests/components/iqvia/test_diagnostics.py b/tests/components/iqvia/test_diagnostics.py index 7c445c9b3e42b..21935a81e86d3 100644 --- a/tests/components/iqvia/test_diagnostics.py +++ b/tests/components/iqvia/test_diagnostics.py @@ -4,15 +4,16 @@ from homeassistant.core import HomeAssistant +from tests.common import MockConfigEntry from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.typing import ClientSessionGenerator async def test_entry_diagnostics( hass: HomeAssistant, - config_entry, + config_entry: MockConfigEntry, hass_client: ClientSessionGenerator, - setup_iqvia, + setup_iqvia: None, # Needs to be injected after config_entry snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics."""