feat: New Web search component (#8135)

* web search component

* update tests

* Update test_web_search.py

* [autofix.ci] apply automated fixes

* add timeout input, santitize query, type check

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Yuqi Tang <yuqi.tang@datastax.com>
This commit is contained in:
Edwin Jose 2025-05-20 15:08:37 -04:00 • committed by GitHub
commit dec42bf447
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 159 additions and 0 deletions

View file

@ -0,0 +1,42 @@
import pytest
from langflow.components.data.web_search import WebSearchComponent
from langflow.schema import DataFrame
from tests.base import ComponentTestBaseWithoutClient
class TestWebSearchComponent(ComponentTestBaseWithoutClient):
@pytest.fixture
def component_class(self):
"""Return the component class to test."""
return WebSearchComponent
@pytest.fixture
def default_kwargs(self):
"""Return the default kwargs for the component."""
return {
"query": "OpenAI GPT-4",
}
@pytest.fixture
def file_names_mapping(self):
"""Return the file names mapping for the component."""
return []
async def test_invalid_url_handling(self):
# Create a test instance of the component
component = WebSearchComponent()
# Set an invalid URL
invalid_url = "htp://invalid-url"
# Ensure the URL is invalid
with pytest.raises(ValueError, match="Invalid URL"):
component.ensure_url(invalid_url)
def test_successful_web_search(self):
component = WebSearchComponent()
component.query = "OpenAI GPT-4"
result = component.perform_search()
assert isinstance(result, DataFrame)
assert not result.empty