Skip to content

Commit af0ce7d

Browse files
committed
Feedback
1 parent be8578a commit af0ce7d

1 file changed

Lines changed: 8 additions & 24 deletions

File tree

tests/components/portainer/test_system_health.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Test Portainer system health."""
22

33
import asyncio
4+
from unittest.mock import AsyncMock
45

56
from aiohttp import ClientError
67

78
from homeassistant.components.portainer.const import DOMAIN
8-
from homeassistant.config_entries import ConfigEntryState
99
from homeassistant.core import HomeAssistant
1010
from homeassistant.setup import async_setup_component
1111

12-
from .conftest import MOCK_TEST_CONFIG, TEST_ENTRY, TEST_INSTANCE_ID
12+
from . import setup_integration
1313

1414
from tests.common import MockConfigEntry, get_system_health_info
1515
from tests.test_util.aiohttp import AiohttpClientMocker
@@ -20,22 +20,14 @@
2020
async def test_system_health(
2121
hass: HomeAssistant,
2222
aioclient_mock: AiohttpClientMocker,
23+
mock_config_entry: MockConfigEntry,
24+
mock_portainer_client: AsyncMock,
2325
) -> None:
2426
"""Test system health when server is reachable."""
2527
aioclient_mock.get(MOCK_HEALTH_URL, text="ok")
2628

27-
hass.config.components.add(DOMAIN)
2829
assert await async_setup_component(hass, "system_health", {})
29-
await hass.async_block_till_done()
30-
31-
entry = MockConfigEntry(
32-
domain=DOMAIN,
33-
data=MOCK_TEST_CONFIG,
34-
unique_id=TEST_INSTANCE_ID,
35-
entry_id=TEST_ENTRY,
36-
state=ConfigEntryState.LOADED,
37-
)
38-
entry.add_to_hass(hass)
30+
await setup_integration(hass, mock_config_entry)
3931

4032
info = await get_system_health_info(hass, DOMAIN)
4133

@@ -49,22 +41,14 @@ async def test_system_health(
4941
async def test_system_health_failed_connect(
5042
hass: HomeAssistant,
5143
aioclient_mock: AiohttpClientMocker,
44+
mock_config_entry: MockConfigEntry,
45+
mock_portainer_client: AsyncMock,
5246
) -> None:
5347
"""Test system health when server is unreachable."""
5448
aioclient_mock.get(MOCK_HEALTH_URL, exc=ClientError)
5549

56-
hass.config.components.add(DOMAIN)
5750
assert await async_setup_component(hass, "system_health", {})
58-
await hass.async_block_till_done()
59-
60-
entry = MockConfigEntry(
61-
domain=DOMAIN,
62-
data=MOCK_TEST_CONFIG,
63-
unique_id=TEST_INSTANCE_ID,
64-
entry_id=TEST_ENTRY,
65-
state=ConfigEntryState.LOADED,
66-
)
67-
entry.add_to_hass(hass)
51+
await setup_integration(hass, mock_config_entry)
6852

6953
info = await get_system_health_info(hass, DOMAIN)
7054

0 commit comments

Comments
 (0)