mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Retry setup in case of empty response from Pushover api (#80602)
Retry setup in case of empty response
This commit is contained in:
parent
c70614fd7c
commit
3aa24afad8
@ -35,7 +35,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
pushover_api.validate, entry.data[CONF_USER_KEY]
|
pushover_api.validate, entry.data[CONF_USER_KEY]
|
||||||
)
|
)
|
||||||
|
|
||||||
except BadAPIRequestError as err:
|
except (BadAPIRequestError, ValueError) as err:
|
||||||
if "application token is invalid" in str(err):
|
if "application token is invalid" in str(err):
|
||||||
raise ConfigEntryAuthFailed(err) from err
|
raise ConfigEntryAuthFailed(err) from err
|
||||||
raise ConfigEntryNotReady(err) from err
|
raise ConfigEntryNotReady(err) from err
|
||||||
|
@ -6,6 +6,7 @@ from unittest.mock import MagicMock, patch
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
from pushover_complete import BadAPIRequestError
|
from pushover_complete import BadAPIRequestError
|
||||||
import pytest
|
import pytest
|
||||||
|
from requests_mock import Mocker
|
||||||
|
|
||||||
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
|
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
|
||||||
from homeassistant.components.pushover.const import DOMAIN
|
from homeassistant.components.pushover.const import DOMAIN
|
||||||
@ -19,7 +20,7 @@ from tests.common import MockConfigEntry
|
|||||||
from tests.components.repairs import get_repairs
|
from tests.components.repairs import get_repairs
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=False)
|
||||||
def mock_pushover():
|
def mock_pushover():
|
||||||
"""Mock pushover."""
|
"""Mock pushover."""
|
||||||
with patch(
|
with patch(
|
||||||
@ -33,6 +34,7 @@ async def test_setup(
|
|||||||
hass_ws_client: Callable[
|
hass_ws_client: Callable[
|
||||||
[HomeAssistant], Awaitable[aiohttp.ClientWebSocketResponse]
|
[HomeAssistant], Awaitable[aiohttp.ClientWebSocketResponse]
|
||||||
],
|
],
|
||||||
|
mock_pushover: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test integration failed due to an error."""
|
"""Test integration failed due to an error."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
@ -56,7 +58,9 @@ async def test_setup(
|
|||||||
assert issues[0]["issue_id"] == "deprecated_yaml"
|
assert issues[0]["issue_id"] == "deprecated_yaml"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_setup_entry_success(hass: HomeAssistant) -> None:
|
async def test_async_setup_entry_success(
|
||||||
|
hass: HomeAssistant, mock_pushover: MagicMock
|
||||||
|
) -> None:
|
||||||
"""Test pushover successful setup."""
|
"""Test pushover successful setup."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
@ -68,7 +72,7 @@ async def test_async_setup_entry_success(hass: HomeAssistant) -> None:
|
|||||||
assert entry.state == ConfigEntryState.LOADED
|
assert entry.state == ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
|
||||||
async def test_unique_id_updated(hass: HomeAssistant) -> None:
|
async def test_unique_id_updated(hass: HomeAssistant, mock_pushover: MagicMock) -> None:
|
||||||
"""Test updating unique_id to new format."""
|
"""Test updating unique_id to new format."""
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, unique_id="MYUSERKEY")
|
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, unique_id="MYUSERKEY")
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
@ -106,3 +110,20 @@ async def test_async_setup_entry_failed_conn_error(
|
|||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert entry.state == ConfigEntryState.SETUP_RETRY
|
assert entry.state == ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_setup_entry_failed_json_error(
|
||||||
|
hass: HomeAssistant, requests_mock: Mocker
|
||||||
|
) -> None:
|
||||||
|
"""Test pushover failed setup due to bad json response from library."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data=MOCK_CONFIG,
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
requests_mock.post(
|
||||||
|
"https://api.pushover.net/1/users/validate.json", status_code=204
|
||||||
|
)
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert entry.state == ConfigEntryState.SETUP_RETRY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user