adapt google api toolset and api hub toolset to new toolset interface

PiperOrigin-RevId: 757946541
This commit is contained in:
Xiang (Sean) Zhou
2025-05-12 15:57:56 -07:00
committed by Copybara-Service
parent 27b229719e
commit 6a04ff84ba
7 changed files with 168 additions and 122 deletions

View File

@@ -77,22 +77,26 @@ def mock_auth_credential():
# Test cases
def test_apihub_toolset_initialization(basic_apihub_toolset):
@pytest.mark.asyncio
async def test_apihub_toolset_initialization(basic_apihub_toolset):
assert basic_apihub_toolset.name == 'mock_api'
assert basic_apihub_toolset.description == 'Mock API Description'
assert basic_apihub_toolset.apihub_resource_name == 'test_resource'
assert not basic_apihub_toolset.lazy_load_spec
assert len(basic_apihub_toolset.generated_tools) == 1
assert 'test_get' in basic_apihub_toolset.generated_tools
generated_tools = await basic_apihub_toolset.get_tools()
assert len(generated_tools) == 1
assert 'test_get' == generated_tools[0].name
def test_apihub_toolset_lazy_loading(lazy_apihub_toolset):
@pytest.mark.asyncio
async def test_apihub_toolset_lazy_loading(lazy_apihub_toolset):
assert lazy_apihub_toolset.lazy_load_spec
assert not lazy_apihub_toolset.generated_tools
generated_tools = await lazy_apihub_toolset.get_tools()
assert generated_tools
tools = lazy_apihub_toolset.get_tools()
tools = await lazy_apihub_toolset.get_tools()
assert len(tools) == 1
assert lazy_apihub_toolset.get_tool('test_get') == tools[0]
'test_get' == tools[0].name
def test_apihub_toolset_no_title_in_spec(basic_apihub_toolset):
@@ -155,7 +159,8 @@ paths:
assert toolset.description == ''
def test_get_tools_with_auth(mock_auth_scheme, mock_auth_credential):
@pytest.mark.asyncio
async def test_get_tools_with_auth(mock_auth_scheme, mock_auth_credential):
apihub_client = MockAPIHubClient()
tool = APIHubToolset(
apihub_resource_name='test_resource',
@@ -163,11 +168,12 @@ def test_get_tools_with_auth(mock_auth_scheme, mock_auth_credential):
auth_scheme=mock_auth_scheme,
auth_credential=mock_auth_credential,
)
tools = tool.get_tools()
tools = await tool.get_tools()
assert len(tools) == 1
def test_apihub_toolset_get_tools_lazy_load_empty_spec():
@pytest.mark.asyncio
async def test_apihub_toolset_get_tools_lazy_load_empty_spec():
class MockAPIHubClientEmptySpec(BaseAPIHubClient):
@@ -180,11 +186,12 @@ def test_apihub_toolset_get_tools_lazy_load_empty_spec():
apihub_client=apihub_client,
lazy_load_spec=True,
)
tools = tool.get_tools()
tools = await tool.get_tools()
assert not tools
def test_apihub_toolset_get_tools_invalid_yaml():
@pytest.mark.asyncio
async def test_apihub_toolset_get_tools_invalid_yaml():
class MockAPIHubClientInvalidYAML(BaseAPIHubClient):
@@ -197,7 +204,7 @@ def test_apihub_toolset_get_tools_invalid_yaml():
apihub_resource_name='test_resource',
apihub_client=apihub_client,
)
tool.get_tools()
await tool.get_tools()
if __name__ == '__main__':