@@ -545,85 +545,6 @@ async def mock_generator(*args, **kwargs):
545545 assert response is not None
546546
547547
548- @pytest .mark .asyncio
549- async def test_process_image_file (mock_files ):
550- # Import directly in the test to use the already established mocks
551- from backend .services .file_management_service import process_image_file
552-
553- with patch ("backend.services.file_management_service.convert_image_to_text" ) as mock_convert :
554- # Configure mock
555- mock_convert .return_value = "Extracted text from image"
556-
557- # Test the function
558- result = await process_image_file (
559- query = "Test query" ,
560- filename = "test.jpg" ,
561- file_content = mock_files ["mock_image_content" ],
562- tenant_id = "tenant123"
563- )
564-
565- # Assertions
566- assert "Image file test.jpg content" in result
567- assert "Extracted text from image" in result
568-
569-
570- @pytest .mark .asyncio
571- async def test_process_text_file (mock_files ):
572- # Import directly in the test to use the already established mocks
573- from backend .services .file_management_service import process_text_file
574-
575- # Mock multiple functions to ensure complete coverage of all call paths
576- with patch ('backend.utils.config_utils.get_model_name_from_config' , return_value = "test-model" ), \
577- patch ('backend.utils.attachment_utils.get_model_name_from_config' , return_value = "test-model" ), \
578- patch ('backend.utils.attachment_utils.convert_long_text_to_text' , return_value = "Processed text content" ), \
579- patch ('backend.services.file_management_service.convert_long_text_to_text' , return_value = "Processed text content" ):
580-
581- with patch ('httpx.AsyncClient' ) as mock_client :
582- # Setup mock response for httpx client
583- mock_response = MagicMock ()
584- mock_response .status_code = 200
585- mock_response .json .return_value = {
586- "text" : "Extracted raw text from file" }
587-
588- mock_client_instance = MagicMock ()
589- mock_client_instance .post .return_value = asyncio .Future ()
590- mock_client_instance .post .return_value .set_result (mock_response )
591- mock_client .return_value .__aenter__ .return_value = mock_client_instance
592-
593- # Test the function
594- result , truncation_percentage = await process_text_file (
595- query = "Test query" ,
596- filename = "test.txt" ,
597- file_content = mock_files ["mock_file_content" ],
598- tenant_id = "tenant123" ,
599- language = "en"
600- )
601-
602- # Assertions
603- assert "File test.txt content" in result
604- assert truncation_percentage is None
605-
606-
607- def test_get_file_description (mock_files ):
608- # Import directly in the test to use the already established mocks
609- from backend .services .file_management_service import get_file_description
610-
611- # Create mock UploadFile objects
612- text_file = MagicMock ()
613- text_file .filename = "document.txt"
614-
615- image_file = MagicMock ()
616- image_file .filename = "photo.jpg"
617-
618- # Test the function
619- result = get_file_description ([text_file , image_file ])
620-
621- # Assertions
622- assert "User provided some reference files" in result
623- assert "Image file photo.jpg" in result
624- assert "File document.txt" in result
625-
626-
627548def test_options_route ():
628549 # Create test client
629550 with TestClient (app ) as client :
0 commit comments