Skip to content

Commit

Permalink
Add missing mock in axis config flow tests (home-assistant#89365)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored and jpbaltazar committed Mar 8, 2023
1 parent 0d315f4 commit d546c35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
13 changes: 12 additions & 1 deletion tests/components/axis/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Axis conftest."""
from __future__ import annotations

from collections.abc import Generator
from copy import deepcopy
from unittest.mock import patch
from unittest.mock import AsyncMock, patch

from axis.rtsp import Signal, State
import pytest
Expand Down Expand Up @@ -41,6 +42,16 @@
from tests.common import MockConfigEntry
from tests.components.light.conftest import mock_light_profiles # noqa: F401


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.axis.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry


# Config entry fixtures


Expand Down
19 changes: 11 additions & 8 deletions tests/components/axis/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@


@pytest.fixture(name="mock_config_entry")
async def mock_config_entry_fixture(hass, config_entry):
async def mock_config_entry_fixture(hass, config_entry, mock_setup_entry):
"""Mock config entry and setup entry."""
with patch("homeassistant.components.axis.async_setup_entry", return_value=True):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
yield config_entry
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
return config_entry


async def test_flow_manual_configuration(
hass: HomeAssistant, setup_default_vapix_requests
hass: HomeAssistant, setup_default_vapix_requests, mock_setup_entry
) -> None:
"""Test that config flow works."""
MockConfigEntry(domain=AXIS_DOMAIN, source=SOURCE_IGNORE).add_to_hass(hass)
Expand Down Expand Up @@ -164,7 +163,7 @@ async def test_flow_fails_cannot_connect(hass: HomeAssistant) -> None:


async def test_flow_create_entry_multiple_existing_entries_of_same_model(
hass: HomeAssistant, setup_default_vapix_requests
hass: HomeAssistant, setup_default_vapix_requests, mock_setup_entry
) -> None:
"""Test that create entry can generate a name with other entries."""
entry = MockConfigEntry(
Expand Down Expand Up @@ -310,7 +309,11 @@ async def test_reauth_flow_update_configuration(
],
)
async def test_discovery_flow(
hass: HomeAssistant, setup_default_vapix_requests, source: str, discovery_info: dict
hass: HomeAssistant,
setup_default_vapix_requests,
source: str,
discovery_info: dict,
mock_setup_entry,
) -> None:
"""Test the different discovery flows for new devices work."""
result = await hass.config_entries.flow.async_init(
Expand Down

0 comments on commit d546c35

Please sign in to comment.