mirror of
https://github.com/home-assistant/core.git
synced 2025-11-20 00:10:13 +00:00
Compare commits
5 Commits
revert-156
...
adguard/im
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b1ed36b74 | ||
|
|
ef1ab3fc61 | ||
|
|
2a54d812ba | ||
|
|
93a2504f23 | ||
|
|
e1b03faac0 |
393
tests/components/adguard/snapshots/test_sensor.ambr
Normal file
393
tests/components/adguard/snapshots/test_sensor.ambr
Normal file
@@ -0,0 +1,393 @@
|
||||
# serializer version: 1
|
||||
# name: test_sensors[sensor.adguard_home_average_processing_speed-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.adguard_home_average_processing_speed',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Average processing speed',
|
||||
'platform': 'adguard',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'average_processing_speed',
|
||||
'unique_id': 'adguard_127.0.0.1_3000_sensor_average_speed',
|
||||
'unit_of_measurement': <UnitOfTime.MILLISECONDS: 'ms'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_average_processing_speed-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'AdGuard Home Average processing speed',
|
||||
'unit_of_measurement': <UnitOfTime.MILLISECONDS: 'ms'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.adguard_home_average_processing_speed',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '31.41',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_dns_queries-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.adguard_home_dns_queries',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'DNS queries',
|
||||
'platform': 'adguard',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'dns_queries',
|
||||
'unique_id': 'adguard_127.0.0.1_3000_sensor_dns_queries',
|
||||
'unit_of_measurement': 'queries',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_dns_queries-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'AdGuard Home DNS queries',
|
||||
'unit_of_measurement': 'queries',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.adguard_home_dns_queries',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '666',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_dns_queries_blocked-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.adguard_home_dns_queries_blocked',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'DNS queries blocked',
|
||||
'platform': 'adguard',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'dns_queries_blocked',
|
||||
'unique_id': 'adguard_127.0.0.1_3000_sensor_blocked_filtering',
|
||||
'unit_of_measurement': 'queries',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_dns_queries_blocked-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'AdGuard Home DNS queries blocked',
|
||||
'unit_of_measurement': 'queries',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.adguard_home_dns_queries_blocked',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '1337',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_dns_queries_blocked_ratio-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.adguard_home_dns_queries_blocked_ratio',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'DNS queries blocked ratio',
|
||||
'platform': 'adguard',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'dns_queries_blocked_ratio',
|
||||
'unique_id': 'adguard_127.0.0.1_3000_sensor_blocked_percentage',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_dns_queries_blocked_ratio-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'AdGuard Home DNS queries blocked ratio',
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.adguard_home_dns_queries_blocked_ratio',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '200.75',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_parental_control_blocked-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.adguard_home_parental_control_blocked',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Parental control blocked',
|
||||
'platform': 'adguard',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'parental_control_blocked',
|
||||
'unique_id': 'adguard_127.0.0.1_3000_sensor_blocked_parental',
|
||||
'unit_of_measurement': 'requests',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_parental_control_blocked-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'AdGuard Home Parental control blocked',
|
||||
'unit_of_measurement': 'requests',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.adguard_home_parental_control_blocked',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '13',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_rules_count-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.adguard_home_rules_count',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Rules count',
|
||||
'platform': 'adguard',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'rules_count',
|
||||
'unique_id': 'adguard_127.0.0.1_3000_sensor_rules_count',
|
||||
'unit_of_measurement': 'rules',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_rules_count-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'AdGuard Home Rules count',
|
||||
'unit_of_measurement': 'rules',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.adguard_home_rules_count',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '100',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_safe_browsing_blocked-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.adguard_home_safe_browsing_blocked',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Safe browsing blocked',
|
||||
'platform': 'adguard',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'safe_browsing_blocked',
|
||||
'unique_id': 'adguard_127.0.0.1_3000_sensor_blocked_safebrowsing',
|
||||
'unit_of_measurement': 'requests',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_safe_browsing_blocked-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'AdGuard Home Safe browsing blocked',
|
||||
'unit_of_measurement': 'requests',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.adguard_home_safe_browsing_blocked',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '42',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_safe_searches_enforced-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.adguard_home_safe_searches_enforced',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Safe searches enforced',
|
||||
'platform': 'adguard',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'safe_searches_enforced',
|
||||
'unique_id': 'adguard_127.0.0.1_3000_sensor_enforced_safesearch',
|
||||
'unit_of_measurement': 'requests',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.adguard_home_safe_searches_enforced-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'AdGuard Home Safe searches enforced',
|
||||
'unit_of_measurement': 'requests',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.adguard_home_safe_searches_enforced',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '18',
|
||||
})
|
||||
# ---
|
||||
41
tests/components/adguard/test_init.py
Normal file
41
tests/components/adguard/test_init.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""Tests for the AdGuard Home."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from adguardhome import AdGuardHomeConnectionError
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
async def test_setup(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the adguard setup."""
|
||||
with patch("homeassistant.components.adguard.PLATFORMS", []):
|
||||
await setup_integration(hass, mock_config_entry, aioclient_mock)
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_setup_failed(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the adguard setup failed."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
aioclient_mock.get(
|
||||
"https://127.0.0.1:3000/control/status",
|
||||
exc=AdGuardHomeConnectionError("Connection error"),
|
||||
)
|
||||
|
||||
assert not await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
48
tests/components/adguard/test_sensor.py
Normal file
48
tests/components/adguard/test_sensor.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Tests for the AdGuard Home sensor entities."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import CONTENT_TYPE_JSON, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_sensors(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the adguard sensor platform."""
|
||||
aioclient_mock.get(
|
||||
"https://127.0.0.1:3000/control/stats",
|
||||
json={
|
||||
"num_dns_queries": 666,
|
||||
"num_blocked_filtering": 1337,
|
||||
"num_replaced_safebrowsing": 42,
|
||||
"num_replaced_parental": 13,
|
||||
"num_replaced_safesearch": 18,
|
||||
"avg_processing_time": 0.03141,
|
||||
},
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
aioclient_mock.get(
|
||||
"https://127.0.0.1:3000/control/filtering/status",
|
||||
json={"filters": [{"rules_count": 99}, {"rules_count": 1}]},
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
|
||||
with patch("homeassistant.components.adguard.PLATFORMS", [Platform.SENSOR]):
|
||||
await setup_integration(hass, mock_config_entry, aioclient_mock)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
184
tests/components/adguard/test_service.py
Normal file
184
tests/components/adguard/test_service.py
Normal file
@@ -0,0 +1,184 @@
|
||||
"""Tests for the AdGuard Home sensor entities."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.adguard.const import (
|
||||
DOMAIN,
|
||||
SERVICE_ADD_URL,
|
||||
SERVICE_DISABLE_URL,
|
||||
SERVICE_ENABLE_URL,
|
||||
SERVICE_REFRESH,
|
||||
SERVICE_REMOVE_URL,
|
||||
)
|
||||
from homeassistant.const import CONTENT_TYPE_JSON
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
async def test_service_registration(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the adguard services be registered."""
|
||||
with patch("homeassistant.components.adguard.PLATFORMS", []):
|
||||
await setup_integration(hass, mock_config_entry, aioclient_mock)
|
||||
|
||||
services = hass.services.async_services_for_domain(DOMAIN)
|
||||
|
||||
assert len(services) == 5
|
||||
assert SERVICE_ADD_URL in services
|
||||
assert SERVICE_DISABLE_URL in services
|
||||
assert SERVICE_ENABLE_URL in services
|
||||
assert SERVICE_REFRESH in services
|
||||
assert SERVICE_REMOVE_URL in services
|
||||
|
||||
|
||||
async def test_service_unregistration(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the adguard services be unregistered with unloading last entry."""
|
||||
with patch("homeassistant.components.adguard.PLATFORMS", []):
|
||||
await setup_integration(hass, mock_config_entry, aioclient_mock)
|
||||
|
||||
services = hass.services.async_services_for_domain(DOMAIN)
|
||||
assert len(services) == 5
|
||||
|
||||
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
services = hass.services.async_services_for_domain(DOMAIN)
|
||||
assert len(services) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("service", "mocked_requests", "service_call_data"),
|
||||
[
|
||||
(
|
||||
SERVICE_ADD_URL,
|
||||
[
|
||||
{
|
||||
"method": "post",
|
||||
"url": "https://127.0.0.1:3000/control/filtering/add_url",
|
||||
"json": {
|
||||
"whitelist": False,
|
||||
"name": "Example",
|
||||
"url": "https://example.com/1.txt",
|
||||
},
|
||||
}
|
||||
],
|
||||
{"name": "Example", "url": "https://example.com/1.txt"},
|
||||
),
|
||||
(
|
||||
SERVICE_DISABLE_URL,
|
||||
[
|
||||
{
|
||||
"method": "get",
|
||||
"url": "https://127.0.0.1:3000/control/filtering/status",
|
||||
"json": {
|
||||
"filters": [
|
||||
{
|
||||
"name": "Example",
|
||||
"url": "https://example.com/1.txt",
|
||||
}
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"method": "post",
|
||||
"url": "https://127.0.0.1:3000/control/filtering/set_url",
|
||||
"json": {
|
||||
"whitelist": False,
|
||||
"url": "https://example.com/1.txt",
|
||||
},
|
||||
},
|
||||
],
|
||||
{"url": "https://example.com/1.txt"},
|
||||
),
|
||||
(
|
||||
SERVICE_ENABLE_URL,
|
||||
[
|
||||
{
|
||||
"method": "get",
|
||||
"url": "https://127.0.0.1:3000/control/filtering/status",
|
||||
"json": {
|
||||
"filters": [
|
||||
{
|
||||
"name": "Example",
|
||||
"url": "https://example.com/1.txt",
|
||||
}
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"method": "post",
|
||||
"url": "https://127.0.0.1:3000/control/filtering/set_url",
|
||||
"json": {
|
||||
"whitelist": False,
|
||||
"url": "https://example.com/1.txt",
|
||||
},
|
||||
},
|
||||
],
|
||||
{"url": "https://example.com/1.txt"},
|
||||
),
|
||||
(
|
||||
SERVICE_REFRESH,
|
||||
[
|
||||
{
|
||||
"method": "post",
|
||||
"url": "https://127.0.0.1:3000/control/filtering/refresh?force=false",
|
||||
"json": {"whitelist": False},
|
||||
}
|
||||
],
|
||||
{"force": False},
|
||||
),
|
||||
(
|
||||
SERVICE_REMOVE_URL,
|
||||
[
|
||||
{
|
||||
"method": "post",
|
||||
"url": "https://127.0.0.1:3000/control/filtering/remove_url",
|
||||
"json": {
|
||||
"whitelist": False,
|
||||
"url": "https://example.com/1.txt",
|
||||
},
|
||||
}
|
||||
],
|
||||
{"url": "https://example.com/1.txt"},
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_service(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
service: str,
|
||||
mocked_requests: list[dict],
|
||||
service_call_data: dict,
|
||||
) -> None:
|
||||
"""Test the adguard services be unregistered with unloading last entry."""
|
||||
for mocked_request in mocked_requests:
|
||||
aioclient_mock.request(
|
||||
mocked_request["method"],
|
||||
mocked_request["url"],
|
||||
json=mocked_request["json"],
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
|
||||
with patch("homeassistant.components.adguard.PLATFORMS", []):
|
||||
await setup_integration(hass, mock_config_entry, aioclient_mock)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
service,
|
||||
service_call_data,
|
||||
blocking=True,
|
||||
)
|
||||
@@ -17,14 +17,8 @@ from tests.common import MockConfigEntry, snapshot_platform
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
async def test_update(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the adguard update platform."""
|
||||
def aioclient_mock_update_available(aioclient_mock: AiohttpClientMocker) -> None:
|
||||
"""Mock AdGuard Home update available response."""
|
||||
aioclient_mock.post(
|
||||
"https://127.0.0.1:3000/control/version.json",
|
||||
json={
|
||||
@@ -37,6 +31,17 @@ async def test_update(
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
|
||||
|
||||
async def test_update(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the adguard update platform."""
|
||||
aioclient_mock_update_available(aioclient_mock)
|
||||
|
||||
with patch("homeassistant.components.adguard.PLATFORMS", [Platform.UPDATE]):
|
||||
await setup_integration(hass, mock_config_entry, aioclient_mock)
|
||||
|
||||
@@ -67,17 +72,7 @@ async def test_update_install(
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the adguard update installation."""
|
||||
aioclient_mock.post(
|
||||
"https://127.0.0.1:3000/control/version.json",
|
||||
json={
|
||||
"new_version": "v0.107.59",
|
||||
"announcement": "AdGuard Home v0.107.59 is now available!",
|
||||
"announcement_url": "https://github.com/AdguardTeam/AdGuardHome/releases/tag/v0.107.59",
|
||||
"can_autoupdate": True,
|
||||
"disabled": False,
|
||||
},
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
aioclient_mock_update_available(aioclient_mock)
|
||||
aioclient_mock.post("https://127.0.0.1:3000/control/update")
|
||||
|
||||
with patch("homeassistant.components.adguard.PLATFORMS", [Platform.UPDATE]):
|
||||
@@ -104,17 +99,7 @@ async def test_update_install_failed(
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the adguard update install failed."""
|
||||
aioclient_mock.post(
|
||||
"https://127.0.0.1:3000/control/version.json",
|
||||
json={
|
||||
"new_version": "v0.107.59",
|
||||
"announcement": "AdGuard Home v0.107.59 is now available!",
|
||||
"announcement_url": "https://github.com/AdguardTeam/AdGuardHome/releases/tag/v0.107.59",
|
||||
"can_autoupdate": True,
|
||||
"disabled": False,
|
||||
},
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
aioclient_mock_update_available(aioclient_mock)
|
||||
aioclient_mock.post(
|
||||
"https://127.0.0.1:3000/control/update", exc=AdGuardHomeError("boom")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user