mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Fixed issue when tests (should) fail in Smarla (#146102)
* Fixed issue when tests (should) fail * Use usefixture decorator * Throw ConfigEntryError instead of AuthFailed
This commit is contained in:
parent
a296324c30
commit
d4b548b169
@ -5,7 +5,7 @@ from pysmarlaapi import Connection, Federwiege
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryError
|
||||||
|
|
||||||
from .const import HOST, PLATFORMS
|
from .const import HOST, PLATFORMS
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: FederwiegeConfigEntry) -
|
|||||||
|
|
||||||
# Check if token still has access
|
# Check if token still has access
|
||||||
if not await connection.refresh_token():
|
if not await connection.refresh_token():
|
||||||
raise ConfigEntryAuthFailed("Invalid authentication")
|
raise ConfigEntryError("Invalid authentication")
|
||||||
|
|
||||||
federwiege = Federwiege(hass.loop, connection)
|
federwiege = Federwiege(hass.loop, connection)
|
||||||
federwiege.register()
|
federwiege.register()
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.smarla.const import DOMAIN
|
from homeassistant.components.smarla.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -12,9 +14,8 @@ from .const import MOCK_SERIAL_NUMBER, MOCK_USER_INPUT
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_config_flow(
|
@pytest.mark.usefixtures("mock_setup_entry", "mock_connection")
|
||||||
hass: HomeAssistant, mock_setup_entry, mock_connection: MagicMock
|
async def test_config_flow(hass: HomeAssistant) -> None:
|
||||||
) -> None:
|
|
||||||
"""Test creating a config entry."""
|
"""Test creating a config entry."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -35,9 +36,8 @@ async def test_config_flow(
|
|||||||
assert result["result"].unique_id == MOCK_SERIAL_NUMBER
|
assert result["result"].unique_id == MOCK_SERIAL_NUMBER
|
||||||
|
|
||||||
|
|
||||||
async def test_malformed_token(
|
@pytest.mark.usefixtures("mock_setup_entry", "mock_connection")
|
||||||
hass: HomeAssistant, mock_setup_entry, mock_connection: MagicMock
|
async def test_malformed_token(hass: HomeAssistant) -> None:
|
||||||
) -> None:
|
|
||||||
"""Test we show user form on malformed token input."""
|
"""Test we show user form on malformed token input."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.smarla.config_flow.Connection", side_effect=ValueError
|
"homeassistant.components.smarla.config_flow.Connection", side_effect=ValueError
|
||||||
@ -60,9 +60,8 @@ async def test_malformed_token(
|
|||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_auth(
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
hass: HomeAssistant, mock_setup_entry, mock_connection: MagicMock
|
async def test_invalid_auth(hass: HomeAssistant, mock_connection: MagicMock) -> None:
|
||||||
) -> None:
|
|
||||||
"""Test we show user form on invalid auth."""
|
"""Test we show user form on invalid auth."""
|
||||||
with patch.object(
|
with patch.object(
|
||||||
mock_connection, "refresh_token", new=AsyncMock(return_value=False)
|
mock_connection, "refresh_token", new=AsyncMock(return_value=False)
|
||||||
@ -85,8 +84,9 @@ async def test_invalid_auth(
|
|||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry", "mock_connection")
|
||||||
async def test_device_exists_abort(
|
async def test_device_exists_abort(
|
||||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_connection: MagicMock
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we abort config flow if Smarla device already configured."""
|
"""Test we abort config flow if Smarla device already configured."""
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
@ -10,6 +12,7 @@ from . import setup_integration
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_federwiege")
|
||||||
async def test_init_invalid_auth(
|
async def test_init_invalid_auth(
|
||||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_connection: MagicMock
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_connection: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user