Handle zone exception when setting up Cloudflare (#85110)
parent
90ac0c870f
commit
ab2f05d3e9
|
@ -10,6 +10,7 @@ from pycfdns.exceptions import (
|
|||
CloudflareAuthenticationException,
|
||||
CloudflareConnectionException,
|
||||
CloudflareException,
|
||||
CloudflareZoneException,
|
||||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -47,7 +48,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
zone_id = await cfupdate.get_zone_id()
|
||||
except CloudflareAuthenticationException as error:
|
||||
raise ConfigEntryAuthFailed from error
|
||||
except CloudflareConnectionException as error:
|
||||
except (CloudflareConnectionException, CloudflareZoneException) as error:
|
||||
raise ConfigEntryNotReady from error
|
||||
|
||||
async def update_records(now):
|
||||
|
|
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
|||
from pycfdns.exceptions import (
|
||||
CloudflareAuthenticationException,
|
||||
CloudflareConnectionException,
|
||||
CloudflareZoneException,
|
||||
)
|
||||
import pytest
|
||||
|
||||
|
@ -31,14 +32,21 @@ async def test_unload_entry(hass, cfupdate):
|
|||
assert not hass.data.get(DOMAIN)
|
||||
|
||||
|
||||
async def test_async_setup_raises_entry_not_ready(hass, cfupdate):
|
||||
@pytest.mark.parametrize(
|
||||
"side_effect",
|
||||
(
|
||||
CloudflareConnectionException(),
|
||||
CloudflareZoneException(),
|
||||
),
|
||||
)
|
||||
async def test_async_setup_raises_entry_not_ready(hass, cfupdate, side_effect):
|
||||
"""Test that it throws ConfigEntryNotReady when exception occurs during setup."""
|
||||
instance = cfupdate.return_value
|
||||
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_CONFIG)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
instance.get_zone_id.side_effect = CloudflareConnectionException()
|
||||
instance.get_zone_id.side_effect = side_effect
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
|
Loading…
Reference in New Issue