Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ def __init__(

def get_search_url(self, engine: str, query: str) -> str:
if engine == "yandex":
return f"https://yandex.com/search/?text=${query}"
return f"https://yandex.com/search/?text={query}"
if engine == "bing":
return f"https://www.bing.com/search?q=${query}"
return f"https://www.google.com/search?q=${query}"
return f"https://www.bing.com/search?q={query}"
return f"https://www.google.com/search?q={query}"

def _run(
self,
Expand Down
54 changes: 54 additions & 0 deletions lib/crewai-tools/tests/tools/brightdata_serp_tool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,60 @@ def test_run_with_request_exception(self, mock_post):
result = self.tool._run(query="AI", search_engine="google")
self.assertIn("Error", result)

@patch.dict(
"os.environ",
{"BRIGHT_DATA_API_KEY": "test_api_key", "BRIGHT_DATA_ZONE": "test_zone"},
)
def test_get_search_url_google_no_dollar_prefix(self):
"""Test that Google search URL does not contain a '$' prefix before the query."""
tool = BrightDataSearchTool()
url = tool.get_search_url("google", "AI news")
self.assertEqual(url, "https://www.google.com/search?q=AI news")
self.assertNotIn("$", url)

@patch.dict(
"os.environ",
{"BRIGHT_DATA_API_KEY": "test_api_key", "BRIGHT_DATA_ZONE": "test_zone"},
)
def test_get_search_url_bing_no_dollar_prefix(self):
"""Test that Bing search URL does not contain a '$' prefix before the query."""
tool = BrightDataSearchTool()
url = tool.get_search_url("bing", "AI news")
self.assertEqual(url, "https://www.bing.com/search?q=AI news")
self.assertNotIn("$", url)

@patch.dict(
"os.environ",
{"BRIGHT_DATA_API_KEY": "test_api_key", "BRIGHT_DATA_ZONE": "test_zone"},
)
def test_get_search_url_yandex_no_dollar_prefix(self):
"""Test that Yandex search URL does not contain a '$' prefix before the query."""
tool = BrightDataSearchTool()
url = tool.get_search_url("yandex", "AI news")
self.assertEqual(url, "https://yandex.com/search/?text=AI news")
self.assertNotIn("$", url)

@patch.dict(
"os.environ",
{"BRIGHT_DATA_API_KEY": "test_api_key", "BRIGHT_DATA_ZONE": "test_zone"},
)
@patch("requests.post")
def test_run_search_url_no_dollar_prefix(self, mock_post):
"""Test that the full _run flow produces URLs without '$' prefix in the query."""
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.text = "mock response text"
mock_post.return_value = mock_response

tool = BrightDataSearchTool()
tool._run(query="test query", search_engine="google")

call_args = mock_post.call_args
request_body = call_args[1]["json"] if "json" in call_args[1] else call_args[0][1]
url_sent = request_body["url"]
self.assertNotIn("$", url_sent.split("?q=")[1])
self.assertIn("q=test%20query", url_sent)

def tearDown(self):
# Clean up env vars
pass
Expand Down
Loading