@@ -35,19 +35,22 @@ def tool_invoke_params_example(self) -> dict:
35
35
"website_url" : "https://example.com" ,
36
36
}
37
37
38
+
39
+ class TestSmartScraperToolCustom :
38
40
def test_invoke_with_html (self ):
39
41
"""Test invoking the tool with HTML content."""
40
- tool = self .tool_constructor (** self .tool_constructor_params )
41
- result = tool .invoke (
42
- {
43
- "user_prompt" : "Extract the main heading" ,
44
- "website_url" : "https://example.com" ,
45
- "website_html" : "<html><body><h1>Test</h1></body></html>" ,
46
- }
47
- )
48
- assert isinstance (result , dict )
49
- assert "main_heading" in result
50
- assert result ["main_heading" ] == "Test"
42
+ with patch ("langchain_scrapegraph.tools.smartscraper.Client" , MockClient ):
43
+ tool = MockSmartScraperTool (api_key = "sgai-test-api-key" )
44
+ result = tool .invoke (
45
+ {
46
+ "user_prompt" : "Extract the main heading" ,
47
+ "website_url" : "https://example.com" ,
48
+ "website_html" : "<html><body><h1>Test</h1></body></html>" ,
49
+ }
50
+ )
51
+ assert isinstance (result , dict )
52
+ assert "main_heading" in result
53
+ assert result ["main_heading" ] == "Test"
51
54
52
55
53
56
class TestSearchScraperToolUnit (ToolsUnitTests ):
@@ -66,6 +69,8 @@ def tool_invoke_params_example(self) -> dict:
66
69
"user_prompt" : "What are the key features of Product X?" ,
67
70
}
68
71
72
+
73
+ class TestSearchScraperToolCustom :
69
74
def test_invoke_with_schema (self ):
70
75
"""Test invoking the tool with a schema."""
71
76
from typing import List
@@ -77,14 +82,17 @@ class TestSchema(BaseModel):
77
82
features : List [dict ] = Field (description = "List of features" )
78
83
reference_urls : List [str ] = Field (description = "Reference URLs" )
79
84
80
- tool = self .tool_constructor (** self .tool_constructor_params )
81
- tool .llm_output_schema = TestSchema
82
- result = tool .invoke (self .tool_invoke_params_example )
83
- assert isinstance (result , dict )
84
- assert "product" in result
85
- assert "features" in result
86
- assert "reference_urls" in result
87
- assert isinstance (result ["reference_urls" ], list )
85
+ with patch ("langchain_scrapegraph.tools.searchscraper.Client" , MockClient ):
86
+ tool = MockSearchScraperTool (api_key = "sgai-test-api-key" )
87
+ tool .llm_output_schema = TestSchema
88
+ result = tool .invoke (
89
+ {"user_prompt" : "What are the key features of Product X?" }
90
+ )
91
+ assert isinstance (result , dict )
92
+ assert "product" in result
93
+ assert "features" in result
94
+ assert "reference_urls" in result
95
+ assert isinstance (result ["reference_urls" ], list )
88
96
89
97
90
98
class TestGetCreditsToolUnit (ToolsUnitTests ):
0 commit comments