Skip to content

Commit 5fbaeb4

Browse files
committed
chore: Add unit test coverage
1 parent b4ce8ef commit 5fbaeb4

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

packages/toolbox-core/tests/test_sync_tool.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,39 @@ def test_toolbox_sync_tool_add_auth_token_getters(
237237
)
238238

239239

240+
def test_toolbox_sync_tool_add_auth_token_getter(
241+
toolbox_sync_tool: ToolboxSyncTool,
242+
mock_async_tool: MagicMock,
243+
event_loop: asyncio.AbstractEventLoop,
244+
mock_thread: MagicMock,
245+
):
246+
"""Tests the add_auth_token_getter method."""
247+
auth_service = "service1"
248+
auth_token_getter = lambda: "token1"
249+
250+
new_mock_async_tool = mock_async_tool.add_auth_token_getters.return_value
251+
new_mock_async_tool.__name__ = "new_async_tool_with_auth"
252+
253+
new_sync_tool = toolbox_sync_tool.add_auth_token_getter(
254+
auth_service, auth_token_getter
255+
)
256+
257+
mock_async_tool.add_auth_token_getters.assert_called_once_with(
258+
{auth_service: auth_token_getter}
259+
)
260+
261+
assert isinstance(new_sync_tool, ToolboxSyncTool)
262+
assert new_sync_tool is not toolbox_sync_tool
263+
assert new_sync_tool._ToolboxSyncTool__async_tool is new_mock_async_tool
264+
assert new_sync_tool._ToolboxSyncTool__loop is event_loop # Should be the same loop
265+
assert (
266+
new_sync_tool._ToolboxSyncTool__thread is mock_thread
267+
) # Should be the same thread
268+
assert (
269+
new_sync_tool.__qualname__ == f"ToolboxSyncTool.{new_mock_async_tool.__name__}"
270+
)
271+
272+
240273
def test_toolbox_sync_tool_bind_params(
241274
toolbox_sync_tool: ToolboxSyncTool,
242275
mock_async_tool: MagicMock,

packages/toolbox-core/tests/test_tool.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,35 @@ def test_add_auth_token_getters_unused_token(
502502
tool_instance.add_auth_token_getters(unused_auth_getters)
503503

504504

505+
def test_add_auth_token_getter_unused_token(
506+
http_session: ClientSession,
507+
sample_tool_params: list[ParameterSchema],
508+
sample_tool_description: str,
509+
unused_auth_getters: Mapping[str, Callable[[], str]],
510+
):
511+
"""
512+
Tests ValueError when add_auth_token_getters is called with a getter for
513+
an unused authentication service.
514+
"""
515+
tool_instance = ToolboxTool(
516+
session=http_session,
517+
base_url=HTTPS_BASE_URL,
518+
name=TEST_TOOL_NAME,
519+
description=sample_tool_description,
520+
params=sample_tool_params,
521+
required_authn_params={},
522+
required_authz_tokens=[],
523+
auth_service_token_getters={},
524+
bound_params={},
525+
client_headers={},
526+
)
527+
528+
expected_error_message = "Authentication source\(s\) \`unused-auth-service\` unused by tool \`sample_tool\`."
529+
530+
with pytest.raises(ValueError, match=expected_error_message):
531+
tool_instance.add_auth_token_getter(next(iter(unused_auth_getters)), unused_auth_getters[next(iter(unused_auth_getters))])
532+
533+
505534
def test_toolbox_tool_underscore_name_property(toolbox_tool: ToolboxTool):
506535
"""Tests the _name property."""
507536
assert toolbox_tool._name == TEST_TOOL_NAME

0 commit comments

Comments
 (0)