77from thordata_langchain_tools import (
88 ThordataSerpTool ,
99 ThordataScrapeTool ,
10- ThordataUniversalTool ,
10+ ThordataMarkdownTool ,
1111 ThordataProxyTool ,
12+ ThordataAccountTool ,
1213)
1314
1415
@@ -36,7 +37,7 @@ def test_run_success(self, mock_client_class):
3637 """Test successful SERP search."""
3738 # Setup mock
3839 mock_client = MagicMock ()
39- mock_client .serp_search .return_value = {
40+ mock_client .serp_search_advanced .return_value = {
4041 "organic" : [{"title" : "Test Result" , "link" : "https://example.com" }]
4142 }
4243 mock_client_class .return_value = mock_client
@@ -48,13 +49,13 @@ def test_run_success(self, mock_client_class):
4849 # Verify
4950 assert "organic" in result
5051 assert len (result ["organic" ]) == 1
51- mock_client .serp_search .assert_called_once ()
52+ mock_client .serp_search_advanced .assert_called_once ()
5253
5354 @patch ("thordata_langchain_tools.serp_tool.ThordataClient" )
5455 def test_run_error_handling (self , mock_client_class ):
5556 """Test error handling in SERP search."""
5657 mock_client = MagicMock ()
57- mock_client .serp_search .side_effect = Exception ("API Error" )
58+ mock_client .serp_search_advanced .side_effect = Exception ("API Error" )
5859 mock_client_class .return_value = mock_client
5960
6061 tool = ThordataSerpTool ()
@@ -80,20 +81,20 @@ def test_tool_description(self):
8081 def test_run_success (self , mock_client_class ):
8182 """Test successful scrape."""
8283 mock_client = MagicMock ()
83- mock_client .universal_scrape .return_value = "<html><body>Test</body></html>"
84+ mock_client .universal . scrape .return_value = "<html><body>Test</body></html>"
8485 mock_client_class .return_value = mock_client
8586
8687 tool = ThordataScrapeTool ()
8788 result = tool ._run (url = "https://example.com" , js_render = False , max_length = 1000 )
8889
8990 assert "html" in result .lower ()
90- mock_client .universal_scrape .assert_called_once ()
91+ mock_client .universal . scrape .assert_called_once ()
9192
9293 @patch ("thordata_langchain_tools.scrape_tool.ThordataClient" )
9394 def test_run_truncates_long_content (self , mock_client_class ):
9495 """Test that long content is truncated."""
9596 mock_client = MagicMock ()
96- mock_client .universal_scrape .return_value = "x" * 100000
97+ mock_client .universal . scrape .return_value = "x" * 100000
9798 mock_client_class .return_value = mock_client
9899
99100 tool = ThordataScrapeTool ()
@@ -103,46 +104,31 @@ def test_run_truncates_long_content(self, mock_client_class):
103104 assert "truncated" in result .lower ()
104105
105106
106- class TestThordataUniversalTool :
107- """Tests for ThordataUniversalTool ."""
107+ class TestThordataMarkdownTool :
108+ """Tests for ThordataMarkdownTool ."""
108109
109110 def test_tool_name (self ):
110111 """Test tool has correct name."""
111- tool = ThordataUniversalTool ()
112- assert tool .name == "thordata_universal_scrape "
112+ tool = ThordataMarkdownTool ()
113+ assert tool .name == "thordata_fetch_markdown "
113114
114115 def test_tool_description (self ):
115116 """Test tool has description."""
116- tool = ThordataUniversalTool ()
117- assert (
118- "scrape" in tool .description .lower ()
119- or "scraping" in tool .description .lower ()
120- )
121-
122- @patch ("thordata_langchain_tools.universal_tool.ThordataClient" )
123- def test_run_with_js_render (self , mock_client_class ):
124- """Test scrape with JS rendering."""
117+ tool = ThordataMarkdownTool ()
118+ assert "markdown" in tool .description .lower ()
119+
120+ @patch ("thordata_langchain_tools.markdown_tool.ThordataClient" )
121+ def test_run_success (self , mock_client_class ):
122+ """Test successful markdown conversion."""
125123 mock_client = MagicMock ()
126- mock_client .universal_scrape . return_value = "<html>Rendered </html>"
124+ mock_client .universal . scrape . return_value = "<html><body>Test</body> </html>"
127125 mock_client_class .return_value = mock_client
128126
129- tool = ThordataUniversalTool ()
130- result = tool ._run (
131- url = "https://example.com" ,
132- js_render = True ,
133- output_format = "html" ,
134- country = "us" ,
135- wait_for = ".content" ,
136- )
127+ tool = ThordataMarkdownTool ()
128+ result = tool ._run (url = "https://example.com" , js_render = False , max_chars = 1000 )
137129
138- assert "html" in result .lower ()
139- mock_client .universal_scrape .assert_called_once_with (
140- url = "https://example.com" ,
141- js_render = True ,
142- output_format = "html" ,
143- country = "us" ,
144- wait_for = ".content" ,
145- )
130+ assert isinstance (result , str )
131+ assert len (result ) > 0
146132
147133
148134class TestThordataProxyTool :
@@ -173,3 +159,31 @@ def test_run_basic_request(self, mock_client_class):
173159 result = tool ._run (url = "https://httpbin.org/ip" )
174160
175161 assert "1.2.3.4" in result
162+
163+
164+ class TestThordataAccountTool :
165+ """Tests for ThordataAccountTool."""
166+
167+ def test_tool_name (self ):
168+ """Test tool has correct name."""
169+ tool = ThordataAccountTool ()
170+ assert tool .name == "thordata_account_info"
171+
172+ def test_tool_description (self ):
173+ """Test tool has description."""
174+ tool = ThordataAccountTool ()
175+ assert "account" in tool .description .lower ()
176+
177+ @patch ("thordata_langchain_tools.account_tool.ThordataClient" )
178+ def test_run_success (self , mock_client_class ):
179+ """Test successful account info retrieval."""
180+ mock_client = MagicMock ()
181+ mock_client .get_traffic_balance .return_value = 1000.0
182+ mock_client .account .get_usage_statistics .return_value = {"total" : 500 }
183+ mock_client_class .return_value = mock_client
184+
185+ tool = ThordataAccountTool ()
186+ result = tool ._run ()
187+
188+ assert "traffic_balance" in result
189+ assert result ["traffic_balance" ] == 1000.0
0 commit comments