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

Skip to content

Commit 7f76af4

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: trigger in ApplicationIntegrationTools is changed to triggers and is a list of strings
PiperOrigin-RevId: 756111287
1 parent e7d9cf3 commit 7f76af4

File tree

3 files changed

+30
-105
lines changed

3 files changed

+30
-105
lines changed

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

Lines changed: 7 additions & 7 deletions
8000
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-
triggers: Optional[List[str]] = None,
79+
trigger: Optional[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-
triggers=["api_trigger/test_trigger"],
101+
trigger="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-
triggers: The list of trigger names in the integration.
133+
trigger: The trigger name.
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.triggers = triggers
152+
self.trigger = trigger
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-
triggers,
165+
trigger,
166166
connection,
167167
entity_operations,
168168
actions,
169169
service_account_json,
170170
)
171171
connection_details = {}
172-
if integration:
172+
if integration and trigger:
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:
213+
if self.integration and self.trigger:
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 List, Optional
16+
from typing import 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-
triggers: List[str] = None,
38+
trigger: Optional[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-
triggers: The list of trigger IDs for the integration.
50+
trigger: The trigger ID 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.triggers = triggers
62+
self.trigger = trigger
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.triggers,
91+
"triggerId": [self.trigger],
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.triggers})."
112+
f" integration({self.integration}) and trigger({self.trigger})."
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: 17 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,6 @@ 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-
7355
def get_mocked_parsed_operation(operation_id, attributes):
7456
mock_openapi_spec_parser_instance = mock.MagicMock()
7557
mock_parsed_operation = mock.MagicMock(spec=ParsedOperation)
@@ -162,17 +144,10 @@ def test_initialization_with_integration_and_trigger(
162144
integration_name = "test-integration"
163145
trigger_name = "test-trigger"
164146
toolset = ApplicationIntegrationToolset(
165-
project, location, integration=integration_name, triggers=[trigger_name]
147+
project, location, integration=integration_name, trigger=trigger_name
166148
)
167149
mock_integration_client.assert_called_once_with(
168-
project,
169-
location,
170-
integration_name,
171-
[trigger_name],
172-
None,
173-
None,
174-
None,
175-
None,
150+
project, location, integration_name, trigger_name, None, None, None, None
176151
)
177152
mock_integration_client.return_value.get_openapi_spec_for_integration.assert_called_once()
178153
mock_connections_client.assert_not_called()
@@ -181,58 +156,6 @@ def test_initialization_with_integration_and_trigger(
181156
assert toolset.get_tools()[0].name == "Test Tool"
182157

183158

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-
236159
def test_initialization_with_connection_and_entity_operations(
237160
project,
238161
location,
@@ -340,7 +263,16 @@ def test_initialization_without_required_params(project, location):
340263
" \\(entity_operations or actions\\)\\) should be provided."
341264
),
342265
):
343-
ApplicationIntegrationToolset(project, location, triggers=["test"])
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")
344276

345277
with pytest.raises(
346278
ValueError,
@@ -378,14 +310,14 @@ def test_initialization_with_service_account_credentials(
378310
project,
379311
location,
380312
integration=integration_name,
381-
triggers=[trigger_name],
313+
trigger=trigger_name,
382314
service_account_json=service_account_json,
383315
)
384316
mock_integration_client.assert_called_once_with(
385317
project,
386318
location,
387319
integration_name,
388-
[trigger_name],
320+
trigger_name,
389321
None,
390322
None,
391323
None,
@@ -408,17 +340,10 @@ def test_initialization_without_explicit_service_account_credentials(
408340
integration_name = "test-integration"
409341
trigger_name = "test-trigger"
410342
toolset = ApplicationIntegrationToolset(
411-
project, location, integration=integration_name, triggers=[trigger_name]
343+
project, location, integration=integration_name, trigger=trigger_name
412344
)
413345
mock_integration_client.assert_called_once_with(
414-
project,
415-
location,
416-
integration_name,
417-
[trigger_name],
418-
None,
419-
None,
420-
None,
421-
None,
346+
project, location, integration_name, trigger_name, None, None, None, None
422347
)
423348
mock_openapi_toolset.assert_called_once()
424349
_, kwargs = mock_openapi_toolset.call_args
@@ -432,7 +357,7 @@ def test_get_tools(
432357
integration_name = "test-integration"
433358
trigger_name = "test-trigger"
434359
toolset = ApplicationIntegrationToolset(
435-
project, location, integration=integration_name, triggers=[trigger_name]
360+
project, location, integration=integration_name, trigger=trigger_name
436361
)
437362
tools = toolset.get_tools()
438363
assert len(tools) == 1

0 commit comments

Comments
 (0)
0