Add additional WWLLN test (#25111)
parent
de43237f6d
commit
c73fa6157d
|
@ -29,9 +29,6 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the WWLLN component."""
|
||||
hass.data[DOMAIN] = {}
|
||||
hass.data[DOMAIN][DATA_CLIENT] = {}
|
||||
|
||||
if DOMAIN not in config:
|
||||
return True
|
||||
|
||||
|
@ -66,6 +63,9 @@ async def async_setup(hass, config):
|
|||
|
||||
async def async_setup_entry(hass, config_entry):
|
||||
"""Set up the WWLLN as config entry."""
|
||||
hass.data[DOMAIN] = {}
|
||||
hass.data[DOMAIN][DATA_CLIENT] = {}
|
||||
|
||||
websession = aiohttp_client.async_get_clientsession(hass)
|
||||
|
||||
hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id] = Client(websession)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
"""Define various utilities for WWLLN tests."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.wwlln import CONF_WINDOW, DOMAIN
|
||||
from homeassistant.const import (
|
||||
CONF_LATITUDE, CONF_LONGITUDE, CONF_RADIUS, CONF_UNIT_SYSTEM)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_entry():
|
||||
"""Create a mock WWLLN config entry."""
|
||||
return MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_LATITUDE: 39.128712,
|
||||
CONF_LONGITUDE: -104.9812612,
|
||||
CONF_RADIUS: 25,
|
||||
CONF_UNIT_SYSTEM: 'metric',
|
||||
CONF_WINDOW: 3600
|
||||
},
|
||||
title='39.128712, -104.9812612')
|
|
@ -1,15 +1,16 @@
|
|||
"""Define tests for the WWLLN config flow."""
|
||||
from datetime import timedelta
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.wwlln import CONF_WINDOW, DOMAIN, config_flow
|
||||
from homeassistant.components.wwlln import (
|
||||
CONF_WINDOW, DATA_CLIENT, DOMAIN, async_setup_entry, config_flow)
|
||||
from homeassistant.const import (
|
||||
CONF_LATITUDE, CONF_LONGITUDE, CONF_RADIUS, CONF_UNIT_SYSTEM)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_duplicate_error(hass):
|
||||
async def test_duplicate_error(hass, config_entry):
|
||||
"""Test that errors are shown when duplicates are added."""
|
||||
conf = {
|
||||
CONF_LATITUDE: 39.128712,
|
||||
|
@ -17,7 +18,7 @@ async def test_duplicate_error(hass):
|
|||
CONF_RADIUS: 25,
|
||||
}
|
||||
|
||||
MockConfigEntry(domain=DOMAIN, data=conf).add_to_hass(hass)
|
||||
config_entry.add_to_hass(hass)
|
||||
flow = config_flow.WWLLNFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
|
@ -108,3 +109,15 @@ async def test_custom_window(hass):
|
|||
CONF_UNIT_SYSTEM: 'metric',
|
||||
CONF_WINDOW: 3600,
|
||||
}
|
||||
|
||||
|
||||
async def test_component_load_config_entry(hass, config_entry):
|
||||
"""Test that loading an existing config entry yields a client."""
|
||||
config_entry.add_to_hass(hass)
|
||||
with patch.object(
|
||||
hass.config_entries, 'async_forward_entry_setup') as forward_mock:
|
||||
assert await async_setup_entry(hass, config_entry)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert forward_mock.call_count == 1
|
||||
assert len(hass.data[DOMAIN][DATA_CLIENT]) == 1
|
||||
|
|
Loading…
Reference in New Issue