From 9c6eaf0bed161c84891bff1d97c76181047ad14c Mon Sep 17 00:00:00 2001 From: hyoukadev Date: Wed, 24 Jun 2026 10:32:16 +0800 Subject: [PATCH] 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 --- tests/tools/test_web_search_tool.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/tools/test_web_search_tool.py b/tests/tools/test_web_search_tool.py index 0caee43b8..60c26a511 100644 --- a/tests/tools/test_web_search_tool.py +++ b/tests/tools/test_web_search_tool.py @@ -369,21 +369,25 @@ async def test_duckduckgo_search(monkeypatch): async def test_duckduckgo_search_passes_proxy(monkeypatch): """DDGS client must receive the configured proxy so search works behind a proxy.""" captured: dict = {} + proxy_url = "http://proxy.example:8080" class ProxyCaptorDDGS: def __init__(self, **kw): captured.update(kw) 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) - tool = _tool(provider="duckduckgo") - tool.proxy = "http://192.168.1.1:8080" - result = await tool.execute(query="hello") - assert captured.get("proxy") == "http://192.168.1.1:8080" - assert "Proxied" in result + tool = WebSearchTool( + config=WebSearchConfig(provider="duckduckgo"), + proxy=proxy_url, + ) + result = await tool.execute(query="test") + assert captured["proxy"] == proxy_url + assert captured["timeout"] == 10 + assert "Result" in result @pytest.mark.asyncio