@@ -52,6 +52,24 @@ def mock_openapi_toolset():
52
52
yield mock_toolset
53
53
54
54
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
+
55
73
def get_mocked_parsed_operation (operation_id , attributes ):
56
74
mock_openapi_spec_parser_instance = mock .MagicMock ()
57
75
mock_parsed_operation = mock .MagicMock (spec = ParsedOperation )
@@ -144,10 +162,17 @@ def test_initialization_with_integration_and_trigger(
144
162
integration_name = "test-integration"
145
163
trigger_name = "test-trigger"
146
164
toolset = ApplicationIntegrationToolset (
147
- project , location , integration = integration_name , trigger = trigger_name
165
+ project , location , integration = integration_name , triggers = [ trigger_name ]
148
166
)
149
167
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 ,
151
176
)
152
177
mock_integration_client .return_value .get_openapi_spec_for_integration .assert_called_once ()
153
178
mock_connections_client .assert_not_called ()
@@ -156,6 +181,58 @@ def test_initialization_with_integration_and_trigger(
156
181
assert toolset .get_tools ()[0 ].name == "Test Tool"
157
182
158
183
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
+
159
236
def test_initialization_with_connection_and_entity_operations (
160
237
project ,
161
238
location ,
@@ -263,16 +340,7 @@ def test_initialization_without_required_params(project, location):
263
340
" \\ (entity_operations or actions\\ )\\ ) should be provided."
264
341
),
265
342
):
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" ])
276
344
277
345
with pytest .raises (
278
346
ValueError ,
@@ -310,14 +378,14 @@ def test_initialization_with_service_account_credentials(
310
378
project ,
311
379
location ,
312
380
integration = integration_name ,
313
- trigger = trigger_name ,
381
+ triggers = [ trigger_name ] ,
314
382
service_account_json = service_account_json ,
315
383
)
316
384
mock_integration_client .assert_called_once_with (
317
385
project ,
318
386
location ,
319
387
integration_name ,
320
- trigger_name ,
388
+ [ trigger_name ] ,
321
389
None ,
322
390
None ,
323
391
None ,
@@ -340,10 +408,17 @@ def test_initialization_without_explicit_service_account_credentials(
340
408
integration_name = "test-integration"
341
409
trigger_name = "test-trigger"
342
410
toolset = ApplicationIntegrationToolset (
343
- project , location , integration = integration_name , trigger = trigger_name
411
+ project , location , integration = integration_name , triggers = [ trigger_name ]
344
412
)
345
413
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 ,
347
422
)
348
423
mock_openapi_toolset .assert_called_once ()
349
424
_ , kwargs = mock_openapi_toolset .call_args
@@ -357,7 +432,7 @@ def test_get_tools(
357
432
integration_name = "test-integration"
358
433
trigger_name = "test-trigger"
359
434
toolset = ApplicationIntegrationToolset (
360
- project , location , integration = integration_name , trigger = trigger_name
435
+ project , location , integration = integration_name , triggers = [ trigger_name ]
361
436
)
362
437
tools = toolset .get_tools ()
363
438
assert len (tools ) == 1
0 commit comments