Skip to content

Commit 03055dd

Browse files
authored
Fix filter refresh handling (#258)
1 parent 40a0f05 commit 03055dd

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/adguardhome/filtering.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,24 @@ async def disable_url(self, url: str) -> None:
176176
"Failed disabling URL on AdGuard Home filter"
177177
) from exception
178178

179-
async def refresh(self, force=False) -> None:
179+
async def refresh(self, *, allowlist: bool = False, force: bool = False) -> None:
180180
"""Reload filtering subscriptions from URLs specified in AdGuard Home.
181181
182182
Args:
183183
force: Force the reload of all filter subscriptions.
184+
allowlist: True to update the allowlists, False for the blocklists.
184185
185186
Raises:
186187
AdGuardHomeError: Failed to refresh filter subscriptions.
187188
"""
188-
force = "true" if force else "false"
189+
force_value = "true" if force else "false"
189190

190191
try:
191192
await self._adguard.request(
192-
"filtering/refresh", method="POST", params={"force": force}
193+
"filtering/refresh",
194+
method="POST",
195+
json_data={"whitelist": allowlist},
196+
params={"force": force_value},
193197
)
194198
except AdGuardHomeError as exception:
195199
raise AdGuardHomeError(

tests/test_filtering.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,31 @@ async def response_handler(request):
334334
@pytest.mark.asyncio
335335
async def test_refresh(aresponses):
336336
"""Test enabling filter subscription in AdGuard Home filtering."""
337+
338+
async def response_handler_whitelist(request):
339+
"""Response handler for this test."""
340+
data = await request.json()
341+
assert data == {"whitelist": True}
342+
return aresponses.Response(status=200)
343+
344+
async def response_handler_blocklist(request):
345+
"""Response handler for this test."""
346+
data = await request.json()
347+
assert data == {"whitelist": False}
348+
return aresponses.Response(status=200)
349+
337350
aresponses.add(
338351
"example.com:3000",
339352
"/control/filtering/refresh?force=false",
340353
"POST",
341-
aresponses.Response(status=200, text="OK"),
354+
response_handler_blocklist,
355+
match_querystring=True,
356+
)
357+
aresponses.add(
358+
"example.com:3000",
359+
"/control/filtering/refresh?force=false",
360+
"POST",
361+
response_handler_whitelist,
342362
match_querystring=True,
343363
)
344364
aresponses.add(
@@ -358,7 +378,8 @@ async def test_refresh(aresponses):
358378

359379
async with aiohttp.ClientSession() as session:
360380
adguard = AdGuardHome("example.com", session=session)
361-
await adguard.filtering.refresh(False)
362-
await adguard.filtering.refresh(True)
381+
await adguard.filtering.refresh(force=False)
382+
await adguard.filtering.refresh(force=False, allowlist=True)
383+
await adguard.filtering.refresh(force=True)
363384
with pytest.raises(AdGuardHomeError):
364-
await adguard.filtering.refresh(False)
385+
await adguard.filtering.refresh(force=False)

0 commit comments

Comments
 (0)