From be7c4295dcfedadf8ac5fe7562c509e1377f2b2d Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 15 Mar 2024 18:26:28 +0100 Subject: [PATCH] Fix MyUplink tests (#113534) --- tests/components/myuplink/conftest.py | 19 ++++++++++--------- tests/components/myuplink/test_number.py | 7 ++----- tests/components/myuplink/test_switch.py | 5 +---- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/tests/components/myuplink/conftest.py b/tests/components/myuplink/conftest.py index 87f8b37726b..e08dc4255be 100644 --- a/tests/components/myuplink/conftest.py +++ b/tests/components/myuplink/conftest.py @@ -6,6 +6,7 @@ from typing import Any from unittest.mock import MagicMock, patch from myuplink import Device, DevicePoint, System +import orjson import pytest from homeassistant.components.application_credentials import ( @@ -107,22 +108,22 @@ def system_fixture(load_systems_file: str) -> list[System]: # Fixture group for device points API endpoint. -@pytest.fixture(scope="session") +@pytest.fixture def load_device_points_file() -> str: """Load fixture file for device-points endpoint.""" - return load_fixture("device_points_nibe_f730.json", DOMAIN) + return "device_points_nibe_f730.json" @pytest.fixture -def load_device_points_jv_file(): +def load_device_points_jv_file(load_device_points_file) -> str: """Load fixture file for device_points.""" - return json_loads(load_device_points_file) + return load_fixture(load_device_points_file, DOMAIN) @pytest.fixture -def device_points_fixture(load_device_points_file: str) -> list[DevicePoint]: - """Fixture for devce_points.""" - data = json_loads(load_device_points_file) +def device_points_fixture(load_device_points_jv_file: str) -> list[DevicePoint]: + """Fixture for device_points.""" + data = orjson.loads(load_device_points_jv_file) return [DevicePoint(point_data) for point_data in data] @@ -130,7 +131,7 @@ def device_points_fixture(load_device_points_file: str) -> list[DevicePoint]: def mock_myuplink_client( load_device_file, device_fixture, - load_device_points_file, + load_device_points_jv_file, device_points_fixture, system_fixture, load_systems_jv_file, @@ -150,7 +151,7 @@ def mock_myuplink_client( client.async_get_device_json.return_value = load_device_file client.async_get_device_points.return_value = device_points_fixture - client.async_get_device_points_json.return_value = load_device_points_file + client.async_get_device_points_json.return_value = load_device_points_jv_file yield client diff --git a/tests/components/myuplink/test_number.py b/tests/components/myuplink/test_number.py index 2f898b1db9e..899b2302b3c 100644 --- a/tests/components/myuplink/test_number.py +++ b/tests/components/myuplink/test_number.py @@ -5,15 +5,12 @@ from unittest.mock import MagicMock from aiohttp import ClientError import pytest -from homeassistant.components.myuplink.const import DOMAIN from homeassistant.components.number import SERVICE_SET_VALUE from homeassistant.const import ATTR_ENTITY_ID, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_registry as er -from tests.common import load_fixture - TEST_PLATFORM = Platform.NUMBER pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)]) @@ -91,7 +88,7 @@ async def test_api_failure( @pytest.mark.parametrize( "load_device_points_file", - [load_fixture("device_points_nibe_smo20.json", DOMAIN)], + ["device_points_nibe_smo20.json"], ) async def test_entity_registry_smo20( hass: HomeAssistant, @@ -101,5 +98,5 @@ async def test_entity_registry_smo20( ) -> None: """Test that the entities are registered in the entity registry.""" - entry = entity_registry.async_get("number.f730_cu_3x400v_change_in_curve") + entry = entity_registry.async_get("number.gotham_city_change_in_curve") assert entry.unique_id == "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-47028" diff --git a/tests/components/myuplink/test_switch.py b/tests/components/myuplink/test_switch.py index 7635cc43a05..efbc2c88371 100644 --- a/tests/components/myuplink/test_switch.py +++ b/tests/components/myuplink/test_switch.py @@ -5,7 +5,6 @@ from unittest.mock import MagicMock from aiohttp import ClientError import pytest -from homeassistant.components.myuplink.const import DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, SERVICE_TURN_OFF, @@ -17,8 +16,6 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_registry as er -from tests.common import load_fixture - TEST_PLATFORM = Platform.SWITCH pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)]) @@ -101,7 +98,7 @@ async def test_api_failure( @pytest.mark.parametrize( "load_device_points_file", - [load_fixture("device_points_nibe_smo20.json", DOMAIN)], + ["device_points_nibe_smo20.json"], ) async def test_entity_registry_smo20( hass: HomeAssistant,