Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test: add API endpoint integration tests and binary format tests

LearningCircuit421bcbfc062a
diff --git a/tests/document_loaders/test_upload_integration.py b/tests/document_loaders/test_upload_integration.py
index 5a16cfa851..21ad19a67f 100644
--- a/tests/document_loaders/test_upload_integration.py
+++ b/tests/document_loaders/test_upload_integration.py
@@ -603,3 +603,114 @@ class TestFilePathExtraction:
loader = get_loader_for_path(file_path)
assert loader is None
+
+
+class TestBinaryFileFormats:
+ """Tests for binary file formats (DOCX, XLSX) that require special libraries."""
+
+ def test_docx_file_extraction(self, tmp_path):
+ """Test extracting text from a real .docx file."""
+ try:
+ from docx import Document as DocxDocument
+ except ImportError:
+ pytest.skip("python-docx not installed")
+
+ from local_deep_research.document_loaders import extract_text_from_bytes
+
+ # Create a real DOCX file
+ doc = DocxDocument()
+ doc.add_heading("Test Document Title", 0)
+ doc.add_paragraph("This is a test paragraph in the Word document.")
+ doc.add_paragraph("It contains multiple paragraphs for testing.")
+
+ file_path = tmp_path / "test.docx"
+ doc.save(str(file_path))
+
+ # Read as bytes and extract
+ file_bytes = file_path.read_bytes()
+ extracted = extract_text_from_bytes(file_bytes, ".docx", "test.docx")
+
+ assert extracted is not None
+ assert (
+ "Test Document Title" in extracted or "test paragraph" in extracted
+ )
+
+ def test_xlsx_file_extraction(self, tmp_path):
+ """Test extracting text from a real .xlsx file."""
+ try:
+ from openpyxl import Workbook
+ except ImportError:
+ pytest.skip("openpyxl not installed")
+
+ from local_deep_research.document_loaders import extract_text_from_bytes
+
+ # Create a real XLSX file
+ wb = Workbook()
+ ws = wb.active
+ ws.title = "Test Sheet"
+ ws["A1"] = "Name"
+ ws["B1"] = "Value"
+ ws["A2"] = "Test Item"
+ ws["B2"] = 12345
+ ws["A3"] = "Another Item"
+ ws["B3"] = 67890
+
+ file_path = tmp_path / "test.xlsx"
+ wb.save(str(file_path))
+
+ # Read as bytes and extract
+ file_bytes = file_path.read_bytes()
+ extracted = extract_text_from_bytes(file_bytes, ".xlsx", "test.xlsx")
+
+ assert extracted is not None
+ # Should contain some of the data
+ assert (
+ "Test Item" in extracted
+ or "Name" in extracted
+ or "12345" in extracted
+ )
+
+ def test_docx_from_path(self, tmp_path):
+ """Test loading DOCX file using get_loader_for_path."""
+ try:
+ from docx import Document as DocxDocument
+ except ImportError:
+ pytest.skip("python-docx not installed")
+
+ from local_deep_research.document_loaders import get_loader_for_path
+
+ # Create a real DOCX file
+ doc = DocxDocument()
+ doc.add_paragraph("Content loaded via path API")
+
+ file_path = tmp_path / "path_test.docx"
+ doc.save(str(file_path))
+
+ loader = get_loader_for_path(file_path)
+
+ assert loader is not None
+ docs = loader.load()
+ assert len(docs) > 0
+
+ def test_xlsx_from_path(self, tmp_path):
+ """Test loading XLSX file using get_loader_for_path."""
+ try:
+ from openpyxl import Workbook
+ except ImportError:
+ pytest.skip("openpyxl not installed")
+
+ from local_deep_research.document_loaders import get_loader_for_path
+
+ # Create a real XLSX file
+ wb = Workbook()
+ ws = wb.active
+ ws["A1"] = "Path Test Data"
+
+ file_path = tmp_path / "path_test.xlsx"
+ wb.save(str(file_path))
+
+ loader = get_loader_for_path(file_path)
+
+ assert loader is not None
+ docs = loader.load()
+ assert len(docs) > 0
diff --git a/tests/research_library/routes/test_rag_routes.py b/tests/research_library/routes/test_rag_routes.py
index 6b4ec75a53..34f19c8429 100644
--- a/tests/research_library/routes/test_rag_routes.py
+++ b/tests/research_library/routes/test_rag_routes.py
@@ -1194,6 +1194,128 @@ class TestUploadWithDocumentLoaders:
assert error["error"] == "Unsupported format: .unsupported"
+class TestSupportedFormatsAPIEndpoint:
+ """Integration tests for the /api/config/supported-formats endpoint."""
+
+ @pytest.fixture
+ def app(self):
+ """Create a test Flask app with the rag blueprint."""
+ from flask import Flask
+ from local_deep_research.research_library.routes.rag_routes import (
+ rag_bp,
+ )
+
+ app = Flask(__name__)
+ app.secret_key = "test-secret-key"
+ app.register_blueprint(rag_bp)
+ return app
+
+ @pytest.fixture
+ def client(self, app):
+ """Create a test client."""
+ return app.test_client()
+
+ def test_endpoint_requires_authentication(self, client):
+ """Test that endpoint requires authentication."""
+ response = client.get("/library/api/config/supported-formats")
+ # Should redirect to login (302) or fail (500 if auth blueprint missing)
+ assert response.status_code in [302, 401, 500]
+
+ def test_endpoint_returns_json_when_authenticated(self, client, app):
+ """Test endpoint returns proper JSON when authenticated."""
+ with patch(
+ "local_deep_research.web.auth.decorators.db_manager"
+ ) as mock_db_manager:
+ # Mock the database connection check
+ mock_db_manager.connections = {"testuser": Mock()}
+
+ with client.session_transaction() as sess:
+ sess["username"] = "testuser"
+
+ response = client.get("/library/api/config/supported-formats")
+
+ assert response.status_code == 200
+ data = response.get_json()
+
+ # Verify response structure
+ assert "extensions" in data
+ assert "accept_string" in data
+ assert "count" in data
+
+ # Verify extensions is a list
+ assert isinstance(data["extensions"], list)
+ assert len(data["extensions"]) > 0
+
+ # Verify count matches
+ assert data["count"] == len(data["extensions"])
+
+ # Verify accept_string is comma-separated
+ assert "," in data["accept_string"]
+
+ def test_endpoint_returns_sorted_extensions(self, client, app):
+ """Test that extensions are returned in sorted order."""
+ with patch(
+ "local_deep_research.web.auth.decorators.db_manager"
+ ) as mock_db_manager:
+ mock_db_manager.connections = {"testuser": Mock()}
+
+ with client.session_transaction() as sess:
+ sess["username"] = "testuser"
+
+ response = client.get("/library/api/config/supported-formats")
+
+ assert response.status_code == 200
+ data = response.get_json()
+
+ extensions = data["extensions"]
+ assert extensions == sorted(extensions)
+
+ def test_endpoint_includes_common_formats(self, client, app):
+ """Test that common formats are included in response."""
+ with patch(
+ "local_deep_research.web.auth.decorators.db_manager"
+ ) as mock_db_manager:
+ mock_db_manager.connections = {"testuser": Mock()}
+
+ with client.session_transaction() as sess:
+ sess["username"] = "testuser"
+
+ response = client.get("/library/api/config/supported-formats")
+
+ assert response.status_code == 200
+ data = response.get_json()
+
+ extensions = data["extensions"]
+
+ # Check common formats
+ assert ".pdf" in extensions
+ assert ".txt" in extensions
+ assert ".json" in extensions
+ assert ".yaml" in extensions
+ assert ".csv" in extensions
+ assert ".html" in extensions
+ assert ".docx" in extensions
+
+ def test_accept_string_matches_extensions(self, client, app):
+ """Test that accept_string contains all extensions."""
+ with patch(
+ "local_deep_research.web.auth.decorators.db_manager"
+ ) as mock_db_manager:
+ mock_db_manager.connections = {"testuser": Mock()}
+
+ with client.session_transaction() as sess:
+ sess["username"] = "testuser"
+
+ response = client.get("/library/api/config/supported-formats")
+
+ assert response.status_code == 200
+ data = response.get_json()
+
+ # All extensions should be in accept_string
+ for ext in data["extensions"]:
+ assert ext in data["accept_string"]
+
+
# ============= Extended Tests for Phase 3.2 Coverage =============