45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""Define tests for the AEMET OpenData init."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import requests_mock
|
|
|
|
from homeassistant.components.aemet.const import DOMAIN
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
|
import homeassistant.util.dt as dt_util
|
|
|
|
from .util import aemet_requests_mock
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
CONFIG = {
|
|
CONF_NAME: "aemet",
|
|
CONF_API_KEY: "foo",
|
|
CONF_LATITUDE: 40.30403754,
|
|
CONF_LONGITUDE: -3.72935236,
|
|
}
|
|
|
|
|
|
async def test_unload_entry(hass):
|
|
"""Test that the options form."""
|
|
|
|
now = dt_util.parse_datetime("2021-01-09 12:00:00+00:00")
|
|
with patch("homeassistant.util.dt.now", return_value=now), patch(
|
|
"homeassistant.util.dt.utcnow", return_value=now
|
|
), requests_mock.mock() as _m:
|
|
aemet_requests_mock(_m)
|
|
|
|
config_entry = MockConfigEntry(
|
|
domain=DOMAIN, unique_id="aemet_unique_id", data=CONFIG
|
|
)
|
|
config_entry.add_to_hass(hass)
|
|
|
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
assert config_entry.state is ConfigEntryState.LOADED
|
|
|
|
await hass.config_entries.async_unload(config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
assert config_entry.state is ConfigEntryState.NOT_LOADED
|