Use flow result type constants more (#51122)

This commit is contained in:
Ville Skyttä
2021-05-29 14:09:13 +02:00
committed by GitHub
parent b6716ecebd
commit c2f5dcefa5
7 changed files with 25 additions and 21 deletions
@@ -8,6 +8,7 @@ import voluptuous as vol
from homeassistant import auth
from homeassistant.auth import auth_store
from homeassistant.auth.providers import trusted_networks as tn_auth
from homeassistant.data_entry_flow import RESULT_TYPE_ABORT, RESULT_TYPE_CREATE_ENTRY
@pytest.fixture
@@ -161,7 +162,7 @@ async def test_login_flow(manager, provider):
# not from trusted network
flow = await provider.async_login_flow({"ip_address": ip_address("127.0.0.1")})
step = await flow.async_step_init()
assert step["type"] == "abort"
assert step["type"] == RESULT_TYPE_ABORT
assert step["reason"] == "not_allowed"
# from trusted network, list users
@@ -176,7 +177,7 @@ async def test_login_flow(manager, provider):
# login with valid user
step = await flow.async_step_init({"user": user.id})
assert step["type"] == "create_entry"
assert step["type"] == RESULT_TYPE_CREATE_ENTRY
assert step["data"]["user"] == user.id
@@ -200,7 +201,7 @@ async def test_trusted_users_login(manager_with_user, provider_with_user):
{"ip_address": ip_address("127.0.0.1")}
)
step = await flow.async_step_init()
assert step["type"] == "abort"
assert step["type"] == RESULT_TYPE_ABORT
assert step["reason"] == "not_allowed"
# from trusted network, list users intersect trusted_users
@@ -284,7 +285,7 @@ async def test_trusted_group_login(manager_with_user, provider_with_user):
{"ip_address": ip_address("127.0.0.1")}
)
step = await flow.async_step_init()
assert step["type"] == "abort"
assert step["type"] == RESULT_TYPE_ABORT
assert step["reason"] == "not_allowed"
# from trusted network, list users intersect trusted_users
@@ -322,7 +323,7 @@ async def test_bypass_login_flow(manager_bypass_login, provider_bypass_login):
{"ip_address": ip_address("127.0.0.1")}
)
step = await flow.async_step_init()
assert step["type"] == "abort"
assert step["type"] == RESULT_TYPE_ABORT
assert step["reason"] == "not_allowed"
# from trusted network, only one available user, bypass the login flow
@@ -330,7 +331,7 @@ async def test_bypass_login_flow(manager_bypass_login, provider_bypass_login):
{"ip_address": ip_address("192.168.0.1")}
)
step = await flow.async_step_init()
assert step["type"] == "create_entry"
assert step["type"] == RESULT_TYPE_CREATE_ENTRY
assert step["data"]["user"] == owner.id
user = await manager_bypass_login.async_create_user("test-user")
+6 -5
View File
@@ -9,6 +9,7 @@ import pytest
from homeassistant import config_entries, data_entry_flow, loader
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import CoreState, callback
from homeassistant.data_entry_flow import RESULT_TYPE_ABORT
from homeassistant.exceptions import (
ConfigEntryAuthFailed,
ConfigEntryNotReady,
@@ -1612,7 +1613,7 @@ async def test_unique_id_update_existing_entry_without_reload(hass, manager):
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert entry.data["host"] == "1.1.1.1"
assert entry.data["additional"] == "data"
@@ -1657,7 +1658,7 @@ async def test_unique_id_update_existing_entry_with_reload(hass, manager):
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert entry.data["host"] == "1.1.1.1"
assert entry.data["additional"] == "data"
@@ -1674,7 +1675,7 @@ async def test_unique_id_update_existing_entry_with_reload(hass, manager):
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert entry.data["host"] == "2.2.2.2"
assert entry.data["additional"] == "data"
@@ -1717,7 +1718,7 @@ async def test_unique_id_not_update_existing_entry(hass, manager):
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert entry.data["host"] == "0.0.0.0"
assert entry.data["additional"] == "data"
@@ -2861,5 +2862,5 @@ async def test__async_abort_entries_match(hass, manager, matchers, reason):
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == reason
+2 -2
View File
@@ -121,7 +121,7 @@ async def test_show_form(manager):
)
form = await manager.async_init("test")
assert form["type"] == "form"
assert form["type"] == data_entry_flow.RESULT_TYPE_FORM
assert form["data_schema"] is schema
assert form["errors"] == {"username": "Should be unique."}
@@ -369,7 +369,7 @@ async def test_abort_flow_exception(manager):
raise data_entry_flow.AbortFlow("mock-reason", {"placeholder": "yo"})
form = await manager.async_init("test")
assert form["type"] == "abort"
assert form["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert form["reason"] == "mock-reason"
assert form["description_placeholders"] == {"placeholder": "yo"}