Skip to content

Commit fef1f7f

Browse files
committed
try fix test errors
1 parent d75828e commit fef1f7f

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

packages/toolbox-core/src/toolbox_core/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __parse_tool(
7575
else: # regular parameter
7676
params.append(p)
7777

78-
authn_params = filter_required_authn_params(authn_params, auth_sources)
78+
authn_params = filter_required_authn_params(authn_params, auth_token_getters.keys())
7979

8080
tool = ToolboxTool(
8181
session=self.__session,

packages/toolbox-core/src/toolbox_core/tool.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Any,
2222
Callable,
2323
DefaultDict,
24+
TypeVar,
2425
Iterable,
2526
Mapping,
2627
Optional,
@@ -31,6 +32,8 @@
3132
from aiohttp import ClientSession
3233
from pytest import Session
3334

35+
T = TypeVar('T')
36+
3437

3538
class ToolboxTool:
3639
"""
@@ -122,16 +125,20 @@ def __copy(
122125
that produce a token)
123126
124127
"""
128+
129+
def _resolve_value(override_value: Optional[T], default_value: T) -> T:
130+
"""Returns the override_value if it's not None, otherwise the default_value."""
131+
return override_value if override_value is not None else default_value
132+
125133
return ToolboxTool(
126-
session=session or self.__session,
127-
base_url=base_url or self.__base_url,
128-
name=name or self.__name__,
129-
desc=desc or self.__desc,
130-
params=params or self.__params,
131-
required_authn_params=required_authn_params or self.__required_authn_params,
132-
auth_service_token_getters=auth_service_token_getters
133-
or self.__auth_service_token_getters,
134-
bound_params=bound_params or self.__bound_parameters,
134+
session=_resolve_value(session, self.__session),
135+
base_url=_resolve_value(base_url, self.__base_url),
136+
name=_resolve_value(name, self.__name__),
137+
desc=_resolve_value(desc, self.__desc),
138+
params=_resolve_value(params, self.__params),
139+
required_authn_params=_resolve_value(required_authn_params, self.__required_authn_params),
140+
auth_service_token_getters=_resolve_value(auth_service_token_getters, self.__auth_service_token_getters),
141+
bound_params=_resolve_value(bound_params, self.__bound_parameters),
135142
)
136143

137144
async def __call__(self, *args: Any, **kwargs: Any) -> str:

packages/toolbox-core/tests/test_e2e.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,14 @@ async def test_run_tool_param_auth_no_auth(self, toolbox):
159159
):
160160
await tool()
161161

162-
# TODO: Uncomment after fix
163-
# async def test_run_tool_param_auth_no_service(self, toolbox):
164-
# """Tests running a tool with a param requiring auth, without a registered auth service."""
165-
# tool = await toolbox.load_tool("get-row-by-email-auth-wrong-auth-source")
166-
# with pytest.raises(
167-
# Exception,
168-
# match="One of more of the following authn services are required to invoke this tool: my-test-auth3",
169-
# ):
170-
# await tool()
162+
async def test_run_tool_param_auth_no_service(self, toolbox):
163+
"""Tests running a tool with a param requiring auth, without a registered auth service."""
164+
tool = await toolbox.load_tool("get-row-by-email-auth-wrong-auth-source")
165+
with pytest.raises(
166+
Exception,
167+
match="One of more of the following authn services are required to invoke this tool: my-test-auth3",
168+
):
169+
await tool()
171170

172171
async def test_run_tool_param_auth(self, toolbox, auth_token1):
173172
"""Tests running a tool with a param requiring auth, with correct auth."""

0 commit comments

Comments
 (0)