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
321 lines
9.9 KiB
Python
321 lines
9.9 KiB
Python
"""
|
|
Comprehensive tests for preference_manager/storage.py module.
|
|
Tests SQLPreferenceStorage class interface and basic behavior.
|
|
"""
|
|
|
|
import pytest
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
class TestSQLPreferenceStorageInit:
|
|
"""Tests for SQLPreferenceStorage initialization."""
|
|
|
|
def test_requires_session(self):
|
|
"""Test requires a session parameter."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
with pytest.raises(ValueError):
|
|
SQLPreferenceStorage(None)
|
|
|
|
def test_stores_session(self):
|
|
"""Test stores the session in _session attribute."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert storage._session is mock_session
|
|
|
|
def test_session_property_returns_session(self):
|
|
"""Test session property returns the stored session."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert storage.session is mock_session
|
|
|
|
|
|
class TestSQLPreferenceStorageMethods:
|
|
"""Tests for SQLPreferenceStorage method signatures."""
|
|
|
|
def test_has_create_method(self):
|
|
"""Test has create method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "create")
|
|
assert callable(storage.create)
|
|
|
|
def test_has_get_method(self):
|
|
"""Test has get method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "get")
|
|
assert callable(storage.get)
|
|
|
|
def test_has_update_method(self):
|
|
"""Test has update method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "update")
|
|
assert callable(storage.update)
|
|
|
|
def test_has_delete_method(self):
|
|
"""Test has delete method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "delete")
|
|
assert callable(storage.delete)
|
|
|
|
def test_has_list_method(self):
|
|
"""Test has list method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "list")
|
|
assert callable(storage.list)
|
|
|
|
def test_has_get_user_preferences_method(self):
|
|
"""Test has get_user_preferences method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "get_user_preferences")
|
|
assert callable(storage.get_user_preferences)
|
|
|
|
def test_has_upsert_preferences_method(self):
|
|
"""Test has upsert_preferences method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "upsert_preferences")
|
|
assert callable(storage.upsert_preferences)
|
|
|
|
def test_has_add_liked_item_method(self):
|
|
"""Test has add_liked_item method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "add_liked_item")
|
|
assert callable(storage.add_liked_item)
|
|
|
|
def test_has_add_disliked_item_method(self):
|
|
"""Test has add_disliked_item method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "add_disliked_item")
|
|
assert callable(storage.add_disliked_item)
|
|
|
|
def test_has_update_preference_embedding_method(self):
|
|
"""Test has update_preference_embedding method."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
assert hasattr(storage, "update_preference_embedding")
|
|
assert callable(storage.update_preference_embedding)
|
|
|
|
|
|
class TestSQLPreferenceStorageMethodSignatures:
|
|
"""Tests for method parameter signatures."""
|
|
|
|
def test_create_accepts_data_dict(self):
|
|
"""Test create accepts data dictionary."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
import inspect
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
sig = inspect.signature(storage.create)
|
|
params = list(sig.parameters.keys())
|
|
|
|
assert "data" in params
|
|
|
|
def test_get_accepts_id(self):
|
|
"""Test get accepts id parameter."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
import inspect
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
sig = inspect.signature(storage.get)
|
|
params = list(sig.parameters.keys())
|
|
|
|
assert "id" in params
|
|
|
|
def test_update_accepts_id_and_data(self):
|
|
"""Test update accepts id and data parameters."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
import inspect
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
sig = inspect.signature(storage.update)
|
|
params = list(sig.parameters.keys())
|
|
|
|
assert "id" in params
|
|
assert "data" in params
|
|
|
|
def test_delete_accepts_id(self):
|
|
"""Test delete accepts id parameter."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
import inspect
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
sig = inspect.signature(storage.delete)
|
|
params = list(sig.parameters.keys())
|
|
|
|
assert "id" in params
|
|
|
|
def test_list_accepts_filters_limit_offset(self):
|
|
"""Test list accepts filters, limit, and offset parameters."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
import inspect
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
sig = inspect.signature(storage.list)
|
|
params = list(sig.parameters.keys())
|
|
|
|
assert "filters" in params
|
|
assert "limit" in params
|
|
assert "offset" in params
|
|
|
|
def test_get_user_preferences_accepts_user_id(self):
|
|
"""Test get_user_preferences accepts user_id parameter."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
import inspect
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
sig = inspect.signature(storage.get_user_preferences)
|
|
params = list(sig.parameters.keys())
|
|
|
|
assert "user_id" in params
|
|
|
|
def test_add_liked_item_accepts_user_id_item_id(self):
|
|
"""Test add_liked_item accepts user_id and item_id parameters."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
import inspect
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
sig = inspect.signature(storage.add_liked_item)
|
|
params = list(sig.parameters.keys())
|
|
|
|
assert "user_id" in params
|
|
assert "item_id" in params
|
|
|
|
def test_update_preference_embedding_accepts_user_id_embedding(self):
|
|
"""Test update_preference_embedding accepts user_id and embedding."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
import inspect
|
|
|
|
mock_session = MagicMock()
|
|
storage = SQLPreferenceStorage(mock_session)
|
|
|
|
sig = inspect.signature(storage.update_preference_embedding)
|
|
params = list(sig.parameters.keys())
|
|
|
|
assert "user_id" in params
|
|
assert "embedding" in params
|
|
|
|
|
|
class TestSQLPreferenceStorageInheritance:
|
|
"""Tests for class inheritance."""
|
|
|
|
def test_extends_preference_storage(self):
|
|
"""Test SQLPreferenceStorage extends PreferenceStorage."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
from local_deep_research.news.core.storage import PreferenceStorage
|
|
|
|
assert issubclass(SQLPreferenceStorage, PreferenceStorage)
|
|
|
|
|
|
class TestSQLPreferenceStorageImports:
|
|
"""Tests for module imports."""
|
|
|
|
def test_is_class(self):
|
|
"""Test SQLPreferenceStorage is a class."""
|
|
from local_deep_research.news.preference_manager.storage import (
|
|
SQLPreferenceStorage,
|
|
)
|
|
|
|
assert isinstance(SQLPreferenceStorage, type)
|