@@ -170,14 +170,15 @@ async def test_get_adapter(self, test_client, auth_headers):
170170 assert adapter .get ("config" ) == TEST_ADAPTER_CONFIG
171171
172172 @pytest .mark .asyncio
173- async def test_create_adapter (self , test_client , auth_headers ):
173+ async def test_create_adapter (self , test_client , auth_headers , monkeypatch ):
174174 """测试创建适配器"""
175175 adapter_data = IMAdapterConfig (
176176 name = "new-adapter" , adapter = TEST_ADAPTER_TYPE , config = TEST_ADAPTER_CONFIG
177177 )
178178
179179 # Mock 配置文件保存
180- ConfigLoader .save_config_with_backup = MagicMock ()
180+ mock_save = MagicMock ()
181+ monkeypatch .setattr (ConfigLoader , "save_config_with_backup" , mock_save )
181182 response = test_client .post (
182183 "/backend-api/api/im/adapters" ,
183184 headers = auth_headers ,
@@ -192,10 +193,10 @@ async def test_create_adapter(self, test_client, auth_headers):
192193 assert adapter .get ("config" ) == TEST_ADAPTER_CONFIG
193194
194195 # 验证配置保存
195- ConfigLoader . save_config_with_backup .assert_called_once ()
196+ mock_save .assert_called_once ()
196197
197198 @pytest .mark .asyncio
198- async def test_update_adapter (self , test_client , auth_headers ):
199+ async def test_update_adapter (self , test_client , auth_headers , monkeypatch ):
199200 """测试更新适配器"""
200201 adapter_data = IMAdapterConfig (
201202 name = TEST_ADAPTER_ID ,
@@ -204,7 +205,8 @@ async def test_update_adapter(self, test_client, auth_headers):
204205 )
205206
206207 # Mock 配置文件保存
207- ConfigLoader .save_config_with_backup = MagicMock ()
208+ mock_save = MagicMock ()
209+ monkeypatch .setattr (ConfigLoader , "save_config_with_backup" , mock_save )
208210 response = test_client .put (
209211 f"/backend-api/api/im/adapters/{ TEST_ADAPTER_ID } " ,
210212 headers = auth_headers ,
@@ -220,7 +222,7 @@ async def test_update_adapter(self, test_client, auth_headers):
220222 assert adapter .get ("config" ).get ("name" ) == "Updated Bot"
221223
222224 # 验证配置保存
223- ConfigLoader . save_config_with_backup .assert_called_once ()
225+ mock_save .assert_called_once ()
224226
225227 @pytest .mark .asyncio
226228 async def test_stop_adapter (self , test_client , auth_headers ):
@@ -260,7 +262,7 @@ async def test_start_adapter(self, test_client, auth_headers):
260262 assert data .get ("adapter" ).get ("is_running" ) is True
261263
262264 @pytest .mark .asyncio
263- async def test_delete_adapter (self , test_client , auth_headers ):
265+ async def test_delete_adapter (self , test_client , auth_headers , monkeypatch ):
264266 """测试删除适配器"""
265267 # 先启动适配器
266268 test_client .post (
@@ -269,7 +271,8 @@ async def test_delete_adapter(self, test_client, auth_headers):
269271 )
270272
271273 # Mock 配置文件保存
272- ConfigLoader .save_config_with_backup = MagicMock ()
274+ mock_save = MagicMock ()
275+ monkeypatch .setattr (ConfigLoader , "save_config_with_backup" , mock_save )
273276 response = test_client .delete (
274277 f"/backend-api/api/im/adapters/{ TEST_ADAPTER_ID } " , headers = auth_headers
275278 )
@@ -279,7 +282,7 @@ async def test_delete_adapter(self, test_client, auth_headers):
279282 assert data .get ("message" ) == "Adapter deleted successfully"
280283
281284 # 验证配置保存
282- ConfigLoader . save_config_with_backup .assert_called_once ()
285+ mock_save .assert_called_once ()
283286
284287 @pytest .mark .asyncio
285288 async def test_get_adapter_config_schema (self , test_client , auth_headers ):
0 commit comments