Skip to content

Bulk asynchronous downloader for multiple file hosts

test: update for max invalid responses (flaresolverr)

NTFSvolume7291f2e1b3ab
diff --git a/cyberdrop_dl/clients/flaresolverr.py b/cyberdrop_dl/clients/flaresolverr.py
index bc1a85d04..03cf5670a 100644
--- a/cyberdrop_dl/clients/flaresolverr.py
+++ b/cyberdrop_dl/clients/flaresolverr.py
@@ -8,7 +8,7 @@ import time
from contextvars import ContextVar
from enum import StrEnum
from http.cookies import SimpleCookie
-from typing import TYPE_CHECKING, Any, Literal, Self, TypedDict, Unpack
+from typing import TYPE_CHECKING, Any, ClassVar, Literal, Self, TypedDict, Unpack
import aiohttp
from multidict import CIMultiDict, CIMultiDictProxy
@@ -178,6 +178,8 @@ class Limiter:
class Client:
"""Class that handles communication with Flaresolverr."""
+ MAX_INVALID_RESPONSES: ClassVar[int] = 5
+
def __init__(self, http: aiohttp.ClientSession, config: Config) -> None:
self.http: aiohttp.ClientSession = http
self.config: Config = config
@@ -218,8 +220,8 @@ class Client:
raise
except _InvalidResponseError:
self._invalid_responses += 1
- if self._invalid_responses > (max_wrong := 5):
- self.disable(f"Too many invalid/missing solutions [{max_wrong}+]")
+ if self._invalid_responses > self.MAX_INVALID_RESPONSES:
+ self.disable(f"Too many invalid/missing solutions [{self.MAX_INVALID_RESPONSES}+]")
raise
except Exception:
self.disable()
diff --git a/tests/test_flaresolverr.py b/tests/test_flaresolverr.py
index c36c11ae7..f1b962e21 100644
--- a/tests/test_flaresolverr.py
+++ b/tests/test_flaresolverr.py
@@ -200,8 +200,10 @@ async def test_request_error_response(
async with aiohttp.ClientSession() as session:
client = Client(session, _config(proxy=False, use_session=False))
monkeypatch.setattr(client, "_request", fake_request)
- with pytest.raises(expected_error):
- await client.request(AbsoluteHttpURL("https://example.com"))
+ for _ in range(client.MAX_INVALID_RESPONSES + 1):
+ assert client.is_down is False
+ with pytest.raises(expected_error):
+ await client.request(AbsoluteHttpURL("https://example.com"))
assert client.is_down is disabled