Skip to content

Commit 9e843dc

Browse files
committed
chore: Cover tool not found case
1 parent e034d57 commit 9e843dc

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

packages/toolbox-core/tests/test_client.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,43 @@ async def test_new_add_auth_token_getters_duplicate_fail(aioresponses, test_tool
390390
status=200,
391391
)
392392

393-
def token_handler_1():
394-
return "token1"
395-
396-
def token_handler_2():
397-
return "token2"
398-
399393
async with ToolboxClient(TEST_BASE_URL) as client:
400394
tool = await client.load_tool(TOOL_NAME)
401395

402-
authed_tool = tool.add_auth_token_getters({AUTH_SERVICE: token_handler_1})
396+
authed_tool = tool.add_auth_token_getters({AUTH_SERVICE: {}})
403397
assert AUTH_SERVICE in authed_tool._ToolboxTool__auth_service_token_getters
404398

405399
with pytest.raises(
406400
ValueError,
407401
match=f"Authentication source\\(s\\) `{AUTH_SERVICE}` already registered in tool `{TOOL_NAME}`.",
408402
):
409-
authed_tool.add_auth_token_getters({AUTH_SERVICE: token_handler_2})
403+
authed_tool.add_auth_token_getters({AUTH_SERVICE: {}})
404+
405+
406+
@pytest.mark.asyncio
407+
async def test_load_tool_not_found_in_manifest(aioresponses, test_tool_str):
408+
"""
409+
Tests that load_tool raises an Exception when the requested tool name
410+
is not found in the manifest returned by the server, using existing fixtures.
411+
"""
412+
ACTUAL_TOOL_IN_MANIFEST = "actual_tool_abc"
413+
REQUESTED_TOOL_NAME = "non_existent_tool_xyz"
414+
415+
manifest = ManifestSchema(
416+
serverVersion="0.0.0",
417+
tools={ACTUAL_TOOL_IN_MANIFEST: test_tool_str}
418+
)
419+
420+
aioresponses.get(
421+
f"{TEST_BASE_URL}/api/tool/{REQUESTED_TOOL_NAME}",
422+
payload=manifest.model_dump(),
423+
status=200,
424+
)
425+
426+
async with ToolboxClient(TEST_BASE_URL) as client:
427+
with pytest.raises(Exception, match=f"Tool '{REQUESTED_TOOL_NAME}' not found!"):
428+
await client.load_tool(REQUESTED_TOOL_NAME)
429+
430+
aioresponses.assert_called_once_with(
431+
f"{TEST_BASE_URL}/api/tool/{REQUESTED_TOOL_NAME}", method='GET'
432+
)

0 commit comments

Comments
 (0)