@@ -180,12 +180,14 @@ async def test_get_sql_response_openai_error(self, mock_get_sql_agent, mock_conf
180180 assert "OpenAI API error" in result
181181
182182 @pytest .mark .asyncio
183+ @patch ("backend.plugins.chat_with_data_plugin.hasattr" , return_value = False )
183184 @patch ("backend.agents.agent_factory.AgentFactory.get_search_agent" )
185+ @patch ("backend.plugins.chat_with_data_plugin.config" )
184186 async def test_get_answers_from_calltranscripts_success (
185- self , mock_get_search_agent
187+ self , mock_config , mock_get_search_agent , mock_hasattr
186188 ):
187189 """Test successful retrieval of answers from call transcripts using AI Search Agent."""
188- # Setup mocks for agent factory
190+ # Setup mocks for agent factory (fallback case when current_app.search_agent is None)
189191 mock_agent = MagicMock ()
190192 mock_agent .id = "test-agent-id"
191193
@@ -195,6 +197,10 @@ async def test_get_answers_from_calltranscripts_success(
195197 "client" : mock_project_client ,
196198 }
197199
200+ # Mock config values
201+ mock_config .AZURE_SEARCH_INDEX = "test-index"
202+ mock_config .AZURE_SEARCH_CONNECTION_NAME = "test-connection"
203+
198204 # Mock project index creation
199205 mock_index = MagicMock ()
200206 mock_index .name = "project-index-test"
@@ -229,7 +235,7 @@ async def test_get_answers_from_calltranscripts_success(
229235 assert "Based on call transcripts" in result
230236 assert "investment options" in result
231237
232- # Verify agent factory was called
238+ # Verify agent factory was called (fallback case)
233239 mock_get_search_agent .assert_called_once ()
234240
235241 # Verify project index was created/updated
@@ -249,9 +255,11 @@ async def test_get_answers_from_calltranscripts_success(
249255 mock_project_client .agents .runs .create_and_process .assert_called_once ()
250256
251257 @pytest .mark .asyncio
258+ @patch ("backend.plugins.chat_with_data_plugin.hasattr" , return_value = False )
252259 @patch ("backend.agents.agent_factory.AgentFactory.get_search_agent" )
260+ @patch ("backend.plugins.chat_with_data_plugin.config" )
253261 async def test_get_answers_from_calltranscripts_no_results (
254- self , mock_get_search_agent
262+ self , mock_config , mock_get_search_agent , mock_hasattr
255263 ):
256264 """Test call transcripts search with no results."""
257265 # Setup mocks for agent factory
@@ -264,6 +272,10 @@ async def test_get_answers_from_calltranscripts_no_results(
264272 "client" : mock_project_client ,
265273 }
266274
275+ # Mock config values
276+ mock_config .AZURE_SEARCH_INDEX = "test-index"
277+ mock_config .AZURE_SEARCH_CONNECTION_NAME = "test-connection"
278+
267279 # Mock project index creation
268280 mock_index = MagicMock ()
269281 mock_index .name = "project-index-test"
@@ -295,9 +307,11 @@ async def test_get_answers_from_calltranscripts_no_results(
295307 assert "No data found for that client." in result
296308
297309 @pytest .mark .asyncio
310+ @patch ("backend.plugins.chat_with_data_plugin.hasattr" , return_value = False )
298311 @patch ("backend.agents.agent_factory.AgentFactory.get_search_agent" )
312+ @patch ("backend.plugins.chat_with_data_plugin.config" )
299313 async def test_get_answers_from_calltranscripts_openai_error (
300- self , mock_get_search_agent
314+ self , mock_config , mock_get_search_agent , mock_hasattr
301315 ):
302316 """Test call transcripts with AI Search processing error."""
303317 # Setup mocks for agent factory
@@ -310,6 +324,10 @@ async def test_get_answers_from_calltranscripts_openai_error(
310324 "client" : mock_project_client ,
311325 }
312326
327+ # Mock config values
328+ mock_config .AZURE_SEARCH_INDEX = "test-index"
329+ mock_config .AZURE_SEARCH_CONNECTION_NAME = "test-connection"
330+
313331 # Mock project index creation
314332 mock_index = MagicMock ()
315333 mock_index .name = "project-index-test"
@@ -336,9 +354,11 @@ async def test_get_answers_from_calltranscripts_openai_error(
336354 assert "Error retrieving data from call transcripts" in result
337355
338356 @pytest .mark .asyncio
357+ @patch ("backend.plugins.chat_with_data_plugin.hasattr" , return_value = False )
339358 @patch ("backend.agents.agent_factory.AgentFactory.get_search_agent" )
359+ @patch ("backend.plugins.chat_with_data_plugin.config" )
340360 async def test_get_answers_from_calltranscripts_failed_run (
341- self , mock_get_search_agent
361+ self , mock_config , mock_get_search_agent , mock_hasattr
342362 ):
343363 """Test call transcripts with failed AI Search run."""
344364 # Setup mocks for agent factory
@@ -351,6 +371,10 @@ async def test_get_answers_from_calltranscripts_failed_run(
351371 "client" : mock_project_client ,
352372 }
353373
374+ # Mock config values
375+ mock_config .AZURE_SEARCH_INDEX = "test-index"
376+ mock_config .AZURE_SEARCH_CONNECTION_NAME = "test-connection"
377+
354378 # Mock project index creation
355379 mock_index = MagicMock ()
356380 mock_index .name = "project-index-test"
@@ -378,9 +402,11 @@ async def test_get_answers_from_calltranscripts_failed_run(
378402 assert "Error retrieving data from call transcripts" in result
379403
380404 @pytest .mark .asyncio
405+ @patch ("backend.plugins.chat_with_data_plugin.hasattr" , return_value = False )
381406 @patch ("backend.agents.agent_factory.AgentFactory.get_search_agent" )
407+ @patch ("backend.plugins.chat_with_data_plugin.config" )
382408 async def test_get_answers_from_calltranscripts_empty_response (
383- self , mock_get_search_agent
409+ self , mock_config , mock_get_search_agent , mock_hasattr
384410 ):
385411 """Test call transcripts with empty response text."""
386412 # Setup mocks for agent factory
@@ -393,6 +419,10 @@ async def test_get_answers_from_calltranscripts_empty_response(
393419 "client" : mock_project_client ,
394420 }
395421
422+ # Mock config values
423+ mock_config .AZURE_SEARCH_INDEX = "test-index"
424+ mock_config .AZURE_SEARCH_CONNECTION_NAME = "test-connection"
425+
396426 # Mock project index creation
397427 mock_index = MagicMock ()
398428 mock_index .name = "project-index-test"
0 commit comments