@@ -468,3 +468,115 @@ def test_invoke_openai(self, mock_client_class, mock_data_api_class):
468468 def test_invoke_openai_async (self , mock_client_class , mock_data_api_class ):
469469 """测试 invoke_openai_async - 跳过因为私有属性问题"""
470470 pass
471+
472+
473+ class TestAgentRuntimeEndpointAbstractMethods :
474+ """测试 AgentRuntimeEndpoint 抽象方法实现
475+
476+ 此测试类用于验证 AgentRuntimeEndpoint 正确实现了 ResourceBase 要求的抽象方法。
477+ 这是为了防止类似于 Issue #XXX 的问题再次发生,确保 from_inner_object 能够正常实例化对象。
478+ """
479+
480+ def test_from_inner_object_instantiation (self ):
481+ """测试 from_inner_object 能够正常实例化对象
482+
483+ 这个测试确保 AgentRuntimeEndpoint 类实现了所有必需的抽象方法。
484+ 如果抽象方法未实现,from_inner_object 会抛出 TypeError。
485+ """
486+
487+ # 准备一个最小的有效数据
488+ class MockDaraModel :
489+
490+ def to_map (self ):
491+ return {
492+ "agentRuntimeEndpointId" : "are-test-123" ,
493+ "agentRuntimeEndpointName" : "test-endpoint" ,
494+ "agentRuntimeId" : "ar-test-123" ,
495+ "status" : "READY" ,
496+ }
497+
498+ inner_obj = MockDaraModel ()
499+
500+ # 这里不应该抛出 TypeError: Can't instantiate abstract class
501+ endpoint = AgentRuntimeEndpoint .from_inner_object (inner_obj )
502+
503+ # 验证对象正确创建
504+ assert endpoint is not None
505+ assert endpoint .agent_runtime_endpoint_id == "are-test-123"
506+ assert endpoint .agent_runtime_endpoint_name == "test-endpoint"
507+
508+ def test_list_page_method_exists (self ):
509+ """测试 _list_page 方法存在且可调用"""
510+ # 验证类有 _list_page 方法
511+ assert hasattr (AgentRuntimeEndpoint , "_list_page" )
512+ assert callable (getattr (AgentRuntimeEndpoint , "_list_page" ))
513+
514+ def test_list_page_async_method_exists (self ):
515+ """测试 _list_page_async 方法存在且可调用"""
516+ # 验证类有 _list_page_async 方法
517+ assert hasattr (AgentRuntimeEndpoint , "_list_page_async" )
518+ assert callable (getattr (AgentRuntimeEndpoint , "_list_page_async" ))
519+
520+ @patch (CLIENT_PATH )
521+ def test_list_page_requires_agent_runtime_id (self , mock_client_class ):
522+ """测试 _list_page 需要 agent_runtime_id 参数"""
523+ from agentrun .utils .model import PageableInput
524+
525+ # 不提供 agent_runtime_id 应该抛出 ValueError
526+ with pytest .raises (ValueError , match = "agent_runtime_id is required" ):
527+ AgentRuntimeEndpoint ._list_page (
528+ PageableInput (page_number = 1 , page_size = 10 )
529+ )
530+
531+ @patch (CLIENT_PATH )
532+ def test_list_page_async_requires_agent_runtime_id (self , mock_client_class ):
533+ """测试 _list_page_async 需要 agent_runtime_id 参数"""
534+ from agentrun .utils .model import PageableInput
535+
536+ # 不提供 agent_runtime_id 应该抛出 ValueError
537+ with pytest .raises (ValueError , match = "agent_runtime_id is required" ):
538+ asyncio .run (
539+ AgentRuntimeEndpoint ._list_page_async (
540+ PageableInput (page_number = 1 , page_size = 10 )
541+ )
542+ )
543+
544+ @patch (CLIENT_PATH )
545+ def test_list_page_with_agent_runtime_id (self , mock_client_class ):
546+ """测试 _list_page 正确传递 agent_runtime_id"""
547+ from agentrun .utils .model import PageableInput
548+
549+ mock_client = MagicMock ()
550+ mock_client .list_endpoints .return_value = []
551+ mock_client_class .return_value = mock_client
552+
553+ # 提供 agent_runtime_id 应该正常执行
554+ result = AgentRuntimeEndpoint ._list_page (
555+ PageableInput (page_number = 1 , page_size = 10 ),
556+ agent_runtime_id = "ar-test-123" ,
557+ )
558+
559+ # 验证调用了 list_endpoints
560+ mock_client .list_endpoints .assert_called_once ()
561+ assert result == []
562+
563+ @patch (CLIENT_PATH )
564+ def test_list_page_async_with_agent_runtime_id (self , mock_client_class ):
565+ """测试 _list_page_async 正确传递 agent_runtime_id"""
566+ from agentrun .utils .model import PageableInput
567+
568+ mock_client = MagicMock ()
569+ mock_client .list_endpoints_async = AsyncMock (return_value = [])
570+ mock_client_class .return_value = mock_client
571+
572+ # 提供 agent_runtime_id 应该正常执行
573+ result = asyncio .run (
574+ AgentRuntimeEndpoint ._list_page_async (
575+ PageableInput (page_number = 1 , page_size = 10 ),
576+ agent_runtime_id = "ar-test-123" ,
577+ )
578+ )
579+
580+ # 验证调用了 list_endpoints_async
581+ mock_client .list_endpoints_async .assert_called_once ()
582+ assert result == []
0 commit comments