mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Handle zone exception when setting up Cloudflare (#85110)
This commit is contained in:
parent
22dbbd4b71
commit
f5c35ac0c1
@ -10,6 +10,7 @@ from pycfdns.exceptions import (
|
|||||||
CloudflareAuthenticationException,
|
CloudflareAuthenticationException,
|
||||||
CloudflareConnectionException,
|
CloudflareConnectionException,
|
||||||
CloudflareException,
|
CloudflareException,
|
||||||
|
CloudflareZoneException,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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()
|
zone_id = await cfupdate.get_zone_id()
|
||||||
except CloudflareAuthenticationException as error:
|
except CloudflareAuthenticationException as error:
|
||||||
raise ConfigEntryAuthFailed from error
|
raise ConfigEntryAuthFailed from error
|
||||||
except CloudflareConnectionException as error:
|
except (CloudflareConnectionException, CloudflareZoneException) as error:
|
||||||
raise ConfigEntryNotReady from error
|
raise ConfigEntryNotReady from error
|
||||||
|
|
||||||
async def update_records(now):
|
async def update_records(now):
|
||||||
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
|||||||
from pycfdns.exceptions import (
|
from pycfdns.exceptions import (
|
||||||
CloudflareAuthenticationException,
|
CloudflareAuthenticationException,
|
||||||
CloudflareConnectionException,
|
CloudflareConnectionException,
|
||||||
|
CloudflareZoneException,
|
||||||
)
|
)
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -31,14 +32,21 @@ async def test_unload_entry(hass, cfupdate):
|
|||||||
assert not hass.data.get(DOMAIN)
|
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."""
|
"""Test that it throws ConfigEntryNotReady when exception occurs during setup."""
|
||||||
instance = cfupdate.return_value
|
instance = cfupdate.return_value
|
||||||
|
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_CONFIG)
|
entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_CONFIG)
|
||||||
entry.add_to_hass(hass)
|
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)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
|
||||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user