2525 RlsapiV1Terminal ,
2626)
2727from models .rlsapi .responses import RlsapiV1InferResponse
28- from tests .unit .conftest import AgentFixtures
2928from tests .unit .utils .auth_helpers import mock_authorization_resolvers
3029from utils .suid import check_suid
3130
@@ -44,29 +43,31 @@ def mock_configuration_fixture(
4443
4544
4645@pytest .fixture (name = "mock_llm_response" )
47- def mock_llm_response_fixture (
48- mocker : MockerFixture , prepare_agent_mocks : AgentFixtures
49- ) -> None :
50- """Mock the LLM integration for successful responses."""
51- mock_client , mock_agent = prepare_agent_mocks
46+ def mock_llm_response_fixture (mocker : MockerFixture ) -> None :
47+ """Mock the LLM integration for successful responses via chat.completions."""
48+ # Create mock message with content
49+ mock_message = mocker . Mock ()
50+ mock_message . content = "This is a test LLM response."
5251
53- # Create mock output message with content
54- mock_output_message = mocker .Mock ()
55- mock_output_message . content = "This is a test LLM response."
52+ # Create mock choice with message
53+ mock_choice = mocker .Mock ()
54+ mock_choice . message = mock_message
5655
57- # Create mock turn response
58- mock_turn = mocker .Mock ()
59- mock_turn .output_message = mock_output_message
60- mock_turn .steps = []
56+ # Create mock completion response with choices
57+ mock_response = mocker .Mock ()
58+ mock_response .choices = [mock_choice ]
6159
62- # Use AsyncMock for async method
63- mock_agent .create_turn = mocker .AsyncMock (return_value = mock_turn )
60+ # Create mock chat.completions.create() method
61+ mock_completions = mocker .Mock ()
62+ mock_completions .create = mocker .AsyncMock (return_value = mock_response )
6463
65- # Mock get_temp_agent to return our mock agent
66- mocker .patch (
67- "app.endpoints.rlsapi_v1.get_temp_agent" ,
68- return_value = (mock_agent , "test_session_id" , None ),
69- )
64+ # Create mock chat object
65+ mock_chat = mocker .Mock ()
66+ mock_chat .completions = mock_completions
67+
68+ # Create mock client
69+ mock_client = mocker .Mock ()
70+ mock_client .chat = mock_chat
7071
7172 # Mock the client holder
7273 mock_client_holder = mocker .Mock ()
@@ -78,27 +79,20 @@ def mock_llm_response_fixture(
7879
7980
8081@pytest .fixture (name = "mock_empty_llm_response" )
81- def mock_empty_llm_response_fixture (
82- mocker : MockerFixture , prepare_agent_mocks : AgentFixtures
83- ) -> None :
84- """Mock the LLM integration for empty responses (output_message=None)."""
85- mock_client , mock_agent = prepare_agent_mocks
82+ def mock_empty_llm_response_fixture (mocker : MockerFixture ) -> None :
83+ """Mock chat.completions to return empty choices list."""
84+ mock_response = mocker .Mock ()
85+ mock_response .choices = []
8686
87- # Create mock turn response with no output
88- mock_turn = mocker .Mock ()
89- mock_turn .output_message = None
90- mock_turn .steps = []
87+ mock_completions = mocker .Mock ()
88+ mock_completions .create = mocker .AsyncMock (return_value = mock_response )
9189
92- # Use AsyncMock for async method
93- mock_agent . create_turn = mocker . AsyncMock ( return_value = mock_turn )
90+ mock_chat = mocker . Mock ()
91+ mock_chat . completions = mock_completions
9492
95- # Mock get_temp_agent to return our mock agent
96- mocker .patch (
97- "app.endpoints.rlsapi_v1.get_temp_agent" ,
98- return_value = (mock_agent , "test_session_id" , None ),
99- )
93+ mock_client = mocker .Mock ()
94+ mock_client .chat = mock_chat
10095
101- # Mock the client holder
10296 mock_client_holder = mocker .Mock ()
10397 mock_client_holder .get_client .return_value = mock_client
10498 mocker .patch (
@@ -109,11 +103,20 @@ def mock_empty_llm_response_fixture(
109103
110104@pytest .fixture (name = "mock_api_connection_error" )
111105def mock_api_connection_error_fixture (mocker : MockerFixture ) -> None :
112- """Mock AsyncLlamaStackClientHolder to raise APIConnectionError."""
113- mock_client_holder = mocker .Mock ()
114- mock_client_holder . get_client . side_effect = APIConnectionError (
115- request = mocker .Mock ()
106+ """Mock chat.completions.create() to raise APIConnectionError."""
107+ mock_completions = mocker .Mock ()
108+ mock_completions . create = mocker . AsyncMock (
109+ side_effect = APIConnectionError ( request = mocker .Mock () )
116110 )
111+
112+ mock_chat = mocker .Mock ()
113+ mock_chat .completions = mock_completions
114+
115+ mock_client = mocker .Mock ()
116+ mock_client .chat = mock_chat
117+
118+ mock_client_holder = mocker .Mock ()
119+ mock_client_holder .get_client .return_value = mock_client
117120 mocker .patch (
118121 "app.endpoints.rlsapi_v1.AsyncLlamaStackClientHolder" ,
119122 return_value = mock_client_holder ,
@@ -212,6 +215,7 @@ async def test_infer_minimal_request(
212215
213216 assert isinstance (response , RlsapiV1InferResponse )
214217 assert response .data .text == "This is a test LLM response."
218+ assert response .data .request_id is not None
215219 assert check_suid (response .data .request_id )
216220
217221
0 commit comments