Perform some more AirVisual test cleanup (#64470)
* Perform some more AirVisual test cleanup * Smarter startup patch * Simplify
This commit is contained in:
parent
ee215fb589
commit
4d72e41a3e
2 changed files with 35 additions and 49 deletions
|
@ -3,30 +3,50 @@ from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.airvisual.const import DOMAIN
|
from homeassistant.components.airvisual.const import (
|
||||||
from homeassistant.const import CONF_SHOW_ON_MAP
|
CONF_INTEGRATION_TYPE,
|
||||||
|
DOMAIN,
|
||||||
|
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||||
|
)
|
||||||
|
from homeassistant.const import (
|
||||||
|
CONF_API_KEY,
|
||||||
|
CONF_LATITUDE,
|
||||||
|
CONF_LONGITUDE,
|
||||||
|
CONF_SHOW_ON_MAP,
|
||||||
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="config_entry")
|
@pytest.fixture(name="config_entry")
|
||||||
def config_entry_fixture(hass, config, unique_id):
|
def config_entry_fixture(hass, config, config_entry_version, unique_id):
|
||||||
"""Define a config entry fixture."""
|
"""Define a config entry fixture."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
unique_id=unique_id,
|
unique_id=unique_id,
|
||||||
data=config,
|
data={CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_GEOGRAPHY_COORDS, **config},
|
||||||
options={CONF_SHOW_ON_MAP: True},
|
options={CONF_SHOW_ON_MAP: True},
|
||||||
|
version=config_entry_version,
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="config_entry_version")
|
||||||
|
def config_entry_version_fixture():
|
||||||
|
"""Define a config entry version fixture."""
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="config")
|
@pytest.fixture(name="config")
|
||||||
def config_fixture(hass):
|
def config_fixture(hass):
|
||||||
"""Define a config entry data fixture."""
|
"""Define a config entry data fixture."""
|
||||||
return {}
|
return {
|
||||||
|
CONF_API_KEY: "abcde12345",
|
||||||
|
CONF_LATITUDE: 51.528308,
|
||||||
|
CONF_LONGITUDE: -0.3817765,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="setup_airvisual")
|
@pytest.fixture(name="setup_airvisual")
|
||||||
|
@ -38,10 +58,10 @@ async def setup_airvisual_fixture(hass, config):
|
||||||
"pyairvisual.node.NodeSamba.async_get_latest_measurements"
|
"pyairvisual.node.NodeSamba.async_get_latest_measurements"
|
||||||
), patch(
|
), patch(
|
||||||
"pyairvisual.node.NodeSamba.async_disconnect"
|
"pyairvisual.node.NodeSamba.async_disconnect"
|
||||||
), patch.object(
|
), patch(
|
||||||
hass.config_entries, "async_forward_entry_setup"
|
"homeassistant.components.airvisual.PLATFORMS", []
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: config})
|
assert await async_setup_component(hass, DOMAIN, config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ async def test_errors(hass, data, exc, errors, integration_type):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"config,unique_id",
|
"config,config_entry_version,unique_id",
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
|
@ -145,6 +145,7 @@ async def test_errors(hass, data, exc, errors, integration_type):
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
1,
|
||||||
"abcde12345",
|
"abcde12345",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -175,17 +176,8 @@ async def test_migration(hass, config, config_entry, setup_airvisual, unique_id)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"config,unique_id",
|
"unique_id",
|
||||||
[
|
[("51.528308, -0.3817765",)],
|
||||||
(
|
|
||||||
{
|
|
||||||
CONF_API_KEY: "abcde12345",
|
|
||||||
CONF_LATITUDE: 51.528308,
|
|
||||||
CONF_LONGITUDE: -0.3817765,
|
|
||||||
},
|
|
||||||
"51.528308, -0.3817765",
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
async def test_options_flow(hass, config_entry):
|
async def test_options_flow(hass, config_entry):
|
||||||
"""Test config flow options."""
|
"""Test config flow options."""
|
||||||
|
@ -206,18 +198,6 @@ async def test_options_flow(hass, config_entry):
|
||||||
assert config_entry.options == {CONF_SHOW_ON_MAP: False}
|
assert config_entry.options == {CONF_SHOW_ON_MAP: False}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"config",
|
|
||||||
[
|
|
||||||
(
|
|
||||||
{
|
|
||||||
CONF_API_KEY: "abcde12345",
|
|
||||||
CONF_LATITUDE: 51.528308,
|
|
||||||
CONF_LONGITUDE: -0.3817765,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_step_geography_by_coords(hass, config, setup_airvisual):
|
async def test_step_geography_by_coords(hass, config, setup_airvisual):
|
||||||
"""Test setting up a geography entry by latitude/longitude."""
|
"""Test setting up a geography entry by latitude/longitude."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -302,20 +282,6 @@ async def test_step_node_pro(hass, config, setup_airvisual):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"config,unique_id",
|
|
||||||
[
|
|
||||||
(
|
|
||||||
{
|
|
||||||
CONF_API_KEY: "abcde12345",
|
|
||||||
CONF_LATITUDE: 51.528308,
|
|
||||||
CONF_LONGITUDE: -0.3817765,
|
|
||||||
CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
|
||||||
},
|
|
||||||
"51.528308, -0.3817765",
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_step_reauth(hass, config_entry):
|
async def test_step_reauth(hass, config_entry):
|
||||||
"""Test that the reauth step works."""
|
"""Test that the reauth step works."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -329,9 +295,9 @@ async def test_step_reauth(hass, config_entry):
|
||||||
|
|
||||||
new_api_key = "defgh67890"
|
new_api_key = "defgh67890"
|
||||||
|
|
||||||
with patch(
|
with patch("homeassistant.config_entries.ConfigEntries.async_reload"), patch(
|
||||||
"homeassistant.components.airvisual.async_setup_entry", return_value=True
|
"pyairvisual.air_quality.AirQuality.nearest_city"
|
||||||
), patch("pyairvisual.air_quality.AirQuality.nearest_city", return_value=True):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input={CONF_API_KEY: new_api_key}
|
result["flow_id"], user_input={CONF_API_KEY: new_api_key}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue