8000 feat: trigger in ApplicationIntegrationTools is changed to triggers a… · aphraz/adk-python@357143c · GitHub
[go: up one dir, main page]

Skip to content < 8000 link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-react.47f1598729334a521d2a.module.css" />

Commit 357143c

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: trigger in ApplicationIntegrationTools is changed to triggers and is a list of strings
PiperOrigin-RevId: 755691136
1 parent d5b3a89 commit 357143c

File tree

3 files changed

+105
-30
lines changed

3 files changed

+105
-30
lines changed

src/google/adk/tools/application_integration_tool/application_integration_toolset.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(
7676
project: str,
7777
location: str,
7878
integration: Optional[str] = None,
79-
trigger: Optional[str] = None,
79+
triggers: Optional[List[str]] = None,
8080
connection: Optional[str] = None,
8181
entity_operations: Optional[str] = None,
8282
actions: Optional[str] = None,
@@ -98,7 +98,7 @@ def __init__(
9898
project="test-project",
9999
location="us-central1"
100100
integration="test-integration",
101-
trigger="api_trigger/test_trigger",
101+
triggers=["api_trigger/test_trigger"],
102102
service_account_credentials={...},
103103
)
104104
@@ -130,7 +130,7 @@ def __init__(
130130
project: The GCP project ID.
131131
location: The GCP location.
132132
integration: The integration name.
133-
trigger: The trigger name.
133+
triggers: The list of trigger names in the integration.
134134
connection: The connection name.
135135
entity_operations: The entity operations supported by the connection.
136136
actions: The actions supported by the connection.
@@ -149,7 +149,7 @@ def __init__(
149149
self.project = project
150150
self.location = location
151151
self.integration = integration
152-
self.trigger = trigger
152+
self.triggers = triggers
153153
self.connection = connection
154154
self.entity_operations = entity_operations
155155
self.actions = actions
@@ -162,14 +162,14 @@ def __init__(
162162
project,
163163
location,
164164
integration,
165-
trigger,
165+
triggers,
166166
connection,
167167
entity_operations,
168168
actions,
169169
service_account_json,
170170
)
171171
connection_details = {}
172-
if integration and trigger:
172+
if integration:
173173
spec = integration_client.get_openapi_spec_for_integration()
174174
elif connection and (entity_operations or actions):
175175
connections_client = ConnectionsClient(
@@ -210,7 +210,7 @@ def _parse_spec_to_tools(self, spec_dict, connection_details):
210210
)
211211
auth_scheme = HTTPBearer(bearerFormat="JWT")
212212

213-
if self.integration and self.trigger:
213+
if self.integration:
214214
tools = OpenAPIToolset(
215215
spec_dict=spec_dict,
216216
auth_credential=auth_credential,

src/google/adk/tools/application_integration_tool/clients/integration_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import json
16-
from typing import Optional
16+
from typing import List, Optional
1717
from google.adk.tools.application_integration_tool.clients.connections_client import ConnectionsClient
1818
import google.auth
1919
from google.auth import default as default_service_credential
@@ -35,7 +35,7 @@ def __init__(
3535
project: str,
3636
location: str,
3737
integration: Optional[str] = None,
38-
trigger: Optional[str] = None,
38+
triggers: List[str] = None,
3939
connection: Optional[str] = None,
4040
entity_operations: Optional[dict[str, list[str]]] = None,
4141
actions: Optional[list[str]] = None,
@@ -47,7 +47,7 @@ def __init__(
4747
project: The Google Cloud project ID.
4848
location: The Google Cloud location (e.g., us-central1).
4949
integration: The integration name.
50-
trigger: The trigger ID for the integration.
50+
triggers: The list of trigger IDs for the integration.
5151
connection: The connection name.
5252
entity_operations: A dictionary mapping entity names to a list of
5353
operations (e.g., LIST, CREATE, UPDATE, DELETE, GET).
@@ -59,7 +59,7 @@ def __init__(
5959
self.project = project
6060
self.location = location
6161
self.integration = integration
62-
self.trigger = trigger
62+
self.triggers = triggers
6363
self.connection = connection
6464
self.entity_operations = (
6565
entity_operations if entity_operations is not None else {}
@@ -88,7 +88,7 @@ def get_openapi_spec_for_integration(self):
8888
"apiTriggerResources": [
8989
{
9090
"integrationResource": self.integration,
91-
"triggerId": [self.trigger],
91+
"triggerId": self.triggers,
9292
},
9393
],
9494
"fileFormat": "JSON",
@@ -109,7 +109,7 @@ def get_openapi_spec_for_integration(self):
109109
raise ValueError(
110110
"Invalid request. Please check the provided values of"
111111
f" project({self.project}), location({self.location}),"
112-
f" integration({self.integration}) and trigger({self.trigger})."
112+
f" integration({self.integration}) and trigger({self.triggers})."
113113
) from e
114114
raise ValueError(f"Request error: {e}") from e
115115
except Exception as e:

tests/unittests/tools/application_integration_tool/test_application_integration_toolset.py

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ def mock_openapi_toolset():
5252
yield mock_toolset
5353

5454

55+
@pytest.fixture
56+
def mock_openapi_toolset_with_multiple_tools_and_no_tools():
57+
with mock.patch(
58+
"google.adk.tools.application_integration_tool.application_integration_toolset.OpenAPIToolset"
59+
) as mock_toolset:
60+
mock_toolset_instance = mock.MagicMock()
61+
mock_rest_api_tool = mock.MagicMock(spec=rest_api_tool.RestApiTool)
62+
mock_rest_api_tool.name = "Test Tool"
63+
mock_rest_api_tool_2 = mock.MagicMock(spec=rest_api_tool.RestApiTool)
64+
mock_rest_api_tool_2.name = "Test Tool 2"
65+
mock_toolset_instance.get_tools.return_value = [
66+
mock_rest_api_tool,
67+
mock_rest_api_tool_2,
68+
]
69+
mock_toolset.return_value = mock_toolset_instance
70+
yield mock_toolset
71+
72+
5573
def get_mocked_parsed_operation(operation_id, attributes):
5674
mock_openapi_spec_parser_instance = mock.MagicMock()
5775
mock_parsed_operation = mock.MagicMock(spec=ParsedOperation)
@@ -144,10 +162,17 @@ def test_initialization_with_integration_and_trigger(
144162
integration_name = "test-integration"
145163
trigger_name = "test-trigger"
146164
toolset = ApplicationIntegrationToolset(
147-
project, location, integration=integration_name, trigger=trigger_name
165+
project, location, integration=integration_name, triggers=[trigger_name]
148166
)
149167
mock_integration_client.assert_called_once_with(
150-
project, location, integration_name, trigger_name, None, None, None, None
168+
project,
169+
location,
170+
integration_name,
171+
[trigger_name],
172+
None,
173+
None,
174+
None,
175+
None,
151176
)
152177
mock_integration_client.return_value.get_openapi_spec_for_integration.assert_called_once()
153178
mock_connections_client.assert_not_called()
@@ -156,6 +181,58 @@ def test_initialization_with_integration_and_trigger(
156181
assert toolset.get_tools()[0].name == "Test Tool"
157182

158183

184+
def test_initialization_with_integration_and_list_of_triggers(
185+
project,
186+
location,
187+
mock_integration_client,
188+
mock_connections_client,
189+
mock_openapi_toolset_with_multiple_tools_and_no_tools,
190+
):
191+
integration_name = "test-integration"
192+
trigger_name = ["test-trigger1", "test-trigger2"]
193+
toolset = ApplicationIntegrationToolset(
194+
project, location, integration=integration_name, triggers=trigger_name
195+
)
196+
mock_integration_client.assert_called_once_with(
197+
project,
198+
location,
199+
integration_name,
200+
trigger_name,
201+
None,
202+
None,
203+
None,
204+
None,
205+
)
206+
mock_integration_client.return_value.get_openapi_spec_for_integration.assert_called_once()
207+
mock_connections_client.assert_not_called()
208+
mock_openapi_toolset_with_multiple_tools_and_no_tools.assert_called_once()
209+
assert len(toolset.get_tools()) == 2
210+
assert toolset.get_tools()[0].name == "Test Tool"
211+
assert toolset.get_tools()[1].name == "Test Tool 2"
212+
213+
214+
def test_initialization_with_integration_and_empty_trigger_list(
215+
project,
216+
location,
217+
mock_integration_client,
218+
mock_connections_client,
219+
mock_openapi_toolset_with_multiple_tools_and_no_tools,
220+
):
221+
integration_name = "test-integration"
222+
toolset = ApplicationIntegrationToolset(
223+
project, location, integration=integration_name
224+
)
225+
mock_integration_client.assert_called_once_with(
226+
project, location, integration_name, None, None, None, None, None
227+
)
228+
mock_integration_client.return_value.get_openapi_spec_for_integration.assert_called_once()
229+
mock_connections_client.assert_not_called()
230+
mock_openapi_toolset_with_multiple_tools_and_no_tools.assert_called_once()
231+
assert len(toolset.get_tools()) == 2
232+
assert toolset.get_tools()[0].name == "Test Tool"
233+
assert toolset.get_tools()[1].name == "Test Tool 2"
234+
235+
159236
def test_initialization_with_connection_and_entity_operations(
160237
project,
161238
location,
@@ -263,16 +340,7 @@ def test_initialization_without_required_params(project, location):
263340
" \\(entity_operations or actions\\)\\) should be provided."
264341
),
265342
):
266-
ApplicationIntegrationToolset(project, location, integration="test")
267-
268-
with pytest.raises(
269-
ValueError,
270-
match=(
271-
"Either \\(integration and trigger\\) or \\(connection and"
272-
" \\(entity_operations or actions\\)\\) should be provided."
273-
),
274-
):
275-
ApplicationIntegrationToolset(project, location, trigger="test")
343+
ApplicationIntegrationToolset(project, location, triggers=["test"])
276344

277345
with pytest.raises(
278346
ValueError,
@@ -310,14 +378,14 @@ def test_initialization_with_service_account_credentials(
310378
project,
311379
location,
312380
integration=integration_name,
313-
trigger=trigger_name,
381+
triggers=[trigger_name],
314382
service_account_json=service_account_json,
315383
)
316384
mock_integration_client.assert_called_once_with(
317385
project,
318386
location,
319387
integration_name,
320-
trigger_name,
388+
[trigger_name],
321389
None,
322390
None,
323391
None,
@@ -340,10 +408,17 @@ def test_initialization_without_explicit_service_account_credentials(
340408
integration_name = "test-integration"
341409
trigger_name = "test-trigger"
342410
toolset = ApplicationIntegrationToolset(
343-
project, location, integration=integration_name, trigger=trigger_name
411+
project, location, integration=integration_name, triggers=[trigger_name]
344412
)
345413
mock_integration_client.assert_called_once_with(
346-
project, location, integration_name, trigger_name, None, None, None, None
414+
project,
415+
location,
416+
integration_name,
417+
[trigger_name],
418+
None,
419+
None,
420+
None,
421+
None,
347422
)
348423
mock_openapi_toolset.assert_called_once()
349424
_, kwargs = mock_openapi_toolset.call_args
@@ -357,7 +432,7 @@ def test_get_tools(
357432
integration_name = "test-integration"
358433
trigger_name = "test-trigger"
359434
toolset = ApplicationIntegrationToolset(
360-
project, location, integration=integration_name, trigger=trigger_name
435+
project, location, integration=integration_name, triggers=[trigger_name]
361436
)
362437
tools = toolset.get_tools()
363438
assert len(tools) == 1

0 commit comments

Comments
 (0)
0