mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 10:08:23 +00:00
Fix leaking tests
This commit is contained in:
parent
acc32eea3e
commit
00ccaf1ff9
@ -14,7 +14,7 @@ type FederwiegeConfigEntry = ConfigEntry[Federwiege]
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: FederwiegeConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: FederwiegeConfigEntry) -> bool:
|
||||||
"""Set up this integration using UI."""
|
"""Set up this integration using UI."""
|
||||||
connection = Connection(HOST, token_b64=entry.data.get(CONF_ACCESS_TOKEN))
|
connection = Connection(HOST, token_b64=entry.data[CONF_ACCESS_TOKEN])
|
||||||
|
|
||||||
# Check if token still has access
|
# Check if token still has access
|
||||||
if not await connection.refresh_token():
|
if not await connection.refresh_token():
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
"""Configuration for Sentry tests."""
|
"""Configuration for smarla tests."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from unittest.mock import patch
|
from collections.abc import Generator
|
||||||
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
from pysmarlaapi.classes import AuthToken
|
from pysmarlaapi.classes import AuthToken
|
||||||
import pytest
|
import pytest
|
||||||
@ -27,7 +28,16 @@ def mock_config_entry() -> MockConfigEntry:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_connection():
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
||||||
|
"""Override async_setup_entry."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.smarla.async_setup_entry", return_value=True
|
||||||
|
) as mock_setup_entry:
|
||||||
|
yield mock_setup_entry
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_connection() -> Generator[MagicMock]:
|
||||||
"""Patch Connection object."""
|
"""Patch Connection object."""
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
|
@ -12,7 +12,9 @@ from . import MOCK_SERIAL_NUMBER, MOCK_USER_INPUT
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_config_flow(hass: HomeAssistant, mock_connection) -> None:
|
async def test_config_flow(
|
||||||
|
hass: HomeAssistant, mock_setup_entry, mock_connection
|
||||||
|
) -> 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,
|
||||||
@ -33,7 +35,9 @@ async def test_config_flow(hass: HomeAssistant, mock_connection) -> None:
|
|||||||
assert result["result"].unique_id == MOCK_SERIAL_NUMBER
|
assert result["result"].unique_id == MOCK_SERIAL_NUMBER
|
||||||
|
|
||||||
|
|
||||||
async def test_malformed_token(hass: HomeAssistant, mock_connection) -> None:
|
async def test_malformed_token(
|
||||||
|
hass: HomeAssistant, mock_setup_entry, mock_connection
|
||||||
|
) -> 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
|
||||||
@ -56,7 +60,9 @@ async def test_malformed_token(hass: HomeAssistant, mock_connection) -> None:
|
|||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_auth(hass: HomeAssistant, mock_connection) -> None:
|
async def test_invalid_auth(
|
||||||
|
hass: HomeAssistant, mock_setup_entry, mock_connection
|
||||||
|
) -> 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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user