litellm/tests/search_tests/test_linkup_search.py
yuneng-jiang 6a0d03914c
test: drop the cwd-relative sys.path.insert calls from the test suite (#37802)
* test: drop the cwd-relative sys.path.insert calls from the test suite

TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.

Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.

Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.

* test: drop the duplicate imports the sys.path sweep exposed to F811

* test(pre-call-utils): restore the os import the new bedrock tests need
2026-08-22 09:25:58 -07:00

118 lines
4.1 KiB
Python

"""
Tests for Linkup Search API integration.
"""
import os
import pytest
from unittest.mock import Mock, patch
import litellm
from tests.search_tests.base_search_unit_tests import BaseSearchTest
@pytest.mark.skip(reason="Local only tested search providers")
class TestLinkupSearch(BaseSearchTest):
"""
E2E tests for Linkup Search functionality that make real API calls.
Inherits from BaseSearchTest to run standard search tests.
"""
def get_search_provider(self) -> str:
"""
Return search_provider for Linkup Search.
"""
return "linkup"
class TestLinkupSearchTransformation:
"""
Unit tests for Linkup Search request/response transformation with mocked responses.
"""
def test_linkup_search_request_transformation(self):
"""
Test that validates the Linkup search request is correctly transformed from
unified params to Linkup API format.
"""
mock_response = Mock()
mock_response.status_code = 200
mock_response.json.return_value = {
"results": [
{
"type": "text",
"name": "Test Title",
"url": "https://example.com",
"content": "Test content",
}
]
}
with patch.dict(os.environ, {"LINKUP_API_KEY": "test-api-key"}):
with patch(
"litellm.llms.custom_httpx.http_handler.HTTPHandler.post",
return_value=mock_response,
) as mock_post:
litellm.search(
query="test query",
search_provider="linkup",
max_results=10,
search_domain_filter=["arxiv.org", "nature.com"],
)
assert mock_post.called
call_kwargs = mock_post.call_args.kwargs
request_body = call_kwargs.get("json")
# Verify request transformation
assert request_body is not None
assert request_body["q"] == "test query"
assert request_body["maxResults"] == 10
assert request_body["depth"] == "standard"
assert request_body["outputType"] == "searchResults"
assert request_body["includeDomains"] == ["arxiv.org", "nature.com"]
def test_linkup_search_response_transformation(self):
"""
Test that validates the Linkup API response is correctly transformed to
the unified SearchResponse format.
"""
mock_response = Mock()
mock_response.status_code = 200
mock_response.json.return_value = {
"results": [
{
"type": "text",
"name": "Microsoft 2024 Annual Report",
"url": "https://www.microsoft.com/investor/reports/ar24/index.html",
"content": "Highlights from fiscal year 2024: Microsoft Cloud revenue increased 23% to $137.4 billion.",
},
{
"type": "text",
"name": "Another Result",
"url": "https://example.com/page",
"content": "Some other content",
},
]
}
with patch.dict(os.environ, {"LINKUP_API_KEY": "test-api-key"}):
with patch(
"litellm.llms.custom_httpx.http_handler.HTTPHandler.post",
return_value=mock_response,
):
response = litellm.search(
query="Microsoft revenue", search_provider="linkup"
)
# Verify response transformation
assert response.object == "search"
assert len(response.results) == 2
first_result = response.results[0]
assert first_result.title == "Microsoft 2024 Annual Report"
assert (
first_result.url
== "https://www.microsoft.com/investor/reports/ar24/index.html"
)
assert "Microsoft Cloud revenue" in first_result.snippet