mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
KNX: use async_load_json_object_fixture
in tests (#147991)
This commit is contained in:
parent
f0e0c954e7
commit
c137c96cfd
@ -40,15 +40,9 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import KnxEntityGenerator
|
||||
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
async_load_json_object_fixture,
|
||||
load_json_object_fixture,
|
||||
)
|
||||
from tests.common import MockConfigEntry, async_load_json_object_fixture
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
FIXTURE_PROJECT_DATA = load_json_object_fixture("project.json", DOMAIN)
|
||||
|
||||
|
||||
class KNXTestKit:
|
||||
"""Test helper for the KNX integration."""
|
||||
@ -338,11 +332,19 @@ async def knx(
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def load_knxproj(hass_storage: dict[str, Any]) -> None:
|
||||
async def project_data(hass: HomeAssistant) -> dict[str, Any]:
|
||||
"""Return the fixture project data."""
|
||||
return await async_load_json_object_fixture(hass, "project.json", DOMAIN)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def load_knxproj(
|
||||
project_data: dict[str, Any], hass_storage: dict[str, Any]
|
||||
) -> None:
|
||||
"""Mock KNX project data."""
|
||||
hass_storage[KNX_PROJECT_STORAGE_KEY] = {
|
||||
"version": 1,
|
||||
"data": FIXTURE_PROJECT_DATA,
|
||||
"data": project_data,
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ from homeassistant.components.knx.schema import SwitchSchema
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import FIXTURE_PROJECT_DATA, KNXTestKit
|
||||
from .conftest import KNXTestKit
|
||||
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
@ -32,11 +32,11 @@ async def test_knx_info_command(
|
||||
assert res["result"]["project"] is None
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("load_knxproj")
|
||||
async def test_knx_info_command_with_project(
|
||||
hass: HomeAssistant,
|
||||
knx: KNXTestKit,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
load_knxproj: None,
|
||||
) -> None:
|
||||
"""Test knx/info command with loaded project."""
|
||||
await knx.setup_integration()
|
||||
@ -59,11 +59,11 @@ async def test_knx_project_file_process(
|
||||
knx: KNXTestKit,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
project_data: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test knx/project_file_process command for storing and loading new data."""
|
||||
_file_id = "1234"
|
||||
_password = "pw-test"
|
||||
_parse_result = FIXTURE_PROJECT_DATA
|
||||
|
||||
await knx.setup_integration()
|
||||
client = await hass_ws_client(hass)
|
||||
@ -80,7 +80,7 @@ async def test_knx_project_file_process(
|
||||
patch(
|
||||
"homeassistant.components.knx.project.process_uploaded_file",
|
||||
) as file_upload_mock,
|
||||
patch("xknxproject.XKNXProj.parse", return_value=_parse_result) as parse_mock,
|
||||
patch("xknxproject.XKNXProj.parse", return_value=project_data) as parse_mock,
|
||||
):
|
||||
file_upload_mock.return_value.__enter__.return_value = ""
|
||||
res = await client.receive_json()
|
||||
@ -90,7 +90,7 @@ async def test_knx_project_file_process(
|
||||
|
||||
assert res["success"], res
|
||||
assert hass.data[KNX_MODULE_KEY].project.loaded
|
||||
assert hass_storage[KNX_PROJECT_STORAGE_KEY]["data"] == _parse_result
|
||||
assert hass_storage[KNX_PROJECT_STORAGE_KEY]["data"] == project_data
|
||||
|
||||
|
||||
async def test_knx_project_file_process_error(
|
||||
@ -124,11 +124,11 @@ async def test_knx_project_file_process_error(
|
||||
assert not hass.data[KNX_MODULE_KEY].project.loaded
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("load_knxproj")
|
||||
async def test_knx_project_file_remove(
|
||||
hass: HomeAssistant,
|
||||
knx: KNXTestKit,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
load_knxproj: None,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test knx/project_file_remove command."""
|
||||
@ -145,11 +145,12 @@ async def test_knx_project_file_remove(
|
||||
assert not hass_storage.get(KNX_PROJECT_STORAGE_KEY)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("load_knxproj")
|
||||
async def test_knx_get_project(
|
||||
hass: HomeAssistant,
|
||||
knx: KNXTestKit,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
load_knxproj: None,
|
||||
project_data: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test retrieval of kxnproject from store."""
|
||||
await knx.setup_integration()
|
||||
@ -160,7 +161,7 @@ async def test_knx_get_project(
|
||||
res = await client.receive_json()
|
||||
assert res["success"], res
|
||||
assert res["result"]["project_loaded"] is True
|
||||
assert res["result"]["knxproject"] == FIXTURE_PROJECT_DATA
|
||||
assert res["result"]["knxproject"] == project_data
|
||||
|
||||
|
||||
async def test_knx_group_monitor_info_command(
|
||||
|
Loading…
x
Reference in New Issue
Block a user