@@ -47,7 +47,14 @@ def mock_openapi_toolset():
47
47
mock_toolset_instance = mock .MagicMock ()
48
48
mock_rest_api_tool = mock .MagicMock (spec = rest_api_tool .RestApiTool )
49
49
mock_rest_api_tool .name = "Test Tool"
50
- mock_toolset_instance .get_tools .return_value = [mock_rest_api_tool ]
50
+
51
+ # Create an async mock for the get_tools method
52
+ async def mock_get_tools ():
53
+ return [mock_rest_api_tool ]
54
+
55
+ # Assign the async mock function to get_tools
56
+ mock_toolset_instance .get_tools = mock_get_tools
57
+
51
58
mock_toolset .return_value = mock_toolset_instance
52
59
yield mock_toolset
53
60
@@ -62,10 +69,12 @@ def mock_openapi_toolset_with_multiple_tools_and_no_tools():
62
69
mock_rest_api_tool .name = "Test Tool"
63
70
mock_rest_api_tool_2 = mock .MagicMock (spec = rest_api_tool .RestApiTool )
64
71
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
- ]
72
+
73
+ # Create an async mock for the get_tools method
74
+ async def mock_get_tools ():
75
+ return [mock_rest_api_tool , mock_rest_api_tool_2 ]
76
+
77
+ mock_toolset_instance .get_tools = mock_get_tools
69
78
mock_toolset .return_value = mock_toolset_instance
70
79
yield mock_toolset
71
80
@@ -152,7 +161,8 @@ def connection_details():
152
161
}
153
162
154
163
155
- def test_initialization_with_integration_and_trigger (
164
+ @pytest .mark .asyncio
165
+ async def test_initialization_with_integration_and_trigger (
156
166
project ,
157
167
location ,
158
168
mock_integration_client ,
@@ -170,11 +180,13 @@ def test_initialization_with_integration_and_trigger(
170
180
mock_integration_client .return_value .get_openapi_spec_for_integration .assert_called_once ()
171
181
mock_connections_client .assert_not_called ()
172
182
mock_openapi_toolset .assert_called_once ()
173
- assert len (toolset .get_tools ()) == 1
174
- assert toolset .get_tools ()[0 ].name == "Test Tool"
183
+ tools = await toolset .get_tools ()
184
+ assert len (tools ) == 1
185
+ assert tools [0 ].name == "Test Tool"
175
186
176
187
177
- def test_initialization_with_integration_and_list_of_triggers (
188
+ @pytest .mark .asyncio
189
+ async def test_initialization_with_integration_and_list_of_triggers (
178
190
project ,
179
191
location ,
180
192
mock_integration_client ,
@@ -199,12 +211,14 @@ def test_initialization_with_integration_and_list_of_triggers(
199
211
mock_integration_client .return_value .get_openapi_spec_for_integration .assert_called_once ()
200
212
mock_connections_client .assert_not_called ()
201
213
mock_openapi_toolset_with_multiple_tools_and_no_tools .assert_called_once ()
202
- assert len (toolset .get_tools ()) == 2
203
- assert toolset .get_tools ()[0 ].name == "Test Tool"
204
- assert toolset .get_tools ()[1 ].name == "Test Tool 2"
214
+ tools = await toolset .get_tools ()
215
+ assert len (tools ) == 2
216
+ assert tools [0 ].name == "Test Tool"
217
+ assert tools [1 ].name == "Test Tool 2"
205
218
206
219
207
- def test_initialization_with_integration_and_empty_trigger_list (
220
+ @pytest .mark .asyncio
221
+ async def test_initialization_with_integration_and_empty_trigger_list (
208
222
project ,
209
223
location ,
210
224
mock_integration_client ,
@@ -221,12 +235,14 @@ def test_initialization_with_integration_and_empty_trigger_list(
221
235
mock_integration_client .return_value .get_openapi_spec_for_integration .assert_called_once ()
222
236
mock_connections_client .assert_not_called ()
223
237
mock_openapi_toolset_with_multiple_tools_and_no_tools .assert_called_once ()
224
- assert len (toolset .get_tools ()) == 2
225
- assert toolset .get_tools ()[0 ].name == "Test Tool"
226
- assert toolset .get_tools ()[1 ].name == "Test Tool 2"
238
+ tools = await toolset .get_tools ()
239
+ assert len (tools ) == 2
240
+ assert tools [0 ].name == "Test Tool"
241
+ assert tools [1 ].name == "Test Tool 2"
227
242
228
243
229
- def test_initialization_with_connection_and_entity_operations (
244
+ @pytest .mark .asyncio
245
+ async def test_initialization_with_connection_and_entity_operations (
230
246
project ,
231
247
location ,
232
248
mock_integration_client ,
@@ -268,14 +284,17 @@ def test_initialization_with_connection_and_entity_operations(
268
284
tool_name ,
269
285
tool_instructions ,
270
286
)
271
- assert len (toolset .get_tools ()) == 1
272
- assert toolset .get_tools ()[0 ].name == "list_issues"
273
- assert isinstance (toolset .get_tools ()[0 ], IntegrationConnectorTool )
274
- assert toolset .get_tools ()[0 ].entity == "Issues"
275
- assert toolset .get_tools ()[0 ].operation == "LIST_ENTITIES"
287
+
288
+ tools = await toolset .get_tools ()
289
+ assert len (tools ) == 1
290
+ assert tools [0 ].name == "list_issues"
291
+ assert isinstance (tools [0 ], IntegrationConnectorTool )
292
+ assert tools [0 ].entity == "Issues"
293
+ assert tools [0 ].operation == "LIST_ENTITIES"
276
294
277
295
278
- def test_initialization_with_connection_and_actions (
296
+ @pytest .mark .asyncio
297
+ async def test_initialization_with_connection_and_actions (
279
298
project ,
280
299
location ,
281
300
mock_integration_client ,
@@ -309,11 +328,12 @@ def test_initialization_with_connection_and_actions(
309
328
tool_name , tool_instructions
310
329
)
311
330
mock_openapi_action_spec_parser .return_value .parse .assert_called_once ()
312
- assert len (toolset .get_tools ()) == 1
313
- assert toolset .get_tools ()[0 ].name == "list_issues_operation"
314
- assert isinstance (toolset .get_tools ()[0 ], IntegrationConnectorTool )
315
- assert toolset .get_tools ()[0 ].action == "CustomAction"
316
- assert toolset .get_tools ()[0 ].operation == "EXECUTE_ACTION"
331
+ tools = await toolset .get_tools ()
332
+ assert len (tools ) == 1
333
+ assert tools [0 ].name == "list_issues_operation"
334
+ assert isinstance (tools [0 ], IntegrationConnectorTool )
335
+ assert tools [0 ].action == "CustomAction"
336
+ assert tools [0 ].operation == "EXECUTE_ACTION"
317
337
318
338
319
339
def test_initialization_without_required_params (project , location ):
@@ -412,15 +432,16 @@ def test_initialization_without_explicit_service_account_credentials(
412
432
assert kwargs ["auth_credential" ].service_account .use_default_credential
413
433
414
434
415
- def test_get_tools (
435
+ @pytest .mark .asyncio
436
+ async def test_get_tools (
416
437
project , location , mock_integration_client , mock_openapi_toolset
417
438
):
418
439
integration_name = "test-integration"
419
440
triggers = ["test-trigger" ]
420
441
toolset = ApplicationIntegrationToolset (
421
442
project , location , integration = integration_name , triggers = triggers
422
443
)
423
- tools = toolset .get_tools ()
444
+ tools = await toolset .get_tools ()
424
445
assert len (tools ) == 1
425
446
assert isinstance (tools [0 ], rest_api_tool .RestApiTool )
426
447
assert tools [0 ].name == "Test Tool"
0 commit comments