Skip to content

Commit 988355e

Browse files
authored
Add tests for the switch platform to the AdGuard Home integration (home-assistant#157105)
1 parent 7711eac commit 988355e

File tree

3 files changed

+472
-8
lines changed

3 files changed

+472
-8
lines changed

tests/components/adguard/conftest.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
from unittest.mock import AsyncMock
44

5-
from adguardhome.update import AdGuardHomeAvailableUpdate
5+
from adguardhome import AdGuardHome
6+
from adguardhome.filtering import AdGuardHomeFiltering
7+
from adguardhome.parental import AdGuardHomeParental
8+
from adguardhome.querylog import AdGuardHomeQueryLog
9+
from adguardhome.safebrowsing import AdGuardHomeSafeBrowsing
10+
from adguardhome.safesearch import AdGuardHomeSafeSearch
11+
from adguardhome.stats import AdGuardHomeStats
12+
from adguardhome.update import AdGuardHomeAvailableUpdate, AdGuardHomeUpdate
613
import pytest
714

815
from homeassistant.components.adguard import DOMAIN
@@ -38,7 +45,14 @@ def mock_config_entry() -> MockConfigEntry:
3845
@pytest.fixture
3946
async def mock_adguard() -> AsyncMock:
4047
"""Fixture for setting up the component."""
41-
adguard_mock = AsyncMock()
48+
adguard_mock = AsyncMock(spec=AdGuardHome)
49+
adguard_mock.filtering = AsyncMock(spec=AdGuardHomeFiltering)
50+
adguard_mock.parental = AsyncMock(spec=AdGuardHomeParental)
51+
adguard_mock.querylog = AsyncMock(spec=AdGuardHomeQueryLog)
52+
adguard_mock.safebrowsing = AsyncMock(spec=AdGuardHomeSafeBrowsing)
53+
adguard_mock.safesearch = AsyncMock(spec=AdGuardHomeSafeSearch)
54+
adguard_mock.stats = AsyncMock(spec=AdGuardHomeStats)
55+
adguard_mock.update = AsyncMock(spec=AdGuardHomeUpdate)
4256

4357
# static properties
4458
adguard_mock.host = "127.0.0.1"
@@ -48,6 +62,10 @@ async def mock_adguard() -> AsyncMock:
4862

4963
# async method mocks
5064
adguard_mock.version = AsyncMock(return_value="v0.107.50")
65+
adguard_mock.protection_enabled = AsyncMock(return_value=True)
66+
adguard_mock.parental.enabled = AsyncMock(return_value=True)
67+
adguard_mock.safesearch.enabled = AsyncMock(return_value=True)
68+
adguard_mock.safebrowsing.enabled = AsyncMock(return_value=True)
5169
adguard_mock.stats.dns_queries = AsyncMock(return_value=666)
5270
adguard_mock.stats.blocked_filtering = AsyncMock(return_value=1337)
5371
adguard_mock.stats.blocked_percentage = AsyncMock(return_value=200.75)
@@ -56,11 +74,8 @@ async def mock_adguard() -> AsyncMock:
5674
adguard_mock.stats.replaced_safesearch = AsyncMock(return_value=18)
5775
adguard_mock.stats.avg_processing_time = AsyncMock(return_value=31.41)
5876
adguard_mock.filtering.rules_count = AsyncMock(return_value=100)
59-
adguard_mock.filtering.add_url = AsyncMock()
60-
adguard_mock.filtering.remove_url = AsyncMock()
61-
adguard_mock.filtering.enable_url = AsyncMock()
62-
adguard_mock.filtering.disable_url = AsyncMock()
63-
adguard_mock.filtering.refresh = AsyncMock()
77+
adguard_mock.filtering.enabled = AsyncMock(return_value=True)
78+
adguard_mock.querylog.enabled = AsyncMock(return_value=True)
6479
adguard_mock.update.update_available = AsyncMock(
6580
return_value=AdGuardHomeAvailableUpdate(
6681
new_version="v0.107.59",
@@ -70,6 +85,5 @@ async def mock_adguard() -> AsyncMock:
7085
disabled=False,
7186
)
7287
)
73-
adguard_mock.update.begin_update = AsyncMock()
7488

7589
return adguard_mock
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
# serializer version: 1
2+
# name: test_switch[switch.adguard_home_filtering-entry]
3+
EntityRegistryEntrySnapshot({
4+
'aliases': set({
5+
}),
6+
'area_id': None,
7+
'capabilities': None,
8+
'config_entry_id': <ANY>,
9+
'config_subentry_id': <ANY>,
10+
'device_class': None,
11+
'device_id': <ANY>,
12+
'disabled_by': None,
13+
'domain': 'switch',
14+
'entity_category': None,
15+
'entity_id': 'switch.adguard_home_filtering',
16+
'has_entity_name': True,
17+
'hidden_by': None,
18+
'icon': None,
19+
'id': <ANY>,
20+
'labels': set({
21+
}),
22+
'name': None,
23+
'options': dict({
24+
}),
25+
'original_device_class': None,
26+
'original_icon': None,
27+
'original_name': 'Filtering',
28+
'platform': 'adguard',
29+
'previous_unique_id': None,
30+
'suggested_object_id': None,
31+
'supported_features': 0,
32+
'translation_key': 'filtering',
33+
'unique_id': 'adguard_127.0.0.1_3000_switch_filtering',
34+
'unit_of_measurement': None,
35+
})
36+
# ---
37+
# name: test_switch[switch.adguard_home_filtering-state]
38+
StateSnapshot({
39+
'attributes': ReadOnlyDict({
40+
'friendly_name': 'AdGuard Home Filtering',
41+
}),
42+
'context': <ANY>,
43+
'entity_id': 'switch.adguard_home_filtering',
44+
'last_changed': <ANY>,
45+
'last_reported': <ANY>,
46+
'last_updated': <ANY>,
47+
'state': 'on',
48+
})
49+
# ---
50+
# name: test_switch[switch.adguard_home_parental_control-entry]
51+
EntityRegistryEntrySnapshot({
52+
'aliases': set({
53+
}),
54+
'area_id': None,
55+
'capabilities': None,
56+
'config_entry_id': <ANY>,
57+
'config_subentry_id': <ANY>,
58+
'device_class': None,
59+
'device_id': <ANY>,
60+
'disabled_by': None,
61+
'domain': 'switch',
62+
'entity_category': None,
63+
'entity_id': 'switch.adguard_home_parental_control',
64+
'has_entity_name': True,
65+
'hidden_by': None,
66+
'icon': None,
67+
'id': <ANY>,
68+
'labels': set({
69+
}),
70+
'name': None,
71+
'options': dict({
72+
}),
73+
'original_device_class': None,
74+
'original_icon': None,
75+
'original_name': 'Parental control',
76+
'platform': 'adguard',
77+
'previous_unique_id': None,
78+
'suggested_object_id': None,
79+
'supported_features': 0,
80+
'translation_key': 'parental',
81+
'unique_id': 'adguard_127.0.0.1_3000_switch_parental',
82+
'unit_of_measurement': None,
83+
})
84+
# ---
85+
# name: test_switch[switch.adguard_home_parental_control-state]
86+
StateSnapshot({
87+
'attributes': ReadOnlyDict({
88+
'friendly_name': 'AdGuard Home Parental control',
89+
}),
90+
'context': <ANY>,
91+
'entity_id': 'switch.adguard_home_parental_control',
92+
'last_changed': <ANY>,
93+
'last_reported': <ANY>,
94+
'last_updated': <ANY>,
95+
'state': 'on',
96+
})
97+
# ---
98+
# name: test_switch[switch.adguard_home_protection-entry]
99+
EntityRegistryEntrySnapshot({
100+
'aliases': set({
101+
}),
102+
'area_id': None,
103+
'capabilities': None,
104+
'config_entry_id': <ANY>,
105+
'config_subentry_id': <ANY>,
106+
'device_class': None,
107+
'device_id': <ANY>,
108+
'disabled_by': None,
109+
'domain': 'switch',
110+
'entity_category': None,
111+
'entity_id': 'switch.adguard_home_protection',
112+
'has_entity_name': True,
113+
'hidden_by': None,
114+
'icon': None,
115+
'id': <ANY>,
116+
'labels': set({
117+
}),
118+
'name': None,
119+
'options': dict({
120+
}),
121+
'original_device_class': None,
122+
'original_icon': None,
123+
'original_name': 'Protection',
124+
'platform': 'adguard',
125+
'previous_unique_id': None,
126+
'suggested_object_id': None,
127+
'supported_features': 0,
128+
'translation_key': 'protection',
129+
'unique_id': 'adguard_127.0.0.1_3000_switch_protection',
130+
'unit_of_measurement': None,
131+
})
132+
# ---
133+
# name: test_switch[switch.adguard_home_protection-state]
134+
StateSnapshot({
135+
'attributes': ReadOnlyDict({
136+
'friendly_name': 'AdGuard Home Protection',
137+
}),
138+
'context': <ANY>,
139+
'entity_id': 'switch.adguard_home_protection',
140+
'last_changed': <ANY>,
141+
'last_reported': <ANY>,
142+
'last_updated': <ANY>,
143+
'state': 'on',
144+
})
145+
# ---
146+
# name: test_switch[switch.adguard_home_query_log-entry]
147+
EntityRegistryEntrySnapshot({
148+
'aliases': set({
149+
}),
150+
'area_id': None,
151+
'capabilities': None,
152+
'config_entry_id': <ANY>,
153+
'config_subentry_id': <ANY>,
154+
'device_class': None,
155+
'device_id': <ANY>,
156+
'disabled_by': None,
157+
'domain': 'switch',
158+
'entity_category': None,
159+
'entity_id': 'switch.adguard_home_query_log',
160+
'has_entity_name': True,
161+
'hidden_by': None,
162+
'icon': None,
163+
'id': <ANY>,
164+
'labels': set({
165+
}),
166+
'name': None,
167+
'options': dict({
168+
}),
169+
'original_device_class': None,
170+
'original_icon': None,
171+
'original_name': 'Query log',
172+
'platform': 'adguard',
173+
'previous_unique_id': None,
174+
'suggested_object_id': None,
175+
'supported_features': 0,
176+
'translation_key': 'query_log',
177+
'unique_id': 'adguard_127.0.0.1_3000_switch_querylog',
178+
'unit_of_measurement': None,
179+
})
180+
# ---
181+
# name: test_switch[switch.adguard_home_query_log-state]
182+
StateSnapshot({
183+
'attributes': ReadOnlyDict({
184+
'friendly_name': 'AdGuard Home Query log',
185+
}),
186+
'context': <ANY>,
187+
'entity_id': 'switch.adguard_home_query_log',
188+
'last_changed': <ANY>,
189+
'last_reported': <ANY>,
190+
'last_updated': <ANY>,
191+
'state': 'on',
192+
})
193+
# ---
194+
# name: test_switch[switch.adguard_home_safe_browsing-entry]
195+
EntityRegistryEntrySnapshot({
196+
'aliases': set({
197+
}),
198+
'area_id': None,
199+
'capabilities': None,
200+
'config_entry_id': <ANY>,
201+
'config_subentry_id': <ANY>,
202+
'device_class': None,
203+
'device_id': <ANY>,
204+
'disabled_by': None,
205+
'domain': 'switch',
206+
'entity_category': None,
207+
'entity_id': 'switch.adguard_home_safe_browsing',
208+
'has_entity_name': True,
209+
'hidden_by': None,
210+
'icon': None,
211+
'id': <ANY>,
212+
'labels': set({
213+
}),
214+
'name': None,
215+
'options': dict({
216+
}),
217+
'original_device_class': None,
218+
'original_icon': None,
219+
'original_name': 'Safe browsing',
220+
'platform': 'adguard',
221+
'previous_unique_id': None,
222+
'suggested_object_id': None,
223+
'supported_features': 0,
224+
'translation_key': 'safe_browsing',
225+
'unique_id': 'adguard_127.0.0.1_3000_switch_safebrowsing',
226+
'unit_of_measurement': None,
227+
})
228+
# ---
229+
# name: test_switch[switch.adguard_home_safe_browsing-state]
230+
StateSnapshot({
231+
'attributes': ReadOnlyDict({
232+
'friendly_name': 'AdGuard Home Safe browsing',
233+
}),
234+
'context': <ANY>,
235+
'entity_id': 'switch.adguard_home_safe_browsing',
236+
'last_changed': <ANY>,
237+
'last_reported': <ANY>,
238+
'last_updated': <ANY>,
239+
'state': 'on',
240+
})
241+
# ---
242+
# name: test_switch[switch.adguard_home_safe_search-entry]
243+
EntityRegistryEntrySnapshot({
244+
'aliases': set({
245+
}),
246+
'area_id': None,
247+
'capabilities': None,
248+
'config_entry_id': <ANY>,
249+
'config_subentry_id': <ANY>,
250+
'device_class': None,
251+
'device_id': <ANY>,
252+
'disabled_by': None,
253+
'domain': 'switch',
254+
'entity_category': None,
255+
'entity_id': 'switch.adguard_home_safe_search',
256+
'has_entity_name': True,
257+
'hidden_by': None,
258+
'icon': None,
259+
'id': <ANY>,
260+
'labels': set({
261+
}),
262+
'name': None,
263+
'options': dict({
264+
}),
265+
'original_device_class': None,
266+
'original_icon': None,
267+
'original_name': 'Safe search',
268+
'platform': 'adguard',
269+
'previous_unique_id': None,
270+
'suggested_object_id': None,
271+
'supported_features': 0,
272+
'translation_key': 'safe_search',
273+
'unique_id': 'adguard_127.0.0.1_3000_switch_safesearch',
274+
'unit_of_measurement': None,
275+
})
276+
# ---
277+
# name: test_switch[switch.adguard_home_safe_search-state]
278+
StateSnapshot({
279+
'attributes': ReadOnlyDict({
280+
'friendly_name': 'AdGuard Home Safe search',
281+
}),
282+
'context': <ANY>,
283+
'entity_id': 'switch.adguard_home_safe_search',
284+
'last_changed': <ANY>,
285+
'last_reported': <ANY>,
286+
'last_updated': <ANY>,
287+
'state': 'on',
288+
})
289+
# ---

0 commit comments

Comments
 (0)