19
19
1. Loading a tool.
20
20
2. Loading a specific toolset.
21
21
3. Loading the default toolset (contains all tools).
22
- 4. Running a tool with no required auth, with auth provided.
23
- 5. Running a tool with required auth:
22
+ 4. Running a tool with
23
+ a. Missing params.
24
+ b. Wrong param type.
25
+ 5. Running a tool with no required auth, with auth provided.
26
+ 6. Running a tool with required auth:
24
27
a. No auth provided.
25
28
b. Wrong auth provided: The tool requires a different authentication
26
29
than the one provided.
27
30
c. Correct auth provided.
28
- 6 . Running a tool with a parameter that requires auth:
31
+ 7 . Running a tool with a parameter that requires auth:
29
32
a. No auth provided.
30
33
b. Correct auth provided.
31
34
c. Auth provided does not contain the required claim.
34
37
import pytest
35
38
import pytest_asyncio
36
39
from aiohttp import ClientResponseError
40
+ from pydantic import ValidationError
37
41
38
42
from toolbox_langchain_sdk .client import ToolboxClient
39
43
@@ -85,6 +89,18 @@ async def test_load_toolset_all(self, toolbox):
85
89
for tool in toolset :
86
90
assert tool .name in tool_names
87
91
92
+ @pytest .mark .asyncio
93
+ async def test_run_tool_missing_params (self , toolbox ):
94
+ tool = await toolbox .load_tool ("get-n-rows" )
95
+ with pytest .raises (ValidationError , match = "Field required" ):
96
+ await tool .ainvoke ({})
97
+
98
+ @pytest .mark .asyncio
99
+ async def test_run_tool_wrong_param_type (self , toolbox ):
100
+ tool = await toolbox .load_tool ("get-n-rows" )
101
+ with pytest .raises (ValidationError , match = "Input should be a valid string" ):
102
+ await tool .ainvoke ({"num_rows" : 2 })
103
+
88
104
##### Auth tests
89
105
@pytest .mark .asyncio
90
106
@pytest .mark .skip (reason = "b/389574566" )
@@ -93,7 +109,7 @@ async def test_run_tool_unauth_with_auth(self, toolbox, auth_token2):
93
109
tool = await toolbox .load_tool (
94
110
"get-row-by-id" , auth_tokens = {"my-test-auth" : lambda : auth_token2 }
95
111
)
96
- response = await tool .arun ({"id" : "2" })
112
+ response = await tool .ainvoke ({"id" : "2" })
97
113
assert "row2" in response ["result" ]
98
114
99
115
@pytest .mark .asyncio
@@ -103,7 +119,7 @@ async def test_run_tool_no_auth(self, toolbox):
103
119
"get-row-by-id-auth" ,
104
120
)
105
121
with pytest .raises (ClientResponseError , match = "401, message='Unauthorized'" ):
106
- await tool .arun ({"id" : "2" })
122
+ await tool .ainvoke ({"id" : "2" })
107
123
108
124
@pytest .mark .asyncio
109
125
async def test_run_tool_wrong_auth (self , toolbox , auth_token2 ):
@@ -114,7 +130,7 @@ async def test_run_tool_wrong_auth(self, toolbox, auth_token2):
114
130
)
115
131
# TODO: Fix error message (b/389577313)
116
132
with pytest .raises (ClientResponseError , match = "400, message='Bad Request'" ):
117
- await tool .arun ({"id" : "2" })
133
+ await tool .ainvoke ({"id" : "2" })
118
134
119
135
@pytest .mark .asyncio
120
136
async def test_run_tool_auth (self , toolbox , auth_token1 ):
@@ -123,23 +139,23 @@ async def test_run_tool_auth(self, toolbox, auth_token1):
123
139
tool = await toolbox .load_tool (
124
140
"get-row-by-id-auth" ,
125
141
)
126
- response = await tool .arun ({"id" : "2" })
142
+ response = await tool .ainvoke ({"id" : "2" })
127
143
assert "row2" in response ["result" ]
128
144
129
145
@pytest .mark .asyncio
130
146
async def test_run_tool_param_auth_no_auth (self , toolbox ):
131
147
"""Tests running a tool with a param requiring auth, without auth."""
132
148
tool = await toolbox .load_tool ("get-row-by-email-auth" )
133
149
with pytest .raises (PermissionError , match = "Login required" ):
134
- await tool .arun ({})
150
+ await tool .ainvoke ({})
135
151
136
152
@pytest .mark .asyncio
137
153
async def test_run_tool_param_auth (self , toolbox , auth_token1 ):
138
154
"""Tests running a tool with a param requiring auth, with correct auth."""
139
155
tool = await toolbox .load_tool (
140
156
"get-row-by-email-auth" , auth_tokens = {"my-test-auth" : lambda : auth_token1 }
141
157
)
142
- response = await tool .arun ({})
158
+ response = await tool .ainvoke ({})
143
159
result = response ["result" ]
144
160
assert "row4" in result
145
161
assert "row5" in result
@@ -152,4 +168,4 @@ async def test_run_tool_param_auth_no_field(self, toolbox, auth_token1):
152
168
"get-row-by-content-auth" , auth_tokens = {"my-test-auth" : lambda : auth_token1 }
153
169
)
154
170
with pytest .raises (ClientResponseError , match = "400, message='Bad Request'" ):
155
- await tool .arun ({})
171
+ await tool .ainvoke ({})
0 commit comments