53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
"""Tests for web_scrape tool (FastMCP)."""
|
|
import pytest
|
|
|
|
from fastmcp import FastMCP
|
|
from aden_tools.tools.web_scrape_tool import register_tools
|
|
|
|
|
|
@pytest.fixture
|
|
def web_scrape_fn(mcp: FastMCP):
|
|
"""Register and return the web_scrape tool function."""
|
|
register_tools(mcp)
|
|
return mcp._tool_manager._tools["web_scrape"].fn
|
|
|
|
|
|
class TestWebScrapeTool:
|
|
"""Tests for web_scrape tool."""
|
|
|
|
def test_url_auto_prefixed_with_https(self, web_scrape_fn):
|
|
"""URLs without scheme get https:// prefix."""
|
|
# This will fail to connect, but we can verify the behavior
|
|
result = web_scrape_fn(url="example.com")
|
|
# Should either succeed or have a network error (not a validation error)
|
|
assert isinstance(result, dict)
|
|
|
|
def test_max_length_clamped_low(self, web_scrape_fn):
|
|
"""max_length below 1000 is clamped to 1000."""
|
|
# Test with a very low max_length - implementation clamps to 1000
|
|
result = web_scrape_fn(url="https://example.com", max_length=500)
|
|
# Should not error due to invalid max_length
|
|
assert isinstance(result, dict)
|
|
|
|
def test_max_length_clamped_high(self, web_scrape_fn):
|
|
"""max_length above 500000 is clamped to 500000."""
|
|
# Test with a very high max_length - implementation clamps to 500000
|
|
result = web_scrape_fn(url="https://example.com", max_length=600000)
|
|
# Should not error due to invalid max_length
|
|
assert isinstance(result, dict)
|
|
|
|
def test_valid_max_length_accepted(self, web_scrape_fn):
|
|
"""Valid max_length values are accepted."""
|
|
result = web_scrape_fn(url="https://example.com", max_length=10000)
|
|
assert isinstance(result, dict)
|
|
|
|
def test_include_links_option(self, web_scrape_fn):
|
|
"""include_links parameter is accepted."""
|
|
result = web_scrape_fn(url="https://example.com", include_links=True)
|
|
assert isinstance(result, dict)
|
|
|
|
def test_selector_option(self, web_scrape_fn):
|
|
"""selector parameter is accepted."""
|
|
result = web_scrape_fn(url="https://example.com", selector=".content")
|
|
assert isinstance(result, dict)
|