Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

search test fix credits

Ishaan Jaffer434149550834
diff --git a/tests/search_tests/test_dataforseo_search.py b/tests/search_tests/test_dataforseo_search.py
index 59955323908..364fb141d48 100644
--- a/tests/search_tests/test_dataforseo_search.py
+++ b/tests/search_tests/test_dataforseo_search.py
@@ -1,26 +1,52 @@
"""
Unit tests for DataForSEO Search functionality.
-
-These tests verify that the DataForSEO search provider integration works correctly
-with LiteLLM's unified search interface.
"""
import sys
import os
+import pytest
+from unittest.mock import AsyncMock, MagicMock, patch
-# Add the parent directory to the path so we can import litellm
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
-from tests.search_tests.base_search_unit_tests import BaseSearchTest
+import litellm
+from litellm.llms.base_llm.search.transformation import SearchResponse, SearchResult
-class TestDataForSEOSearch(BaseSearchTest):
+async def test_dataforseo_search_basic():
"""
- Test suite for DataForSEO search provider.
- Inherits all test cases from BaseSearchTest.
+ Test DataForSEO search with mocked network response.
"""
-
- def get_search_provider(self) -> str:
- """Return the search provider name for DataForSEO."""
- return "dataforseo"
-
+ os.environ["DATAFORSEO_LOGIN"] = "test_login"
+ os.environ["DATAFORSEO_PASSWORD"] = "test_password"
+
+ mock_response = SearchResponse(
+ object="search",
+ results=[
+ SearchResult(
+ title="Latest AI Developments in 2025",
+ url="https://example.com/ai-news",
+ snippet="Recent advances in artificial intelligence have shown remarkable progress in machine learning and neural networks."
+ ),
+ SearchResult(
+ title="AI Research Breakthroughs",
+ url="https://example.com/ai-research",
+ snippet="Scientists announce breakthrough in AI technology with new models achieving unprecedented accuracy."
+ )
+ ]
+ )
+
+ with patch("litellm.llms.custom_httpx.llm_http_handler.BaseLLMHTTPHandler.async_search", new_callable=AsyncMock) as mock_search:
+ mock_search.return_value = mock_response
+
+ response = await litellm.asearch(
+ query="latest developments in AI",
+ search_provider="dataforseo",
+ )
+
+ assert response.object == "search"
+ assert len(response.results) == 2
+ assert response.results[0].title == "Latest AI Developments in 2025"
+ assert response.results[0].url == "https://example.com/ai-news"
+ assert len(response.results[0].snippet) > 0