Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump pycfdns from 2.0.1 to 3.0.0 #103426

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
More coverage
  • Loading branch information
ludeeus committed Nov 6, 2023
commit 05f678e48aa5eda9cae4110d7ef9b426f8e7b46e
13 changes: 13 additions & 0 deletions tests/components/cloudflare/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Test Cloudflare integration helpers."""
from homeassistant.components.cloudflare.helpers import get_zone_id


def test_get_zone_id():
"""Test get_zone_id."""
zones = [
{"id": "1", "name": "example.com"},
{"id": "2", "name": "example.org"},
]
assert get_zone_id("example.com", zones) == "1"
assert get_zone_id("example.org", zones) == "2"
assert get_zone_id("example.net", zones) is None
54 changes: 53 additions & 1 deletion tests/components/cloudflare/test_init.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
"""Test the Cloudflare integration."""
from datetime import timedelta
from unittest.mock import patch

import pycfdns
import pytest

from homeassistant.components.cloudflare.const import (
CONF_RECORDS,
DEFAULT_UPDATE_INTERVAL,
DOMAIN,
SERVICE_UPDATE_RECORDS,
)
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
import homeassistant.util.dt as dt_util
from homeassistant.util.location import LocationInfo

from . import ENTRY_CONFIG, init_integration

from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, async_fire_time_changed


async def test_unload_entry(hass: HomeAssistant, cfupdate) -> None:
Expand Down Expand Up @@ -172,3 +175,52 @@ async def test_integration_services_with_nonexisting_record(

instance.update_dns_record.assert_not_called()
assert "All target records are up to date" in caplog.text


async def test_integration_update_interval(
hass: HomeAssistant,
cfupdate,
caplog,
) -> None:
"""Test integration update interval."""
instance = cfupdate.return_value

entry = await init_integration(hass)
assert entry.state is ConfigEntryState.LOADED

with patch(
"homeassistant.components.cloudflare.async_detect_location_info",
return_value=LocationInfo(
"0.0.0.0",
"US",
"USD",
"CA",
"California",
"San Diego",
"92122",
"America/Los_Angeles",
32.8594,
-117.2073,
True,
),
):
async_fire_time_changed(
hass, dt_util.utcnow() + timedelta(minutes=DEFAULT_UPDATE_INTERVAL)
)
await hass.async_block_till_done()
assert len(instance.update_dns_record.mock_calls) == 2
assert "All target records are up to date" not in caplog.text

instance.list_dns_records.side_effect = pycfdns.AuthenticationException()
async_fire_time_changed(
hass, dt_util.utcnow() + timedelta(minutes=DEFAULT_UPDATE_INTERVAL)
)
await hass.async_block_till_done()
assert len(instance.update_dns_record.mock_calls) == 2

instance.list_dns_records.side_effect = pycfdns.ComunicationException()
async_fire_time_changed(
hass, dt_util.utcnow() + timedelta(minutes=DEFAULT_UPDATE_INTERVAL)
)
await hass.async_block_till_done()
assert len(instance.update_dns_record.mock_calls) == 2