@@ -1171,68 +1171,6 @@ def test_health_check_unhealthy(self):
11711171 self .assertIn ("Health check failed" , str (context .exception ))
11721172
11731173
1174- @patch ('backend.services.elasticsearch_service.calculate_term_weights' )
1175- @patch ('database.model_management_db.get_model_by_model_id' )
1176- def test_summary_index_name (self , mock_get_model_by_model_id , mock_calculate_weights ):
1177- """
1178- Test generating a summary for an index.
1179-
1180- This test verifies that:
1181- 1. Random documents are retrieved for summarization
1182- 2. Term weights are calculated to identify important keywords
1183- 3. The summary generation stream is properly initialized
1184- 4. A StreamingResponse object is returned for streaming the summary tokens
1185- """
1186- # Setup
1187- mock_calculate_weights .return_value = {
1188- "keyword1" : 0.8 , "keyword2" : 0.6 }
1189- mock_get_model_by_model_id .return_value = {
1190- 'api_key' : 'test_api_key' ,
1191- 'base_url' : 'https://api.test.com' ,
1192- 'model_name' : 'test-model' ,
1193- 'model_repo' : 'test-repo'
1194- }
1195-
1196- # Mock get_random_documents
1197- with patch .object (ElasticSearchService , 'get_random_documents' ) as mock_get_docs :
1198- mock_get_docs .return_value = {
1199- "total" : 2 ,
1200- "documents" : [
1201- {"title" : "Doc1" , "filename" : "file1.txt" , "content" : "Content1" },
1202- {"title" : "Doc2" , "filename" : "file2.txt" , "content" : "Content2" }
1203- ]
1204- }
1205-
1206- # Execute
1207- async def run_test ():
1208- result = await self .es_service .summary_index_name (
1209- index_name = "test_index" ,
1210- batch_size = 1000 ,
1211- es_core = self .mock_es_core ,
1212- language = 'en' ,
1213- model_id = 1 ,
1214- tenant_id = "test_tenant"
1215- )
1216-
1217- # Consume part of the stream to trigger the generator function
1218- generator = result .body_iterator
1219- # Get at least one item from the generator to trigger execution
1220- try :
1221- async for item in generator :
1222- break # Just get one item to trigger execution
1223- except StopAsyncIteration :
1224- pass
1225-
1226- return result
1227-
1228- result = asyncio .run (run_test ())
1229-
1230- # Assert
1231- self .assertIsInstance (result , StreamingResponse )
1232- mock_get_docs .assert_called_once ()
1233- mock_calculate_weights .assert_called_once ()
1234- mock_get_model_by_model_id .assert_called_once_with (1 , "test_tenant" )
1235-
12361174 def test_get_random_documents (self ):
12371175 """
12381176 Test retrieving random documents from an index.
0 commit comments