@@ -35,19 +35,22 @@ def tool_invoke_params_example(self) -> dict:
3535 "website_url" : "https://example.com" ,
3636 }
3737
38+
39+ class TestSmartScraperToolCustom :
3840 def test_invoke_with_html (self ):
3941 """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"
5154
5255
5356class TestSearchScraperToolUnit (ToolsUnitTests ):
@@ -66,6 +69,8 @@ def tool_invoke_params_example(self) -> dict:
6669 "user_prompt" : "What are the key features of Product X?" ,
6770 }
6871
72+
73+ class TestSearchScraperToolCustom :
6974 def test_invoke_with_schema (self ):
7075 """Test invoking the tool with a schema."""
7176 from typing import List
@@ -77,14 +82,17 @@ class TestSchema(BaseModel):
7782 features : List [dict ] = Field (description = "List of features" )
7883 reference_urls : List [str ] = Field (description = "Reference URLs" )
7984
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 )
8896
8997
9098class TestGetCreditsToolUnit (ToolsUnitTests ):
0 commit comments