55import pytest
66import sys
77import os
8+ from unittest .mock import patch , MagicMock
89
910# Add backend to path
1011sys .path .insert (0 , os .path .join (os .path .dirname (__file__ ), '..' , '..' , 'backend' ))
@@ -32,16 +33,19 @@ def test_summarize_document_with_llm_params_no_config(self):
3233 content = "This is a test document with some content about machine learning and AI."
3334 filename = "test_doc.txt"
3435
35- # Test with model_id and tenant_id but no actual LLM call (will fallback due to missing config)
36- result = summarize_document (
37- content , filename , language = "zh" , max_words = 50 ,
38- model_id = 1 , tenant_id = "test_tenant"
39- )
40-
41- # Should return placeholder summary when model config not found (fallback behavior)
42- assert "[Document Summary: test_doc.txt]" in result
43- assert "max 50 words" in result
44- assert "Content:" in result
36+ # Mock get_model_by_model_id to return None (no config found) to avoid MinIO initialization
37+ # Patch at the source module since it's imported inside the function
38+ with patch ('database.model_management_db.get_model_by_model_id' , return_value = None ):
39+ # Test with model_id and tenant_id but no actual LLM call (will fallback due to missing config)
40+ result = summarize_document (
41+ content , filename , language = "zh" , max_words = 50 ,
42+ model_id = 1 , tenant_id = "test_tenant"
43+ )
44+
45+ # Should return placeholder summary when model config not found (fallback behavior)
46+ assert "[Document Summary: test_doc.txt]" in result
47+ assert "max 50 words" in result
48+ assert "Content:" in result
4549
4650 def test_summarize_cluster_without_llm (self ):
4751 """Test cluster summarization without LLM (fallback mode)"""
@@ -65,15 +69,18 @@ def test_summarize_cluster_with_llm_params_no_config(self):
6569 "Document 2 discusses neural networks and deep learning."
6670 ]
6771
68- result = summarize_cluster (
69- document_summaries , language = "zh" , max_words = 100 ,
70- model_id = 1 , tenant_id = "test_tenant"
71- )
72-
73- # Should return placeholder summary when model config not found (fallback behavior)
74- assert "[Cluster Summary]" in result
75- assert "max 100 words" in result
76- assert "Based on 2 documents" in result
72+ # Mock get_model_by_model_id to return None (no config found) to avoid MinIO initialization
73+ # Patch at the source module since it's imported inside the function
74+ with patch ('database.model_management_db.get_model_by_model_id' , return_value = None ):
75+ result = summarize_cluster (
76+ document_summaries , language = "zh" , max_words = 100 ,
77+ model_id = 1 , tenant_id = "test_tenant"
78+ )
79+
80+ # Should return placeholder summary when model config not found (fallback behavior)
81+ assert "[Cluster Summary]" in result
82+ assert "max 100 words" in result
83+ assert "Based on 2 documents" in result
7784
7885 def test_summarize_document_english (self ):
7986 """Test document summarization in English"""
0 commit comments