mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Clean somfy config flow tests (#50461)
This commit is contained in:
parent
4e24640ff7
commit
f71eb4d34d
@ -934,7 +934,12 @@ omit =
|
|||||||
homeassistant/components/soma/__init__.py
|
homeassistant/components/soma/__init__.py
|
||||||
homeassistant/components/soma/cover.py
|
homeassistant/components/soma/cover.py
|
||||||
homeassistant/components/soma/sensor.py
|
homeassistant/components/soma/sensor.py
|
||||||
homeassistant/components/somfy/*
|
homeassistant/components/somfy/__init__.py
|
||||||
|
homeassistant/components/somfy/api.py
|
||||||
|
homeassistant/components/somfy/climate.py
|
||||||
|
homeassistant/components/somfy/cover.py
|
||||||
|
homeassistant/components/somfy/sensor.py
|
||||||
|
homeassistant/components/somfy/switch.py
|
||||||
homeassistant/components/somfy_mylink/__init__.py
|
homeassistant/components/somfy_mylink/__init__.py
|
||||||
homeassistant/components/somfy_mylink/cover.py
|
homeassistant/components/somfy_mylink/cover.py
|
||||||
homeassistant/components/sonos/*
|
homeassistant/components/sonos/*
|
||||||
|
@ -51,7 +51,6 @@ ALLOWED_IGNORE_VIOLATIONS = {
|
|||||||
("sense", "config_flow.py"),
|
("sense", "config_flow.py"),
|
||||||
("sms", "config_flow.py"),
|
("sms", "config_flow.py"),
|
||||||
("solarlog", "config_flow.py"),
|
("solarlog", "config_flow.py"),
|
||||||
("somfy", "config_flow.py"),
|
|
||||||
("sonos", "config_flow.py"),
|
("sonos", "config_flow.py"),
|
||||||
("speedtestdotnet", "config_flow.py"),
|
("speedtestdotnet", "config_flow.py"),
|
||||||
("spider", "config_flow.py"),
|
("spider", "config_flow.py"),
|
||||||
|
@ -2,10 +2,8 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow, setup
|
from homeassistant import config_entries, data_entry_flow, setup
|
||||||
from homeassistant.components.somfy import DOMAIN, config_flow
|
from homeassistant.components.somfy import DOMAIN
|
||||||
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
|
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
|
||||||
@ -15,39 +13,22 @@ CLIENT_ID_VALUE = "1234"
|
|||||||
CLIENT_SECRET_VALUE = "5678"
|
CLIENT_SECRET_VALUE = "5678"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
async def mock_impl(hass):
|
|
||||||
"""Mock implementation."""
|
|
||||||
await setup.async_setup_component(hass, "http", {})
|
|
||||||
|
|
||||||
impl = config_entry_oauth2_flow.LocalOAuth2Implementation(
|
|
||||||
hass,
|
|
||||||
DOMAIN,
|
|
||||||
CLIENT_ID_VALUE,
|
|
||||||
CLIENT_SECRET_VALUE,
|
|
||||||
"https://accounts.somfy.com/oauth/oauth/v2/auth",
|
|
||||||
"https://accounts.somfy.com/oauth/oauth/v2/token",
|
|
||||||
)
|
|
||||||
config_flow.SomfyFlowHandler.async_register_implementation(hass, impl)
|
|
||||||
return impl
|
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_no_configuration(hass):
|
async def test_abort_if_no_configuration(hass):
|
||||||
"""Check flow abort when no configuration."""
|
"""Check flow abort when no configuration."""
|
||||||
flow = config_flow.SomfyFlowHandler()
|
result = await hass.config_entries.flow.async_init(
|
||||||
flow.hass = hass
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
result = await flow.async_step_user()
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "missing_configuration"
|
assert result["reason"] == "missing_configuration"
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_existing_entry(hass):
|
async def test_abort_if_existing_entry(hass):
|
||||||
"""Check flow abort when an entry already exist."""
|
"""Check flow abort when an entry already exist."""
|
||||||
flow = config_flow.SomfyFlowHandler()
|
|
||||||
flow.hass = hass
|
|
||||||
MockConfigEntry(domain=DOMAIN).add_to_hass(hass)
|
MockConfigEntry(domain=DOMAIN).add_to_hass(hass)
|
||||||
|
|
||||||
result = await flow.async_step_user()
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "single_instance_allowed"
|
assert result["reason"] == "single_instance_allowed"
|
||||||
|
|
||||||
@ -63,8 +44,7 @@ async def test_full_flow(
|
|||||||
DOMAIN: {
|
DOMAIN: {
|
||||||
CONF_CLIENT_ID: CLIENT_ID_VALUE,
|
CONF_CLIENT_ID: CLIENT_ID_VALUE,
|
||||||
CONF_CLIENT_SECRET: CLIENT_SECRET_VALUE,
|
CONF_CLIENT_SECRET: CLIENT_SECRET_VALUE,
|
||||||
},
|
}
|
||||||
"http": {"base_url": "https://example.com"},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -123,17 +103,27 @@ async def test_full_flow(
|
|||||||
assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED
|
assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_authorization_timeout(
|
async def test_abort_if_authorization_timeout(hass, current_request_with_host):
|
||||||
hass, mock_impl, current_request_with_host
|
|
||||||
):
|
|
||||||
"""Check Somfy authorization timeout."""
|
"""Check Somfy authorization timeout."""
|
||||||
flow = config_flow.SomfyFlowHandler()
|
assert await setup.async_setup_component(
|
||||||
flow.hass = hass
|
hass,
|
||||||
|
DOMAIN,
|
||||||
|
{
|
||||||
|
DOMAIN: {
|
||||||
|
CONF_CLIENT_ID: CLIENT_ID_VALUE,
|
||||||
|
CONF_CLIENT_SECRET: CLIENT_SECRET_VALUE,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
with patch.object(
|
with patch(
|
||||||
mock_impl, "async_generate_authorize_url", side_effect=asyncio.TimeoutError
|
"homeassistant.components.somfy.config_entry_oauth2_flow."
|
||||||
|
"LocalOAuth2Implementation.async_generate_authorize_url",
|
||||||
|
side_effect=asyncio.TimeoutError,
|
||||||
):
|
):
|
||||||
result = await flow.async_step_user()
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "authorize_url_timeout"
|
assert result["reason"] == "authorize_url_timeout"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user