1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 00:20:30 +01:00

Fix open sockets in tests for Telegram bot (#166451)

This commit is contained in:
hanwg
2026-03-25 16:45:44 +08:00
committed by GitHub
parent a6dd56eed0
commit 32221a1ec4
2 changed files with 29 additions and 6 deletions

View File

@@ -298,7 +298,12 @@ async def test_reconfigure_flow_logout_failed(
assert mock_broadcast_config_entry.data[CONF_API_ENDPOINT] == "http://mock2"
async def test_create_entry(hass: HomeAssistant) -> None:
async def test_create_entry(
hass: HomeAssistant,
mock_register_webhook: None,
mock_external_calls: None,
mock_generate_secret_token: str,
) -> None:
"""Test user flow."""
# test: no input
@@ -334,10 +339,9 @@ async def test_create_entry(hass: HomeAssistant) -> None:
# test: telegram error
with patch(
"homeassistant.components.telegram_bot.config_flow.Bot.get_me",
) as mock_bot:
mock_bot.side_effect = NetworkError("mock network error")
"homeassistant.components.telegram_bot.bot.Bot.get_me",
side_effect=NetworkError("mock network error"),
) as mock_get_me:
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
@@ -350,6 +354,7 @@ async def test_create_entry(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
mock_get_me.assert_called_once()
assert result["step_id"] == "user"
assert result["type"] is FlowResultType.FORM
assert result["errors"]["base"] == "telegram_error"
@@ -389,7 +394,7 @@ async def test_create_entry(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Testbot"
assert result["title"] == "Testbot mock last name"
assert result["data"][CONF_PLATFORM] == PLATFORM_WEBHOOKS
assert result["data"][CONF_API_KEY] == "mock api key"
assert result["data"][CONF_PROXY_URL] == "https://proxy"

View File

@@ -90,6 +90,7 @@ from homeassistant.components.telegram_bot.const import (
SERVICE_SEND_VOICE,
)
from homeassistant.components.telegram_bot.webhooks import TELEGRAM_WEBHOOK_URL
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import (
ATTR_DOMAIN,
ATTR_ENTITY_ID,
@@ -132,6 +133,23 @@ async def test_polling_platform_init(
assert hass.services.has_service(DOMAIN, SERVICE_SEND_MESSAGE) is True
async def test_polling_platform_init_failed(
hass: HomeAssistant,
mock_polling_config_entry: MockConfigEntry,
) -> None:
"""Test failed initialization of the polling platform."""
with patch(
"homeassistant.components.telegram_bot.bot.Bot.get_me",
side_effect=NetworkError("mock network error"),
) as mock_get_me:
mock_polling_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_polling_config_entry.entry_id)
await hass.async_block_till_done()
mock_get_me.assert_called_once()
assert mock_polling_config_entry.state == ConfigEntryState.SETUP_RETRY
@pytest.mark.parametrize(
("service", "input"),
[