Fix lingering timer in sabnzbd (#92462)

This commit is contained in:
epenet 2023-05-04 12:19:40 +02:00 committed by GitHub
parent 88019d70fe
commit 71b86e9f97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 7 deletions

View file

@ -237,7 +237,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
except SabnzbdApiException as err: except SabnzbdApiException as err:
_LOGGER.error(err) _LOGGER.error(err)
async_track_time_interval(hass, async_update_sabnzbd, UPDATE_INTERVAL) entry.async_on_unload(
async_track_time_interval(hass, async_update_sabnzbd, UPDATE_INTERVAL)
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

View file

@ -0,0 +1,14 @@
"""Configuration for Sabnzbd tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.sabnzbd.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry

View file

@ -1,7 +1,8 @@
"""Define tests for the Sabnzbd config flow.""" """Define tests for the Sabnzbd config flow."""
from unittest.mock import patch from unittest.mock import AsyncMock, patch
from pysabnzbd import SabnzbdApiException from pysabnzbd import SabnzbdApiException
import pytest
from homeassistant import config_entries, data_entry_flow from homeassistant import config_entries, data_entry_flow
from homeassistant.components.sabnzbd import DOMAIN from homeassistant.components.sabnzbd import DOMAIN
@ -31,8 +32,10 @@ VALID_CONFIG_OLD = {
CONF_SSL: False, CONF_SSL: False,
} }
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def test_create_entry(hass: HomeAssistant) -> None:
async def test_create_entry(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"""Test that the user step works.""" """Test that the user step works."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -43,10 +46,7 @@ async def test_create_entry(hass: HomeAssistant) -> None:
with patch( with patch(
"homeassistant.components.sabnzbd.sab.SabnzbdApi.check_available", "homeassistant.components.sabnzbd.sab.SabnzbdApi.check_available",
return_value=True, return_value=True,
), patch( ):
"homeassistant.components.sabnzbd.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure( result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
VALID_CONFIG, VALID_CONFIG,