Skip to content

Commit 70876de

Browse files
committed
test(model): update ModelProxy tests to use proper mocking and parameters
Update the unit tests for ModelProxy completions and responses methods to properly mock litellm functions instead of mocking the data client completions/responses methods. Also correct the test_responses method to pass the correct 'input' parameter instead of 'messages'. The changes ensure that the tests accurately reflect how the ModelProxy interacts with the underlying litellm API while maintaining proper mocking behavior. 更新 ModelProxy 测试以使用正确的模拟和参数 更新 ModelProxy 完成和响应方法的单元测试,以正确模拟 litellm 函数, 而不是模拟数据客户端的完成/响应方法。同时修正 test_responses 方法, 传递正确的 'input' 参数而不是 'messages'。 这些更改确保测试准确反映 ModelProxy 如何与底层 litellm API 交互, 同时保持适当的模拟行为。 Change-Id: I5fffbf165d23efa7607c2618b1fd9604df3caeb6 Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent cfffd23 commit 70876de

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

tests/unittests/model/test_model_proxy.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -527,23 +527,25 @@ class TestModelProxyCompletions:
527527
"AGENTRUN_ACCOUNT_ID": "test-account",
528528
},
529529
)
530-
def test_completions(self):
530+
@patch("litellm.completion")
531+
def test_completions(self, mock_completion):
531532
from agentrun.model.api.data import BaseInfo
532533

534+
mock_completion.return_value = {"choices": []}
535+
533536
proxy = ModelProxy(model_proxy_name="test-proxy")
534537

535-
# Create a mock _data_client directly
538+
# Create a mock _data_client to provide model_info
536539
mock_data_client = MagicMock()
537540
mock_info = BaseInfo(model="gpt-4", base_url="https://api.example.com")
538541
mock_data_client.model_info.return_value = mock_info
539-
mock_data_client.completions.return_value = {"choices": []}
540542

541-
# Bypass the model_info call by setting _data_client
543+
# Set _data_client so model_info() returns our mock info
542544
proxy._data_client = mock_data_client
543545

544546
proxy.completions(messages=[{"role": "user", "content": "Hello"}])
545547

546-
mock_data_client.completions.assert_called_once()
548+
mock_completion.assert_called_once()
547549

548550

549551
class TestModelProxyResponses:
@@ -557,20 +559,24 @@ class TestModelProxyResponses:
557559
"AGENTRUN_ACCOUNT_ID": "test-account",
558560
},
559561
)
560-
def test_responses(self):
562+
@patch("litellm.responses")
563+
def test_responses(self, mock_responses):
561564
from agentrun.model.api.data import BaseInfo
562565

566+
mock_responses.return_value = {}
567+
563568
proxy = ModelProxy(model_proxy_name="test-proxy")
564569

565-
# Create a mock _data_client directly
570+
# Create a mock _data_client to provide model_info
566571
mock_data_client = MagicMock()
567572
mock_info = BaseInfo(model="gpt-4", base_url="https://api.example.com")
568573
mock_data_client.model_info.return_value = mock_info
569-
mock_data_client.responses.return_value = {}
570574

571-
# Bypass the model_info call by setting _data_client
575+
# Set _data_client so model_info() returns our mock info
572576
proxy._data_client = mock_data_client
573577

574-
proxy.responses(messages=[{"role": "user", "content": "Hello"}])
578+
# Note: The responses method expects 'input' parameter (not 'messages')
579+
# based on the ModelAPI.responses signature
580+
proxy.responses(input="Hello")
575581

576-
mock_data_client.responses.assert_called_once()
582+
mock_responses.assert_called_once()

0 commit comments

Comments
 (0)