mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Improve type hints in logi_circle tests (#121518)
This commit is contained in:
parent
f7825eb5b1
commit
10ee554f1f
@ -1,8 +1,10 @@
|
|||||||
"""Tests for Logi Circle config flow."""
|
"""Tests for Logi Circle config flow."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from collections.abc import Generator
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from unittest.mock import AsyncMock, Mock, patch
|
from typing import Any
|
||||||
|
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -24,13 +26,13 @@ from tests.common import MockConfigEntry
|
|||||||
class MockRequest:
|
class MockRequest:
|
||||||
"""Mock request passed to HomeAssistantView."""
|
"""Mock request passed to HomeAssistantView."""
|
||||||
|
|
||||||
def __init__(self, hass, query):
|
def __init__(self, hass: HomeAssistant, query: dict[str, Any]) -> None:
|
||||||
"""Init request object."""
|
"""Init request object."""
|
||||||
self.app = {KEY_HASS: hass}
|
self.app = {KEY_HASS: hass}
|
||||||
self.query = query
|
self.query = query
|
||||||
|
|
||||||
|
|
||||||
def init_config_flow(hass):
|
def init_config_flow(hass: HomeAssistant) -> config_flow.LogiCircleFlowHandler:
|
||||||
"""Init a configuration flow."""
|
"""Init a configuration flow."""
|
||||||
config_flow.register_flow_implementation(
|
config_flow.register_flow_implementation(
|
||||||
hass,
|
hass,
|
||||||
@ -48,7 +50,7 @@ def init_config_flow(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_logi_circle():
|
def mock_logi_circle() -> Generator[MagicMock]:
|
||||||
"""Mock logi_circle."""
|
"""Mock logi_circle."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.logi_circle.config_flow.LogiCircle"
|
"homeassistant.components.logi_circle.config_flow.LogiCircle"
|
||||||
@ -63,7 +65,8 @@ def mock_logi_circle():
|
|||||||
yield LogiCircle
|
yield LogiCircle
|
||||||
|
|
||||||
|
|
||||||
async def test_step_import(hass: HomeAssistant, mock_logi_circle) -> None:
|
@pytest.mark.usefixtures("mock_logi_circle")
|
||||||
|
async def test_step_import(hass: HomeAssistant) -> None:
|
||||||
"""Test that we trigger import when configuring with client."""
|
"""Test that we trigger import when configuring with client."""
|
||||||
flow = init_config_flow(hass)
|
flow = init_config_flow(hass)
|
||||||
|
|
||||||
@ -72,7 +75,8 @@ async def test_step_import(hass: HomeAssistant, mock_logi_circle) -> None:
|
|||||||
assert result["step_id"] == "auth"
|
assert result["step_id"] == "auth"
|
||||||
|
|
||||||
|
|
||||||
async def test_full_flow_implementation(hass: HomeAssistant, mock_logi_circle) -> None:
|
@pytest.mark.usefixtures("mock_logi_circle")
|
||||||
|
async def test_full_flow_implementation(hass: HomeAssistant) -> None:
|
||||||
"""Test registering an implementation and finishing flow works."""
|
"""Test registering an implementation and finishing flow works."""
|
||||||
config_flow.register_flow_implementation(
|
config_flow.register_flow_implementation(
|
||||||
hass,
|
hass,
|
||||||
@ -154,7 +158,10 @@ async def test_abort_if_already_setup(hass: HomeAssistant) -> None:
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_abort_if_authorize_fails(
|
async def test_abort_if_authorize_fails(
|
||||||
hass: HomeAssistant, mock_logi_circle, side_effect, error
|
hass: HomeAssistant,
|
||||||
|
mock_logi_circle: MagicMock,
|
||||||
|
side_effect: type[Exception],
|
||||||
|
error: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we abort if authorizing fails."""
|
"""Test we abort if authorizing fails."""
|
||||||
flow = init_config_flow(hass)
|
flow = init_config_flow(hass)
|
||||||
@ -177,7 +184,8 @@ async def test_not_pick_implementation_if_only_one(hass: HomeAssistant) -> None:
|
|||||||
assert result["step_id"] == "auth"
|
assert result["step_id"] == "auth"
|
||||||
|
|
||||||
|
|
||||||
async def test_gen_auth_url(hass: HomeAssistant, mock_logi_circle) -> None:
|
@pytest.mark.usefixtures("mock_logi_circle")
|
||||||
|
async def test_gen_auth_url(hass: HomeAssistant) -> None:
|
||||||
"""Test generating authorize URL from Logi Circle API."""
|
"""Test generating authorize URL from Logi Circle API."""
|
||||||
config_flow.register_flow_implementation(
|
config_flow.register_flow_implementation(
|
||||||
hass,
|
hass,
|
||||||
@ -206,7 +214,7 @@ async def test_callback_view_rejects_missing_code(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def test_callback_view_accepts_code(
|
async def test_callback_view_accepts_code(
|
||||||
hass: HomeAssistant, mock_logi_circle
|
hass: HomeAssistant, mock_logi_circle: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the auth callback view handles requests with auth code."""
|
"""Test the auth callback view handles requests with auth code."""
|
||||||
init_config_flow(hass)
|
init_config_flow(hass)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
"""Tests for the Logi Circle integration."""
|
"""Tests for the Logi Circle integration."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import AsyncMock, Mock, patch
|
from collections.abc import Generator
|
||||||
|
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -14,14 +15,14 @@ from tests.common import MockConfigEntry
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="disable_platforms")
|
@pytest.fixture(name="disable_platforms")
|
||||||
async def disable_platforms_fixture(hass):
|
def disable_platforms_fixture() -> Generator[None]:
|
||||||
"""Disable logi_circle platforms."""
|
"""Disable logi_circle platforms."""
|
||||||
with patch("homeassistant.components.logi_circle.PLATFORMS", []):
|
with patch("homeassistant.components.logi_circle.PLATFORMS", []):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_logi_circle():
|
def mock_logi_circle() -> Generator[MagicMock]:
|
||||||
"""Mock logi_circle."""
|
"""Mock logi_circle."""
|
||||||
|
|
||||||
auth_provider_mock = Mock()
|
auth_provider_mock = Mock()
|
||||||
@ -37,11 +38,10 @@ def mock_logi_circle():
|
|||||||
yield LogiCircle
|
yield LogiCircle
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("disable_platforms", "mock_logi_circle")
|
||||||
async def test_repair_issue(
|
async def test_repair_issue(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
issue_registry: ir.IssueRegistry,
|
issue_registry: ir.IssueRegistry,
|
||||||
disable_platforms,
|
|
||||||
mock_logi_circle,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the LogiCircle configuration entry loading/unloading handles the repair."""
|
"""Test the LogiCircle configuration entry loading/unloading handles the repair."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user