@@ -146,6 +146,46 @@ async def test_safe_dict_post_and_list_post(monkeypatch, make_client) -> None:
146146 assert result_empty_list == []
147147
148148
149+ @pytest .mark .asyncio
150+ async def test_get_check (make_client ) -> None :
151+ """Test _get_check method returns True for ok responses, False otherwise."""
152+ session = MagicMock (spec = aiohttp .ClientSession )
153+
154+ # Fake response class for testing
155+ class FakeResp :
156+ def __init__ (self , status = 500 , ok = False ):
157+ self .status = status
158+ self .reason = "Test"
159+ self .ok = ok
160+ self .request_info = MagicMock ()
161+ self .history = []
162+ self .headers = {}
163+
164+ async def __aenter__ (self ):
165+ return self
166+
167+ async def __aexit__ (self , exc_type , exc , tb ):
168+ return False
169+
170+ # Test successful response (ok=True)
171+ session .get = lambda * a , ** k : FakeResp (status = 200 , ok = True )
172+ client = make_client (session = session )
173+ result = await client ._get_check ("/api/test" )
174+ assert result is True
175+
176+ # Test failed response (ok=False)
177+ session .get = lambda * a , ** k : FakeResp (status = 404 , ok = False )
178+ client = make_client (session = session )
179+ result = await client ._get_check ("/api/test" )
180+ assert result is False
181+
182+ # Test 403 response specifically
183+ session .get = lambda * a , ** k : FakeResp (status = 403 , ok = False )
184+ client = make_client (session = session )
185+ result = await client ._get_check ("/api/test" )
186+ assert result is False
187+
188+
149189@pytest .mark .asyncio
150190async def test_get_ip_key_sorting (make_client ) -> None :
151191 """Sort IP-like items using get_ip_key ordering."""
@@ -358,6 +398,26 @@ async def test_dhcp_leases_and_keep_latest_and_dnsmasq(make_client) -> None:
358398 await client .async_close ()
359399
360400
401+ @pytest .mark .asyncio
402+ async def test_isc_dhcp_service_not_running (make_client ) -> None :
403+ """Test ISC DHCP lease methods return empty list when service is not running."""
404+ session = MagicMock (spec = aiohttp .ClientSession )
405+ client = make_client (session = session )
406+ try :
407+ # Mock _get_check to return False (service not running)
408+ client ._get_check = AsyncMock (return_value = False )
409+
410+ # Test DHCPv4
411+ leases_v4 = await client ._get_isc_dhcpv4_leases ()
412+ assert leases_v4 == []
413+
414+ # Test DHCPv6
415+ leases_v6 = await client ._get_isc_dhcpv6_leases ()
416+ assert leases_v6 == []
417+ finally :
418+ await client .async_close ()
419+
420+
361421@pytest .mark .asyncio
362422async def test_carp_and_reboot_and_wol (make_client ) -> None :
363423 """Verify CARP interface discovery and system control endpoints (reboot/halt/WOL)."""
0 commit comments