2525consts_const_mock .NEXENT_POSTGRES_PASSWORD = "test_password"
2626consts_const_mock .POSTGRES_DB = "test_db"
2727consts_const_mock .POSTGRES_PORT = 5432
28+ consts_const_mock .LANGUAGE = {"ZH" : "zh" , "EN" : "en" }
2829consts_mock .const = consts_const_mock
2930sys .modules ['consts' ] = consts_mock
3031sys .modules ['consts.const' ] = consts_const_mock
@@ -253,6 +254,28 @@ def test_summarize_document_with_model_placeholder(self):
253254 assert isinstance (result , str )
254255 assert len (result ) > 0
255256
257+ def test_summarize_document_with_model_success (self ):
258+ """Test document summarization when model config exists and LLM returns value"""
259+ with patch ('backend.utils.document_vector_utils.get_model_by_model_id' ) as mock_get_model , \
260+ patch ('backend.utils.document_vector_utils.call_llm_for_system_prompt' ) as mock_llm :
261+ mock_get_model .return_value = {"id" : 1 }
262+ mock_llm .return_value = "Generated summary\n "
263+
264+ result = summarize_document (
265+ document_content = "LLM content" ,
266+ filename = "doc.pdf" ,
267+ language = "en" ,
268+ max_words = 50 ,
269+ model_id = 1 ,
270+ tenant_id = "tenant"
271+ )
272+
273+ assert result == "Generated summary"
274+ mock_llm .assert_called_once ()
275+ call_args = mock_llm .call_args .kwargs
276+ assert call_args ["model_id" ] == 1
277+ assert call_args ["tenant_id" ] == "tenant"
278+
256279
257280class TestSummarizeCluster :
258281 """Test cluster summarization"""
@@ -277,6 +300,27 @@ def test_summarize_cluster_with_model_placeholder(self):
277300 assert isinstance (result , str )
278301 assert len (result ) > 0
279302
303+ def test_summarize_cluster_with_model_success (self ):
304+ """Test cluster summarization when model config exists and LLM returns value"""
305+ with patch ('backend.utils.document_vector_utils.get_model_by_model_id' ) as mock_get_model , \
306+ patch ('backend.utils.document_vector_utils.call_llm_for_system_prompt' ) as mock_llm :
307+ mock_get_model .return_value = {"id" : 1 }
308+ mock_llm .return_value = "Cluster summary text "
309+
310+ result = summarize_cluster (
311+ document_summaries = ["Doc 1 summary" , "Doc 2 summary" ],
312+ language = "en" ,
313+ max_words = 120 ,
314+ model_id = 1 ,
315+ tenant_id = "tenant"
316+ )
317+
318+ assert result == "Cluster summary text"
319+ mock_llm .assert_called_once ()
320+ call_args = mock_llm .call_args .kwargs
321+ assert call_args ["model_id" ] == 1
322+ assert call_args ["tenant_id" ] == "tenant"
323+
280324
281325class TestSummarizeClustersMapReduce :
282326 """Test map-reduce cluster summarization"""
0 commit comments