Skip to content

Commit 47ef875

Browse files
authored
test(llamaindex-sdk): Add more test cases to e2e tests (#219)
Test for tool calls with 1. Missing params 2. Wrong param type
1 parent 316cdc4 commit 47ef875

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

tests/test_e2e.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
1. Loading a tool.
2020
2. Loading a specific toolset.
2121
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:
2427
a. No auth provided.
2528
b. Wrong auth provided: The tool requires a different authentication
2629
than the one provided.
2730
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:
2932
a. No auth provided.
3033
b. Correct auth provided.
3134
c. Auth provided does not contain the required claim.
@@ -34,6 +37,7 @@
3437
import pytest
3538
import pytest_asyncio
3639
from aiohttp import ClientResponseError
40+
from pydantic import ValidationError
3741

3842
from toolbox_langchain_sdk.client import ToolboxClient
3943

@@ -85,6 +89,18 @@ async def test_load_toolset_all(self, toolbox):
8589
for tool in toolset:
8690
assert tool.name in tool_names
8791

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+
88104
##### Auth tests
89105
@pytest.mark.asyncio
90106
@pytest.mark.skip(reason="b/389574566")
@@ -93,7 +109,7 @@ async def test_run_tool_unauth_with_auth(self, toolbox, auth_token2):
93109
tool = await toolbox.load_tool(
94110
"get-row-by-id", auth_tokens={"my-test-auth": lambda: auth_token2}
95111
)
96-
response = await tool.arun({"id": "2"})
112+
response = await tool.ainvoke({"id": "2"})
97113
assert "row2" in response["result"]
98114

99115
@pytest.mark.asyncio
@@ -103,7 +119,7 @@ async def test_run_tool_no_auth(self, toolbox):
103119
"get-row-by-id-auth",
104120
)
105121
with pytest.raises(ClientResponseError, match="401, message='Unauthorized'"):
106-
await tool.arun({"id": "2"})
122+
await tool.ainvoke({"id": "2"})
107123

108124
@pytest.mark.asyncio
109125
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):
114130
)
115131
# TODO: Fix error message (b/389577313)
116132
with pytest.raises(ClientResponseError, match="400, message='Bad Request'"):
117-
await tool.arun({"id": "2"})
133+
await tool.ainvoke({"id": "2"})
118134

119135
@pytest.mark.asyncio
120136
async def test_run_tool_auth(self, toolbox, auth_token1):
@@ -123,23 +139,23 @@ async def test_run_tool_auth(self, toolbox, auth_token1):
123139
tool = await toolbox.load_tool(
124140
"get-row-by-id-auth",
125141
)
126-
response = await tool.arun({"id": "2"})
142+
response = await tool.ainvoke({"id": "2"})
127143
assert "row2" in response["result"]
128144

129145
@pytest.mark.asyncio
130146
async def test_run_tool_param_auth_no_auth(self, toolbox):
131147
"""Tests running a tool with a param requiring auth, without auth."""
132148
tool = await toolbox.load_tool("get-row-by-email-auth")
133149
with pytest.raises(PermissionError, match="Login required"):
134-
await tool.arun({})
150+
await tool.ainvoke({})
135151

136152
@pytest.mark.asyncio
137153
async def test_run_tool_param_auth(self, toolbox, auth_token1):
138154
"""Tests running a tool with a param requiring auth, with correct auth."""
139155
tool = await toolbox.load_tool(
140156
"get-row-by-email-auth", auth_tokens={"my-test-auth": lambda: auth_token1}
141157
)
142-
response = await tool.arun({})
158+
response = await tool.ainvoke({})
143159
result = response["result"]
144160
assert "row4" in result
145161
assert "row5" in result
@@ -152,4 +168,4 @@ async def test_run_tool_param_auth_no_field(self, toolbox, auth_token1):
152168
"get-row-by-content-auth", auth_tokens={"my-test-auth": lambda: auth_token1}
153169
)
154170
with pytest.raises(ClientResponseError, match="400, message='Bad Request'"):
155-
await tool.arun({})
171+
await tool.ainvoke({})

0 commit comments

Comments
 (0)