15
15
import asyncio
16
16
import importlib
17
17
import json
18
+ import logging
18
19
import os
19
20
import pytest
20
21
import sys
@@ -963,10 +964,17 @@ def test_list_agent_engine(self):
963
964
None ,
964
965
)
965
966
967
+ @pytest .mark .usefixtures ("caplog" )
966
968
@mock .patch .object (_agent_engines , "_prepare" )
967
969
@mock .patch .object (agent_engines .AgentEngines , "_await_operation" )
968
- def test_create_agent_engine (self , mock_await_operation , mock_prepare ):
969
- mock_await_operation .return_value = _genai_types .AgentEngineOperation ()
970
+ def test_create_agent_engine (self , mock_await_operation , mock_prepare , caplog ):
971
+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
972
+ response = _genai_types .ReasoningEngine (
973
+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
974
+ spec = _TEST_AGENT_ENGINE_SPEC ,
975
+ )
976
+ )
977
+ caplog .set_level (logging .INFO , logger = "vertexai_genai.agentengines" )
970
978
with mock .patch .object (
971
979
self .client .agent_engines ._api_client , "request"
972
980
) as request_mock :
@@ -1004,6 +1012,12 @@ def test_create_agent_engine(self, mock_await_operation, mock_prepare):
1004
1012
},
1005
1013
None ,
1006
1014
)
1015
+ assert "View progress and logs at" in caplog .text
1016
+ assert "Agent Engine created. To use it in another session:" in caplog .text
1017
+ assert (
1018
+ f"agent_engine=client.agent_engines.get("
1019
+ f"'{ _TEST_AGENT_ENGINE_RESOURCE_NAME } ')" in caplog .text
1020
+ )
1007
1021
1008
1022
@mock .patch .object (agent_engines .AgentEngines , "_create_config" )
1009
1023
@mock .patch .object (agent_engines .AgentEngines , "_await_operation" )
@@ -1016,7 +1030,12 @@ def test_create_agent_engine_lightweight(
1016
1030
display_name = _TEST_AGENT_ENGINE_DISPLAY_NAME ,
1017
1031
description = _TEST_AGENT_ENGINE_DESCRIPTION ,
1018
1032
)
1019
- mock_await_operation .return_value = _genai_types .AgentEngineOperation ()
1033
+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
1034
+ response = _genai_types .ReasoningEngine (
1035
+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
1036
+ spec = _TEST_AGENT_ENGINE_SPEC ,
1037
+ )
1038
+ )
1020
1039
with mock .patch .object (
1021
1040
self .client .agent_engines ._api_client , "request"
1022
1041
) as request_mock :
@@ -1061,7 +1080,12 @@ def test_create_agent_engine_with_env_vars_dict(
1061
1080
"agent_framework" : _TEST_AGENT_ENGINE_FRAMEWORK ,
1062
1081
},
1063
1082
}
1064
- mock_await_operation .return_value = _genai_types .AgentEngineOperation ()
1083
+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
1084
+ response = _genai_types .ReasoningEngine (
1085
+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
1086
+ spec = _TEST_AGENT_ENGINE_SPEC ,
1087
+ )
1088
+ )
1065
1089
with mock .patch .object (
1066
1090
self .client .agent_engines ._api_client , "request"
1067
1091
) as request_mock :
@@ -1106,10 +1130,19 @@ def test_create_agent_engine_with_env_vars_dict(
1106
1130
None ,
1107
1131
)
1108
1132
1133
+ @pytest .mark .usefixtures ("caplog" )
1109
1134
@mock .patch .object (_agent_engines , "_prepare" )
1110
1135
@mock .patch .object (agent_engines .AgentEngines , "_await_operation" )
1111
- def test_update_agent_engine_requirements (self , mock_await_operation , mock_prepare ):
1112
- mock_await_operation .return_value = _genai_types .AgentEngineOperation ()
1136
+ def test_update_agent_engine_requirements (
1137
+ self , mock_await_operation , mock_prepare , caplog
1138
+ ):
1139
+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
1140
+ response = _genai_types .ReasoningEngine (
1141
+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
1142
+ spec = _TEST_AGENT_ENGINE_SPEC ,
1143
+ )
1144
+ )
1145
+ caplog .set_level (logging .INFO , logger = "vertexai_genai.agentengines" )
1113
1146
with mock .patch .object (
1114
1147
self .client .agent_engines ._api_client , "request"
1115
1148
) as request_mock :
@@ -1149,13 +1182,23 @@ def test_update_agent_engine_requirements(self, mock_await_operation, mock_prepa
1149
1182
},
1150
1183
None ,
1151
1184
)
1185
+ assert "Agent Engine updated. To use it in another session:" in caplog .text
1186
+ assert (
1187
+ f"agent_engine=client.agent_engines.get("
1188
+ f"'{ _TEST_AGENT_ENGINE_RESOURCE_NAME } ')" in caplog .text
1189
+ )
1152
1190
1153
1191
@mock .patch .object (_agent_engines , "_prepare" )
1154
1192
@mock .patch .object (agent_engines .AgentEngines , "_await_operation" )
1155
1193
def test_update_agent_engine_extra_packages (
1156
1194
self , mock_await_operation , mock_prepare
1157
1195
):
1158
- mock_await_operation .return_value = _genai_types .AgentEngineOperation ()
1196
+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
1197
+ response = _genai_types .ReasoningEngine (
1198
+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
1199
+ spec = _TEST_AGENT_ENGINE_SPEC ,
1200
+ )
1201
+ )
1159
1202
with mock .patch .object (
1160
1203
self .client .agent_engines ._api_client , "request"
1161
1204
) as request_mock :
@@ -1201,8 +1244,15 @@ def test_update_agent_engine_extra_packages(
1201
1244
1202
1245
@mock .patch .object (_agent_engines , "_prepare" )
1203
1246
@mock .patch .object (agent_engines .AgentEngines , "_await_operation" )
1204
- def test_update_agent_engine_env_vars (self , mock_await_operation , mock_prepare ):
1205
- mock_await_operation .return_value = _genai_types .AgentEngineOperation ()
1247
+ def test_update_agent_engine_env_vars (
1248
+ self , mock_await_operation , mock_prepare , caplog
1249
+ ):
1250
+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
1251
+ response = _genai_types .ReasoningEngine (
1252
+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
1253
+ spec = _TEST_AGENT_ENGINE_SPEC ,
1254
+ )
1255
+ )
1206
1256
with mock .patch .object (
1207
1257
self .client .agent_engines ._api_client , "request"
1208
1258
) as request_mock :
@@ -1251,7 +1301,12 @@ def test_update_agent_engine_env_vars(self, mock_await_operation, mock_prepare):
1251
1301
1252
1302
@mock .patch .object (agent_engines .AgentEngines , "_await_operation" )
1253
1303
def test_update_agent_engine_display_name (self , mock_await_operation ):
1254
- mock_await_operation .return_value = _genai_types .AgentEngineOperation ()
1304
+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
1305
+ response = _genai_types .ReasoningEngine (
1306
+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
1307
+ spec = _TEST_AGENT_ENGINE_SPEC ,
1308
+ )
1309
+ )
1255
1310
with mock .patch .object (
1256
1311
self .client .agent_engines ._api_client , "request"
1257
1312
) as request_mock :
@@ -1275,7 +1330,12 @@ def test_update_agent_engine_display_name(self, mock_await_operation):
1275
1330
1276
1331
@mock .patch .object (agent_engines .AgentEngines , "_await_operation" )
1277
1332
def test_update_agent_engine_description (self , mock_await_operation ):
1278
- mock_await_operation .return_value = _genai_types .AgentEngineOperation ()
1333
+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
1334
+ response = _genai_types .ReasoningEngine (
1335
+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
1336
+ spec = _TEST_AGENT_ENGINE_SPEC ,
1337
+ )
1338
+ )
1279
1339
with mock .patch .object (
1280
1340
self .client .agent_engines ._api_client , "request"
1281
1341
) as request_mock :
0 commit comments