test: consolidate repetitive cases across the suite
This commit is contained in:
1 parent
c406024b59
commit
6eccc2859a
31 files changed
+745
-1315
No files matched your search
@@ -42,11 +42,26 @@ def test_brave_with_api_key_remains_concurrency_safe():
|
||||
assert tool.concurrency_safe is True
|
||||
|
||||
|
||||
def test_brave_without_api_key_is_treated_as_duckduckgo_for_concurrency(monkeypatch):
|
||||
monkeypatch.delenv("BRAVE_API_KEY", raising=False)
|
||||
tool = _tool(provider="brave", api_key="")
|
||||
assert tool.exclusive is True
|
||||
assert tool.concurrency_safe is False
|
||||
@pytest.mark.parametrize(
|
||||
"env_key, expected_exclusive, expected_safe, provider",
|
||||
[
|
||||
pytest.param("BRAVE_API_KEY", True, False, "brave", id="brave-fallback"),
|
||||
pytest.param("KEENABLE_API_KEY", False, True, "keenable", id="keenable"),
|
||||
pytest.param("SERPER_API_KEY", True, False, "serper", id="serper-fallback"),
|
||||
pytest.param("ANYSEARCH_API_KEY", False, True, "anysearch", id="anysearch"),
|
||||
],
|
||||
)
|
||||
def test_search_concurrency_without_api_key(
|
||||
monkeypatch,
|
||||
env_key,
|
||||
expected_exclusive,
|
||||
expected_safe,
|
||||
provider,
|
||||
):
|
||||
monkeypatch.delenv(env_key, raising=False)
|
||||
tool = _tool(provider=provider, api_key="")
|
||||
assert tool.exclusive is expected_exclusive
|
||||
assert tool.concurrency_safe is expected_safe
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -132,13 +147,6 @@ async def test_tavily_search(monkeypatch):
|
||||
assert "https://openclaw.io" in result
|
||||
|
||||
|
||||
def test_keenable_without_api_key_is_concurrency_safe(monkeypatch):
|
||||
monkeypatch.delenv("KEENABLE_API_KEY", raising=False)
|
||||
tool = _tool(provider="keenable", api_key="")
|
||||
assert tool.exclusive is False
|
||||
assert tool.concurrency_safe is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_keenable_search(monkeypatch):
|
||||
async def mock_post(self, url, **kw):
|
||||
@@ -202,14 +210,6 @@ async def test_keenable_search_http_error(monkeypatch):
|
||||
assert "Error: Keenable search failed (401)" in result
|
||||
|
||||
|
||||
def test_serper_without_api_key_is_treated_as_duckduckgo(monkeypatch):
|
||||
# Serper requires a key; without one we fall back to DuckDuckGo for concurrency.
|
||||
monkeypatch.delenv("SERPER_API_KEY", raising=False)
|
||||
tool = _tool(provider="serper", api_key="")
|
||||
assert tool.exclusive is True
|
||||
assert tool.concurrency_safe is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_serper_search(monkeypatch):
|
||||
async def mock_post(self, url, **kw):
|
||||
@@ -287,15 +287,6 @@ async def test_serper_search_rate_limited(monkeypatch):
|
||||
assert is_tool_error_result(result)
|
||||
|
||||
|
||||
def test_anysearch_remains_concurrency_safe_without_api_key(monkeypatch):
|
||||
# Unlike keyed providers, AnySearch works without a key (anonymous quota),
|
||||
# so it must never be treated as exclusive/serialized.
|
||||
monkeypatch.delenv("ANYSEARCH_API_KEY", raising=False)
|
||||
tool = _tool(provider="anysearch", api_key="")
|
||||
assert tool.exclusive is False
|
||||
assert tool.concurrency_safe is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_anysearch_search(monkeypatch):
|
||||
async def mock_post(self, url, **kw):
|
||||
@@ -575,7 +566,15 @@ async def test_duckduckgo_search_passes_proxy(monkeypatch):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_brave_fallback_to_duckduckgo_when_no_key(monkeypatch):
|
||||
@pytest.mark.parametrize(
|
||||
"env_key, provider",
|
||||
[
|
||||
pytest.param("BRAVE_API_KEY", "brave", id="brave_fallback_to_duckduckgo_when_no_key"),
|
||||
pytest.param("KAGI_API_KEY", "kagi", id="kagi_fallback_to_duckduckgo_when_no_key"),
|
||||
pytest.param("EXA_API_KEY", "exa", id="exa_fallback_to_duckduckgo_when_no_key"),
|
||||
],
|
||||
)
|
||||
async def test_provider_falls_back_to_duckduckgo_without_key(monkeypatch, env_key, provider):
|
||||
class MockDDGS:
|
||||
def __init__(self, **kw):
|
||||
pass
|
||||
@@ -584,9 +583,9 @@ async def test_brave_fallback_to_duckduckgo_when_no_key(monkeypatch):
|
||||
return [{"title": "Fallback", "href": "https://ddg.example", "body": "DuckDuckGo fallback"}]
|
||||
|
||||
monkeypatch.setattr("ddgs.DDGS", MockDDGS)
|
||||
monkeypatch.delenv("BRAVE_API_KEY", raising=False)
|
||||
monkeypatch.delenv(env_key, raising=False)
|
||||
|
||||
tool = _tool(provider="brave", api_key="")
|
||||
tool = _tool(provider=provider, api_key="")
|
||||
result = await tool.execute(query="test")
|
||||
assert "Fallback" in result
|
||||
|
||||
@@ -768,40 +767,6 @@ async def test_jina_422_falls_back_to_duckduckgo(monkeypatch):
|
||||
assert "DuckDuckGo fallback" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_kagi_fallback_to_duckduckgo_when_no_key(monkeypatch):
|
||||
class MockDDGS:
|
||||
def __init__(self, **kw):
|
||||
pass
|
||||
|
||||
def text(self, query, max_results=5):
|
||||
return [{"title": "Fallback", "href": "https://ddg.example", "body": "DuckDuckGo fallback"}]
|
||||
|
||||
monkeypatch.setattr("ddgs.DDGS", MockDDGS)
|
||||
monkeypatch.delenv("KAGI_API_KEY", raising=False)
|
||||
|
||||
tool = _tool(provider="kagi", api_key="")
|
||||
result = await tool.execute(query="test")
|
||||
assert "Fallback" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_exa_fallback_to_duckduckgo_when_no_key(monkeypatch):
|
||||
class MockDDGS:
|
||||
def __init__(self, **kw):
|
||||
pass
|
||||
|
||||
def text(self, query, max_results=5):
|
||||
return [{"title": "Fallback", "href": "https://ddg.example", "body": "DuckDuckGo fallback"}]
|
||||
|
||||
monkeypatch.setattr("ddgs.DDGS", MockDDGS)
|
||||
monkeypatch.delenv("EXA_API_KEY", raising=False)
|
||||
|
||||
tool = _tool(provider="exa", api_key="")
|
||||
result = await tool.execute(query="test")
|
||||
assert "Fallback" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_jina_search_uses_path_encoded_query(monkeypatch):
|
||||
calls = {}
|
||||
|
||||
Reference in new issue
Block a user