mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-12-18 11:22:22 -06:00
feat: trigger in ApplicationIntegrationTools is changed to triggers and is a list of strings
PiperOrigin-RevId: 756111287
This commit is contained in:
committed by
Copybara-Service
parent
e7d9cf359a
commit
7f76af4d76
@@ -52,24 +52,6 @@ def mock_openapi_toolset():
|
||||
yield mock_toolset
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_openapi_toolset_with_multiple_tools_and_no_tools():
|
||||
with mock.patch(
|
||||
"google.adk.tools.application_integration_tool.application_integration_toolset.OpenAPIToolset"
|
||||
) as mock_toolset:
|
||||
mock_toolset_instance = mock.MagicMock()
|
||||
mock_rest_api_tool = mock.MagicMock(spec=rest_api_tool.RestApiTool)
|
||||
mock_rest_api_tool.name = "Test Tool"
|
||||
mock_rest_api_tool_2 = mock.MagicMock(spec=rest_api_tool.RestApiTool)
|
||||
mock_rest_api_tool_2.name = "Test Tool 2"
|
||||
mock_toolset_instance.get_tools.return_value = [
|
||||
mock_rest_api_tool,
|
||||
mock_rest_api_tool_2,
|
||||
]
|
||||
mock_toolset.return_value = mock_toolset_instance
|
||||
yield mock_toolset
|
||||
|
||||
|
||||
def get_mocked_parsed_operation(operation_id, attributes):
|
||||
mock_openapi_spec_parser_instance = mock.MagicMock()
|
||||
mock_parsed_operation = mock.MagicMock(spec=ParsedOperation)
|
||||
@@ -162,17 +144,10 @@ def test_initialization_with_integration_and_trigger(
|
||||
integration_name = "test-integration"
|
||||
trigger_name = "test-trigger"
|
||||
toolset = ApplicationIntegrationToolset(
|
||||
project, location, integration=integration_name, triggers=[trigger_name]
|
||||
project, location, integration=integration_name, trigger=trigger_name
|
||||
)
|
||||
mock_integration_client.assert_called_once_with(
|
||||
project,
|
||||
location,
|
||||
integration_name,
|
||||
[trigger_name],
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
project, location, integration_name, trigger_name, None, None, None, None
|
||||
)
|
||||
mock_integration_client.return_value.get_openapi_spec_for_integration.assert_called_once()
|
||||
mock_connections_client.assert_not_called()
|
||||
@@ -181,58 +156,6 @@ def test_initialization_with_integration_and_trigger(
|
||||
assert toolset.get_tools()[0].name == "Test Tool"
|
||||
|
||||
|
||||
def test_initialization_with_integration_and_list_of_triggers(
|
||||
project,
|
||||
location,
|
||||
mock_integration_client,
|
||||
mock_connections_client,
|
||||
mock_openapi_toolset_with_multiple_tools_and_no_tools,
|
||||
):
|
||||
integration_name = "test-integration"
|
||||
trigger_name = ["test-trigger1", "test-trigger2"]
|
||||
toolset = ApplicationIntegrationToolset(
|
||||
project, location, integration=integration_name, triggers=trigger_name
|
||||
)
|
||||
mock_integration_client.assert_called_once_with(
|
||||
project,
|
||||
location,
|
||||
integration_name,
|
||||
trigger_name,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
mock_integration_client.return_value.get_openapi_spec_for_integration.assert_called_once()
|
||||
mock_connections_client.assert_not_called()
|
||||
mock_openapi_toolset_with_multiple_tools_and_no_tools.assert_called_once()
|
||||
assert len(toolset.get_tools()) == 2
|
||||
assert toolset.get_tools()[0].name == "Test Tool"
|
||||
assert toolset.get_tools()[1].name == "Test Tool 2"
|
||||
|
||||
|
||||
def test_initialization_with_integration_and_empty_trigger_list(
|
||||
project,
|
||||
location,
|
||||
mock_integration_client,
|
||||
mock_connections_client,
|
||||
mock_openapi_toolset_with_multiple_tools_and_no_tools,
|
||||
):
|
||||
integration_name = "test-integration"
|
||||
toolset = ApplicationIntegrationToolset(
|
||||
project, location, integration=integration_name
|
||||
)
|
||||
mock_integration_client.assert_called_once_with(
|
||||
project, location, integration_name, None, None, None, None, None
|
||||
)
|
||||
mock_integration_client.return_value.get_openapi_spec_for_integration.assert_called_once()
|
||||
mock_connections_client.assert_not_called()
|
||||
mock_openapi_toolset_with_multiple_tools_and_no_tools.assert_called_once()
|
||||
assert len(toolset.get_tools()) == 2
|
||||
assert toolset.get_tools()[0].name == "Test Tool"
|
||||
assert toolset.get_tools()[1].name == "Test Tool 2"
|
||||
|
||||
|
||||
def test_initialization_with_connection_and_entity_operations(
|
||||
project,
|
||||
location,
|
||||
@@ -340,7 +263,16 @@ def test_initialization_without_required_params(project, location):
|
||||
" \\(entity_operations or actions\\)\\) should be provided."
|
||||
),
|
||||
):
|
||||
ApplicationIntegrationToolset(project, location, triggers=["test"])
|
||||
ApplicationIntegrationToolset(project, location, integration="test")
|
||||
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match=(
|
||||
"Either \\(integration and trigger\\) or \\(connection and"
|
||||
" \\(entity_operations or actions\\)\\) should be provided."
|
||||
),
|
||||
):
|
||||
ApplicationIntegrationToolset(project, location, trigger="test")
|
||||
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
@@ -378,14 +310,14 @@ def test_initialization_with_service_account_credentials(
|
||||
project,
|
||||
location,
|
||||
integration=integration_name,
|
||||
triggers=[trigger_name],
|
||||
trigger=trigger_name,
|
||||
service_account_json=service_account_json,
|
||||
)
|
||||
mock_integration_client.assert_called_once_with(
|
||||
project,
|
||||
location,
|
||||
integration_name,
|
||||
[trigger_name],
|
||||
trigger_name,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
@@ -408,17 +340,10 @@ def test_initialization_without_explicit_service_account_credentials(
|
||||
integration_name = "test-integration"
|
||||
trigger_name = "test-trigger"
|
||||
toolset = ApplicationIntegrationToolset(
|
||||
project, location, integration=integration_name, triggers=[trigger_name]
|
||||
project, location, integration=integration_name, trigger=trigger_name
|
||||
)
|
||||
mock_integration_client.assert_called_once_with(
|
||||
project,
|
||||
location,
|
||||
integration_name,
|
||||
[trigger_name],
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
project, location, integration_name, trigger_name, None, None, None, None
|
||||
)
|
||||
mock_openapi_toolset.assert_called_once()
|
||||
_, kwargs = mock_openapi_toolset.call_args
|
||||
@@ -432,7 +357,7 @@ def test_get_tools(
|
||||
integration_name = "test-integration"
|
||||
trigger_name = "test-trigger"
|
||||
toolset = ApplicationIntegrationToolset(
|
||||
project, location, integration=integration_name, triggers=[trigger_name]
|
||||
project, location, integration=integration_name, trigger=trigger_name
|
||||
)
|
||||
tools = toolset.get_tools()
|
||||
assert len(tools) == 1
|
||||
|
||||
Reference in New Issue
Block a user