|
| 1 | +""" |
| 2 | +测试 AgentRuntimeControlAPI 对底层 SDK client 的调用是否与 SDK 方法签名匹配。 |
| 3 | +""" |
| 4 | + |
| 5 | +from unittest.mock import create_autospec, MagicMock, patch |
| 6 | + |
| 7 | +from alibabacloud_agentrun20250910.client import Client as AgentRunClient |
| 8 | +from alibabacloud_agentrun20250910.models import ( |
| 9 | + CreateAgentRuntimeEndpointInput, |
| 10 | + CreateAgentRuntimeInput, |
| 11 | + GetAgentRuntimeRequest, |
| 12 | + ListAgentRuntimeEndpointsRequest, |
| 13 | + ListAgentRuntimesRequest, |
| 14 | + ListAgentRuntimeVersionsRequest, |
| 15 | + UpdateAgentRuntimeEndpointInput, |
| 16 | + UpdateAgentRuntimeInput, |
| 17 | +) |
| 18 | +import pytest |
| 19 | + |
| 20 | +from agentrun.agent_runtime.api.control import AgentRuntimeControlAPI |
| 21 | +from agentrun.utils.config import Config |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture |
| 25 | +def mock_config(): |
| 26 | + return Config( |
| 27 | + access_key_id="test-ak", |
| 28 | + access_key_secret="test-sk", |
| 29 | + region_id="cn-hangzhou", |
| 30 | + control_endpoint="https://agentrun.cn-hangzhou.aliyuncs.com", |
| 31 | + ) |
| 32 | + |
| 33 | + |
| 34 | +@pytest.fixture |
| 35 | +def mock_response(): |
| 36 | + response = MagicMock() |
| 37 | + response.body.request_id = "test-request-id" |
| 38 | + response.body.data = MagicMock() |
| 39 | + return response |
| 40 | + |
| 41 | + |
| 42 | +@pytest.fixture |
| 43 | +def api_and_client(mock_config, mock_response): |
| 44 | + api = AgentRuntimeControlAPI(config=mock_config) |
| 45 | + mock_client = create_autospec(AgentRunClient, instance=True) |
| 46 | + |
| 47 | + for attr in dir(AgentRunClient): |
| 48 | + if "with_options" in attr: |
| 49 | + getattr(mock_client, attr).return_value = mock_response |
| 50 | + |
| 51 | + with patch.object(api, "_get_client", return_value=mock_client): |
| 52 | + yield api, mock_client |
| 53 | + |
| 54 | + |
| 55 | +class TestAgentRuntimeControlAPISignatures: |
| 56 | + |
| 57 | + def test_create_agent_runtime(self, api_and_client): |
| 58 | + api, client = api_and_client |
| 59 | + input_data = MagicMock(spec=CreateAgentRuntimeInput) |
| 60 | + api.create_agent_runtime(input_data) |
| 61 | + client.create_agent_runtime_with_options.assert_called_once() |
| 62 | + |
| 63 | + def test_delete_agent_runtime(self, api_and_client): |
| 64 | + api, client = api_and_client |
| 65 | + api.delete_agent_runtime("agent-123") |
| 66 | + client.delete_agent_runtime_with_options.assert_called_once() |
| 67 | + |
| 68 | + def test_update_agent_runtime(self, api_and_client): |
| 69 | + api, client = api_and_client |
| 70 | + input_data = MagicMock(spec=UpdateAgentRuntimeInput) |
| 71 | + api.update_agent_runtime("agent-123", input_data) |
| 72 | + client.update_agent_runtime_with_options.assert_called_once() |
| 73 | + |
| 74 | + def test_get_agent_runtime(self, api_and_client): |
| 75 | + api, client = api_and_client |
| 76 | + input_data = MagicMock(spec=GetAgentRuntimeRequest) |
| 77 | + api.get_agent_runtime("agent-123", input_data) |
| 78 | + client.get_agent_runtime_with_options.assert_called_once() |
| 79 | + |
| 80 | + def test_list_agent_runtimes(self, api_and_client): |
| 81 | + api, client = api_and_client |
| 82 | + input_data = MagicMock(spec=ListAgentRuntimesRequest) |
| 83 | + api.list_agent_runtimes(input_data) |
| 84 | + client.list_agent_runtimes_with_options.assert_called_once() |
| 85 | + |
| 86 | + def test_create_agent_runtime_endpoint(self, api_and_client): |
| 87 | + api, client = api_and_client |
| 88 | + input_data = MagicMock(spec=CreateAgentRuntimeEndpointInput) |
| 89 | + api.create_agent_runtime_endpoint("agent-123", input_data) |
| 90 | + client.create_agent_runtime_endpoint_with_options.assert_called_once() |
| 91 | + |
| 92 | + def test_delete_agent_runtime_endpoint(self, api_and_client): |
| 93 | + api, client = api_and_client |
| 94 | + api.delete_agent_runtime_endpoint("agent-123", "endpoint-456") |
| 95 | + client.delete_agent_runtime_endpoint_with_options.assert_called_once() |
| 96 | + |
| 97 | + def test_update_agent_runtime_endpoint(self, api_and_client): |
| 98 | + api, client = api_and_client |
| 99 | + input_data = MagicMock(spec=UpdateAgentRuntimeEndpointInput) |
| 100 | + api.update_agent_runtime_endpoint( |
| 101 | + "agent-123", "endpoint-456", input_data |
| 102 | + ) |
| 103 | + client.update_agent_runtime_endpoint_with_options.assert_called_once() |
| 104 | + |
| 105 | + def test_get_agent_runtime_endpoint(self, api_and_client): |
| 106 | + api, client = api_and_client |
| 107 | + api.get_agent_runtime_endpoint("agent-123", "endpoint-456") |
| 108 | + client.get_agent_runtime_endpoint_with_options.assert_called_once() |
| 109 | + |
| 110 | + def test_list_agent_runtime_endpoints(self, api_and_client): |
| 111 | + api, client = api_and_client |
| 112 | + input_data = MagicMock(spec=ListAgentRuntimeEndpointsRequest) |
| 113 | + api.list_agent_runtime_endpoints("agent-123", input_data) |
| 114 | + client.list_agent_runtime_endpoints_with_options.assert_called_once() |
| 115 | + |
| 116 | + def test_list_agent_runtime_versions(self, api_and_client): |
| 117 | + api, client = api_and_client |
| 118 | + input_data = MagicMock(spec=ListAgentRuntimeVersionsRequest) |
| 119 | + api.list_agent_runtime_versions("agent-123", input_data) |
| 120 | + client.list_agent_runtime_versions_with_options.assert_called_once() |
| 121 | + |
| 122 | + |
| 123 | +class TestAgentRuntimeControlAPIAsyncSignatures: |
| 124 | + |
| 125 | + @pytest.mark.asyncio |
| 126 | + async def test_create_agent_runtime_async(self, api_and_client): |
| 127 | + api, client = api_and_client |
| 128 | + input_data = MagicMock(spec=CreateAgentRuntimeInput) |
| 129 | + await api.create_agent_runtime_async(input_data) |
| 130 | + client.create_agent_runtime_with_options_async.assert_called_once() |
| 131 | + |
| 132 | + @pytest.mark.asyncio |
| 133 | + async def test_delete_agent_runtime_async(self, api_and_client): |
| 134 | + api, client = api_and_client |
| 135 | + await api.delete_agent_runtime_async("agent-123") |
| 136 | + client.delete_agent_runtime_with_options_async.assert_called_once() |
| 137 | + |
| 138 | + @pytest.mark.asyncio |
| 139 | + async def test_update_agent_runtime_async(self, api_and_client): |
| 140 | + api, client = api_and_client |
| 141 | + input_data = MagicMock(spec=UpdateAgentRuntimeInput) |
| 142 | + await api.update_agent_runtime_async("agent-123", input_data) |
| 143 | + client.update_agent_runtime_with_options_async.assert_called_once() |
| 144 | + |
| 145 | + @pytest.mark.asyncio |
| 146 | + async def test_get_agent_runtime_async(self, api_and_client): |
| 147 | + api, client = api_and_client |
| 148 | + input_data = MagicMock(spec=GetAgentRuntimeRequest) |
| 149 | + await api.get_agent_runtime_async("agent-123", input_data) |
| 150 | + client.get_agent_runtime_with_options_async.assert_called_once() |
| 151 | + |
| 152 | + @pytest.mark.asyncio |
| 153 | + async def test_list_agent_runtimes_async(self, api_and_client): |
| 154 | + api, client = api_and_client |
| 155 | + input_data = MagicMock(spec=ListAgentRuntimesRequest) |
| 156 | + await api.list_agent_runtimes_async(input_data) |
| 157 | + client.list_agent_runtimes_with_options_async.assert_called_once() |
| 158 | + |
| 159 | + @pytest.mark.asyncio |
| 160 | + async def test_create_agent_runtime_endpoint_async(self, api_and_client): |
| 161 | + api, client = api_and_client |
| 162 | + input_data = MagicMock(spec=CreateAgentRuntimeEndpointInput) |
| 163 | + await api.create_agent_runtime_endpoint_async("agent-123", input_data) |
| 164 | + client.create_agent_runtime_endpoint_with_options_async.assert_called_once() |
| 165 | + |
| 166 | + @pytest.mark.asyncio |
| 167 | + async def test_delete_agent_runtime_endpoint_async(self, api_and_client): |
| 168 | + api, client = api_and_client |
| 169 | + await api.delete_agent_runtime_endpoint_async( |
| 170 | + "agent-123", "endpoint-456" |
| 171 | + ) |
| 172 | + client.delete_agent_runtime_endpoint_with_options_async.assert_called_once() |
| 173 | + |
| 174 | + @pytest.mark.asyncio |
| 175 | + async def test_update_agent_runtime_endpoint_async(self, api_and_client): |
| 176 | + api, client = api_and_client |
| 177 | + input_data = MagicMock(spec=UpdateAgentRuntimeEndpointInput) |
| 178 | + await api.update_agent_runtime_endpoint_async( |
| 179 | + "agent-123", "endpoint-456", input_data |
| 180 | + ) |
| 181 | + client.update_agent_runtime_endpoint_with_options_async.assert_called_once() |
| 182 | + |
| 183 | + @pytest.mark.asyncio |
| 184 | + async def test_get_agent_runtime_endpoint_async(self, api_and_client): |
| 185 | + api, client = api_and_client |
| 186 | + await api.get_agent_runtime_endpoint_async("agent-123", "endpoint-456") |
| 187 | + client.get_agent_runtime_endpoint_with_options_async.assert_called_once() |
| 188 | + |
| 189 | + @pytest.mark.asyncio |
| 190 | + async def test_list_agent_runtime_endpoints_async(self, api_and_client): |
| 191 | + api, client = api_and_client |
| 192 | + input_data = MagicMock(spec=ListAgentRuntimeEndpointsRequest) |
| 193 | + await api.list_agent_runtime_endpoints_async("agent-123", input_data) |
| 194 | + client.list_agent_runtime_endpoints_with_options_async.assert_called_once() |
| 195 | + |
| 196 | + @pytest.mark.asyncio |
| 197 | + async def test_list_agent_runtime_versions_async(self, api_and_client): |
| 198 | + api, client = api_and_client |
| 199 | + input_data = MagicMock(spec=ListAgentRuntimeVersionsRequest) |
| 200 | + await api.list_agent_runtime_versions_async("agent-123", input_data) |
| 201 | + client.list_agent_runtime_versions_with_options_async.assert_called_once() |
0 commit comments