Use FlowResultType in Devolo Home Control tests (#74490)

* Use FlowResultType in devolo Home Control tests

* Add return types
This commit is contained in:
Guido Schmitz 2022-07-06 09:52:41 +02:00 committed by GitHub
parent 05416f56aa
commit 1b37d9cbc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,8 +3,10 @@ from unittest.mock import patch
import pytest
from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components.devolo_home_control.const import DEFAULT_MYDEVOLO, DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult, FlowResultType
from .const import (
DISCOVERY_INFO,
@ -15,28 +17,28 @@ from .const import (
from tests.common import MockConfigEntry
async def test_form(hass):
async def test_form(hass: HomeAssistant) -> None:
"""Test we get the form."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["step_id"] == "user"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["errors"] == {}
await _setup(hass, result)
@pytest.mark.credentials_invalid
async def test_form_invalid_credentials_user(hass):
async def test_form_invalid_credentials_user(hass: HomeAssistant) -> None:
"""Test if we get the error message on invalid credentials."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["step_id"] == "user"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["errors"] == {}
result = await hass.config_entries.flow.async_configure(
@ -47,7 +49,7 @@ async def test_form_invalid_credentials_user(hass):
assert result["errors"] == {"base": "invalid_auth"}
async def test_form_already_configured(hass):
async def test_form_already_configured(hass: HomeAssistant) -> None:
"""Test if we get the error message on already configured."""
with patch(
"homeassistant.components.devolo_home_control.Mydevolo.uuid",
@ -59,17 +61,17 @@ async def test_form_already_configured(hass):
context={"source": config_entries.SOURCE_USER},
data={"username": "test-username", "password": "test-password"},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
async def test_form_advanced_options(hass):
async def test_form_advanced_options(hass: HomeAssistant) -> None:
"""Test if we get the advanced options if user has enabled it."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["errors"] == {}
with patch(
@ -100,7 +102,7 @@ async def test_form_advanced_options(hass):
assert len(mock_setup_entry.mock_calls) == 1
async def test_form_zeroconf(hass):
async def test_form_zeroconf(hass: HomeAssistant) -> None:
"""Test that the zeroconf confirmation form is served."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
@ -109,13 +111,13 @@ async def test_form_zeroconf(hass):
)
assert result["step_id"] == "zeroconf_confirm"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
await _setup(hass, result)
@pytest.mark.credentials_invalid
async def test_form_invalid_credentials_zeroconf(hass):
async def test_form_invalid_credentials_zeroconf(hass: HomeAssistant) -> None:
"""Test if we get the error message on invalid credentials."""
result = await hass.config_entries.flow.async_init(
@ -125,7 +127,7 @@ async def test_form_invalid_credentials_zeroconf(hass):
)
assert result["step_id"] == "zeroconf_confirm"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
@ -135,7 +137,7 @@ async def test_form_invalid_credentials_zeroconf(hass):
assert result["errors"] == {"base": "invalid_auth"}
async def test_zeroconf_wrong_device(hass):
async def test_zeroconf_wrong_device(hass: HomeAssistant) -> None:
"""Test that the zeroconf ignores wrong devices."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
@ -144,7 +146,7 @@ async def test_zeroconf_wrong_device(hass):
)
assert result["reason"] == "Not a devolo Home Control gateway."
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
result = await hass.config_entries.flow.async_init(
DOMAIN,
@ -153,10 +155,10 @@ async def test_zeroconf_wrong_device(hass):
)
assert result["reason"] == "Not a devolo Home Control gateway."
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
async def test_form_reauth(hass):
async def test_form_reauth(hass: HomeAssistant) -> None:
"""Test that the reauth confirmation form is served."""
mock_config = MockConfigEntry(domain=DOMAIN, unique_id="123456", data={})
mock_config.add_to_hass(hass)
@ -174,7 +176,7 @@ async def test_form_reauth(hass):
)
assert result["step_id"] == "reauth_confirm"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
with patch(
"homeassistant.components.devolo_home_control.async_setup_entry",
@ -189,12 +191,12 @@ async def test_form_reauth(hass):
)
await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result2["type"] == FlowResultType.ABORT
assert len(mock_setup_entry.mock_calls) == 1
@pytest.mark.credentials_invalid
async def test_form_invalid_credentials_reauth(hass):
async def test_form_invalid_credentials_reauth(hass: HomeAssistant) -> None:
"""Test if we get the error message on invalid credentials."""
mock_config = MockConfigEntry(domain=DOMAIN, unique_id="123456", data={})
mock_config.add_to_hass(hass)
@ -219,7 +221,7 @@ async def test_form_invalid_credentials_reauth(hass):
assert result["errors"] == {"base": "invalid_auth"}
async def test_form_uuid_change_reauth(hass):
async def test_form_uuid_change_reauth(hass: HomeAssistant) -> None:
"""Test that the reauth confirmation form is served."""
mock_config = MockConfigEntry(domain=DOMAIN, unique_id="123456", data={})
mock_config.add_to_hass(hass)
@ -237,7 +239,7 @@ async def test_form_uuid_change_reauth(hass):
)
assert result["step_id"] == "reauth_confirm"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
with patch(
"homeassistant.components.devolo_home_control.async_setup_entry",
@ -252,11 +254,11 @@ async def test_form_uuid_change_reauth(hass):
)
await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["type"] == FlowResultType.FORM
assert result2["errors"] == {"base": "reauth_failed"}
async def _setup(hass, result):
async def _setup(hass: HomeAssistant, result: FlowResult) -> None:
"""Finish configuration steps."""
with patch(
"homeassistant.components.devolo_home_control.async_setup_entry",