Files
core/tests/components/nina/__init__.py
T

68 lines
2.0 KiB
Python

"""Tests for the Nina integration."""
from typing import Any
from unittest.mock import patch
from homeassistant.components.nina.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from tests.common import (
MockConfigEntry,
load_json_array_fixture,
load_json_object_fixture,
)
async def setup_platform(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
"""Set up the NINA platform."""
with patch(
"pynina.baseApi.BaseAPI._makeRequest",
wraps=mocked_request_function,
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED
def mocked_request_function(url: str) -> dict[str, Any]:
"""Mock of the request function."""
dummy_response: list[dict[str, Any]] = load_json_array_fixture(
"sample_warnings.json", DOMAIN
)
dummy_response_details: dict[str, Any] = load_json_object_fixture(
"sample_warning_details.json", DOMAIN
)
dummy_response_regions: dict[str, Any] = load_json_object_fixture(
"sample_regions.json", DOMAIN
)
dummy_response_labels: dict[str, Any] = load_json_object_fixture(
"sample_labels.json", DOMAIN
)
if "https://warnung.bund.de/api31/dashboard/" in url: # codespell:ignore bund
return dummy_response
if (
"https://warnung.bund.de/api/appdata/gsb/labels/de_labels.json" # codespell:ignore bund
in url
):
return dummy_response_labels
if (
url
== "https://www.xrepository.de/api/xrepository/urn:de:bund:destatis:bevoelkerungsstatistik:schluessel:rs_2021-07-31/download/Regionalschl_ssel_2021-07-31.json" # codespell:ignore bund
):
return dummy_response_regions
warning_id = url.replace(
"https://warnung.bund.de/api31/warnings/", # codespell:ignore bund
"",
).replace(".json", "")
return dummy_response_details[warning_id]