Skip to content

Commit 716ebcc

Browse files
committed
fix: Integration test errors
1 parent ef34de1 commit 716ebcc

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

packages/toolbox-langchain/tests/test_e2e.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ async def test_run_tool_wrong_param_type(self, get_n_rows_tool):
114114
@pytest.mark.asyncio
115115
async def test_run_tool_unauth_with_auth(self, toolbox, auth_token2):
116116
"""Tests running a tool that doesn't require auth, with auth provided."""
117-
tool = await toolbox.aload_tool(
118-
"get-row-by-id", auth_token_getters={"my-test-auth": lambda: auth_token2}
119-
)
120-
response = await tool.ainvoke({"id": "2"})
121-
assert "row2" in response
117+
with pytest.raises(
118+
ValueError,
119+
match="Validation failed for tool 'get-row-by-id': unused auth tokens: my-test-auth.",
120+
):
121+
await toolbox.aload_tool(
122+
"get-row-by-id", auth_token_getters={"my-test-auth": lambda: auth_token2}
123+
)
122124

123125
async def test_run_tool_no_auth(self, toolbox):
124126
"""Tests running a tool requiring auth without providing auth."""
@@ -127,7 +129,7 @@ async def test_run_tool_no_auth(self, toolbox):
127129
)
128130
with pytest.raises(
129131
PermissionError,
130-
match="Tool get-row-by-id-auth requires authentication, but no valid authentication sources are registered. Please register the required sources before use.",
132+
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
131133
):
132134
await tool.ainvoke({"id": "2"})
133135

@@ -138,8 +140,8 @@ async def test_run_tool_wrong_auth(self, toolbox, auth_token2):
138140
)
139141
auth_tool = tool.add_auth_token_getter("my-test-auth", lambda: auth_token2)
140142
with pytest.raises(
141-
ToolException,
142-
match="{'status': 'Unauthorized', 'error': 'tool invocation not authorized. Please make sure your specify correct auth headers'}",
143+
Exception,
144+
match="tool invocation not authorized. Please make sure your specify correct auth headers",
143145
):
144146
await auth_tool.ainvoke({"id": "2"})
145147

@@ -157,7 +159,7 @@ async def test_run_tool_param_auth_no_auth(self, toolbox):
157159
tool = await toolbox.aload_tool("get-row-by-email-auth")
158160
with pytest.raises(
159161
PermissionError,
160-
match="Parameter\(s\) `email` of tool get-row-by-email-auth require authentication\, but no valid authentication sources are registered\. Please register the required sources before use\.",
162+
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
161163
):
162164
await tool.ainvoke({"email": ""})
163165

@@ -179,12 +181,11 @@ async def test_run_tool_param_auth_no_field(self, toolbox, auth_token1):
179181
auth_token_getters={"my-test-auth": lambda: auth_token1},
180182
)
181183
with pytest.raises(
182-
ToolException,
183-
match="{'status': 'Bad Request', 'error': 'provided parameters were invalid: error parsing authenticated parameter \"data\": no field named row_data in claims'}",
184+
Exception,
185+
match="provided parameters were invalid: error parsing authenticated parameter \"data\": no field named row_data in claims"
184186
):
185187
await tool.ainvoke({})
186188

187-
188189
@pytest.mark.usefixtures("toolbox_server")
189190
class TestE2EClientSync:
190191
@pytest.fixture(scope="session")
@@ -213,7 +214,7 @@ def test_load_toolset_specific(
213214
toolset = toolbox.load_toolset(toolset_name)
214215
assert len(toolset) == expected_length
215216
for tool in toolset:
216-
name = tool._ToolboxTool__async_tool._AsyncToolboxTool__name
217+
name = tool._ToolboxTool__core_sync_tool.__name__
217218
assert name in expected_tools
218219

219220
def test_aload_toolset_all(self, toolbox):
@@ -227,7 +228,7 @@ def test_aload_toolset_all(self, toolbox):
227228
"get-row-by-content-auth",
228229
]
229230
for tool in toolset:
230-
name = tool._ToolboxTool__async_tool._AsyncToolboxTool__name
231+
name = tool._ToolboxTool__core_sync_tool.__name__
231232
assert name in tool_names
232233

233234
@pytest.mark.asyncio
@@ -256,11 +257,13 @@ def test_run_tool_wrong_param_type(self, get_n_rows_tool):
256257
#### Auth tests
257258
def test_run_tool_unauth_with_auth(self, toolbox, auth_token2):
258259
"""Tests running a tool that doesn't require auth, with auth provided."""
259-
tool = toolbox.load_tool(
260-
"get-row-by-id", auth_token_getters={"my-test-auth": lambda: auth_token2}
261-
)
262-
response = tool.invoke({"id": "2"})
263-
assert "row2" in response
260+
with pytest.raises(
261+
ValueError,
262+
match="Validation failed for tool 'get-row-by-id': unused auth tokens: my-test-auth.",
263+
):
264+
toolbox.load_tool(
265+
"get-row-by-id", auth_token_getters={"my-test-auth": lambda: auth_token2}
266+
)
264267

265268
def test_run_tool_no_auth(self, toolbox):
266269
"""Tests running a tool requiring auth without providing auth."""
@@ -269,7 +272,7 @@ def test_run_tool_no_auth(self, toolbox):
269272
)
270273
with pytest.raises(
271274
PermissionError,
272-
match="Tool get-row-by-id-auth requires authentication, but no valid authentication sources are registered. Please register the required sources before use.",
275+
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
273276
):
274277
tool.invoke({"id": "2"})
275278

@@ -281,7 +284,7 @@ def test_run_tool_wrong_auth(self, toolbox, auth_token2):
281284
auth_tool = tool.add_auth_token_getter("my-test-auth", lambda: auth_token2)
282285
with pytest.raises(
283286
ToolException,
284-
match="{'status': 'Unauthorized', 'error': 'tool invocation not authorized. Please make sure your specify correct auth headers'}",
287+
match="tool invocation not authorized. Please make sure your specify correct auth headers",
285288
):
286289
auth_tool.invoke({"id": "2"})
287290

@@ -299,7 +302,7 @@ def test_run_tool_param_auth_no_auth(self, toolbox):
299302
tool = toolbox.load_tool("get-row-by-email-auth")
300303
with pytest.raises(
301304
PermissionError,
302-
match="Parameter\(s\) `email` of tool get-row-by-email-auth require authentication\, but no valid authentication sources are registered\. Please register the required sources before use\.",
305+
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
303306
):
304307
tool.invoke({"email": ""})
305308

@@ -322,6 +325,6 @@ def test_run_tool_param_auth_no_field(self, toolbox, auth_token1):
322325
)
323326
with pytest.raises(
324327
ToolException,
325-
match="{'status': 'Bad Request', 'error': 'provided parameters were invalid: error parsing authenticated parameter \"data\": no field named row_data in claims'}",
328+
match="provided parameters were invalid: error parsing authenticated parameter \"data\": no field named row_data in claims",
326329
):
327330
tool.invoke({})

0 commit comments

Comments
 (0)