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:
parent
6c58c6efc3
commit
dec42bf447
3 changed files with 159 additions and 0 deletions
42
src/backend/tests/unit/components/data/test_web_search.py
Normal file
42
src/backend/tests/unit/components/data/test_web_search.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue