Skip to content

Commit b6485e8

Browse files
committed
Added new unit tests
1 parent 1db7738 commit b6485e8

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

tests/unit/app/endpoints/test_query.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,68 @@ def test_validate_attachments_metadata_invalid_content_type():
384384
)
385385

386386

387+
@pytest.mark.asyncio
388+
async def test_retrieve_response_no_returned_message(prepare_agent_mocks, mocker):
389+
"""Test the retrieve_response function."""
390+
mock_client, mock_agent = prepare_agent_mocks
391+
mock_agent.create_turn.return_value.output_message = None
392+
mock_client.shields.list.return_value = []
393+
mock_vector_db = mocker.Mock()
394+
mock_vector_db.identifier = "VectorDB-1"
395+
mock_client.vector_dbs.list.return_value = [mock_vector_db]
396+
397+
# Mock configuration with empty MCP servers
398+
mock_config = mocker.Mock()
399+
mock_config.mcp_servers = []
400+
mocker.patch("app.endpoints.query.configuration", mock_config)
401+
mocker.patch(
402+
"app.endpoints.query.get_agent",
403+
return_value=(mock_agent, "fake_conversation_id", "fake_session_id"),
404+
)
405+
406+
query_request = QueryRequest(query="What is OpenStack?")
407+
model_id = "fake_model_id"
408+
access_token = "test_token"
409+
410+
response, _ = await retrieve_response(
411+
mock_client, model_id, query_request, access_token
412+
)
413+
414+
# fallback mechanism: check that the response is empty
415+
assert response == ""
416+
417+
418+
@pytest.mark.asyncio
419+
async def test_retrieve_response_message_without_content(prepare_agent_mocks, mocker):
420+
"""Test the retrieve_response function."""
421+
mock_client, mock_agent = prepare_agent_mocks
422+
mock_agent.create_turn.return_value.output_message.content = None
423+
mock_client.shields.list.return_value = []
424+
mock_vector_db = mocker.Mock()
425+
mock_vector_db.identifier = "VectorDB-1"
426+
mock_client.vector_dbs.list.return_value = [mock_vector_db]
427+
428+
# Mock configuration with empty MCP servers
429+
mock_config = mocker.Mock()
430+
mock_config.mcp_servers = []
431+
mocker.patch("app.endpoints.query.configuration", mock_config)
432+
mocker.patch(
433+
"app.endpoints.query.get_agent",
434+
return_value=(mock_agent, "fake_conversation_id", "fake_session_id"),
435+
)
436+
437+
query_request = QueryRequest(query="What is OpenStack?")
438+
model_id = "fake_model_id"
439+
access_token = "test_token"
440+
441+
response, _ = await retrieve_response(
442+
mock_client, model_id, query_request, access_token
443+
)
444+
445+
# fallback mechanism: check that the response is empty
446+
assert response == ""
447+
448+
387449
@pytest.mark.asyncio
388450
async def test_retrieve_response_vector_db_available(prepare_agent_mocks, mocker):
389451
"""Test the retrieve_response function."""

0 commit comments

Comments
 (0)