Add unique ID to Airly config entries (#30681)
* Add unique ID to Airly config entries * Update tests * Update tests * Fix typo * Remove unnecesary and undo changes in first test * Suggested change
This commit is contained in:
1 parent
ce13fb8d73
commit
15645ab0c9
6 files changed
+43
-43
No files matched your search
@@ -5,8 +5,8 @@ from airly.exceptions import AirlyError
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.airly import config_flow
|
||||
from homeassistant.components.airly.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
@@ -21,13 +21,12 @@ CONFIG = {
|
||||
|
||||
async def test_show_form(hass):
|
||||
"""Test that the form is served with no input."""
|
||||
flow = config_flow.AirlyFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
result = await flow.async_step_user(user_input=None)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["step_id"] == SOURCE_USER
|
||||
|
||||
|
||||
async def test_invalid_api_key(hass):
|
||||
@@ -36,10 +35,10 @@ async def test_invalid_api_key(hass):
|
||||
"airly._private._RequestsHandler.get",
|
||||
side_effect=AirlyError(403, {"message": "Invalid authentication credentials"}),
|
||||
):
|
||||
flow = config_flow.AirlyFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
result = await flow.async_step_user(user_input=CONFIG)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
|
||||
)
|
||||
|
||||
assert result["errors"] == {"base": "auth"}
|
||||
|
||||
@@ -50,10 +49,10 @@ async def test_invalid_location(hass):
|
||||
"airly._private._RequestsHandler.get",
|
||||
return_value=json.loads(load_fixture("airly_no_station.json")),
|
||||
):
|
||||
flow = config_flow.AirlyFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
result = await flow.async_step_user(user_input=CONFIG)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
|
||||
)
|
||||
|
||||
assert result["errors"] == {"base": "wrong_location"}
|
||||
|
||||
@@ -65,13 +64,16 @@ async def test_duplicate_error(hass):
|
||||
"airly._private._RequestsHandler.get",
|
||||
return_value=json.loads(load_fixture("airly_valid_station.json")),
|
||||
):
|
||||
MockConfigEntry(domain=DOMAIN, data=CONFIG).add_to_hass(hass)
|
||||
flow = config_flow.AirlyFlowHandler()
|
||||
flow.hass = hass
|
||||
MockConfigEntry(domain=DOMAIN, unique_id="123-456", data=CONFIG).add_to_hass(
|
||||
hass
|
||||
)
|
||||
|
||||
result = await flow.async_step_user(user_input=CONFIG)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
|
||||
)
|
||||
|
||||
assert result["errors"] == {CONF_NAME: "name_exists"}
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_create_entry(hass):
|
||||
@@ -81,10 +83,10 @@ async def test_create_entry(hass):
|
||||
"airly._private._RequestsHandler.get",
|
||||
return_value=json.loads(load_fixture("airly_valid_station.json")),
|
||||
):
|
||||
flow = config_flow.AirlyFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
result = await flow.async_step_user(user_input=CONFIG)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == CONFIG[CONF_NAME]
|
||||
|
||||
Reference in new issue
Block a user