11"""Test Portainer system health."""
22
33import asyncio
4+ from unittest .mock import AsyncMock
45
56from aiohttp import ClientError
67
78from homeassistant .components .portainer .const import DOMAIN
8- from homeassistant .config_entries import ConfigEntryState
99from homeassistant .core import HomeAssistant
1010from 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
1414from tests .common import MockConfigEntry , get_system_health_info
1515from tests .test_util .aiohttp import AiohttpClientMocker
2020async 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(
4941async 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