test: deduplicate proxy value and construct tool via constructor
- Use a local variable for the proxy URL instead of hardcoding it twice - Pass proxy through the WebSearchTool constructor instead of mutating after instantiation (matches real usage path) - Add assertion that timeout is still forwarded correctly - Use generic mock data instead of test-specific strings
This commit is contained in:
@@ -369,21 +369,25 @@ async def test_duckduckgo_search(monkeypatch):
|
|||||||
async def test_duckduckgo_search_passes_proxy(monkeypatch):
|
async def test_duckduckgo_search_passes_proxy(monkeypatch):
|
||||||
"""DDGS client must receive the configured proxy so search works behind a proxy."""
|
"""DDGS client must receive the configured proxy so search works behind a proxy."""
|
||||||
captured: dict = {}
|
captured: dict = {}
|
||||||
|
proxy_url = "http://proxy.example:8080"
|
||||||
|
|
||||||
class ProxyCaptorDDGS:
|
class ProxyCaptorDDGS:
|
||||||
def __init__(self, **kw):
|
def __init__(self, **kw):
|
||||||
captured.update(kw)
|
captured.update(kw)
|
||||||
|
|
||||||
def text(self, query, max_results=5):
|
def text(self, query, max_results=5):
|
||||||
return [{"title": "Proxied", "href": "https://ddg.example", "body": "OK"}]
|
return [{"title": "Result", "href": "https://example.com", "body": "OK"}]
|
||||||
|
|
||||||
monkeypatch.setattr("ddgs.DDGS", ProxyCaptorDDGS)
|
monkeypatch.setattr("ddgs.DDGS", ProxyCaptorDDGS)
|
||||||
|
|
||||||
tool = _tool(provider="duckduckgo")
|
tool = WebSearchTool(
|
||||||
tool.proxy = "http://192.168.1.1:8080"
|
config=WebSearchConfig(provider="duckduckgo"),
|
||||||
result = await tool.execute(query="hello")
|
proxy=proxy_url,
|
||||||
assert captured.get("proxy") == "http://192.168.1.1:8080"
|
)
|
||||||
assert "Proxied" in result
|
result = await tool.execute(query="test")
|
||||||
|
assert captured["proxy"] == proxy_url
|
||||||
|
assert captured["timeout"] == 10
|
||||||
|
assert "Result" in result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|||||||
Reference in New Issue
Block a user