mirror of
https://github.com/home-assistant/core.git
synced 2025-08-01 01:28:24 +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:
|
||||
"""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
|
||||
if not await connection.refresh_token():
|
||||
|
@ -1,8 +1,9 @@
|
||||
"""Configuration for Sentry tests."""
|
||||
"""Configuration for smarla tests."""
|
||||
|
||||
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
|
||||
import pytest
|
||||
@ -27,7 +28,16 @@ def mock_config_entry() -> MockConfigEntry:
|
||||
|
||||
|
||||
@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."""
|
||||
with (
|
||||
patch(
|
||||
|
@ -12,7 +12,9 @@ from . import MOCK_SERIAL_NUMBER, MOCK_USER_INPUT
|
||||
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."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
@ -33,7 +35,9 @@ async def test_config_flow(hass: HomeAssistant, mock_connection) -> None:
|
||||
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."""
|
||||
with patch(
|
||||
"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
|
||||
|
||||
|
||||
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."""
|
||||
with patch.object(
|
||||
mock_connection, "refresh_token", new=AsyncMock(return_value=False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user