Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

88 lines
3.2 KiB
Python

"""Tests for storage factory."""
from unittest.mock import patch
import pytest
from local_deep_research.storage.factory import (
get_report_storage,
)
from local_deep_research.storage.database_with_file_backup import (
DatabaseWithFileBackupStorage,
)
from local_deep_research.config.thread_settings import NoSettingsContextError
class TestGetReportStorage:
"""Tests for get_report_storage factory function."""
def test_raises_when_session_is_none(self):
"""Should raise ValueError when session is None."""
with pytest.raises(ValueError, match="Database session is required"):
get_report_storage(session=None)
def test_returns_database_with_file_backup_storage(self, mock_session):
"""Should return DatabaseWithFileBackupStorage instance."""
with patch(
"local_deep_research.storage.factory.get_setting_from_snapshot"
) as mock_get:
mock_get.return_value = False
storage = get_report_storage(session=mock_session)
assert isinstance(storage, DatabaseWithFileBackupStorage)
def test_uses_provided_enable_file_backup_true(self, mock_session):
"""Should use enable_file_backup=True when explicitly provided."""
storage = get_report_storage(
session=mock_session, enable_file_backup=True
)
assert storage.enable_file_storage is True
def test_uses_provided_enable_file_backup_false(self, mock_session):
"""Should use enable_file_backup=False when explicitly provided."""
storage = get_report_storage(
session=mock_session, enable_file_backup=False
)
assert storage.enable_file_storage is False
def test_reads_setting_when_enable_file_backup_is_none(self, mock_session):
"""Should read from settings when enable_file_backup not provided."""
with patch(
"local_deep_research.storage.factory.get_setting_from_snapshot"
) as mock_get:
mock_get.return_value = True
storage = get_report_storage(session=mock_session)
mock_get.assert_called_once_with(
"report.enable_file_backup",
settings_snapshot=None,
)
assert storage.enable_file_storage is True
def test_passes_settings_snapshot_to_get_setting(self, mock_session):
"""Should pass settings_snapshot to get_setting_from_snapshot."""
snapshot = {"report": {"enable_file_backup": True}}
with patch(
"local_deep_research.storage.factory.get_setting_from_snapshot"
) as mock_get:
mock_get.return_value = True
get_report_storage(session=mock_session, settings_snapshot=snapshot)
mock_get.assert_called_once_with(
"report.enable_file_backup",
settings_snapshot=snapshot,
)
def test_defaults_to_false_when_no_settings_context(self, mock_session):
"""Should default to False when NoSettingsContextError raised."""
with patch(
"local_deep_research.storage.factory.get_setting_from_snapshot"
) as mock_get:
mock_get.side_effect = NoSettingsContextError("No context")
storage = get_report_storage(session=mock_session)
assert storage.enable_file_storage is False