11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
-
15
- """End-to-end tests for the toolbox SDK interacting with the toolbox server.
16
-
17
- This file covers the following test cases:
18
-
19
- 1. Loading a tool.
20
- 2. Loading a specific toolset.
21
- 3. Loading the default toolset (contains all tools).
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:
27
- a. No auth provided.
28
- b. Wrong auth provided: The tool requires a different authentication
29
- than the one provided.
30
- c. Correct auth provided.
31
- 7. Running a tool with a parameter that requires auth:
32
- a. No auth provided.
33
- b. Correct auth provided.
34
- c. Auth provided does not contain the required claim.
35
- 8. Bind params to a tool
36
- a. Static param
37
- b. Callable param value
38
- """
39
14
import pytest
40
15
import pytest_asyncio
41
16
@@ -56,6 +31,7 @@ async def toolbox(self):
56
31
57
32
@pytest_asyncio .fixture (scope = "function" )
58
33
async def get_n_rows_tool (self , toolbox : ToolboxClient ) -> ToolboxTool :
34
+ """Load a tool."""
59
35
tool = await toolbox .load_tool ("get-n-rows" )
60
36
assert tool .__name__ == "get-n-rows"
61
37
return tool
@@ -75,12 +51,14 @@ async def test_load_toolset_specific(
75
51
expected_length : int ,
76
52
expected_tools : list [str ],
77
53
):
54
+ """Load a specific toolset"""
78
55
toolset = await toolbox .load_toolset (toolset_name )
79
56
assert len (toolset ) == expected_length
80
57
tool_names = {tool .__name__ for tool in toolset }
81
58
assert tool_names == set (expected_tools )
82
59
83
60
async def test_run_tool (self , get_n_rows_tool : ToolboxTool ):
61
+ """Invoke a tool."""
84
62
response = await get_n_rows_tool (num_rows = "2" )
85
63
86
64
assert isinstance (response , str )
@@ -89,10 +67,12 @@ async def test_run_tool(self, get_n_rows_tool: ToolboxTool):
89
67
assert "row3" not in response
90
68
91
69
async def test_run_tool_missing_params (self , get_n_rows_tool ):
70
+ """Invoke a tool with missing params."""
92
71
with pytest .raises (TypeError , match = "missing a required argument: 'num_rows'" ):
93
72
await get_n_rows_tool ()
94
73
95
74
async def test_run_tool_wrong_param_type (self , get_n_rows_tool : ToolboxTool ):
75
+ """Invoke a tool with wrong param type."""
96
76
with pytest .raises (
97
77
Exception ,
98
78
match = 'provided parameters were invalid: unable to parse value for "num_rows": .* not type "string"' ,
@@ -101,6 +81,7 @@ async def test_run_tool_wrong_param_type(self, get_n_rows_tool: ToolboxTool):
101
81
102
82
##### Bind param tests
103
83
async def test_bind_params (self , toolbox , get_n_rows_tool ):
84
+ """Bind a param to an existing tool."""
104
85
new_tool = get_n_rows_tool .bind_parameters ({"num_rows" : "3" })
105
86
response = await new_tool ()
106
87
@@ -111,6 +92,7 @@ async def test_bind_params(self, toolbox, get_n_rows_tool):
111
92
assert "row4" not in response
112
93
113
94
async def test_bind_params_callable (self , toolbox , get_n_rows_tool ):
95
+ """Bind a callable param to an existing tool."""
114
96
new_tool = get_n_rows_tool .bind_parameters ({"num_rows" : lambda : "3" })
115
97
response = await new_tool ()
116
98
@@ -141,7 +123,8 @@ async def test_run_tool_no_auth(self, toolbox):
141
123
await tool (id = "2" )
142
124
143
125
async def test_run_tool_wrong_auth (self , toolbox , auth_token2 ):
144
- """Tests running a tool with incorrect auth."""
126
+ """Tests running a tool with incorrect auth. The tool
127
+ requires a different authentication than the one provided."""
145
128
tool = await toolbox .load_tool (
146
129
"get-row-by-id-auth" ,
147
130
)
0 commit comments