mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07: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.const import CONF_ACCESS_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.exceptions import ConfigEntryError
|
||||
|
||||
from .const import HOST, PLATFORMS
|
||||
|
||||
@ -18,7 +18,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: FederwiegeConfigEntry) -
|
||||
|
||||
# Check if token still has access
|
||||
if not await connection.refresh_token():
|
||||
raise ConfigEntryAuthFailed("Invalid authentication")
|
||||
raise ConfigEntryError("Invalid authentication")
|
||||
|
||||
federwiege = Federwiege(hass.loop, connection)
|
||||
federwiege.register()
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.smarla.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -12,9 +14,8 @@ from .const import MOCK_SERIAL_NUMBER, MOCK_USER_INPUT
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_config_flow(
|
||||
hass: HomeAssistant, mock_setup_entry, mock_connection: MagicMock
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_setup_entry", "mock_connection")
|
||||
async def test_config_flow(hass: HomeAssistant) -> None:
|
||||
"""Test creating a config entry."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
@ -35,9 +36,8 @@ async def test_config_flow(
|
||||
assert result["result"].unique_id == MOCK_SERIAL_NUMBER
|
||||
|
||||
|
||||
async def test_malformed_token(
|
||||
hass: HomeAssistant, mock_setup_entry, mock_connection: MagicMock
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_setup_entry", "mock_connection")
|
||||
async def test_malformed_token(hass: HomeAssistant) -> None:
|
||||
"""Test we show user form on malformed token input."""
|
||||
with patch(
|
||||
"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
|
||||
|
||||
|
||||
async def test_invalid_auth(
|
||||
hass: HomeAssistant, mock_setup_entry, mock_connection: MagicMock
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_invalid_auth(hass: HomeAssistant, mock_connection: MagicMock) -> None:
|
||||
"""Test we show user form on invalid auth."""
|
||||
with patch.object(
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_setup_entry", "mock_connection")
|
||||
async def test_device_exists_abort(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_connection: MagicMock
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test we abort config flow if Smarla device already configured."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@ -10,6 +12,7 @@ from . import setup_integration
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_federwiege")
|
||||
async def test_init_invalid_auth(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_connection: MagicMock
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user