Files
local-deep-research/tests/database/test_sqlcipher_missing.py
LearningCircuit d9bc003094 fix: resolve test failures and fix import paths in test suite
- Bulk fix import paths from src.local_deep_research to local_deep_research
  across 190+ test files
- Fix test_settings_routes.py: update validate_setting tests to use proper
  Setting objects instead of incorrect parameter signature
- Fix test_research_service.py: remove tests for non-existent functions,
  correct mimetype assertions for latex export
- Fix test_app_factory.py: use truly public IP (8.8.8.8) instead of
  TEST-NET reserved range for IP validation test
- Fix test_api_functions.py: correct patch paths for get_user_db_session,
  has_request_context, and get_settings_manager
- Fix test_news_api.py: correct patch paths for database session

Test results: 8592 passing, 175 failing (down from 286), 115 skipped
Remaining failures are test isolation issues that pass individually.
2026-01-21 20:50:48 +01:00

109 lines
3.7 KiB
Python

"""
Tests for SQLCipher missing scenario.
Verifies that users get helpful error messages when SQLCipher is not installed
and that the LDR_ALLOW_UNENCRYPTED workaround works.
"""
import os
import pytest
from unittest.mock import patch
from tests.test_utils import add_src_to_path
add_src_to_path()
class TestSQLCipherMissing:
"""Test behavior when SQLCipher is not available."""
def test_error_message_mentions_sqlcipher(self):
"""Error message should mention SQLCipher so users know what's missing."""
from local_deep_research.database.encrypted_db import (
DatabaseManager,
)
old_value = os.environ.pop("LDR_ALLOW_UNENCRYPTED", None)
try:
with patch(
"local_deep_research.database.encrypted_db.get_sqlcipher_module"
) as mock_get:
mock_get.side_effect = ImportError(
"No module named 'sqlcipher3'"
)
with pytest.raises(RuntimeError) as exc_info:
DatabaseManager()
error_msg = str(exc_info.value)
assert "SQLCipher" in error_msg, (
f"Error should mention SQLCipher. Got: {error_msg}"
)
finally:
if old_value is not None:
os.environ["LDR_ALLOW_UNENCRYPTED"] = old_value
def test_error_message_mentions_workaround(self):
"""Error message should mention LDR_ALLOW_UNENCRYPTED workaround."""
from local_deep_research.database.encrypted_db import (
DatabaseManager,
)
old_value = os.environ.pop("LDR_ALLOW_UNENCRYPTED", None)
try:
with patch(
"local_deep_research.database.encrypted_db.get_sqlcipher_module"
) as mock_get:
mock_get.side_effect = ImportError(
"No module named 'sqlcipher3'"
)
with pytest.raises(RuntimeError) as exc_info:
DatabaseManager()
error_msg = str(exc_info.value)
assert "LDR_ALLOW_UNENCRYPTED" in error_msg, (
f"Error should mention workaround. Got: {error_msg}"
)
finally:
if old_value is not None:
os.environ["LDR_ALLOW_UNENCRYPTED"] = old_value
def test_workaround_allows_startup_without_encryption(self):
"""LDR_ALLOW_UNENCRYPTED=true should allow startup without SQLCipher."""
from local_deep_research.database.encrypted_db import (
DatabaseManager,
)
old_value = os.environ.get("LDR_ALLOW_UNENCRYPTED")
os.environ["LDR_ALLOW_UNENCRYPTED"] = "true"
try:
with patch(
"local_deep_research.database.encrypted_db.get_sqlcipher_module"
) as mock_get:
mock_get.side_effect = ImportError(
"No module named 'sqlcipher3'"
)
# Should NOT raise
manager = DatabaseManager()
assert manager.has_encryption is False, (
"With workaround and no SQLCipher, has_encryption should be False"
)
finally:
if old_value is not None:
os.environ["LDR_ALLOW_UNENCRYPTED"] = old_value
else:
os.environ.pop("LDR_ALLOW_UNENCRYPTED", None)
def test_db_manager_has_encryption_is_boolean(self):
"""db_manager.has_encryption should be a boolean."""
from local_deep_research.database.encrypted_db import db_manager
assert isinstance(db_manager.has_encryption, bool), (
f"has_encryption should be bool, got {type(db_manager.has_encryption)}"
)