mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-29 13:15:10 +01:00
Use loopback address in all tests (#841)
This commit is contained in:
parent
73a40131be
commit
e4ab837111
@ -57,7 +57,7 @@ def patchable_api_client() -> APIClient:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
cli = PatchableAPIClient(
|
cli = PatchableAPIClient(
|
||||||
address="1.2.3.4",
|
address="127.0.0.1",
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
)
|
)
|
||||||
|
@ -203,7 +203,7 @@ async def test_finish_connection_wraps_exceptions_as_unhandled_api_error(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Verify finish_connect re-wraps exceptions as UnhandledAPIError."""
|
"""Verify finish_connect re-wraps exceptions as UnhandledAPIError."""
|
||||||
|
|
||||||
cli = APIClient("1.2.3.4", 1234, None)
|
cli = APIClient("127.0.0.1", 1234, None)
|
||||||
with patch("aioesphomeapi.client.APIConnection", PatchableAPIConnection):
|
with patch("aioesphomeapi.client.APIConnection", PatchableAPIConnection):
|
||||||
await cli.start_connection()
|
await cli.start_connection()
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ async def test_finish_connection_wraps_exceptions_as_unhandled_api_error(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_connection_released_if_connecting_is_cancelled() -> None:
|
async def test_connection_released_if_connecting_is_cancelled() -> None:
|
||||||
"""Verify connection is unset if connecting is cancelled."""
|
"""Verify connection is unset if connecting is cancelled."""
|
||||||
cli = APIClient("1.2.3.4", 1234, None)
|
cli = APIClient("127.0.0.1", 1234, None)
|
||||||
asyncio.get_event_loop()
|
asyncio.get_event_loop()
|
||||||
|
|
||||||
async def _start_connection_with_delay(*args, **kwargs):
|
async def _start_connection_with_delay(*args, **kwargs):
|
||||||
@ -930,7 +930,7 @@ async def test_noise_psk_handles_subclassed_string():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
cli = PatchableAPIClient(
|
cli = PatchableAPIClient(
|
||||||
address=Estr("1.2.3.4"),
|
address=Estr("127.0.0.1"),
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
noise_psk=Estr("QRTIErOb/fcE9Ukd/5qA3RGYMn0Y+p06U58SCtOXvPc="),
|
noise_psk=Estr("QRTIErOb/fcE9Ukd/5qA3RGYMn0Y+p06U58SCtOXvPc="),
|
||||||
@ -966,7 +966,7 @@ async def test_noise_psk_handles_subclassed_string():
|
|||||||
async def test_no_noise_psk():
|
async def test_no_noise_psk():
|
||||||
"""Test not using a noise_psk."""
|
"""Test not using a noise_psk."""
|
||||||
cli = APIClient(
|
cli = APIClient(
|
||||||
address=Estr("1.2.3.4"),
|
address=Estr("127.0.0.1"),
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
noise_psk=None,
|
noise_psk=None,
|
||||||
@ -982,7 +982,7 @@ async def test_no_noise_psk():
|
|||||||
async def test_empty_noise_psk_or_expected_name():
|
async def test_empty_noise_psk_or_expected_name():
|
||||||
"""Test an empty noise_psk is treated as None."""
|
"""Test an empty noise_psk is treated as None."""
|
||||||
cli = APIClient(
|
cli = APIClient(
|
||||||
address=Estr("1.2.3.4"),
|
address=Estr("127.0.0.1"),
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
noise_psk="",
|
noise_psk="",
|
||||||
|
@ -46,7 +46,7 @@ async def test_log_runner(
|
|||||||
async_zeroconf = get_mock_async_zeroconf()
|
async_zeroconf = get_mock_async_zeroconf()
|
||||||
|
|
||||||
cli = PatchableAPIClient(
|
cli = PatchableAPIClient(
|
||||||
address=Estr("1.2.3.4"),
|
address=Estr("127.0.0.1"),
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
noise_psk=None,
|
noise_psk=None,
|
||||||
@ -115,7 +115,7 @@ async def test_log_runner_reconnects_on_disconnect(
|
|||||||
async_zeroconf = get_mock_async_zeroconf()
|
async_zeroconf = get_mock_async_zeroconf()
|
||||||
|
|
||||||
cli = PatchableAPIClient(
|
cli = PatchableAPIClient(
|
||||||
address=Estr("1.2.3.4"),
|
address=Estr("127.0.0.1"),
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
noise_psk=None,
|
noise_psk=None,
|
||||||
@ -195,7 +195,7 @@ async def test_log_runner_reconnects_on_subscribe_failure(
|
|||||||
async_zeroconf = get_mock_async_zeroconf()
|
async_zeroconf = get_mock_async_zeroconf()
|
||||||
|
|
||||||
cli = PatchableAPIClient(
|
cli = PatchableAPIClient(
|
||||||
address=Estr("1.2.3.4"),
|
address=Estr("127.0.0.1"),
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
noise_psk=None,
|
noise_psk=None,
|
||||||
|
@ -102,7 +102,7 @@ async def test_reconnect_logic_name_from_host_and_set():
|
|||||||
async def test_reconnect_logic_name_from_address():
|
async def test_reconnect_logic_name_from_address():
|
||||||
"""Test that the name is set correctly from the address."""
|
"""Test that the name is set correctly from the address."""
|
||||||
cli = APIClient(
|
cli = APIClient(
|
||||||
address="1.2.3.4",
|
address="127.0.0.1",
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
)
|
)
|
||||||
@ -119,14 +119,14 @@ async def test_reconnect_logic_name_from_address():
|
|||||||
on_connect=on_connect,
|
on_connect=on_connect,
|
||||||
zeroconf_instance=get_mock_zeroconf(),
|
zeroconf_instance=get_mock_zeroconf(),
|
||||||
)
|
)
|
||||||
assert cli.log_name == "1.2.3.4"
|
assert cli.log_name == "127.0.0.1"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_reconnect_logic_name_from_name():
|
async def test_reconnect_logic_name_from_name():
|
||||||
"""Test that the name is set correctly from the address."""
|
"""Test that the name is set correctly from the address."""
|
||||||
cli = APIClient(
|
cli = APIClient(
|
||||||
address="1.2.3.4",
|
address="127.0.0.1",
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
)
|
)
|
||||||
@ -144,7 +144,7 @@ async def test_reconnect_logic_name_from_name():
|
|||||||
zeroconf_instance=get_mock_zeroconf(),
|
zeroconf_instance=get_mock_zeroconf(),
|
||||||
name="mydevice",
|
name="mydevice",
|
||||||
)
|
)
|
||||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@ -201,7 +201,7 @@ async def test_reconnect_logic_state(patchable_api_client: APIClient):
|
|||||||
name="mydevice",
|
name="mydevice",
|
||||||
on_connect_error=on_connect_fail,
|
on_connect_error=on_connect_fail,
|
||||||
)
|
)
|
||||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||||
|
|
||||||
with patch.object(cli, "start_connection", side_effect=APIConnectionError):
|
with patch.object(cli, "start_connection", side_effect=APIConnectionError):
|
||||||
await rl.start()
|
await rl.start()
|
||||||
@ -274,7 +274,7 @@ async def test_reconnect_retry(
|
|||||||
name="mydevice",
|
name="mydevice",
|
||||||
on_connect_error=on_connect_fail,
|
on_connect_error=on_connect_fail,
|
||||||
)
|
)
|
||||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
|
|
||||||
with patch.object(cli, "start_connection", side_effect=APIConnectionError):
|
with patch.object(cli, "start_connection", side_effect=APIConnectionError):
|
||||||
@ -288,9 +288,9 @@ async def test_reconnect_retry(
|
|||||||
assert len(on_connect_fail_called) == 1
|
assert len(on_connect_fail_called) == 1
|
||||||
assert isinstance(on_connect_fail_called[-1], APIConnectionError)
|
assert isinstance(on_connect_fail_called[-1], APIConnectionError)
|
||||||
assert rl._connection_state is ReconnectLogicState.DISCONNECTED
|
assert rl._connection_state is ReconnectLogicState.DISCONNECTED
|
||||||
assert "connect to ESPHome API for mydevice @ 1.2.3.4" in caplog.text
|
assert "connect to ESPHome API for mydevice @ 127.0.0.1" in caplog.text
|
||||||
for record in caplog.records:
|
for record in caplog.records:
|
||||||
if "connect to ESPHome API for mydevice @ 1.2.3.4" in record.message:
|
if "connect to ESPHome API for mydevice @ 127.0.0.1" in record.message:
|
||||||
assert record.levelno == logging.WARNING
|
assert record.levelno == logging.WARNING
|
||||||
|
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
@ -307,9 +307,9 @@ async def test_reconnect_retry(
|
|||||||
assert len(on_connect_fail_called) == 2
|
assert len(on_connect_fail_called) == 2
|
||||||
assert isinstance(on_connect_fail_called[-1], APIConnectionError)
|
assert isinstance(on_connect_fail_called[-1], APIConnectionError)
|
||||||
assert rl._connection_state is ReconnectLogicState.DISCONNECTED
|
assert rl._connection_state is ReconnectLogicState.DISCONNECTED
|
||||||
assert "connect to ESPHome API for mydevice @ 1.2.3.4" in caplog.text
|
assert "connect to ESPHome API for mydevice @ 127.0.0.1" in caplog.text
|
||||||
for record in caplog.records:
|
for record in caplog.records:
|
||||||
if "connect to ESPHome API for mydevice @ 1.2.3.4" in record.message:
|
if "connect to ESPHome API for mydevice @ 127.0.0.1" in record.message:
|
||||||
assert record.levelno == logging.DEBUG
|
assert record.levelno == logging.DEBUG
|
||||||
|
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
@ -320,7 +320,7 @@ async def test_reconnect_retry(
|
|||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
|
||||||
assert "connect to ESPHome API for mydevice @ 1.2.3.4" not in caplog.text
|
assert "connect to ESPHome API for mydevice @ 127.0.0.1" not in caplog.text
|
||||||
assert len(on_disconnect_called) == 0
|
assert len(on_disconnect_called) == 0
|
||||||
assert len(on_connect_called) == 1
|
assert len(on_connect_called) == 1
|
||||||
assert len(on_connect_fail_called) == 2
|
assert len(on_connect_fail_called) == 2
|
||||||
@ -372,7 +372,7 @@ DNS_POINTER = DNSPointer(
|
|||||||
_TYPE_A,
|
_TYPE_A,
|
||||||
_CLASS_IN,
|
_CLASS_IN,
|
||||||
1000,
|
1000,
|
||||||
ip_address("1.2.3.4").packed,
|
ip_address("127.0.0.1").packed,
|
||||||
),
|
),
|
||||||
True,
|
True,
|
||||||
ReconnectLogicState.READY,
|
ReconnectLogicState.READY,
|
||||||
@ -403,7 +403,7 @@ async def test_reconnect_zeroconf(
|
|||||||
name="mydevice",
|
name="mydevice",
|
||||||
on_connect_error=AsyncMock(),
|
on_connect_error=AsyncMock(),
|
||||||
)
|
)
|
||||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||||
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
cli, "start_connection", side_effect=quick_connect_fail
|
cli, "start_connection", side_effect=quick_connect_fail
|
||||||
@ -474,7 +474,7 @@ async def test_reconnect_zeroconf_not_while_handshaking(
|
|||||||
name="mydevice",
|
name="mydevice",
|
||||||
on_connect_error=AsyncMock(),
|
on_connect_error=AsyncMock(),
|
||||||
)
|
)
|
||||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||||
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
cli, "start_connection", side_effect=quick_connect_fail
|
cli, "start_connection", side_effect=quick_connect_fail
|
||||||
@ -531,7 +531,7 @@ async def test_connect_task_not_cancelled_while_handshaking(
|
|||||||
name="mydevice",
|
name="mydevice",
|
||||||
on_connect_error=AsyncMock(),
|
on_connect_error=AsyncMock(),
|
||||||
)
|
)
|
||||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||||
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
cli, "start_connection", side_effect=quick_connect_fail
|
cli, "start_connection", side_effect=quick_connect_fail
|
||||||
@ -591,7 +591,7 @@ async def test_connect_aborts_if_stopped(
|
|||||||
name="mydevice",
|
name="mydevice",
|
||||||
on_connect_error=AsyncMock(),
|
on_connect_error=AsyncMock(),
|
||||||
)
|
)
|
||||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||||
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
cli, "start_connection", side_effect=quick_connect_fail
|
cli, "start_connection", side_effect=quick_connect_fail
|
||||||
@ -694,7 +694,7 @@ async def test_handling_unexpected_disconnect(aiohappyeyeballs_start_connection)
|
|||||||
async_zeroconf = get_mock_async_zeroconf()
|
async_zeroconf = get_mock_async_zeroconf()
|
||||||
|
|
||||||
cli = PatchableAPIClient(
|
cli = PatchableAPIClient(
|
||||||
address="1.2.3.4",
|
address="127.0.0.1",
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
noise_psk=None,
|
noise_psk=None,
|
||||||
@ -770,7 +770,7 @@ async def test_backoff_on_encryption_error(
|
|||||||
async_zeroconf = get_mock_async_zeroconf()
|
async_zeroconf = get_mock_async_zeroconf()
|
||||||
|
|
||||||
cli = PatchableAPIClient(
|
cli = PatchableAPIClient(
|
||||||
address="1.2.3.4",
|
address="127.0.0.1",
|
||||||
port=6052,
|
port=6052,
|
||||||
password=None,
|
password=None,
|
||||||
noise_psk="",
|
noise_psk="",
|
||||||
|
Loading…
Reference in New Issue
Block a user