1212import os
1313import pytest
1414from unittest .mock import Mock , patch
15- from server . links .analyze import (
15+ from links .analyze import (
1616 generate_analysis ,
1717 run ,
1818 default_options ,
1919 navigate_dict ,
2020 get_analysis_for_type ,
2121)
22- from server . vcon import Vcon
22+ from vcon import Vcon
2323from dotenv import load_dotenv
2424
2525# Load environment variables from .env file for API keys, etc.
3535@pytest .fixture
3636def mock_vcon_redis ():
3737 """Mock the VconRedis class"""
38- with patch ('server. links.analyze.VconRedis' , autospec = True ) as mock :
38+ with patch ('links.analyze.VconRedis' , autospec = True ) as mock :
3939 yield mock
4040
4141
@@ -140,7 +140,7 @@ def test_get_analysis_for_type_not_found(self):
140140class TestGenerateAnalysis :
141141 """Test the generate_analysis function"""
142142
143- @patch ('server. links.analyze.send_ai_usage_data_for_tracking' )
143+ @patch ('links.analyze.send_ai_usage_data_for_tracking' )
144144 def test_generate_analysis_basic (self , mock_send_usage ):
145145 """Test basic analysis generation with mocked client"""
146146 # Setup mock client (injected into generate_analysis)
@@ -170,7 +170,7 @@ def test_generate_analysis_basic(self, mock_send_usage):
170170 assert result == "This is a test analysis."
171171 mock_client .chat .completions .create .assert_called_once ()
172172
173- @patch ('server. links.analyze.send_ai_usage_data_for_tracking' )
173+ @patch ('links.analyze.send_ai_usage_data_for_tracking' )
174174 def test_generate_analysis_with_custom_system_prompt (self , mock_send_usage ):
175175 """Test analysis generation with custom system prompt"""
176176 # Setup mock client (injected into generate_analysis)
@@ -209,7 +209,7 @@ def test_generate_analysis_with_custom_system_prompt(self, mock_send_usage):
209209 assert messages [1 ]['role' ] == 'user'
210210 assert 'Analyze this financial data' in messages [1 ]['content' ]
211211
212- @patch ('server. links.analyze.send_ai_usage_data_for_tracking' )
212+ @patch ('links.analyze.send_ai_usage_data_for_tracking' )
213213 def test_generate_analysis_with_empty_prompt (self , mock_send_usage ):
214214 """Test analysis generation with empty prompt"""
215215 # Setup mock client (injected into generate_analysis)
@@ -243,7 +243,7 @@ def test_generate_analysis_with_empty_prompt(self, mock_send_usage):
243243 messages = call_args [1 ]['messages' ]
244244 assert messages [1 ]['content' ] == "\n \n Test transcript"
245245
246- @patch ('server. links.analyze.send_ai_usage_data_for_tracking' )
246+ @patch ('links.analyze.send_ai_usage_data_for_tracking' )
247247 def test_generate_analysis_with_default_system_prompt (self , mock_send_usage ):
248248 """Test analysis generation uses default system prompt when not provided"""
249249 # Setup mock client (injected into generate_analysis)
@@ -303,10 +303,10 @@ def test_default_options_values(self):
303303class TestRunFunction :
304304 """Test the main run function"""
305305
306- @patch ('server. links.analyze.get_openai_client' )
307- @patch ('server. links.analyze.generate_analysis' )
308- @patch ('server. links.analyze.is_included' , return_value = True )
309- @patch ('server. links.analyze.randomly_execute_with_sampling' , return_value = True )
306+ @patch ('links.analyze.get_openai_client' )
307+ @patch ('links.analyze.generate_analysis' )
308+ @patch ('links.analyze.is_included' , return_value = True )
309+ @patch ('links.analyze.randomly_execute_with_sampling' , return_value = True )
310310 def test_run_basic (self , mock_sampling , mock_is_included , mock_generate_analysis , mock_get_client , mock_redis_with_vcon , sample_vcon ):
311311 """Test the basic run functionality with mocked analysis generation"""
312312 mock_get_client .return_value = Mock ()
@@ -334,10 +334,10 @@ def test_run_basic(self, mock_sampling, mock_is_included, mock_generate_analysis
334334 # Check the vCon has an analysis
335335 sample_vcon .add_analysis .assert_called_once ()
336336
337- @patch ('server. links.analyze.get_openai_client' )
338- @patch ('server. links.analyze.generate_analysis' )
339- @patch ('server. links.analyze.is_included' , return_value = True )
340- @patch ('server. links.analyze.randomly_execute_with_sampling' , return_value = True )
337+ @patch ('links.analyze.get_openai_client' )
338+ @patch ('links.analyze.generate_analysis' )
339+ @patch ('links.analyze.is_included' , return_value = True )
340+ @patch ('links.analyze.randomly_execute_with_sampling' , return_value = True )
341341 def test_run_with_custom_system_prompt (
342342 self , mock_sampling , mock_is_included , mock_generate_analysis , mock_get_client ,
343343 mock_redis_with_vcon , sample_vcon
@@ -369,8 +369,8 @@ def test_run_with_custom_system_prompt(
369369 assert call_args [1 ]['opts' ]['system_prompt' ] == "You are a specialized customer service analyst."
370370 assert call_args [1 ]['opts' ]['prompt' ] == "Analyze this customer interaction."
371371
372- @patch ('server. links.analyze.get_openai_client' )
373- @patch ('server. links.analyze.is_included' , return_value = False )
372+ @patch ('links.analyze.get_openai_client' )
373+ @patch ('links.analyze.is_included' , return_value = False )
374374 def test_run_skipped_due_to_filters (self , mock_is_included , mock_get_client , mock_redis_with_vcon ):
375375 """Test that run is skipped when filters exclude the vCon"""
376376 mock_get_client .return_value = Mock ()
@@ -386,9 +386,9 @@ def test_run_skipped_due_to_filters(self, mock_is_included, mock_get_client, moc
386386 # Should have called get_vcon but then skipped due to filters
387387 mock_redis_with_vcon .get_vcon .assert_called_once_with ("test-uuid" )
388388
389- @patch ('server. links.analyze.get_openai_client' )
390- @patch ('server. links.analyze.is_included' , return_value = True )
391- @patch ('server. links.analyze.randomly_execute_with_sampling' , return_value = False )
389+ @patch ('links.analyze.get_openai_client' )
390+ @patch ('links.analyze.is_included' , return_value = True )
391+ @patch ('links.analyze.randomly_execute_with_sampling' , return_value = False )
392392 def test_run_skipped_due_to_sampling (self , mock_sampling , mock_is_included , mock_get_client , mock_redis_with_vcon ):
393393 """Test that run is skipped when sampling excludes the vCon"""
394394 mock_get_client .return_value = Mock ()
@@ -404,10 +404,10 @@ def test_run_skipped_due_to_sampling(self, mock_sampling, mock_is_included, mock
404404 # Should have called get_vcon but then skipped due to sampling
405405 mock_redis_with_vcon .get_vcon .assert_called_once_with ("test-uuid" )
406406
407- @patch ('server. links.analyze.get_openai_client' )
408- @patch ('server. links.analyze.generate_analysis' )
409- @patch ('server. links.analyze.is_included' , return_value = True )
410- @patch ('server. links.analyze.randomly_execute_with_sampling' , return_value = True )
407+ @patch ('links.analyze.get_openai_client' )
408+ @patch ('links.analyze.generate_analysis' )
409+ @patch ('links.analyze.is_included' , return_value = True )
410+ @patch ('links.analyze.randomly_execute_with_sampling' , return_value = True )
411411 def test_run_with_azure_openai (
412412 self , mock_sampling , mock_is_included , mock_generate_analysis , mock_get_client ,
413413 mock_redis_with_vcon , sample_vcon
@@ -439,10 +439,10 @@ def test_run_missing_credentials(self, mock_redis_with_vcon):
439439 with pytest .raises (ValueError , match = "LITELLM_PROXY_URL|OPENAI_API_KEY|AZURE_OPENAI" ):
440440 run ("test-uuid" , "analyze" , {})
441441
442- @patch ('server. links.analyze.get_openai_client' )
443- @patch ('server. links.analyze.generate_analysis' )
444- @patch ('server. links.analyze.is_included' , return_value = True )
445- @patch ('server. links.analyze.randomly_execute_with_sampling' , return_value = True )
442+ @patch ('links.analyze.get_openai_client' )
443+ @patch ('links.analyze.generate_analysis' )
444+ @patch ('links.analyze.is_included' , return_value = True )
445+ @patch ('links.analyze.randomly_execute_with_sampling' , return_value = True )
446446 def test_run_already_has_analysis (
447447 self , mock_sampling , mock_is_included , mock_generate_analysis , mock_get_client ,
448448 mock_redis_with_vcon , sample_vcon
@@ -467,10 +467,10 @@ def test_run_already_has_analysis(
467467 assert result == "test-uuid"
468468 mock_generate_analysis .assert_not_called ()
469469
470- @patch ('server. links.analyze.get_openai_client' )
471- @patch ('server. links.analyze.generate_analysis' )
472- @patch ('server. links.analyze.is_included' , return_value = True )
473- @patch ('server. links.analyze.randomly_execute_with_sampling' , return_value = True )
470+ @patch ('links.analyze.get_openai_client' )
471+ @patch ('links.analyze.generate_analysis' )
472+ @patch ('links.analyze.is_included' , return_value = True )
473+ @patch ('links.analyze.randomly_execute_with_sampling' , return_value = True )
474474 def test_run_analysis_failure (
475475 self , mock_sampling , mock_is_included , mock_generate_analysis , mock_get_client ,
476476 mock_redis_with_vcon , sample_vcon
0 commit comments