File tree Expand file tree Collapse file tree
custom_components/enpal_webparser/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717#
1818
1919import ipaddress
20- from unittest .mock import MagicMock , patch
20+ from unittest .mock import AsyncMock , MagicMock , patch
2121import pytest
2222
2323from custom_components .enpal_webparser .discovery import (
@@ -62,14 +62,17 @@ async def test_check_enpal_device_valid():
6262 # Mock HTML response with Enpal markers (updated to match actual Enpal device HTML)
6363 mock_response = MagicMock ()
6464 mock_response .status = 200
65- mock_response .text = MagicMock (
65+ # Use AsyncMock for the async text() method
66+ mock_response .text = AsyncMock (
6667 return_value = '<html><h1 class="m-3">Device Messages</h1><div class="card"><h2>Inverter</h2><table></table></div></html>'
6768 )
6869
70+ # Properly mock the async context manager
6971 mock_session = MagicMock ()
70- mock_session .get = MagicMock (return_value = mock_response )
71- mock_session .get .return_value .__aenter__ = MagicMock (return_value = mock_response )
72- mock_session .get .return_value .__aexit__ = MagicMock (return_value = None )
72+ mock_get = MagicMock ()
73+ mock_get .__aenter__ = AsyncMock (return_value = mock_response )
74+ mock_get .__aexit__ = AsyncMock (return_value = None )
75+ mock_session .get = MagicMock (return_value = mock_get )
7376
7477 with patch ('custom_components.enpal_webparser.discovery.async_get_clientsession' , return_value = mock_session ):
7578 result = await check_enpal_device (hass , "192.168.178.178" )
You can’t perform that action at this time.
0 commit comments