From 196bbb684ea1633ee527406decd2e2d43a602f06 Mon Sep 17 00:00:00 2001 From: Thomas Protzner Date: Mon, 12 Aug 2024 19:15:19 +0000 Subject: [PATCH] test that we connect and listen successfully --- .../husqvarna_automower/test_init.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/components/husqvarna_automower/test_init.py b/tests/components/husqvarna_automower/test_init.py index 2636e109cd6..88f0a87e865 100644 --- a/tests/components/husqvarna_automower/test_init.py +++ b/tests/components/husqvarna_automower/test_init.py @@ -158,9 +158,15 @@ async def test_websocket_not_available( assert mock_config_entry.state is ConfigEntryState.LOADED # Simulate a successful connection + caplog.clear() mock_automower_client.auth.websocket_connect.side_effect = None await hass.async_block_till_done() + assert ( + mock_automower_client.auth.websocket_connect.call_count + == temporary_recursion_limit + 1 + ) assert mock_automower_client.start_listening.call_count == 1 + assert "Trying to reconnect: Boom" not in caplog.text # Simulate a start_listening TimeoutException mock_automower_client.start_listening.side_effect = TimeoutException("Boom") @@ -169,6 +175,19 @@ async def test_websocket_not_available( mock_automower_client.auth.websocket_connect.call_count == temporary_recursion_limit + 2 ) + assert mock_automower_client.start_listening.call_count == 2 + + # Simulate a successful connection + caplog.clear() + mock_automower_client.start_listening.side_effect = None + await hass.async_block_till_done() + assert ( + mock_automower_client.auth.websocket_connect.call_count + == temporary_recursion_limit + 3 + ) + assert mock_automower_client.start_listening.call_count == 3 + assert "Trying to reconnect: Boom" not in caplog.text + sys.setrecursionlimit(default_recursion_limit) assert sys.getrecursionlimit() == default_recursion_limit