mirror of
https://github.com/home-assistant/core.git
synced 2025-04-22 16:27:56 +00:00
Add missing mock in overkiz config flow tests (#88899)
This commit is contained in:
parent
1c4aa26ab6
commit
7b5c978b95
14
tests/components/overkiz/conftest.py
Normal file
14
tests/components/overkiz/conftest.py
Normal file
@ -0,0 +1,14 @@
|
||||
"""Configuration for overkiz tests."""
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.overkiz.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
yield mock_setup_entry
|
@ -1,7 +1,7 @@
|
||||
"""Tests for Overkiz (by Somfy) config flow."""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from aiohttp import ClientError
|
||||
from pyoverkiz.exceptions import (
|
||||
@ -21,6 +21,8 @@ from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
TEST_EMAIL = "test@testdomain.com"
|
||||
TEST_EMAIL2 = "test@testdomain.nl"
|
||||
TEST_PASSWORD = "test-password"
|
||||
@ -49,7 +51,7 @@ FAKE_ZERO_CONF_INFO = ZeroconfServiceInfo(
|
||||
)
|
||||
|
||||
|
||||
async def test_form(hass: HomeAssistant) -> None:
|
||||
async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
||||
"""Test we get the form."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
@ -60,9 +62,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||
|
||||
with patch("pyoverkiz.client.OverkizClient.login", return_value=True), patch(
|
||||
"pyoverkiz.client.OverkizClient.get_gateways", return_value=None
|
||||
), patch(
|
||||
"homeassistant.components.overkiz.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": TEST_EMAIL, "password": TEST_PASSWORD, "hub": TEST_HUB},
|
||||
@ -157,7 +157,7 @@ async def test_abort_on_duplicate_entry(hass: HomeAssistant) -> None:
|
||||
with patch("pyoverkiz.client.OverkizClient.login", return_value=True), patch(
|
||||
"pyoverkiz.client.OverkizClient.get_gateways",
|
||||
return_value=MOCK_GATEWAY_RESPONSE,
|
||||
), patch("homeassistant.components.overkiz.async_setup_entry", return_value=True):
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": TEST_EMAIL, "password": TEST_PASSWORD},
|
||||
@ -182,7 +182,7 @@ async def test_allow_multiple_unique_entries(hass: HomeAssistant) -> None:
|
||||
with patch("pyoverkiz.client.OverkizClient.login", return_value=True), patch(
|
||||
"pyoverkiz.client.OverkizClient.get_gateways",
|
||||
return_value=MOCK_GATEWAY_RESPONSE,
|
||||
), patch("homeassistant.components.overkiz.async_setup_entry", return_value=True):
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": TEST_EMAIL, "password": TEST_PASSWORD, "hub": TEST_HUB},
|
||||
@ -197,7 +197,7 @@ async def test_allow_multiple_unique_entries(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_dhcp_flow(hass: HomeAssistant) -> None:
|
||||
async def test_dhcp_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
||||
"""Test that DHCP discovery for new bridge works."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
@ -214,9 +214,7 @@ async def test_dhcp_flow(hass: HomeAssistant) -> None:
|
||||
|
||||
with patch("pyoverkiz.client.OverkizClient.login", return_value=True), patch(
|
||||
"pyoverkiz.client.OverkizClient.get_gateways", return_value=None
|
||||
), patch(
|
||||
"homeassistant.components.overkiz.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": TEST_EMAIL, "password": TEST_PASSWORD, "hub": TEST_HUB},
|
||||
@ -256,7 +254,7 @@ async def test_dhcp_flow_already_configured(hass: HomeAssistant) -> None:
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_zeroconf_flow(hass: HomeAssistant) -> None:
|
||||
async def test_zeroconf_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
||||
"""Test that zeroconf discovery for new bridge works."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
@ -269,9 +267,7 @@ async def test_zeroconf_flow(hass: HomeAssistant) -> None:
|
||||
|
||||
with patch("pyoverkiz.client.OverkizClient.login", return_value=True), patch(
|
||||
"pyoverkiz.client.OverkizClient.get_gateways", return_value=None
|
||||
), patch(
|
||||
"homeassistant.components.overkiz.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": TEST_EMAIL, "password": TEST_PASSWORD, "hub": TEST_HUB},
|
||||
|
Loading…
x
Reference in New Issue
Block a user