Skip to content

Commit 6ced5cb

Browse files
committed
Supplementary unit tests
Signed-off-by: Zhi Wang <[email protected]>
1 parent 86da03a commit 6ced5cb

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/backend/services/test_agent_service.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,73 @@ def mock_get_model(model_id):
966966
mock_get_model_by_model_id.assert_any_call(789)
967967

968968

969+
@patch('backend.services.agent_service.get_model_by_model_id')
970+
@patch('backend.services.agent_service.query_sub_agents_id_list')
971+
@patch('backend.services.agent_service.search_tools_for_sub_agent')
972+
@patch('backend.services.agent_service.search_agent_info_by_agent_id')
973+
@pytest.mark.asyncio
974+
async def test_get_agent_info_impl_with_business_logic_model_none(mock_search_agent_info, mock_search_tools, mock_query_sub_agents_id, mock_get_model_by_model_id):
975+
"""
976+
Test get_agent_info_impl with business_logic_model_id but get_model_by_model_id returns None.
977+
978+
This test verifies that:
979+
1. The function correctly handles when business_logic_model_id is not None but get_model_by_model_id returns None
980+
2. It sets business_logic_model_name to None when model_info is None
981+
"""
982+
# Setup
983+
mock_agent_info = {
984+
"agent_id": 123,
985+
"model_id": 456,
986+
"business_logic_model_id": 789,
987+
"business_description": "Test agent"
988+
}
989+
mock_search_agent_info.return_value = mock_agent_info
990+
991+
mock_tools = [{"tool_id": 1, "name": "Tool 1"}]
992+
mock_search_tools.return_value = mock_tools
993+
994+
mock_sub_agent_ids = [101, 102]
995+
mock_query_sub_agents_id.return_value = mock_sub_agent_ids
996+
997+
# Mock model info for main model
998+
mock_main_model_info = {
999+
"model_id": 456,
1000+
"display_name": "GPT-4",
1001+
"provider": "openai"
1002+
}
1003+
1004+
# Mock get_model_by_model_id to return None for business_logic_model_id
1005+
def mock_get_model(model_id):
1006+
if model_id == 456:
1007+
return mock_main_model_info
1008+
elif model_id == 789:
1009+
return None # Business logic model not found
1010+
return None
1011+
1012+
mock_get_model_by_model_id.side_effect = mock_get_model
1013+
1014+
# Execute
1015+
result = await get_agent_info_impl(agent_id=123, tenant_id="test_tenant")
1016+
1017+
# Assert
1018+
expected_result = {
1019+
"agent_id": 123,
1020+
"model_id": 456,
1021+
"business_logic_model_id": 789,
1022+
"business_description": "Test agent",
1023+
"tools": mock_tools,
1024+
"sub_agent_id_list": mock_sub_agent_ids,
1025+
"model_name": "GPT-4",
1026+
"business_logic_model_name": None # Should be None when model info is not found
1027+
}
1028+
assert result == expected_result
1029+
1030+
# Verify both models were looked up
1031+
assert mock_get_model_by_model_id.call_count == 2
1032+
mock_get_model_by_model_id.assert_any_call(456)
1033+
mock_get_model_by_model_id.assert_any_call(789)
1034+
1035+
9691036
async def test_list_all_agent_info_impl_success():
9701037
"""
9711038
Test successful retrieval of all agent information.

0 commit comments

Comments
 (0)