mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
Use async_load_fixture in remaining tests (#146021)
This commit is contained in:
parent
2dbf24e798
commit
54c20d5d5a
@ -54,7 +54,7 @@ from homeassistant.setup import async_setup_component
|
|||||||
|
|
||||||
from .test_init import MOCK_ENVIRON
|
from .test_init import MOCK_ENVIRON
|
||||||
|
|
||||||
from tests.common import load_json_object_fixture, mock_platform
|
from tests.common import async_load_json_object_fixture, mock_platform
|
||||||
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
||||||
|
|
||||||
TEST_BACKUP = supervisor_backups.Backup(
|
TEST_BACKUP = supervisor_backups.Backup(
|
||||||
@ -1018,8 +1018,10 @@ async def test_reader_writer_create_addon_folder_error(
|
|||||||
supervisor_client.jobs.get_job.side_effect = [
|
supervisor_client.jobs.get_job.side_effect = [
|
||||||
TEST_JOB_NOT_DONE,
|
TEST_JOB_NOT_DONE,
|
||||||
supervisor_jobs.Job.from_dict(
|
supervisor_jobs.Job.from_dict(
|
||||||
load_json_object_fixture(
|
(
|
||||||
"backup_done_with_addon_folder_errors.json", DOMAIN
|
await async_load_json_object_fixture(
|
||||||
|
hass, "backup_done_with_addon_folder_errors.json", DOMAIN
|
||||||
|
)
|
||||||
)["data"]
|
)["data"]
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -15,7 +15,7 @@ from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
|
|||||||
|
|
||||||
from .const import DHCP_DATA, DISCOVERY_DATA, HOMEKIT_DATA, MOCK_SERIAL
|
from .const import DHCP_DATA, DISCOVERY_DATA, HOMEKIT_DATA, MOCK_SERIAL
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
from tests.common import MockConfigEntry, async_load_json_object_fixture
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_hunterdouglas_hub")
|
@pytest.mark.usefixtures("mock_hunterdouglas_hub")
|
||||||
@ -330,7 +330,9 @@ async def test_form_unsupported_device(
|
|||||||
# Simulate a gen 3 secondary hub
|
# Simulate a gen 3 secondary hub
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hunterdouglas_powerview.util.Hub.request_raw_data",
|
"homeassistant.components.hunterdouglas_powerview.util.Hub.request_raw_data",
|
||||||
return_value=load_json_object_fixture("gen3/gateway/secondary.json", DOMAIN),
|
return_value=await async_load_json_object_fixture(
|
||||||
|
hass, "gen3/gateway/secondary.json", DOMAIN
|
||||||
|
),
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
|
@ -29,7 +29,7 @@ async def test_nexia_sensor_switch(
|
|||||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test NexiaRoomIQSensorSwitch."""
|
"""Test NexiaRoomIQSensorSwitch."""
|
||||||
await async_init_integration(hass, house_fixture="nexia/sensors_xl1050_house.json")
|
await async_init_integration(hass, house_fixture="sensors_xl1050_house.json")
|
||||||
sw1_id = f"{Platform.SWITCH}.center_nativezone_include_center"
|
sw1_id = f"{Platform.SWITCH}.center_nativezone_include_center"
|
||||||
sw1 = {ATTR_ENTITY_ID: sw1_id}
|
sw1 = {ATTR_ENTITY_ID: sw1_id}
|
||||||
sw2_id = f"{Platform.SWITCH}.center_nativezone_include_upstairs"
|
sw2_id = f"{Platform.SWITCH}.center_nativezone_include_upstairs"
|
||||||
|
@ -9,7 +9,7 @@ from homeassistant.components.nexia.const import DOMAIN
|
|||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, async_load_fixture
|
||||||
from tests.test_util.aiohttp import mock_aiohttp_client
|
from tests.test_util.aiohttp import mock_aiohttp_client
|
||||||
|
|
||||||
|
|
||||||
@ -18,13 +18,13 @@ async def async_init_integration(
|
|||||||
skip_setup: bool = False,
|
skip_setup: bool = False,
|
||||||
exception: Exception | None = None,
|
exception: Exception | None = None,
|
||||||
*,
|
*,
|
||||||
house_fixture="nexia/mobile_houses_123456.json",
|
house_fixture="mobile_houses_123456.json",
|
||||||
) -> MockConfigEntry:
|
) -> MockConfigEntry:
|
||||||
"""Set up the nexia integration in Home Assistant."""
|
"""Set up the nexia integration in Home Assistant."""
|
||||||
|
|
||||||
session_fixture = "nexia/session_123456.json"
|
session_fixture = "session_123456.json"
|
||||||
sign_in_fixture = "nexia/sign_in.json"
|
sign_in_fixture = "sign_in.json"
|
||||||
set_fan_speed_fixture = "nexia/set_fan_speed_2293892.json"
|
set_fan_speed_fixture = "set_fan_speed_2293892.json"
|
||||||
with (
|
with (
|
||||||
mock_aiohttp_client() as mock_session,
|
mock_aiohttp_client() as mock_session,
|
||||||
patch("nexia.home.load_or_create_uuid", return_value=uuid.uuid4()),
|
patch("nexia.home.load_or_create_uuid", return_value=uuid.uuid4()),
|
||||||
@ -40,19 +40,20 @@ async def async_init_integration(
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
mock_session.post(
|
mock_session.post(
|
||||||
nexia.API_MOBILE_SESSION_URL, text=load_fixture(session_fixture)
|
nexia.API_MOBILE_SESSION_URL,
|
||||||
|
text=await async_load_fixture(hass, session_fixture, DOMAIN),
|
||||||
)
|
)
|
||||||
mock_session.get(
|
mock_session.get(
|
||||||
nexia.API_MOBILE_HOUSES_URL.format(house_id=123456),
|
nexia.API_MOBILE_HOUSES_URL.format(house_id=123456),
|
||||||
text=load_fixture(house_fixture),
|
text=await async_load_fixture(hass, house_fixture, DOMAIN),
|
||||||
)
|
)
|
||||||
mock_session.post(
|
mock_session.post(
|
||||||
nexia.API_MOBILE_ACCOUNTS_SIGN_IN_URL,
|
nexia.API_MOBILE_ACCOUNTS_SIGN_IN_URL,
|
||||||
text=load_fixture(sign_in_fixture),
|
text=await async_load_fixture(hass, sign_in_fixture, DOMAIN),
|
||||||
)
|
)
|
||||||
mock_session.post(
|
mock_session.post(
|
||||||
"https://www.mynexia.com/mobile/xxl_thermostats/2293892/fan_speed",
|
"https://www.mynexia.com/mobile/xxl_thermostats/2293892/fan_speed",
|
||||||
text=load_fixture(set_fan_speed_fixture),
|
text=await async_load_fixture(hass, set_fan_speed_fixture, DOMAIN),
|
||||||
)
|
)
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -9,8 +9,8 @@ from .mock import MOCK_INFO, setup_nuki_integration
|
|||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
MockConfigEntry,
|
MockConfigEntry,
|
||||||
load_json_array_fixture,
|
async_load_json_array_fixture,
|
||||||
load_json_object_fixture,
|
async_load_json_object_fixture,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -21,15 +21,19 @@ async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
|
|||||||
mock.get("http://1.1.1.1:8080/info", json=MOCK_INFO)
|
mock.get("http://1.1.1.1:8080/info", json=MOCK_INFO)
|
||||||
mock.get(
|
mock.get(
|
||||||
"http://1.1.1.1:8080/list",
|
"http://1.1.1.1:8080/list",
|
||||||
json=load_json_array_fixture("list.json", DOMAIN),
|
json=await async_load_json_array_fixture(hass, "list.json", DOMAIN),
|
||||||
)
|
)
|
||||||
mock.get(
|
mock.get(
|
||||||
"http://1.1.1.1:8080/callback/list",
|
"http://1.1.1.1:8080/callback/list",
|
||||||
json=load_json_object_fixture("callback_list.json", DOMAIN),
|
json=await async_load_json_object_fixture(
|
||||||
|
hass, "callback_list.json", DOMAIN
|
||||||
|
),
|
||||||
)
|
)
|
||||||
mock.get(
|
mock.get(
|
||||||
"http://1.1.1.1:8080/callback/add",
|
"http://1.1.1.1:8080/callback/add",
|
||||||
json=load_json_object_fixture("callback_add.json", DOMAIN),
|
json=await async_load_json_object_fixture(
|
||||||
|
hass, "callback_add.json", DOMAIN
|
||||||
|
),
|
||||||
)
|
)
|
||||||
entry = await setup_nuki_integration(hass)
|
entry = await setup_nuki_integration(hass)
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
@ -8,7 +8,7 @@ from homeassistant.components.overkiz.const import DOMAIN
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
from tests.common import MockConfigEntry, async_load_json_object_fixture
|
||||||
from tests.components.diagnostics import (
|
from tests.components.diagnostics import (
|
||||||
get_diagnostics_for_config_entry,
|
get_diagnostics_for_config_entry,
|
||||||
get_diagnostics_for_device,
|
get_diagnostics_for_device,
|
||||||
@ -23,7 +23,9 @@ async def test_diagnostics(
|
|||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test diagnostics."""
|
"""Test diagnostics."""
|
||||||
diagnostic_data = load_json_object_fixture("overkiz/setup_tahoma_switch.json")
|
diagnostic_data = await async_load_json_object_fixture(
|
||||||
|
hass, "setup_tahoma_switch.json", DOMAIN
|
||||||
|
)
|
||||||
|
|
||||||
with patch.multiple(
|
with patch.multiple(
|
||||||
"pyoverkiz.client.OverkizClient",
|
"pyoverkiz.client.OverkizClient",
|
||||||
@ -44,7 +46,9 @@ async def test_device_diagnostics(
|
|||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device diagnostics."""
|
"""Test device diagnostics."""
|
||||||
diagnostic_data = load_json_object_fixture("overkiz/setup_tahoma_switch.json")
|
diagnostic_data = await async_load_json_object_fixture(
|
||||||
|
hass, "setup_tahoma_switch.json", DOMAIN
|
||||||
|
)
|
||||||
|
|
||||||
device = device_registry.async_get_device(
|
device = device_registry.async_get_device(
|
||||||
identifiers={(DOMAIN, "rts://****-****-6867/16756006")}
|
identifiers={(DOMAIN, "rts://****-****-6867/16756006")}
|
||||||
|
@ -12,7 +12,7 @@ from homeassistant.helpers import entity_registry as er
|
|||||||
|
|
||||||
from . import configure_integration
|
from . import configure_integration
|
||||||
|
|
||||||
from tests.common import load_json_object_fixture, snapshot_platform
|
from tests.common import async_load_json_object_fixture, snapshot_platform
|
||||||
|
|
||||||
|
|
||||||
async def test_meter(
|
async def test_meter(
|
||||||
@ -33,7 +33,9 @@ async def test_meter(
|
|||||||
hubDeviceId="test-hub-id",
|
hubDeviceId="test-hub-id",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
mock_get_status.return_value = load_json_object_fixture("meter_status.json", DOMAIN)
|
mock_get_status.return_value = await async_load_json_object_fixture(
|
||||||
|
hass, "meter_status.json", DOMAIN
|
||||||
|
)
|
||||||
|
|
||||||
with patch("homeassistant.components.switchbot_cloud.PLATFORMS", [Platform.SENSOR]):
|
with patch("homeassistant.components.switchbot_cloud.PLATFORMS", [Platform.SENSOR]):
|
||||||
entry = await configure_integration(hass)
|
entry = await configure_integration(hass)
|
||||||
|
@ -8,8 +8,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
MockConfigEntry,
|
MockConfigEntry,
|
||||||
load_json_array_fixture,
|
async_load_json_array_fixture,
|
||||||
load_json_object_fixture,
|
async_load_json_object_fixture,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -18,16 +18,22 @@ async def init_component(hass: HomeAssistant) -> MockConfigEntry:
|
|||||||
with requests_mock.Mocker() as mock:
|
with requests_mock.Mocker() as mock:
|
||||||
mock.get(
|
mock.get(
|
||||||
"http://1.1.1.1/d",
|
"http://1.1.1.1/d",
|
||||||
json=load_json_object_fixture("device.json", youless.DOMAIN),
|
json=await async_load_json_object_fixture(
|
||||||
|
hass, "device.json", youless.DOMAIN
|
||||||
|
),
|
||||||
)
|
)
|
||||||
mock.get(
|
mock.get(
|
||||||
"http://1.1.1.1/e",
|
"http://1.1.1.1/e",
|
||||||
json=load_json_array_fixture("enologic.json", youless.DOMAIN),
|
json=await async_load_json_array_fixture(
|
||||||
|
hass, "enologic.json", youless.DOMAIN
|
||||||
|
),
|
||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
)
|
)
|
||||||
mock.get(
|
mock.get(
|
||||||
"http://1.1.1.1/f",
|
"http://1.1.1.1/f",
|
||||||
json=load_json_object_fixture("phase.json", youless.DOMAIN),
|
json=await async_load_json_object_fixture(
|
||||||
|
hass, "phase.json", youless.DOMAIN
|
||||||
|
),
|
||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user